Release Drafter / auto_label (push) Skipped
Release Drafter / draft_release (push) Canceled after 0s
CodeQL / Analyze (javascript-typescript) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
Backend Lint and Test / tests (sqlite) (push) Canceled after 0s
Backend Lint and Test / tests (postgres) (push) Canceled after 0s
Docker Nightly Production / Backend Server Tests (push) Canceled after 0s
Frontend Lint and Test / lint (push) Canceled after 0s
Docker Nightly Production / Frontend Tests (push) Canceled after 0s
Build Package / Build frontend and wheel (push) Canceled after 0s
Docker Nightly Production / Build Package (push) Canceled after 0s
Docker Nightly Production / Build E2E Image Cache (push) Canceled after 0s
Docker Nightly Production / Build Tagged Release (push) Canceled after 0s
Docker Nightly Production / Notify Discord (push) Canceled after 0s
95 lines
2.9 KiB
Vue
95 lines
2.9 KiB
Vue
<template>
|
|
<v-number-input
|
|
v-if="isEditMode"
|
|
:model-value="inputMinutes"
|
|
class="step-duration"
|
|
:min="0"
|
|
:max="35791394"
|
|
:precision="0"
|
|
:hint="modelValue && modelValue % 60 ? $t('recipe.step-duration-saved', { duration: formattedDuration }) : undefined"
|
|
persistent-hint
|
|
:label="$t('recipe.step-duration-minutes')"
|
|
:placeholder="$t('recipe.step-duration-placeholder')"
|
|
density="compact"
|
|
inset
|
|
hide-details="auto"
|
|
@update:model-value="updateDuration"
|
|
@keypress="(e: KeyboardEvent) => e.key === '-' && e.preventDefault()"
|
|
@click.stop
|
|
/>
|
|
<v-number-input
|
|
v-if="isEditMode"
|
|
:model-value="modelValue ?? null"
|
|
class="step-duration"
|
|
:min="0"
|
|
:max="2147483647"
|
|
:step="0.001"
|
|
:precision="3"
|
|
:label="$t('recipe.step-duration-seconds')"
|
|
density="compact"
|
|
inset
|
|
clearable
|
|
hide-details="auto"
|
|
@update:model-value="emit('update:modelValue', $event || null)"
|
|
@keypress="(e: KeyboardEvent) => e.key === '-' && e.preventDefault()"
|
|
@click.stop
|
|
/>
|
|
<span v-else-if="modelValue" class="text-body-2">
|
|
{{ formattedDuration }}
|
|
</span>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { computed, ref, watch } from "vue";
|
|
import { useI18n } from "vue-i18n";
|
|
|
|
const props = defineProps<{
|
|
modelValue?: number | null;
|
|
isEditMode: boolean;
|
|
}>();
|
|
const emit = defineEmits<{ "update:modelValue": [value: number | null] }>();
|
|
const { t } = useI18n();
|
|
// Display whole minutes only; keep imported seconds untouched until the minutes change.
|
|
// The hint exposes any remainder before the user deliberately replaces it.
|
|
const inputMinutes = ref<number | null>(null);
|
|
|
|
function toSeconds(minutes: number | null) {
|
|
return (minutes ?? 0) * 60 || null;
|
|
}
|
|
|
|
watch(
|
|
() => props.modelValue,
|
|
(value) => {
|
|
// Only re-sync outside changes, so stepping down to 0 (saved as no duration) keeps showing 0
|
|
if ((value ?? null) === toSeconds(inputMinutes.value)) return;
|
|
inputMinutes.value = value ? Math.floor(value / 60) : null;
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
|
|
function updateDuration(value: number | null) {
|
|
if (value === inputMinutes.value) return;
|
|
inputMinutes.value = value;
|
|
emit("update:modelValue", toSeconds(value));
|
|
}
|
|
|
|
const formattedDuration = computed(() => {
|
|
const seconds = props.modelValue ?? 0;
|
|
const hours = Math.floor(seconds / 3600);
|
|
const minutes = Math.floor((seconds % 3600) / 60);
|
|
const remainder = (Math.round(seconds * 1000) % 60000) / 1000;
|
|
return [
|
|
hours ? t("recipe.step-duration-value-hours", { hours }) : "",
|
|
minutes ? t("recipe.step-duration-value-minutes", { minutes }) : "",
|
|
remainder ? t("recipe.step-duration-value-seconds", { seconds: remainder }) : "",
|
|
].filter(Boolean).join(" ");
|
|
});
|
|
</script>
|
|
|
|
<style scoped>
|
|
/* Override the instruction title's larger input text only for this field. */
|
|
.step-duration.v-text-field :deep(input) {
|
|
font-size: 1rem;
|
|
}
|
|
</style>
|