@quazardous/qdadm 2.40.0 → 2.42.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/display/LogStream.vue +59 -2
- package/src/components/layout/CardsDashboard.vue +53 -11
- package/src/components/tasks/TaskDialog.vue +198 -14
- package/src/components/tasks/TaskHost.vue +16 -1
- package/src/components/tasks/TaskTray.vue +14 -6
- package/src/composables/useCardsArrangement.ts +164 -28
- package/src/dashboard/dashboardConfig.ts +36 -0
- package/src/i18n/defaults/core.en.generated.ts +38 -0
- package/src/i18n/defaults/core.en.yml +38 -0
- package/src/i18n/defaults/core.fr.generated.ts +38 -0
- package/src/i18n/defaults/core.fr.yml +38 -0
- package/src/index.ts +31 -0
- package/src/sessions/SessionsModule.ts +152 -0
- package/src/sessions/SessionsPage.vue +228 -0
- package/src/sessions/presence.ts +109 -0
- package/src/sessions/sessionsAdapter.ts +105 -0
- package/src/styles/_cards-dashboard.scss +6 -0
- package/src/styles/_log-stream.scss +13 -0
- package/src/styles/_sessions.scss +106 -0
- package/src/styles/_tasks.scss +37 -0
- package/src/styles/index.scss +1 -0
- package/src/tasks/taskStore.ts +7 -0
- package/src/tasks/taskUi.ts +89 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tab's heartbeat (#4336): every `interval` seconds while the tab is
|
|
3
|
+
* visible and someone is signed in, with a tab id kept for the tab's life.
|
|
4
|
+
* The others the server returns feed the "Also signed in" banner.
|
|
5
|
+
*/
|
|
6
|
+
import { ref, type Ref } from 'vue'
|
|
7
|
+
import type { SessionPresence, SessionsAdapter } from './sessionsAdapter'
|
|
8
|
+
|
|
9
|
+
const TAB_KEY = 'qdadm.sessions.tab'
|
|
10
|
+
|
|
11
|
+
/** One id per tab, kept across reloads of that tab (sessionStorage) */
|
|
12
|
+
export function tabId(): string {
|
|
13
|
+
try {
|
|
14
|
+
const known = sessionStorage.getItem(TAB_KEY)
|
|
15
|
+
if (known) return known
|
|
16
|
+
} catch {
|
|
17
|
+
// No session storage: a fresh id per page
|
|
18
|
+
}
|
|
19
|
+
const id = globalThis.crypto?.randomUUID?.() ?? `tab-${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`
|
|
20
|
+
try {
|
|
21
|
+
sessionStorage.setItem(TAB_KEY, id)
|
|
22
|
+
} catch {
|
|
23
|
+
// Same
|
|
24
|
+
}
|
|
25
|
+
return id
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface PresenceOptions {
|
|
29
|
+
adapter: SessionsAdapter
|
|
30
|
+
/** Seconds between beats */
|
|
31
|
+
interval: number
|
|
32
|
+
onOthers: (others: SessionPresence[]) => void
|
|
33
|
+
/** A beat failed; logged once until one succeeds */
|
|
34
|
+
onError?: (error: unknown) => void
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface Presence {
|
|
38
|
+
others: Ref<SessionPresence[]>
|
|
39
|
+
running: Ref<boolean>
|
|
40
|
+
start(): void
|
|
41
|
+
stop(): void
|
|
42
|
+
/** Beat now (the tab came back, a test) */
|
|
43
|
+
beat(): Promise<void>
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function createPresence(options: PresenceOptions): Presence {
|
|
47
|
+
const others = ref<SessionPresence[]>([])
|
|
48
|
+
const running = ref(false)
|
|
49
|
+
const tab = tabId()
|
|
50
|
+
let timer: ReturnType<typeof setInterval> | null = null
|
|
51
|
+
let failing = false
|
|
52
|
+
|
|
53
|
+
const visible = () => typeof document === 'undefined' || document.visibilityState !== 'hidden'
|
|
54
|
+
|
|
55
|
+
async function beat(): Promise<void> {
|
|
56
|
+
if (!running.value || !visible()) return
|
|
57
|
+
try {
|
|
58
|
+
const res = await options.adapter.heartbeat(tab)
|
|
59
|
+
failing = false
|
|
60
|
+
if (!running.value) return // stopped while the beat was in flight
|
|
61
|
+
others.value = res.others
|
|
62
|
+
options.onOthers(res.others)
|
|
63
|
+
} catch (err) {
|
|
64
|
+
if (!failing) (options.onError ?? ((e) => console.warn('[qdadm] sessions heartbeat failed:', e)))(err)
|
|
65
|
+
failing = true // the next tick retries
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function arm(): void {
|
|
70
|
+
disarm()
|
|
71
|
+
if (running.value && visible()) timer = setInterval(() => void beat(), options.interval * 1000)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function disarm(): void {
|
|
75
|
+
if (timer) clearInterval(timer)
|
|
76
|
+
timer = null
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Hidden: no beats; back: one at once, then the interval again
|
|
80
|
+
function onVisibility(): void {
|
|
81
|
+
if (!running.value) return
|
|
82
|
+
if (visible()) {
|
|
83
|
+
void beat()
|
|
84
|
+
arm()
|
|
85
|
+
} else {
|
|
86
|
+
disarm()
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return {
|
|
91
|
+
others,
|
|
92
|
+
running,
|
|
93
|
+
start() {
|
|
94
|
+
if (running.value) return
|
|
95
|
+
running.value = true
|
|
96
|
+
if (typeof document !== 'undefined') document.addEventListener('visibilitychange', onVisibility)
|
|
97
|
+
void beat()
|
|
98
|
+
arm()
|
|
99
|
+
},
|
|
100
|
+
stop() {
|
|
101
|
+
running.value = false
|
|
102
|
+
disarm()
|
|
103
|
+
if (typeof document !== 'undefined') document.removeEventListener('visibilitychange', onVisibility)
|
|
104
|
+
others.value = []
|
|
105
|
+
options.onOthers([])
|
|
106
|
+
},
|
|
107
|
+
beat,
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the sessions module (#4336) reaches the server. `restSessionsAdapter`
|
|
3
|
+
* speaks this contract; any other transport implements SessionsAdapter.
|
|
4
|
+
*
|
|
5
|
+
* POST <base>/heartbeat { tab } → { others: [{ id, login, via, since, seen, tabs }] }
|
|
6
|
+
* GET <base> → { sessions: [... (+ ip, agent for an admin)], mine }
|
|
7
|
+
* GET <base>/history?limit=&offset= → { history: [{ at, event, login, via, by, reason, source, ip?, agent? }], notice? }
|
|
8
|
+
* DELETE <base>/<id>?reason= (an admin closes a session)
|
|
9
|
+
*
|
|
10
|
+
* Nothing here belongs to one app: a server that reports a degraded history
|
|
11
|
+
* in its own field maps it with `historyNotice`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export interface SessionPresence {
|
|
15
|
+
id: string | number
|
|
16
|
+
login: string
|
|
17
|
+
/** How they signed in: a provider name, "local"… */
|
|
18
|
+
via?: string
|
|
19
|
+
/** ISO dates */
|
|
20
|
+
since?: string
|
|
21
|
+
seen?: string
|
|
22
|
+
tabs?: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface SessionInfo extends SessionPresence {
|
|
26
|
+
ip?: string
|
|
27
|
+
agent?: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SessionHistoryEntry {
|
|
31
|
+
at: string
|
|
32
|
+
/** login, logout, refused, closed… */
|
|
33
|
+
event: string
|
|
34
|
+
login?: string
|
|
35
|
+
via?: string
|
|
36
|
+
/** Who closed it */
|
|
37
|
+
by?: string
|
|
38
|
+
reason?: string
|
|
39
|
+
source?: string
|
|
40
|
+
ip?: string
|
|
41
|
+
agent?: string
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SessionsAdapter {
|
|
45
|
+
heartbeat(tab: string): Promise<{ others: SessionPresence[] }>
|
|
46
|
+
list(): Promise<{ sessions: SessionInfo[]; mine?: string | number | null }>
|
|
47
|
+
history(page: { limit: number; offset: number }): Promise<{ history: SessionHistoryEntry[]; notice?: string | null }>
|
|
48
|
+
/** Without it, no Close button */
|
|
49
|
+
close?(id: string | number, reason: string): Promise<unknown>
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface RestSessionsAdapterOptions {
|
|
53
|
+
/** The app's fetch (auth headers, base URL…). Default: window.fetch. */
|
|
54
|
+
fetch?: typeof fetch
|
|
55
|
+
headers?: Record<string, string>
|
|
56
|
+
/** Read a notice about the history from the response; default: its `notice` field */
|
|
57
|
+
historyNotice?: (body: Record<string, unknown>) => string | null | undefined
|
|
58
|
+
/** No DELETE on this server: no Close button */
|
|
59
|
+
canClose?: boolean
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function restSessionsAdapter(base: string, options: RestSessionsAdapterOptions = {}): SessionsAdapter {
|
|
63
|
+
const doFetch = options.fetch ?? ((input: RequestInfo | URL, init?: RequestInit) => fetch(input, init))
|
|
64
|
+
const root = base.replace(/\/$/, '')
|
|
65
|
+
const headers = { Accept: 'application/json', ...options.headers }
|
|
66
|
+
|
|
67
|
+
async function call(url: string, init: RequestInit = {}): Promise<Record<string, unknown>> {
|
|
68
|
+
const res = await doFetch(url, {
|
|
69
|
+
...init,
|
|
70
|
+
headers: { ...headers, ...(init.body ? { 'Content-Type': 'application/json' } : {}), ...(init.headers as Record<string, string>) },
|
|
71
|
+
})
|
|
72
|
+
const text = await res.text()
|
|
73
|
+
let body: unknown = null
|
|
74
|
+
try {
|
|
75
|
+
body = text ? JSON.parse(text) : null
|
|
76
|
+
} catch {
|
|
77
|
+
body = { message: text }
|
|
78
|
+
}
|
|
79
|
+
if (!res.ok) {
|
|
80
|
+
const b = (body ?? {}) as { message?: string; detail?: string }
|
|
81
|
+
throw new Error(String(b.message ?? b.detail ?? `${res.status} ${res.statusText}`))
|
|
82
|
+
}
|
|
83
|
+
return (body ?? {}) as Record<string, unknown>
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const adapter: SessionsAdapter = {
|
|
87
|
+
async heartbeat(tab) {
|
|
88
|
+
const body = await call(`${root}/heartbeat`, { method: 'POST', body: JSON.stringify({ tab }) })
|
|
89
|
+
return { others: Array.isArray(body.others) ? (body.others as SessionPresence[]) : [] }
|
|
90
|
+
},
|
|
91
|
+
async list() {
|
|
92
|
+
const body = await call(root)
|
|
93
|
+
return { sessions: Array.isArray(body.sessions) ? (body.sessions as SessionInfo[]) : [], mine: (body.mine as string | number | null) ?? null }
|
|
94
|
+
},
|
|
95
|
+
async history({ limit, offset }) {
|
|
96
|
+
const body = await call(`${root}/history?limit=${encodeURIComponent(limit)}&offset=${encodeURIComponent(offset)}`)
|
|
97
|
+
const notice = options.historyNotice ? options.historyNotice(body) : typeof body.notice === 'string' ? body.notice : null
|
|
98
|
+
return { history: Array.isArray(body.history) ? (body.history as SessionHistoryEntry[]) : [], notice: notice ?? null }
|
|
99
|
+
},
|
|
100
|
+
}
|
|
101
|
+
if (options.canClose !== false) {
|
|
102
|
+
adapter.close = async (id, reason) => call(`${root}/${encodeURIComponent(String(id))}?reason=${encodeURIComponent(reason)}`, { method: 'DELETE' })
|
|
103
|
+
}
|
|
104
|
+
return adapter
|
|
105
|
+
}
|
|
@@ -22,6 +22,12 @@
|
|
|
22
22
|
gap: 1rem;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// An async arrangement in its grace (#4338): held back, room kept, so the
|
|
26
|
+
// saved order shows without a jump from the default one
|
|
27
|
+
.qd-cards-grid.qd-cards-loading {
|
|
28
|
+
visibility: hidden;
|
|
29
|
+
}
|
|
30
|
+
|
|
25
31
|
.qd-cards-slot {
|
|
26
32
|
grid-column: span var(--qd-card-span, 1);
|
|
27
33
|
display: flex;
|
|
@@ -75,6 +75,19 @@
|
|
|
75
75
|
font-variant-numeric: tabular-nums;
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
.qd-log-copy-status {
|
|
79
|
+
color: var(--p-green-600);
|
|
80
|
+
font-size: $font-size-xs;
|
|
81
|
+
|
|
82
|
+
&:empty {
|
|
83
|
+
display: none;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
&--error {
|
|
87
|
+
color: var(--p-red-500);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
78
91
|
.qd-log-search {
|
|
79
92
|
display: inline-flex;
|
|
80
93
|
align-items: center;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SessionsPage (#4336): who is signed in, the history, Close with a reason.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
.qd-sessions {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-direction: column;
|
|
8
|
+
gap: 1rem;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.qd-sessions-head {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: space-between;
|
|
15
|
+
gap: 0.5rem;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.qd-sessions-table {
|
|
19
|
+
width: 100%;
|
|
20
|
+
border-collapse: collapse;
|
|
21
|
+
font-size: 0.875rem;
|
|
22
|
+
|
|
23
|
+
th {
|
|
24
|
+
text-align: left;
|
|
25
|
+
font-weight: 600;
|
|
26
|
+
color: var(--p-text-muted-color);
|
|
27
|
+
padding: 0.5rem;
|
|
28
|
+
border-bottom: 1px solid var(--p-content-border-color);
|
|
29
|
+
white-space: nowrap;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
td {
|
|
33
|
+
padding: 0.5rem;
|
|
34
|
+
border-bottom: 1px solid var(--p-content-border-color);
|
|
35
|
+
vertical-align: middle;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.qd-sessions-mine td {
|
|
40
|
+
background: var(--p-highlight-background, rgba(16, 185, 129, 0.06));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.qd-sessions-badge {
|
|
44
|
+
margin-left: 0.375rem;
|
|
45
|
+
padding: 0 0.375rem;
|
|
46
|
+
border-radius: 999px;
|
|
47
|
+
font-size: 0.75rem;
|
|
48
|
+
background: var(--p-primary-color);
|
|
49
|
+
color: var(--p-primary-contrast-color, #fff);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.qd-sessions-origin {
|
|
53
|
+
color: var(--p-text-muted-color);
|
|
54
|
+
font-size: 0.8125rem;
|
|
55
|
+
max-width: 22rem;
|
|
56
|
+
overflow-wrap: anywhere;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.qd-sessions-actions {
|
|
60
|
+
text-align: right;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.qd-sessions-event {
|
|
64
|
+
padding: 0.0625rem 0.5rem;
|
|
65
|
+
border-radius: 999px;
|
|
66
|
+
background: var(--p-content-hover-background);
|
|
67
|
+
white-space: nowrap;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.qd-sessions-event--refused .qd-sessions-event,
|
|
71
|
+
.qd-sessions-event--closed .qd-sessions-event {
|
|
72
|
+
background: var(--p-red-50);
|
|
73
|
+
color: var(--p-red-700);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
.qd-sessions-empty {
|
|
77
|
+
margin: 0;
|
|
78
|
+
color: var(--p-text-muted-color);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.qd-sessions-notice {
|
|
82
|
+
margin-bottom: 0.75rem;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.qd-sessions-pager {
|
|
86
|
+
display: flex;
|
|
87
|
+
justify-content: flex-end;
|
|
88
|
+
gap: 0.5rem;
|
|
89
|
+
margin-top: 0.5rem;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.qd-sessions-reason-label {
|
|
93
|
+
display: block;
|
|
94
|
+
margin-bottom: 0.5rem;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.qd-sessions-reason {
|
|
98
|
+
width: 100%;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Narrow screens: the tables scroll inside their card
|
|
102
|
+
@media (max-width: 640px) {
|
|
103
|
+
.qd-sessions-card .p-card-content {
|
|
104
|
+
overflow-x: auto;
|
|
105
|
+
}
|
|
106
|
+
}
|
package/src/styles/_tasks.scss
CHANGED
|
@@ -49,8 +49,45 @@
|
|
|
49
49
|
font-size: $font-size-sm;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
// The content is a column: the log takes what the window leaves (#4334)
|
|
53
|
+
.qd-task-dialog .p-dialog-content {
|
|
54
|
+
display: flex;
|
|
55
|
+
flex-direction: column;
|
|
56
|
+
flex: 1 1 auto;
|
|
57
|
+
min-height: 0;
|
|
58
|
+
}
|
|
59
|
+
|
|
52
60
|
.qd-task-log {
|
|
53
61
|
margin-top: 0.75rem;
|
|
62
|
+
flex: 1 1 16rem;
|
|
63
|
+
min-height: 8rem;
|
|
64
|
+
display: flex;
|
|
65
|
+
flex-direction: column;
|
|
66
|
+
|
|
67
|
+
// The viewport fills the log under its toolbar, whatever the window's height
|
|
68
|
+
.qd-log-viewport {
|
|
69
|
+
flex: 1 1 auto;
|
|
70
|
+
min-height: 0;
|
|
71
|
+
height: auto !important;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
.qd-task-before-log,
|
|
76
|
+
.qd-task-after-log {
|
|
77
|
+
margin-top: 0.75rem;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
.qd-task-header {
|
|
81
|
+
flex: 1;
|
|
82
|
+
min-width: 0;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Resize by the corner; PrimeVue has none of its own
|
|
86
|
+
.qd-task-dialog--resizable {
|
|
87
|
+
resize: both;
|
|
88
|
+
overflow: hidden;
|
|
89
|
+
min-width: min(24rem, 96vw);
|
|
90
|
+
min-height: 16rem;
|
|
54
91
|
}
|
|
55
92
|
|
|
56
93
|
.qd-task-error,
|
package/src/styles/index.scss
CHANGED
package/src/tasks/taskStore.ts
CHANGED
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
* they live in. Runs of a registered kind survive a reload (sessionStorage).
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
|
+
import type { TaskDialogOptions, TaskUiOptions } from './taskUi'
|
|
15
16
|
import { reactive, computed, type ComputedRef } from 'vue'
|
|
16
17
|
import type { LogSource } from '../composables/useLogStream'
|
|
17
18
|
|
|
@@ -55,6 +56,12 @@ export interface TaskKind {
|
|
|
55
56
|
notify?: boolean
|
|
56
57
|
/** Called once the run ends, whatever the outcome (read `run.status`). */
|
|
57
58
|
onSettled?: (run: TaskRun) => void
|
|
59
|
+
/** The follow dialog's window options for this kind, over the app's (#4334). */
|
|
60
|
+
dialog?: TaskDialogOptions
|
|
61
|
+
/** Slot components for this kind's dialog, over the app's. */
|
|
62
|
+
slots?: TaskUiOptions['slots']
|
|
63
|
+
/** A dialog of its own for this kind, instead of TaskDialog. */
|
|
64
|
+
component?: TaskUiOptions['component']
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
export interface TaskConfirm {
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the TaskRunner looks (#4334): the follow dialog's window options, slot
|
|
3
|
+
* components, a replacement dialog, and the tray's row. Layered: qdadm's
|
|
4
|
+
* defaults, then the app's (configureTasks), then the task kind's
|
|
5
|
+
* (registerTaskKind / run options), then a page's own TaskDialog props.
|
|
6
|
+
*
|
|
7
|
+
* configureTasks({ dialog: { width: '56rem', modal: false }, slots: { 'after-log': DeliverySummary } })
|
|
8
|
+
* registerTaskKind('deploy', { task, log, dialog: { maximizable: false }, component: DeployDialog })
|
|
9
|
+
*/
|
|
10
|
+
import { shallowReactive, type Component } from 'vue'
|
|
11
|
+
|
|
12
|
+
export interface TaskDialogOptions {
|
|
13
|
+
width?: string
|
|
14
|
+
modal?: boolean
|
|
15
|
+
/** Move by the title bar */
|
|
16
|
+
draggable?: boolean
|
|
17
|
+
/** Resize by the corner */
|
|
18
|
+
resizable?: boolean
|
|
19
|
+
/** A full-screen button; Escape leaves full screen first */
|
|
20
|
+
maximizable?: boolean
|
|
21
|
+
/** Where it opens (PrimeVue Dialog position) */
|
|
22
|
+
position?: 'center' | 'top' | 'bottom' | 'left' | 'right' | 'topleft' | 'topright' | 'bottomleft' | 'bottomright'
|
|
23
|
+
/** Extra class on the dialog */
|
|
24
|
+
class?: string
|
|
25
|
+
/** Keep size, position and full screen in localStorage, per app */
|
|
26
|
+
rememberLayout?: boolean
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The TaskDialog slots an app fills with components; each gets `{ run, kind, final }`. */
|
|
30
|
+
export type TaskDialogSlotName = 'header' | 'before-log' | 'after-log' | 'actions' | 'result'
|
|
31
|
+
|
|
32
|
+
export interface TaskUiOptions {
|
|
33
|
+
dialog?: TaskDialogOptions
|
|
34
|
+
slots?: Partial<Record<TaskDialogSlotName, Component>>
|
|
35
|
+
/**
|
|
36
|
+
* Renders instead of TaskDialog, with props `{ runId, options }` and a
|
|
37
|
+
* `close` event; it reads the run through getTaskStore().
|
|
38
|
+
*/
|
|
39
|
+
component?: Component
|
|
40
|
+
tray?: {
|
|
41
|
+
/** Replaces a tray row's content; gets `{ run }` */
|
|
42
|
+
item?: Component
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export const TASK_DIALOG_DEFAULTS: Required<Omit<TaskDialogOptions, 'position' | 'class'>> & Pick<TaskDialogOptions, 'position' | 'class'> = {
|
|
47
|
+
width: '46rem',
|
|
48
|
+
modal: true,
|
|
49
|
+
draggable: true,
|
|
50
|
+
resizable: true,
|
|
51
|
+
maximizable: true,
|
|
52
|
+
rememberLayout: true,
|
|
53
|
+
position: undefined,
|
|
54
|
+
class: undefined,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const app = shallowReactive<TaskUiOptions>({})
|
|
58
|
+
|
|
59
|
+
/** The app's TaskRunner look, once at boot. Later calls merge over earlier ones. */
|
|
60
|
+
export function configureTasks(options: TaskUiOptions): void {
|
|
61
|
+
if (options.dialog) app.dialog = { ...app.dialog, ...options.dialog }
|
|
62
|
+
if (options.slots) app.slots = { ...app.slots, ...options.slots }
|
|
63
|
+
if (options.component !== undefined) app.component = options.component
|
|
64
|
+
if (options.tray) app.tray = { ...app.tray, ...options.tray }
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** For tests: back to qdadm's defaults. */
|
|
68
|
+
export function resetTaskUi(): void {
|
|
69
|
+
delete app.dialog
|
|
70
|
+
delete app.slots
|
|
71
|
+
delete app.component
|
|
72
|
+
delete app.tray
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The app's options (reactive). */
|
|
76
|
+
export function getTaskUi(): Readonly<TaskUiOptions> {
|
|
77
|
+
return app
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** One run's look: defaults, then the app's, then the kind's, then a page's props. */
|
|
81
|
+
export function resolveTaskUi(kind?: TaskUiOptions | null, page?: TaskDialogOptions | null) {
|
|
82
|
+
const strip = (o?: TaskDialogOptions | null) =>
|
|
83
|
+
Object.fromEntries(Object.entries(o ?? {}).filter(([, v]) => v !== undefined)) as TaskDialogOptions
|
|
84
|
+
return {
|
|
85
|
+
dialog: { ...TASK_DIALOG_DEFAULTS, ...strip(app.dialog), ...strip(kind?.dialog), ...strip(page) },
|
|
86
|
+
slots: { ...app.slots, ...kind?.slots } as Partial<Record<TaskDialogSlotName, Component>>,
|
|
87
|
+
component: kind?.component ?? app.component ?? null,
|
|
88
|
+
}
|
|
89
|
+
}
|