@quazardous/qdadm 2.46.0 → 2.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/styles/qdadm.css +1 -1
  2. package/package.json +1 -1
  3. package/src/components/SeverityTag.vue +15 -1
  4. package/src/components/display/QdPending.vue +58 -0
  5. package/src/components/display/QdPendingZone.vue +104 -0
  6. package/src/components/index.ts +5 -0
  7. package/src/components/lists/ListPage.vue +33 -4
  8. package/src/components/show/ShowDisplay.vue +13 -2
  9. package/src/components/show/ShowPage.vue +6 -6
  10. package/src/components/tasks/TaskDialog.vue +13 -157
  11. package/src/components/tasks/TaskHost.vue +28 -2
  12. package/src/components/tasks/TaskRunStatus.vue +63 -0
  13. package/src/components/tasks/TaskRunView.vue +197 -0
  14. package/src/components/tasks/TaskSequenceDialog.vue +157 -0
  15. package/src/components/tasks/TaskTray.vue +33 -13
  16. package/src/composables/index.ts +6 -0
  17. package/src/composables/useAsyncRead.ts +109 -0
  18. package/src/composables/useEntityItemFormPage.ts +13 -6
  19. package/src/composables/useEntityItemFormPage.types.ts +4 -1
  20. package/src/composables/useEntityItemShowPage.ts +18 -7
  21. package/src/composables/useFieldManager.ts +11 -2
  22. package/src/composables/useListPage.filters.ts +21 -1
  23. package/src/composables/useListPage.ts +68 -9
  24. package/src/composables/useListPage.types.ts +4 -1
  25. package/src/composables/useNavContext.ts +5 -4
  26. package/src/entity/EntityManager.ts +17 -0
  27. package/src/entity/EntityManager.types.ts +2 -0
  28. package/src/entity/storage/MockApiStorage.ts +31 -7
  29. package/src/i18n/defaults/core.en.generated.ts +32 -0
  30. package/src/i18n/defaults/core.en.yml +32 -0
  31. package/src/i18n/defaults/core.fr.generated.ts +32 -0
  32. package/src/i18n/defaults/core.fr.yml +32 -0
  33. package/src/i18n/optionLabels.ts +35 -0
  34. package/src/i18n/types.ts +5 -0
  35. package/src/index.ts +11 -0
  36. package/src/kernel/Kernel.i18n.ts +36 -3
  37. package/src/kernel/Kernel.registries.ts +11 -7
  38. package/src/kernel/Kernel.ts +2 -0
  39. package/src/kernel/KernelContext.permissions.ts +11 -0
  40. package/src/kernel/KernelContext.ts +6 -0
  41. package/src/kernel/KernelContext.types.ts +2 -0
  42. package/src/orchestrator/Orchestrator.ts +3 -0
  43. package/src/security/PersistableRolesProvider.ts +61 -3
  44. package/src/security/StaticRolesProvider.ts +6 -0
  45. package/src/styles/_pending.scss +125 -0
  46. package/src/styles/_tasks.scss +126 -0
  47. package/src/styles/index.scss +1 -0
  48. package/src/tasks/taskStore.ts +449 -14
  49. package/src/tasks/taskUi.ts +6 -0
  50. package/src/tasks/useTaskNotifications.ts +6 -2
  51. package/src/tasks/useTaskRunner.ts +24 -0
@@ -22,10 +22,13 @@ import ActionButtons from './ActionButtons.vue'
22
22
  import DataTable from 'primevue/datatable'
23
23
  import Column from 'primevue/column'
24
24
  import QdButton from '../base/QdButton.vue'
25
+ import SeverityTag from '../SeverityTag.vue'
26
+ import { useI18n } from '../../i18n/useI18n'
27
+ import ShowDisplay from '../show/ShowDisplay.vue'
25
28
  import Select from 'primevue/select'
26
29
  import AutoComplete from 'primevue/autocomplete'
27
30
  import SplitButton from 'primevue/splitbutton'
28
- import type { FilterConfig, CardConfig, ResolvedAction, ResolvedHeaderAction } from '../../composables/useListPage'
31
+ import type { FilterConfig, CardConfig, ResolvedAction, ResolvedHeaderAction, ColumnConfig } from '../../composables/useListPage'
29
32
 
30
33
  /**
31
34
  * Header action state for label function (matches useListPage)
@@ -86,6 +89,8 @@ const props = defineProps({
86
89
 
87
90
  // Table data
88
91
  items: { type: Array as PropType<unknown[]>, required: true },
92
+ /** Declared columns, shown when the page gives no #columns slot */
93
+ columns: { type: Array as PropType<Array<ColumnConfig & { display?: Record<string, unknown> & { severity?: boolean; entity?: string } }>>, default: () => [] },
89
94
  /**
90
95
  * Extra props forwarded verbatim to the underlying PrimeVue DataTable
91
96
  * (#1217) — e.g. { nullSortOrder: -1 } to sort null values last. Bound
@@ -133,6 +138,18 @@ const props = defineProps({
133
138
  hasRowTapAction: { type: Boolean, default: false }
134
139
  })
135
140
 
141
+ const { tOr } = useI18n()
142
+
143
+ // `{ name, label }` is read as `{ field, header }`; a column without either is skipped
144
+ const declaredColumns = computed(() =>
145
+ props.columns
146
+ .map((c) => {
147
+ const loose = c as typeof c & { name?: string; label?: string }
148
+ return { ...c, field: c.field ?? loose.name, header: c.header ?? loose.label }
149
+ })
150
+ .filter((c) => typeof c.field === 'string' && c.field !== '')
151
+ )
152
+
136
153
  function resolveLabel(label: LabelType): string {
137
154
  if (typeof label === 'function') {
138
155
  const state: HeaderActionState = {
@@ -458,11 +475,23 @@ function getFilterClass(filter: FilterConfig): Record<string, boolean> {
458
475
  removableSort
459
476
  v-bind="tableProps"
460
477
  >
461
- <!-- Columns from slot -->
462
- <slot name="columns" ></slot>
478
+ <!-- The page's own columns, else the declared ones (addColumn / generateColumns, #4685) -->
479
+ <slot name="columns">
480
+ <Column v-for="col in declaredColumns" :key="col.field" :field="col.field" :header="col.header"
481
+ :sortable="!!col.sortable" :style="col.style">
482
+ <template #body="{ data }">
483
+ <slot :name="`column-${col.field}`" :data="data" :value="(data as Record<string, unknown>)[col.field]">
484
+ <template v-if="col.body">{{ col.body(data) }}</template>
485
+ <SeverityTag v-else-if="col.display?.severity" :entity="col.display.entity" :field="col.field"
486
+ :value="((data as Record<string, unknown>)[col.field] as never)" />
487
+ <ShowDisplay v-else :field="((col.display ?? { name: col.field }) as never)" :value="((data as Record<string, unknown>)[col.field] as never)" />
488
+ </slot>
489
+ </template>
490
+ </Column>
491
+ </slot>
463
492
 
464
493
  <!-- Actions column -->
465
- <Column v-if="getActions" header="Actions" :style="{ width: actionsWidth }">
494
+ <Column v-if="getActions" :header="tOr('core.table.actions', 'Actions')" :style="{ width: actionsWidth }">
466
495
  <template #body="{ data }">
467
496
  <ActionButtons :actions="getActions(data)" />
468
497
  </template>
@@ -31,6 +31,7 @@ import { RouterLink, type RouteLocationRaw } from 'vue-router'
31
31
  import Tag from 'primevue/tag'
32
32
  import { formatDate, formatNumber, formatCurrency, formatBytes, getEmptyPlaceholder } from '../../utils/formatters'
33
33
  import { useFormatBytes } from '../../composables/useFormatBytes'
34
+ import { useI18n } from '../../i18n/useI18n'
34
35
 
35
36
  type DisplayType =
36
37
  | 'text'
@@ -74,6 +75,8 @@ interface FieldConfig {
74
75
  referenceLabel?: string | ((value: unknown, option?: unknown) => string)
75
76
  // Select options (for label lookup)
76
77
  options?: SelectOption[]
78
+ // The entity, when the options translate here (a list cell, #4686)
79
+ entity?: string
77
80
  optionLabel?: string
78
81
  optionValue?: string
79
82
  // Badge options
@@ -140,10 +143,12 @@ const bytesValue = computed(() => {
140
143
  return props.field.locale ? formatBytes(num, props.field.locale) : appBytes(num)
141
144
  })
142
145
 
143
- // Format boolean value
146
+ const { tOr, i18n } = useI18n()
147
+
148
+ // Format boolean value: the catalogue's yes and no (#4686), or the field's own
144
149
  const booleanValue = computed(() => {
145
150
  if (isEmpty.value) return emptyText.value
146
- const labels = props.field.booleanLabels || { true: 'Yes', false: 'No' }
151
+ const labels = props.field.booleanLabels || { true: tOr('core.values.yes', 'Yes'), false: tOr('core.values.no', 'No') }
147
152
  return props.value ? labels.true : labels.false
148
153
  })
149
154
 
@@ -183,6 +188,12 @@ const selectValue = computed(() => {
183
188
  const optionValue = props.field.optionValue || 'value'
184
189
  const optionLabel = props.field.optionLabel || 'label'
185
190
 
191
+ // A field that names its entity (a list cell) translates its options here (#4686)
192
+ const entity = props.field.entity as string | undefined
193
+ if (entity && i18n && props.value !== null && props.value !== undefined) {
194
+ const trace = i18n.resolve(`entities.${entity}.fields.${props.field.name}.options.${String(props.value)}`)
195
+ if (trace.hit) return trace.result
196
+ }
186
197
  const option = options.find((opt) => opt[optionValue] === props.value)
187
198
  if (option) {
188
199
  return option[optionLabel] as string
@@ -162,15 +162,15 @@ defineEmits<{
162
162
  (e: 'back'): void
163
163
  }>()
164
164
 
165
+ // Where an action goes: its own `placement`, else the header for edit and the
166
+ // footer for the rest (#4693)
167
+ const inHeader = (a: ResolvedAction) => (a.placement ? a.placement === 'header' : a.name === 'edit')
168
+
165
169
  // Header actions: actions that go in the header (e.g., edit)
166
- const headerActions = computed<ResolvedAction[]>(() =>
167
- props.actions.filter((a: ResolvedAction) => ['edit'].includes(a.name))
168
- )
170
+ const headerActions = computed<ResolvedAction[]>(() => props.actions.filter(inHeader))
169
171
 
170
172
  // Footer actions: actions that go in the footer (e.g., back, delete)
171
- const footerActions = computed<ResolvedAction[]>(() =>
172
- props.actions.filter((a: ResolvedAction) => !['edit'].includes(a.name))
173
- )
173
+ const footerActions = computed<ResolvedAction[]>(() => props.actions.filter((a: ResolvedAction) => !inHeader(a)))
174
174
 
175
175
  // Get error message from fetchError
176
176
  const fetchErrorMessage = computed<string | null>(() => formatFetchError(props.fetchError))
@@ -15,20 +15,17 @@
15
15
  * `actions` and `result` get `{ run, kind, final }`.
16
16
  *
17
17
  * A kind with `phases` gets a frieze above the log (#4655), read at the log's
18
- * pace while the run lasts; picking a step shows only its lines.
18
+ * pace while the run lasts; picking a step shows only its lines. The body is
19
+ * TaskRunView (#4934).
19
20
  */
20
21
  import { computed, inject, onBeforeUnmount, onMounted, ref, useSlots, watch, type Component } from 'vue'
21
22
  import { RouterLink } from 'vue-router'
22
23
  import Dialog from 'primevue/dialog'
23
- import ProgressBar from 'primevue/progressbar'
24
24
  import QdButton from '../base/QdButton.vue'
25
- import LogStream from '../display/LogStream.vue'
26
- import TaskPhases from './TaskPhases.vue'
27
- import JsonViewer from '../editors/JsonViewer.vue'
25
+ import TaskRunView from './TaskRunView.vue'
28
26
  import { useI18n } from '../../i18n/useI18n'
29
27
  import { getTaskStore } from '../../tasks/taskStore'
30
28
  import { resolveTaskUi, type TaskDialogOptions, type TaskDialogSlotName } from '../../tasks/taskUi'
31
- import { phaseLabel, phasesMarkedIn, phaseSteps, type TaskPhase } from '../../tasks/taskPhases'
32
29
 
33
30
  interface Props {
34
31
  runId: string | null
@@ -42,125 +39,26 @@ const props = withDefaults(defineProps<Props>(), { options: null, width: undefin
42
39
  const emit = defineEmits<{ close: [] }>()
43
40
  const slots = useSlots()
44
41
 
45
- const { t, tOr } = useI18n()
42
+ const { t } = useI18n()
46
43
  const store = getTaskStore()
47
44
  const appConfig = inject<{ name?: string }>('qdadmApp', {})
48
45
 
49
46
  const run = computed(() => (props.runId ? store.state.runs.find((r) => r.id === props.runId) ?? null : null))
50
47
  const def = computed(() => (props.runId ? store.definition(props.runId) : undefined))
51
48
  const final = computed(() => (run.value ? store.isFinal(run.value.status) : false))
52
- const logSource = computed(() => (run.value?.taskId != null && def.value?.log ? def.value.log(run.value.taskId) : null))
53
- /** The log's download name: the kind and the task, e.g. "deploy-42.log" */
54
- const logFilename = computed(() => {
55
- const r = run.value
56
- const name = `${r?.kind ?? 'task'}-${r?.taskId ?? r?.id ?? 'log'}`.replace(/[^\w.-]+/g, '_')
57
- return `${name}.log`
58
- })
59
49
  const link = computed(() => (run.value?.taskId != null && def.value?.to ? def.value.to(run.value.taskId) : null))
60
50
  const canCancel = computed(() => !!def.value?.cancel && !final.value && run.value?.taskId != null)
61
- const resultIsObject = computed(() => run.value?.result !== null && typeof run.value?.result === 'object')
62
51
 
63
- const ui = computed(() => resolveTaskUi(def.value, { ...props.options, ...(props.width ? { width: props.width } : {}) }))
52
+ const pageOptions = computed(() => ({ ...props.options, ...(props.width ? { width: props.width } : {}) }))
53
+ const ui = computed(() => resolveTaskUi(def.value, pageOptions.value))
54
+ /** The page's slots the body takes */
55
+ const bodySlots = computed(() => (['before-log', 'after-log', 'result'] as const).filter((name) => !!slots[name]))
64
56
  const opts = computed(() => ui.value.dialog)
65
57
  const slotProps = computed(() => ({ run: run.value, kind: run.value?.kind ?? null, final: final.value }))
66
58
  /** A page's slot, else the component the app or the kind gave for it */
67
59
  const slotComponent = (name: TaskDialogSlotName): Component | null => (slots[name] ? null : (ui.value.slots[name] ?? null))
68
60
  const has = (name: TaskDialogSlotName) => !!slots[name] || !!ui.value.slots[name]
69
61
 
70
- // ── The phases (#4655) ────────────────────────────────────────────────────
71
- const phases = ref<TaskPhase[] | null>(null)
72
- const selectedPhase = ref<string | null>(null)
73
- const logView = ref<InstanceType<typeof LogStream> | null>(null)
74
- /** The sub-phases the log has markers for: the only ones it can be filtered on */
75
- const markedSubs = computed(() => {
76
- const marked = phasesMarkedIn(logView.value?.log.lines.value ?? [])
77
- return (phases.value ?? []).flatMap((s) => s.subs ?? []).map((s) => s.name).filter((name) => marked.has(name))
78
- })
79
- const selectedLabel = computed(() => {
80
- const name = selectedPhase.value
81
- if (!name) return ''
82
- const isSub = !(phases.value ?? []).some((s) => s.name === name)
83
- return phaseLabel(tOr, name, isSub)
84
- })
85
- /** The log's pace, else the task's */
86
- const phasesInterval = computed(() => {
87
- const src = logSource.value as { intervalMs?: number } | null
88
- return src?.intervalMs ?? def.value?.task?.intervalMs ?? 2000
89
- })
90
-
91
- let phasesTimer: ReturnType<typeof setTimeout> | null = null
92
- let phasesRead = 0
93
-
94
- async function readPhases(): Promise<void> {
95
- const source = def.value?.phases
96
- if (!source) {
97
- phases.value = null
98
- return
99
- }
100
- if (typeof source !== 'function') {
101
- phases.value = phaseSteps(source)
102
- return
103
- }
104
- const taskId = run.value?.taskId
105
- if (taskId === null || taskId === undefined) return
106
- const current = phasesRead
107
- try {
108
- const read = phaseSteps(await source(taskId))
109
- if (current === phasesRead) phases.value = read
110
- } catch {
111
- // Kept as they were: the next read may do better
112
- }
113
- }
114
-
115
- function stopPhases(): void {
116
- phasesRead++
117
- if (phasesTimer) clearTimeout(phasesTimer)
118
- phasesTimer = null
119
- }
120
-
121
- // Read now, then at the log's pace until the run ends, then once more
122
- function followPhases(): void {
123
- stopPhases()
124
- const current = phasesRead
125
- const tick = async () => {
126
- await readPhases()
127
- if (current !== phasesRead || final.value || typeof def.value?.phases !== 'function') return
128
- phasesTimer = setTimeout(tick, phasesInterval.value)
129
- }
130
- void tick()
131
- }
132
-
133
- watch(
134
- () => [run.value?.id, run.value?.taskId] as const,
135
- ([id], previous) => {
136
- const previousId = previous?.[0]
137
- if (id !== previousId) {
138
- phases.value = null
139
- selectedPhase.value = null
140
- }
141
- if (id) followPhases()
142
- else stopPhases()
143
- },
144
- { immediate: true }
145
- )
146
-
147
- watch(final, (done, was) => {
148
- if (done && !was && run.value) {
149
- stopPhases()
150
- void readPhases()
151
- }
152
- })
153
-
154
- const now = ref(Date.now())
155
- const ticker = setInterval(() => (now.value = Date.now()), 1000)
156
-
157
- const elapsed = computed(() => {
158
- if (!run.value) return ''
159
- const ms = (run.value.endedAt ?? now.value) - run.value.startedAt
160
- const s = Math.round(ms / 1000)
161
- return s < 60 ? `${s} s` : `${Math.floor(s / 60)} min ${s % 60} s`
162
- })
163
-
164
62
  // ── The window (#4334) ────────────────────────────────────────────────────
165
63
  const narrowQuery = typeof window !== 'undefined' && window.matchMedia ? window.matchMedia('(max-width: 640px)') : null
166
64
  const narrow = ref(!!narrowQuery?.matches)
@@ -279,8 +177,6 @@ watch(
279
177
  )
280
178
 
281
179
  onBeforeUnmount(() => {
282
- clearInterval(ticker)
283
- stopPhases()
284
180
  narrowQuery?.removeEventListener?.('change', onNarrow)
285
181
  window.removeEventListener('pointerup', onPointerUp)
286
182
  window.removeEventListener('keydown', onKeyDown)
@@ -314,51 +210,11 @@ onBeforeUnmount(() => {
314
210
  </slot>
315
211
  </div>
316
212
  </template>
317
- <template v-if="run">
318
- <div class="qd-task-head">
319
- <span class="qd-task-status" :class="`qd-task-status--${run.status}`">
320
- <i v-if="!final" class="pi pi-spin pi-spinner" />
321
- <i v-else-if="run.status === 'succeeded'" class="pi pi-check-circle" />
322
- <i v-else-if="run.status === 'failed'" class="pi pi-times-circle" />
323
- <i v-else class="pi pi-ban" />
324
- {{ t(`core.task.status.${run.status}`) }}
325
- </span>
326
- <span class="qd-task-elapsed">{{ elapsed }}</span>
327
- <span v-if="run.taskId !== null" class="qd-task-id">#{{ run.taskId }}</span>
328
- </div>
329
- <ProgressBar v-if="!final" class="qd-task-progress" :mode="run.progress === null ? 'indeterminate' : 'determinate'"
330
- :value="Math.round(run.progress ?? 0)" :show-value="run.progress !== null" />
331
- <div v-if="run.step" class="qd-task-step">{{ run.step }}</div>
332
- <TaskPhases v-if="phases?.length" v-model:selected="selectedPhase" class="qd-task-phases-frieze" :phases="phases"
333
- :selectable="!!logSource" :selectable-subs="markedSubs" :icons="ui.phaseIcons" />
334
- <div v-if="selectedPhase && logSource" class="qd-task-phase-filter">
335
- <span>{{ t('core.task.phase.filter', { name: selectedLabel }) }}</span>
336
- <button type="button" class="qd-task-phase-filter-clear" :aria-label="t('core.task.phase.showAll')"
337
- v-tooltip.top="t('core.task.phase.showAll')" @click="selectedPhase = null"><i class="pi pi-times" /></button>
338
- </div>
339
- <div v-if="has('before-log')" class="qd-task-before-log">
340
- <slot name="before-log" v-bind="slotProps">
341
- <component :is="slotComponent('before-log')!" v-bind="slotProps" />
342
- </slot>
343
- </div>
344
- <LogStream v-if="logSource" ref="logView" :key="run.id" class="qd-task-log" :source="logSource" :filename="logFilename" height="16rem"
345
- :phase="selectedPhase"
346
- :error-pattern="ui.logPatterns.errorPattern" :timestamp-pattern="ui.logPatterns.timestampPattern" @done="store.poke(run.id)" />
347
- <div v-if="has('after-log')" class="qd-task-after-log">
348
- <slot name="after-log" v-bind="slotProps">
349
- <component :is="slotComponent('after-log')!" v-bind="slotProps" />
350
- </slot>
351
- </div>
352
- <div v-if="run.status === 'failed' && run.error" class="qd-task-error"><i class="pi pi-exclamation-triangle" /> {{ run.error }}</div>
353
- <div v-else-if="!final && run.error" class="qd-task-warning">{{ t('core.task.readError', { error: run.error }) }}</div>
354
- <div v-if="run.status === 'succeeded' && run.result !== null" class="qd-task-result">
355
- <slot name="result" v-bind="slotProps">
356
- <component :is="slotComponent('result')!" v-if="slotComponent('result')" v-bind="slotProps" />
357
- <JsonViewer v-else-if="resultIsObject" :model-value="(run.result as never)" height="12rem" />
358
- <span v-else>{{ run.result }}</span>
359
- </slot>
360
- </div>
361
- </template>
213
+ <TaskRunView v-if="run" :run-id="runId" :options="pageOptions">
214
+ <template v-for="name in bodySlots" :key="name" #[name]="p">
215
+ <slot :name="name" v-bind="p" />
216
+ </template>
217
+ </TaskRunView>
362
218
  <template #footer>
363
219
  <RouterLink v-if="link" :to="(link as never)" class="qd-task-link" @click="emit('close')">
364
220
  <i class="pi pi-external-link" /> {{ t('core.task.open') }}
@@ -9,12 +9,15 @@
9
9
  *
10
10
  * The follow dialog is TaskDialog, or the `component` the run's kind or the
11
11
  * app gives (#4334), with props `{ runId, options }` and a `close` event. The
12
- * host's slots go to TaskDialog.
12
+ * host's slots go to TaskDialog. A sequence's id opens TaskSequenceDialog
13
+ * (#4934), which gets the same slots for a step's detail.
13
14
  */
14
15
  import { computed, onBeforeUnmount, ref, watch } from 'vue'
16
+ import { useRoute } from 'vue-router'
15
17
  import InputText from 'primevue/inputtext'
16
18
  import SimpleDialog from '../dialogs/SimpleDialog.vue'
17
19
  import TaskDialog from './TaskDialog.vue'
20
+ import TaskSequenceDialog from './TaskSequenceDialog.vue'
18
21
  import { useI18n } from '../../i18n/useI18n'
19
22
  import { useTaskRunner } from '../../tasks/useTaskRunner'
20
23
  import { getTaskStore } from '../../tasks/taskStore'
@@ -30,12 +33,30 @@ const { t } = useI18n()
30
33
  store.state.hosts++
31
34
  onBeforeUnmount(() => store.state.hosts--)
32
35
 
36
+ // The open id is a sequence's: its window, not a run's (#4934)
37
+ const openSequence = computed(() => {
38
+ const id = store.state.openId
39
+ return id && store.state.sequences.some((s) => s.id === id) ? id : null
40
+ })
41
+
33
42
  // The open run's dialog: a replacement from its kind or the app, else TaskDialog
34
43
  const dialogComponent = computed(() => {
35
44
  const id = store.state.openId
36
45
  return (id ? resolveTaskUi(store.definition(id)).component : resolveTaskUi().component) ?? TaskDialog
37
46
  })
38
47
 
48
+ // Another page: the open dialog closes, the run goes on in the tray (#4695).
49
+ // The dialog is modal, and left open it would block the page behind it.
50
+ const route = useRoute() as ReturnType<typeof useRoute> | undefined
51
+ watch(
52
+ () => route?.path,
53
+ (path, previous) => {
54
+ const id = store.state.openId
55
+ if (!id || previous === undefined || path === previous) return
56
+ if (!resolveTaskUi(store.definition(id)).dialog.keepOnNavigate) store.open(null)
57
+ }
58
+ )
59
+
39
60
  const pending = computed(() => store.state.pendingConfirm)
40
61
  const typed = ref('')
41
62
  watch(pending, () => (typed.value = ''))
@@ -45,11 +66,16 @@ const severity = computed(() => pending.value?.confirm.severity ?? (expected.val
45
66
  </script>
46
67
 
47
68
  <template>
48
- <component :is="dialogComponent" :run-id="store.state.openId" :options="null" @close="store.open(null)">
69
+ <component :is="dialogComponent" :run-id="openSequence ? null : store.state.openId" :options="null" @close="store.open(null)">
49
70
  <template v-for="(_, name) in $slots" #[name]="slotProps">
50
71
  <slot :name="name" v-bind="slotProps ?? {}" />
51
72
  </template>
52
73
  </component>
74
+ <TaskSequenceDialog :sequence-id="openSequence" @close="store.open(null)">
75
+ <template v-for="(_, name) in $slots" #[name]="slotProps">
76
+ <slot :name="name" v-bind="slotProps ?? {}" />
77
+ </template>
78
+ </TaskSequenceDialog>
53
79
  <SimpleDialog :visible="!!pending" :title="pending?.label ?? ''" :confirm-label="pending?.confirm.accept ?? t('core.task.start')"
54
80
  :confirm-severity="severity" :confirm-disabled="!confirmable" :cancel-label="t('core.task.dontStart')"
55
81
  @confirm="store.answerConfirm(true)" @cancel="store.answerConfirm(false)"
@@ -0,0 +1,63 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * TaskRunStatus - a run's state, small, on the page of what it is about (#4695)
4
+ *
5
+ * The follow dialog's head in a line: the status (its words and colours),
6
+ * the progress and the step while it runs, the error once it failed, and
7
+ * Follow, which reopens the dialog. Without a run, "Not run yet".
8
+ *
9
+ * Usage:
10
+ * <TaskRunStatus :run="tasks.runFor('stock-check', { supplierId })" />
11
+ * <TaskRunStatus :run="run"><template #result="{ run }">{{ run.result.count }} in stock</template></TaskRunStatus>
12
+ */
13
+ import { computed } from 'vue'
14
+ import ProgressBar from 'primevue/progressbar'
15
+ import QdButton from '../base/QdButton.vue'
16
+ import { useI18n } from '../../i18n/useI18n'
17
+ import { getTaskStore, type TaskRun } from '../../tasks/taskStore'
18
+
19
+ interface Props {
20
+ run: TaskRun | null | undefined
21
+ /** Shown without a run. Default "Not run yet" */
22
+ emptyLabel?: string
23
+ /** The Follow button. Default true */
24
+ follow?: boolean
25
+ }
26
+
27
+ const props = withDefaults(defineProps<Props>(), { emptyLabel: undefined, follow: true })
28
+
29
+ const { t } = useI18n()
30
+ const store = getTaskStore()
31
+
32
+ const active = computed(() => store.isActive(props.run))
33
+ const icon = computed(() => {
34
+ if (active.value) return 'pi pi-spin pi-spinner'
35
+ if (props.run?.status === 'succeeded') return 'pi pi-check-circle'
36
+ if (props.run?.status === 'failed') return 'pi pi-times-circle'
37
+ return 'pi pi-ban'
38
+ })
39
+ </script>
40
+
41
+ <template>
42
+ <div class="qd-task-run-status" :class="run ? `qd-task-run-status--${run.status}` : 'qd-task-run-status--none'"
43
+ :aria-busy="active ? 'true' : 'false'">
44
+ <template v-if="run">
45
+ <span class="qd-task-status" :class="`qd-task-status--${run.status}`" role="status">
46
+ <i :class="icon" aria-hidden="true" />
47
+ {{ t(`core.task.status.${run.status}`) }}
48
+ </span>
49
+ <template v-if="active">
50
+ <ProgressBar class="qd-task-run-status-progress" :mode="run.progress === null ? 'indeterminate' : 'determinate'"
51
+ :value="Math.round(run.progress ?? 0)" :show-value="false" />
52
+ <span v-if="run.step" class="qd-task-run-status-step">{{ run.step }}</span>
53
+ </template>
54
+ <span v-else-if="run.status === 'failed' && run.error" class="qd-task-run-status-error">{{ run.error }}</span>
55
+ <span v-if="!active && run.status === 'succeeded' && $slots.result" class="qd-task-run-status-result">
56
+ <slot name="result" :run="run" />
57
+ </span>
58
+ <QdButton v-if="follow" class="qd-task-run-status-follow" :label="t('core.task.follow')" icon="pi pi-external-link"
59
+ size="small" text @click="store.open(run.id)" />
60
+ </template>
61
+ <span v-else class="qd-task-run-status-empty">{{ emptyLabel ?? t('core.task.notRun') }}</span>
62
+ </div>
63
+ </template>