Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | 223x 1x 1x 5x 5x 5x 5x 5x 5x 1x 5x 5x 5x 1x 37x 155x 155x 155x 4x 3x 2x 155x 155x 155x 159x 159x 135x 135x 24x 24x 24x 24x 48x 48x 24x 9x 8x 8x 8x 16x 16x 8x 9x 155x 48x 159x | <template>
<BaseFormSidebar
:is-open="isOpen"
:dirty="dirty"
storage-key="workflow-state-panel"
:title="t('workflow.editState')"
panel-width="1120px"
:submit-label="t('common.save')"
submit-icon="fa-solid fa-check"
@close="$emit('close')"
@submit="handleSubmit"
>
<div v-if="form">
<!-- Language selector -->
<EditingLanguageSelector v-model="editingLang" :languages="enabledLanguages" class="mb-4" />
<!-- Label -->
<div class="mb-3">
<label class="form-label fw-semibold">{{ t('workflow.label') }}</label>
<input
v-model="form.labels[editingLang]"
type="text"
class="form-control form-control-sm"
:placeholder="t('workflow.label')"
name="state-label"
/>
</div>
<!-- Description -->
<div class="mb-3">
<label class="form-label fw-semibold">{{ t('workflow.description') }}</label>
<input
v-model="form.descriptions[editingLang]"
type="text"
class="form-control form-control-sm"
:placeholder="t('workflow.description')"
name="state-description"
/>
</div>
<!-- Form selector -->
<div v-if="forms && forms.length > 0" class="mb-3">
<label class="form-label fw-semibold">{{ t('workflow.form') }}</label>
<select v-model="form.formId" class="form-select form-select-sm" name="state-form">
<option value="">{{ t('workflow.noForm') }}</option>
<option v-for="f in forms" :key="f.id" :value="f.id">
{{
f.name[currentLanguage] || f.name[defaultLanguage] || Object.values(f.name)[0] || f.id
}}
</option>
</select>
<div class="form-text">{{ t('workflow.formHelp') }}</div>
</div>
<hr />
<!-- Timer (UC-WORKFLOW-009.1): wakes the items in this state up -->
<div class="mb-3">
<label class="form-label fw-semibold">{{ t('workflow.timer.label') }}</label>
<StateTimerEditor v-model="form.timer" :fields="fields" :translate="translate" />
</div>
</div>
</BaseFormSidebar>
</template>
<script setup lang="ts">
// @implements UC-I18N-007.1, UC-I18N-010.1, UC-WORKFLOW-009.1
import { useUnsavedChanges } from '@/composables/useUnsavedChanges'
import { ref, watch } from 'vue'
import BaseFormSidebar from './BaseFormSidebar.vue'
import { useUILanguage } from '@/composables/useUILanguage'
import EditingLanguageSelector from './EditingLanguageSelector.vue'
import StateTimerEditor from './StateTimerEditor.vue'
import type { WorkflowState, WorkflowTimer, FormDefinition } from '@/schemas/entity-schema'
import type { ConditionField } from '@/utils/workflowConditions'
const { t, uiLanguage } = useUILanguage()
// Active editing language (defaults to user's preferred UI language)
const editingLang = ref<string>(uiLanguage.value)
interface Props {
isOpen: boolean
state?: WorkflowState | null
enabledLanguages?: string[]
defaultLanguage?: string
currentLanguage?: string
forms?: FormDefinition[]
/** the entity's fields: its date fields can be the timer's date */
fields?: ConditionField[]
}
interface Emits {
(e: 'close'): void
(e: 'save', state: WorkflowState): void
}
const props = withDefaults(defineProps<Props>(), {
state: null,
enabledLanguages: () => ['en', 'fr'],
defaultLanguage: 'en',
currentLanguage: 'en',
forms: () => [],
fields: () => []
})
function translate(value: string | Record<string, string> | undefined): string {
if (!value) return ''
if (typeof value === 'string') return value
return value[uiLanguage.value] || value[props.defaultLanguage] || Object.values(value)[0] || ''
}
const emit = defineEmits<Emits>()
// ---- local form model ----
interface StateForm {
id: string
labels: Record<string, string>
descriptions: Record<string, string>
formId: string
timer: WorkflowTimer | undefined
}
const form = ref<StateForm | null>(null)
watch(
() => [props.state, props.isOpen] as const,
([state, isOpen]) => {
if (!isOpen || !state) {
form.value = null
return
}
// Reset editing language to user's preferred UI language when panel opens
editingLang.value = uiLanguage.value
const labels: Record<string, string> = {}
const descriptions: Record<string, string> = {}
for (const lang of props.enabledLanguages) {
labels[lang] = typeof state.label === 'string' ? state.label : (state.label[lang] ?? '')
descriptions[lang] = state.description?.[lang] ?? ''
}
form.value = {
id: state.id,
labels,
descriptions,
formId: state.formId ?? '',
timer: state.timer
}
},
{ immediate: true }
)
function handleSubmit() {
if (!form.value || !props.state) return
const label: Record<string, string> = {}
const description: Record<string, string> = {}
for (const lang of props.enabledLanguages) {
Eif (form.value.labels[lang]) label[lang] = form.value.labels[lang]
if (form.value.descriptions[lang]) description[lang] = form.value.descriptions[lang]
}
const updated: WorkflowState = {
...props.state,
label,
description: Object.keys(description).length ? description : undefined,
// Legacy placeholder list, never used: actions live on transitions
actions: undefined,
formId: form.value.formId || undefined,
timer: form.value.timer
}
emit('save', updated)
}
// Closing, or leaving the page, asks before dropping the changes (BaseFormSidebar)
const { dirty } = useUnsavedChanges(
() => form.value,
() => props.isOpen && props.state
)
</script>
|