@quazardous/qdadm 2.47.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.
- package/dist/styles/qdadm.css +1 -1
- package/package.json +1 -1
- package/src/components/index.ts +2 -0
- package/src/components/tasks/TaskDialog.vue +13 -157
- package/src/components/tasks/TaskHost.vue +15 -2
- package/src/components/tasks/TaskRunView.vue +197 -0
- package/src/components/tasks/TaskSequenceDialog.vue +157 -0
- package/src/components/tasks/TaskTray.vue +33 -13
- package/src/i18n/defaults/core.en.generated.ts +13 -0
- package/src/i18n/defaults/core.en.yml +13 -0
- package/src/i18n/defaults/core.fr.generated.ts +13 -0
- package/src/i18n/defaults/core.fr.yml +13 -0
- package/src/index.ts +5 -0
- package/src/styles/_tasks.scss +102 -0
- package/src/tasks/taskStore.ts +411 -12
- package/src/tasks/useTaskNotifications.ts +6 -2
- package/src/tasks/useTaskRunner.ts +15 -1
|
@@ -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
|
|
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
|
|
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
|
|
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
|
-
<
|
|
318
|
-
<
|
|
319
|
-
<
|
|
320
|
-
|
|
321
|
-
|
|
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,13 +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'
|
|
15
16
|
import { useRoute } from 'vue-router'
|
|
16
17
|
import InputText from 'primevue/inputtext'
|
|
17
18
|
import SimpleDialog from '../dialogs/SimpleDialog.vue'
|
|
18
19
|
import TaskDialog from './TaskDialog.vue'
|
|
20
|
+
import TaskSequenceDialog from './TaskSequenceDialog.vue'
|
|
19
21
|
import { useI18n } from '../../i18n/useI18n'
|
|
20
22
|
import { useTaskRunner } from '../../tasks/useTaskRunner'
|
|
21
23
|
import { getTaskStore } from '../../tasks/taskStore'
|
|
@@ -31,6 +33,12 @@ const { t } = useI18n()
|
|
|
31
33
|
store.state.hosts++
|
|
32
34
|
onBeforeUnmount(() => store.state.hosts--)
|
|
33
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
|
+
|
|
34
42
|
// The open run's dialog: a replacement from its kind or the app, else TaskDialog
|
|
35
43
|
const dialogComponent = computed(() => {
|
|
36
44
|
const id = store.state.openId
|
|
@@ -58,11 +66,16 @@ const severity = computed(() => pending.value?.confirm.severity ?? (expected.val
|
|
|
58
66
|
</script>
|
|
59
67
|
|
|
60
68
|
<template>
|
|
61
|
-
<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)">
|
|
62
70
|
<template v-for="(_, name) in $slots" #[name]="slotProps">
|
|
63
71
|
<slot :name="name" v-bind="slotProps ?? {}" />
|
|
64
72
|
</template>
|
|
65
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>
|
|
66
79
|
<SimpleDialog :visible="!!pending" :title="pending?.label ?? ''" :confirm-label="pending?.confirm.accept ?? t('core.task.start')"
|
|
67
80
|
:confirm-severity="severity" :confirm-disabled="!confirmable" :cancel-label="t('core.task.dontStart')"
|
|
68
81
|
@confirm="store.answerConfirm(true)" @cancel="store.answerConfirm(false)"
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* TaskRunView - one run followed, without its window (#4934)
|
|
4
|
+
*
|
|
5
|
+
* The body of TaskDialog: status, elapsed time, progress, current step, the
|
|
6
|
+
* phases frieze (#4655), the live log, then the error or the result. The
|
|
7
|
+
* sequence window shows it for the step picked in its list. Slots
|
|
8
|
+
* `before-log`, `after-log` and `result` get `{ run, kind, final }`; without
|
|
9
|
+
* one, the app's or the kind's component for it.
|
|
10
|
+
*/
|
|
11
|
+
import { computed, onBeforeUnmount, ref, useSlots, watch, type Component } from 'vue'
|
|
12
|
+
import ProgressBar from 'primevue/progressbar'
|
|
13
|
+
import LogStream from '../display/LogStream.vue'
|
|
14
|
+
import TaskPhases from './TaskPhases.vue'
|
|
15
|
+
import JsonViewer from '../editors/JsonViewer.vue'
|
|
16
|
+
import { useI18n } from '../../i18n/useI18n'
|
|
17
|
+
import { getTaskStore } from '../../tasks/taskStore'
|
|
18
|
+
import { resolveTaskUi, type TaskDialogOptions, type TaskDialogSlotName } from '../../tasks/taskUi'
|
|
19
|
+
import { phaseLabel, phasesMarkedIn, phaseSteps, type TaskPhase } from '../../tasks/taskPhases'
|
|
20
|
+
|
|
21
|
+
interface Props {
|
|
22
|
+
runId: string | null
|
|
23
|
+
/** Options over the app's and the kind's (the log's patterns, the phases' icons come from the kind) */
|
|
24
|
+
options?: TaskDialogOptions | null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const props = withDefaults(defineProps<Props>(), { options: null })
|
|
28
|
+
const slots = useSlots()
|
|
29
|
+
|
|
30
|
+
const { t, tOr } = useI18n()
|
|
31
|
+
const store = getTaskStore()
|
|
32
|
+
|
|
33
|
+
const run = computed(() => (props.runId ? store.state.runs.find((r) => r.id === props.runId) ?? null : null))
|
|
34
|
+
const def = computed(() => (props.runId ? store.definition(props.runId) : undefined))
|
|
35
|
+
const final = computed(() => (run.value ? store.isFinal(run.value.status) : false))
|
|
36
|
+
const logSource = computed(() => (run.value?.taskId != null && def.value?.log ? def.value.log(run.value.taskId) : null))
|
|
37
|
+
/** The log's download name: the kind and the task, e.g. "deploy-42.log" */
|
|
38
|
+
const logFilename = computed(() => {
|
|
39
|
+
const r = run.value
|
|
40
|
+
const name = `${r?.kind ?? 'task'}-${r?.taskId ?? r?.id ?? 'log'}`.replace(/[^\w.-]+/g, '_')
|
|
41
|
+
return `${name}.log`
|
|
42
|
+
})
|
|
43
|
+
const resultIsObject = computed(() => run.value?.result !== null && typeof run.value?.result === 'object')
|
|
44
|
+
|
|
45
|
+
const ui = computed(() => resolveTaskUi(def.value, props.options))
|
|
46
|
+
const slotProps = computed(() => ({ run: run.value, kind: run.value?.kind ?? null, final: final.value }))
|
|
47
|
+
/** A page's slot, else the component the app or the kind gave for it */
|
|
48
|
+
const slotComponent = (name: TaskDialogSlotName): Component | null => (slots[name] ? null : (ui.value.slots[name] ?? null))
|
|
49
|
+
const has = (name: TaskDialogSlotName) => !!slots[name] || !!ui.value.slots[name]
|
|
50
|
+
|
|
51
|
+
// ── The phases (#4655) ────────────────────────────────────────────────────
|
|
52
|
+
const phases = ref<TaskPhase[] | null>(null)
|
|
53
|
+
const selectedPhase = ref<string | null>(null)
|
|
54
|
+
const logView = ref<InstanceType<typeof LogStream> | null>(null)
|
|
55
|
+
/** The sub-phases the log has markers for: the only ones it can be filtered on */
|
|
56
|
+
const markedSubs = computed(() => {
|
|
57
|
+
const marked = phasesMarkedIn(logView.value?.log.lines.value ?? [])
|
|
58
|
+
return (phases.value ?? []).flatMap((s) => s.subs ?? []).map((s) => s.name).filter((name) => marked.has(name))
|
|
59
|
+
})
|
|
60
|
+
const selectedLabel = computed(() => {
|
|
61
|
+
const name = selectedPhase.value
|
|
62
|
+
if (!name) return ''
|
|
63
|
+
const isSub = !(phases.value ?? []).some((s) => s.name === name)
|
|
64
|
+
return phaseLabel(tOr, name, isSub)
|
|
65
|
+
})
|
|
66
|
+
/** The log's pace, else the task's */
|
|
67
|
+
const phasesInterval = computed(() => {
|
|
68
|
+
const src = logSource.value as { intervalMs?: number } | null
|
|
69
|
+
return src?.intervalMs ?? def.value?.task?.intervalMs ?? 2000
|
|
70
|
+
})
|
|
71
|
+
|
|
72
|
+
let phasesTimer: ReturnType<typeof setTimeout> | null = null
|
|
73
|
+
let phasesRead = 0
|
|
74
|
+
|
|
75
|
+
async function readPhases(): Promise<void> {
|
|
76
|
+
const source = def.value?.phases
|
|
77
|
+
if (!source) {
|
|
78
|
+
phases.value = null
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
if (typeof source !== 'function') {
|
|
82
|
+
phases.value = phaseSteps(source)
|
|
83
|
+
return
|
|
84
|
+
}
|
|
85
|
+
const taskId = run.value?.taskId
|
|
86
|
+
if (taskId === null || taskId === undefined) return
|
|
87
|
+
const current = phasesRead
|
|
88
|
+
try {
|
|
89
|
+
const read = phaseSteps(await source(taskId))
|
|
90
|
+
if (current === phasesRead) phases.value = read
|
|
91
|
+
} catch {
|
|
92
|
+
// Kept as they were: the next read may do better
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function stopPhases(): void {
|
|
97
|
+
phasesRead++
|
|
98
|
+
if (phasesTimer) clearTimeout(phasesTimer)
|
|
99
|
+
phasesTimer = null
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Read now, then at the log's pace until the run ends, then once more
|
|
103
|
+
function followPhases(): void {
|
|
104
|
+
stopPhases()
|
|
105
|
+
const current = phasesRead
|
|
106
|
+
const tick = async () => {
|
|
107
|
+
await readPhases()
|
|
108
|
+
if (current !== phasesRead || final.value || typeof def.value?.phases !== 'function') return
|
|
109
|
+
phasesTimer = setTimeout(tick, phasesInterval.value)
|
|
110
|
+
}
|
|
111
|
+
void tick()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
watch(
|
|
115
|
+
() => [run.value?.id, run.value?.taskId] as const,
|
|
116
|
+
([id], previous) => {
|
|
117
|
+
const previousId = previous?.[0]
|
|
118
|
+
if (id !== previousId) {
|
|
119
|
+
phases.value = null
|
|
120
|
+
selectedPhase.value = null
|
|
121
|
+
}
|
|
122
|
+
if (id) followPhases()
|
|
123
|
+
else stopPhases()
|
|
124
|
+
},
|
|
125
|
+
{ immediate: true }
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
watch(final, (done, was) => {
|
|
129
|
+
if (done && !was && run.value) {
|
|
130
|
+
stopPhases()
|
|
131
|
+
void readPhases()
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
const now = ref(Date.now())
|
|
136
|
+
const ticker = setInterval(() => (now.value = Date.now()), 1000)
|
|
137
|
+
|
|
138
|
+
const elapsed = computed(() => {
|
|
139
|
+
if (!run.value) return ''
|
|
140
|
+
const ms = (run.value.endedAt ?? now.value) - run.value.startedAt
|
|
141
|
+
const s = Math.round(ms / 1000)
|
|
142
|
+
return s < 60 ? `${s} s` : `${Math.floor(s / 60)} min ${s % 60} s`
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
onBeforeUnmount(() => {
|
|
146
|
+
clearInterval(ticker)
|
|
147
|
+
stopPhases()
|
|
148
|
+
})
|
|
149
|
+
</script>
|
|
150
|
+
|
|
151
|
+
<template>
|
|
152
|
+
<div v-if="run" class="qd-task-run-view">
|
|
153
|
+
<div class="qd-task-head">
|
|
154
|
+
<span class="qd-task-status" :class="`qd-task-status--${run.status}`">
|
|
155
|
+
<i v-if="!final" class="pi pi-spin pi-spinner" />
|
|
156
|
+
<i v-else-if="run.status === 'succeeded'" class="pi pi-check-circle" />
|
|
157
|
+
<i v-else-if="run.status === 'failed'" class="pi pi-times-circle" />
|
|
158
|
+
<i v-else class="pi pi-ban" />
|
|
159
|
+
{{ t(`core.task.status.${run.status}`) }}
|
|
160
|
+
</span>
|
|
161
|
+
<span class="qd-task-elapsed">{{ elapsed }}</span>
|
|
162
|
+
<span v-if="run.taskId !== null" class="qd-task-id">#{{ run.taskId }}</span>
|
|
163
|
+
</div>
|
|
164
|
+
<ProgressBar v-if="!final" class="qd-task-progress" :mode="run.progress === null ? 'indeterminate' : 'determinate'"
|
|
165
|
+
:value="Math.round(run.progress ?? 0)" :show-value="run.progress !== null" />
|
|
166
|
+
<div v-if="run.step" class="qd-task-step">{{ run.step }}</div>
|
|
167
|
+
<TaskPhases v-if="phases?.length" v-model:selected="selectedPhase" class="qd-task-phases-frieze" :phases="phases"
|
|
168
|
+
:selectable="!!logSource" :selectable-subs="markedSubs" :icons="ui.phaseIcons" />
|
|
169
|
+
<div v-if="selectedPhase && logSource" class="qd-task-phase-filter">
|
|
170
|
+
<span>{{ t('core.task.phase.filter', { name: selectedLabel }) }}</span>
|
|
171
|
+
<button type="button" class="qd-task-phase-filter-clear" :aria-label="t('core.task.phase.showAll')"
|
|
172
|
+
v-tooltip.top="t('core.task.phase.showAll')" @click="selectedPhase = null"><i class="pi pi-times" /></button>
|
|
173
|
+
</div>
|
|
174
|
+
<div v-if="has('before-log')" class="qd-task-before-log">
|
|
175
|
+
<slot name="before-log" v-bind="slotProps">
|
|
176
|
+
<component :is="slotComponent('before-log')!" v-bind="slotProps" />
|
|
177
|
+
</slot>
|
|
178
|
+
</div>
|
|
179
|
+
<LogStream v-if="logSource" ref="logView" :key="run.id" class="qd-task-log" :source="logSource" :filename="logFilename" height="16rem"
|
|
180
|
+
:phase="selectedPhase"
|
|
181
|
+
:error-pattern="ui.logPatterns.errorPattern" :timestamp-pattern="ui.logPatterns.timestampPattern" @done="store.poke(run.id)" />
|
|
182
|
+
<div v-if="has('after-log')" class="qd-task-after-log">
|
|
183
|
+
<slot name="after-log" v-bind="slotProps">
|
|
184
|
+
<component :is="slotComponent('after-log')!" v-bind="slotProps" />
|
|
185
|
+
</slot>
|
|
186
|
+
</div>
|
|
187
|
+
<div v-if="run.status === 'failed' && run.error" class="qd-task-error"><i class="pi pi-exclamation-triangle" /> {{ run.error }}</div>
|
|
188
|
+
<div v-else-if="!final && run.error" class="qd-task-warning">{{ t('core.task.readError', { error: run.error }) }}</div>
|
|
189
|
+
<div v-if="run.status === 'succeeded' && run.result !== null" class="qd-task-result">
|
|
190
|
+
<slot name="result" v-bind="slotProps">
|
|
191
|
+
<component :is="slotComponent('result')!" v-if="slotComponent('result')" v-bind="slotProps" />
|
|
192
|
+
<JsonViewer v-else-if="resultIsObject" :model-value="(run.result as never)" height="12rem" />
|
|
193
|
+
<span v-else>{{ run.result }}</span>
|
|
194
|
+
</slot>
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
</template>
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* TaskSequenceDialog - tasks chained in one window (#4934)
|
|
4
|
+
*
|
|
5
|
+
* The list: one line per step, with its state (waiting, running, done,
|
|
6
|
+
* failed, not run), its duration and a recap (the kind's `summary`, else the
|
|
7
|
+
* error, else the step reached); the running step is highlighted. A click on
|
|
8
|
+
* a step shows its detail, the body of TaskDialog (TaskRunView); "Back to the
|
|
9
|
+
* list" returns. Closing does not stop anything: the sequence goes on in the
|
|
10
|
+
* tray. TaskHost renders it when the open id is a sequence's.
|
|
11
|
+
*
|
|
12
|
+
* Slots `before-log`, `after-log` and `result` reach the step's detail.
|
|
13
|
+
*/
|
|
14
|
+
import { computed, onBeforeUnmount, ref, useSlots, watch } from 'vue'
|
|
15
|
+
import Dialog from 'primevue/dialog'
|
|
16
|
+
import ProgressBar from 'primevue/progressbar'
|
|
17
|
+
import QdButton from '../base/QdButton.vue'
|
|
18
|
+
import TaskRunView from './TaskRunView.vue'
|
|
19
|
+
import { useI18n } from '../../i18n/useI18n'
|
|
20
|
+
import { getTaskStore, type SequenceStepStatus, type TaskSequenceStep } from '../../tasks/taskStore'
|
|
21
|
+
import { resolveTaskUi, type TaskDialogOptions } from '../../tasks/taskUi'
|
|
22
|
+
import { formatPhaseDuration } from '../../tasks/taskPhases'
|
|
23
|
+
|
|
24
|
+
interface Props {
|
|
25
|
+
sequenceId: string | null
|
|
26
|
+
/** Window options over the app's */
|
|
27
|
+
options?: TaskDialogOptions | null
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const props = withDefaults(defineProps<Props>(), { options: null })
|
|
31
|
+
const emit = defineEmits<{ close: [] }>()
|
|
32
|
+
const slots = useSlots()
|
|
33
|
+
const { t } = useI18n()
|
|
34
|
+
const store = getTaskStore()
|
|
35
|
+
|
|
36
|
+
const sequence = computed(() => (props.sequenceId ? store.state.sequences.find((s) => s.id === props.sequenceId) ?? null : null))
|
|
37
|
+
const running = computed(() => store.isActive(sequence.value))
|
|
38
|
+
const opts = computed(() => resolveTaskUi(null, props.options).dialog)
|
|
39
|
+
const bodySlots = computed(() => (['before-log', 'after-log', 'result'] as const).filter((name) => !!slots[name]))
|
|
40
|
+
|
|
41
|
+
/** The run shown in detail, or null for the list */
|
|
42
|
+
const detailId = ref<string | null>(null)
|
|
43
|
+
watch(() => props.sequenceId, () => (detailId.value = null))
|
|
44
|
+
const detailStep = computed(() => (detailId.value ? sequence.value?.steps.find((s) => s.runId === detailId.value) ?? null : null))
|
|
45
|
+
const detailIndex = computed(() => (detailStep.value ? sequence.value!.steps.indexOf(detailStep.value) : -1))
|
|
46
|
+
const detailDef = computed(() => (detailId.value ? store.definition(detailId.value) : undefined))
|
|
47
|
+
const detailRun = computed(() => (detailId.value ? store.state.runs.find((r) => r.id === detailId.value) ?? null : null))
|
|
48
|
+
const canCancelStep = computed(() => !!detailDef.value?.cancel && !!detailRun.value && store.isActive(detailRun.value) && detailRun.value.taskId != null)
|
|
49
|
+
|
|
50
|
+
const done = computed(() => sequence.value?.steps.filter((s) => store.isFinal(store.stepStatus(s)) && store.stepStatus(s) !== 'skipped').length ?? 0)
|
|
51
|
+
const total = computed(() => sequence.value?.steps.length ?? 0)
|
|
52
|
+
|
|
53
|
+
const now = ref(Date.now())
|
|
54
|
+
const ticker = setInterval(() => (now.value = Date.now()), 1000)
|
|
55
|
+
onBeforeUnmount(() => clearInterval(ticker))
|
|
56
|
+
|
|
57
|
+
const stepLabel = (step: TaskSequenceStep, i: number) => step.label || t('core.task.sequence.step', { n: i + 1 })
|
|
58
|
+
const runOf = (step: TaskSequenceStep) => (step.runId ? store.state.runs.find((r) => r.id === step.runId) ?? null : null)
|
|
59
|
+
|
|
60
|
+
function stateText(status: SequenceStepStatus): string {
|
|
61
|
+
if (status === 'pending') return t('core.task.sequence.pending')
|
|
62
|
+
if (status === 'skipped') return t('core.task.sequence.skipped')
|
|
63
|
+
return t(`core.task.status.${status}`)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function icon(status: SequenceStepStatus): string {
|
|
67
|
+
if (status === 'pending') return 'pi pi-circle'
|
|
68
|
+
if (status === 'skipped') return 'pi pi-minus-circle'
|
|
69
|
+
if (status === 'succeeded') return 'pi pi-check-circle'
|
|
70
|
+
if (status === 'failed') return 'pi pi-times-circle'
|
|
71
|
+
if (status === 'cancelled') return 'pi pi-ban'
|
|
72
|
+
return 'pi pi-spin pi-spinner'
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function duration(step: TaskSequenceStep): string {
|
|
76
|
+
const run = runOf(step)
|
|
77
|
+
if (!run) return ''
|
|
78
|
+
return formatPhaseDuration(((run.endedAt ?? now.value) - run.startedAt) / 1000)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function recap(step: TaskSequenceStep): string | null {
|
|
82
|
+
if (step.skipped) return t(`core.task.sequence.why.${step.skipped}`)
|
|
83
|
+
return store.stepSummary(step)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const isCurrent = (i: number) => running.value && sequence.value?.current === i
|
|
87
|
+
</script>
|
|
88
|
+
|
|
89
|
+
<template>
|
|
90
|
+
<Dialog
|
|
91
|
+
:visible="!!sequence"
|
|
92
|
+
:modal="opts.modal"
|
|
93
|
+
:style="{ width: opts.width }"
|
|
94
|
+
:breakpoints="{ '640px': '96vw' }"
|
|
95
|
+
:draggable="opts.draggable"
|
|
96
|
+
:position="opts.position"
|
|
97
|
+
class="qd-task-dialog qd-task-sequence-dialog"
|
|
98
|
+
:class="opts.class"
|
|
99
|
+
@update:visible="(v: boolean) => !v && emit('close')"
|
|
100
|
+
>
|
|
101
|
+
<template #header>
|
|
102
|
+
<div v-if="sequence" class="qd-task-header qd-task-sequence-header">
|
|
103
|
+
<span class="p-dialog-title">{{ sequence.label }}</span>
|
|
104
|
+
<span class="qd-task-status" :class="`qd-task-status--${sequence.status}`">
|
|
105
|
+
<i :class="icon(sequence.status)" aria-hidden="true" />
|
|
106
|
+
{{ t('core.task.sequence.progress', { done, total }) }}
|
|
107
|
+
</span>
|
|
108
|
+
</div>
|
|
109
|
+
</template>
|
|
110
|
+
|
|
111
|
+
<template v-if="sequence">
|
|
112
|
+
<ol v-if="!detailStep" class="qd-task-sequence-list">
|
|
113
|
+
<li v-for="(step, i) in sequence.steps" :key="i">
|
|
114
|
+
<button type="button" class="qd-task-sequence-step"
|
|
115
|
+
:class="[`qd-task-sequence-step--${store.stepStatus(step)}`, { 'qd-task-sequence-step--current': isCurrent(i) }]"
|
|
116
|
+
:disabled="!step.runId" :aria-current="isCurrent(i) ? 'step' : undefined"
|
|
117
|
+
:aria-label="step.runId ? `${stepLabel(step, i)} — ${t('core.task.sequence.details')}` : undefined"
|
|
118
|
+
@click="detailId = step.runId">
|
|
119
|
+
<i class="qd-task-sequence-icon" :class="icon(store.stepStatus(step))" aria-hidden="true" />
|
|
120
|
+
<span class="qd-task-sequence-main">
|
|
121
|
+
<span class="qd-task-sequence-label">{{ stepLabel(step, i) }}</span>
|
|
122
|
+
<span v-if="recap(step)" class="qd-task-sequence-recap">{{ recap(step) }}</span>
|
|
123
|
+
<ProgressBar v-if="isCurrent(i) && runOf(step)" class="qd-task-sequence-progress"
|
|
124
|
+
:mode="runOf(step)!.progress === null ? 'indeterminate' : 'determinate'"
|
|
125
|
+
:value="Math.round(runOf(step)!.progress ?? 0)" :show-value="false" />
|
|
126
|
+
</span>
|
|
127
|
+
<span class="qd-task-sequence-state">{{ stateText(store.stepStatus(step)) }}</span>
|
|
128
|
+
<span class="qd-task-sequence-duration">{{ duration(step) }}</span>
|
|
129
|
+
<i v-if="step.runId" class="pi pi-angle-right qd-task-sequence-open" aria-hidden="true" />
|
|
130
|
+
</button>
|
|
131
|
+
</li>
|
|
132
|
+
</ol>
|
|
133
|
+
<template v-else>
|
|
134
|
+
<div class="qd-task-sequence-detail-title">
|
|
135
|
+
<span class="qd-task-sequence-detail-index">{{ detailIndex + 1 }}/{{ total }}</span>
|
|
136
|
+
{{ stepLabel(detailStep, detailIndex) }}
|
|
137
|
+
</div>
|
|
138
|
+
<TaskRunView :run-id="detailId" :options="options">
|
|
139
|
+
<template v-for="name in bodySlots" :key="name" #[name]="p">
|
|
140
|
+
<slot :name="name" v-bind="p" />
|
|
141
|
+
</template>
|
|
142
|
+
</TaskRunView>
|
|
143
|
+
</template>
|
|
144
|
+
</template>
|
|
145
|
+
|
|
146
|
+
<template #footer>
|
|
147
|
+
<QdButton v-if="detailStep" class="qd-task-sequence-back" icon="pi pi-arrow-left" text
|
|
148
|
+
:label="t('core.task.sequence.back')" @click="detailId = null" />
|
|
149
|
+
<span class="qd-task-spacer" />
|
|
150
|
+
<QdButton v-if="detailStep && canCancelStep" severity="danger" text :loading="detailRun?.cancelling" icon="pi pi-stop-circle"
|
|
151
|
+
:label="t('core.task.cancel')" @click="detailRun && store.cancel(detailRun.id)" />
|
|
152
|
+
<QdButton v-else-if="!detailStep && running" severity="danger" text :loading="sequence?.cancelling" icon="pi pi-stop-circle"
|
|
153
|
+
:label="t('core.task.sequence.cancel')" @click="sequence && store.cancelSequence(sequence.id)" />
|
|
154
|
+
<QdButton :label="running ? t('core.task.background') : t('core.task.close')" severity="secondary" @click="emit('close')" />
|
|
155
|
+
</template>
|
|
156
|
+
</Dialog>
|
|
157
|
+
</template>
|