@quazardous/qdadm 2.34.0 → 2.36.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.
@@ -15,10 +15,19 @@
15
15
  */
16
16
  import { RouterLink, useRouter, type RouteLocationRaw } from 'vue-router'
17
17
  import { useNotifications } from './NotificationStore'
18
- import type { Notification, NotificationSeverity } from './NotificationStore'
18
+ import type { Notification, NotificationSeverity, StatusItem } from './NotificationStore'
19
+ import { useI18n } from '../i18n/useI18n'
19
20
 
20
21
  const store = useNotifications()
21
22
  const router = useRouter()
23
+ const { tOr } = useI18n()
24
+
25
+ /** A status item with `onClick` (#4171) runs it; one with `to` is a link. Both close the panel. */
26
+ function openStatus(item: StatusItem): void {
27
+ if (!item.onClick && !item.to) return
28
+ store.close()
29
+ item.onClick?.()
30
+ }
22
31
 
23
32
  /** An entry is read when clicked; one with a `to` also takes the user there (#2677). */
24
33
  function openNotification(notif: Notification): void {
@@ -48,11 +57,11 @@ function formatTime(timestamp: number): string {
48
57
  const diffMs = now.getTime() - date.getTime()
49
58
  const diffMins = Math.floor(diffMs / 60000)
50
59
 
51
- if (diffMins < 1) return 'just now'
52
- if (diffMins < 60) return `${diffMins}m ago`
60
+ if (diffMins < 1) return tOr('core.notifications.justNow', 'just now')
61
+ if (diffMins < 60) return tOr('core.notifications.minutesAgo', '{count}m ago', { count: diffMins })
53
62
 
54
63
  const diffHours = Math.floor(diffMins / 60)
55
- if (diffHours < 24) return `${diffHours}h ago`
64
+ if (diffHours < 24) return tOr('core.notifications.hoursAgo', '{count}h ago', { count: diffHours })
56
65
 
57
66
  return date.toLocaleDateString()
58
67
  }
@@ -69,7 +78,7 @@ function formatTime(timestamp: number): string {
69
78
  <button
70
79
  v-if="store.unreadCount.value > 0"
71
80
  class="notification-toolbar-btn"
72
- title="Mark all read"
81
+ :title="tOr('core.notifications.markAllRead', 'Mark all read')"
73
82
  @click="store.markAllRead()"
74
83
  >
75
84
  <i class="pi pi-check-circle" />
@@ -77,14 +86,14 @@ function formatTime(timestamp: number): string {
77
86
  <button
78
87
  v-if="store.notifications.value.length > 0"
79
88
  class="notification-toolbar-btn"
80
- title="Clear all"
89
+ :title="tOr('core.notifications.clearAll', 'Clear all')"
81
90
  @click="store.clearNotifications()"
82
91
  >
83
92
  <i class="pi pi-trash" />
84
93
  </button>
85
94
  <button
86
95
  class="notification-toolbar-btn notification-toolbar-close"
87
- title="Close"
96
+ :title="tOr('core.notifications.close', 'Close')"
88
97
  @click="store.close()"
89
98
  >
90
99
  <i class="pi pi-times" />
@@ -104,13 +113,14 @@ function formatTime(timestamp: number): string {
104
113
  class="notification-status-item"
105
114
  :class="[
106
115
  `notification-status-item--${item.severity}`,
107
- { 'notification-status-item--link': !!item.to }
116
+ { 'notification-status-item--link': !!item.to || !!item.onClick }
108
117
  ]"
109
- @click="item.to ? store.close() : undefined"
118
+ :role="item.onClick && !item.to ? 'button' : undefined"
119
+ @click="openStatus(item)"
110
120
  >
111
121
  <i :class="item.icon || statusIcons[item.severity]" />
112
122
  <span class="notification-status-label">{{ item.label }}</span>
113
- <i v-if="item.to" class="pi pi-chevron-right notification-status-arrow" />
123
+ <i v-if="item.to || item.onClick" class="pi pi-chevron-right notification-status-arrow" />
114
124
  <span v-else-if="item.count != null" class="notification-status-count">{{ item.count }}</span>
115
125
  </component>
116
126
  </div>
@@ -142,7 +152,7 @@ function formatTime(timestamp: number): string {
142
152
  </div>
143
153
  <button
144
154
  class="notification-item-dismiss"
145
- title="Dismiss"
155
+ :title="tOr('core.notifications.dismiss', 'Dismiss')"
146
156
  @click.stop="store.removeNotification(notif.id)"
147
157
  >
148
158
  <i class="pi pi-times" />
@@ -155,7 +165,7 @@ function formatTime(timestamp: number): string {
155
165
  class="notification-panel-empty"
156
166
  >
157
167
  <i class="pi pi-bell" />
158
- <span>No notifications</span>
168
+ <span>{{ tOr('core.notifications.empty', 'No notifications') }}</span>
159
169
  </div>
160
170
  </div>
161
171
  </div>
@@ -76,6 +76,8 @@ export interface StatusItem {
76
76
  icon?: string
77
77
  /** Route location for navigation (vue-router LocationAsRelativeRaw) */
78
78
  to?: { name: string; params?: Record<string, unknown>; query?: Record<string, unknown> }
79
+ /** Called on click, then the panel closes (#4171): reopen a dialog, run an action. */
80
+ onClick?: () => void
79
81
  }
80
82
 
81
83
  export interface NotificationStoreConfig {
package/src/plugin.ts CHANGED
@@ -5,7 +5,8 @@
5
5
  */
6
6
 
7
7
  import type { App } from 'vue'
8
- import type { Router, RouteLocationNormalized, NavigationGuardNext } from 'vue-router'
8
+ import type { Router, RouteLocationNormalized, RouteLocationRaw, NavigationGuardNext } from 'vue-router'
9
+ import type { UserAvatarResolver } from './composables/useUserBox'
9
10
  import { Orchestrator } from './orchestrator/Orchestrator'
10
11
  import { EntityManager } from './entity/EntityManager'
11
12
  import qdadmLogo from './assets/logo.svg'
@@ -50,9 +51,17 @@ export interface AppConfig {
50
51
  shortName?: string
51
52
  logo?: string | null
52
53
  logoSmall?: string | null
53
- favicon?: string | null
54
+ /**
55
+ * The page icon. Default: the page's own `link[rel~=icon]` is kept, the
56
+ * qdadm logo is added only when it has none. `false` / `null`: never touch it.
57
+ */
58
+ favicon?: string | false | null
54
59
  version?: string | null
55
60
  theme?: AppTheme
61
+ /** The signed-in user's profile page (#4157). */
62
+ userRoute?: RouteLocationRaw | null
63
+ /** The sidebar avatar picture (#4157). */
64
+ userAvatar?: UserAvatarResolver | null
56
65
  [key: string]: unknown
57
66
  }
58
67
 
@@ -104,6 +113,22 @@ export interface QdadmPlugin {
104
113
  /**
105
114
  * Creates the qdadm plugin with the given configuration
106
115
  */
116
+ /**
117
+ * Set the page icon (#4166). An explicit `favicon` wins; without one, the
118
+ * page's own `link[rel~=icon]` stays (index.html, or set in JS before the
119
+ * mount) and the qdadm logo is only a fallback; `false` / `null` leave the
120
+ * head alone.
121
+ */
122
+ export function applyFavicon(favicon: string | false | null | undefined, doc: Document = document): void {
123
+ if (favicon === false || favicon === null) return
124
+ const existing = doc.querySelector("link[rel~='icon']")
125
+ if (!favicon && existing) return
126
+ const link = existing || doc.createElement('link')
127
+ link.setAttribute('rel', 'icon')
128
+ link.setAttribute('href', favicon || qdadmLogo)
129
+ if (!existing) doc.head.appendChild(link)
130
+ }
131
+
107
132
  export function createQdadm(options: QdadmOptions): QdadmPlugin {
108
133
  return {
109
134
  install(app: App) {
@@ -146,7 +171,6 @@ export function createQdadm(options: QdadmOptions): QdadmPlugin {
146
171
  shortName: 'Admin',
147
172
  logo: null,
148
173
  logoSmall: null,
149
- favicon: qdadmLogo,
150
174
  version: null,
151
175
  theme: {
152
176
  primary: '#3B82F6',
@@ -238,16 +262,7 @@ export function createQdadm(options: QdadmOptions): QdadmPlugin {
238
262
  }
239
263
  }
240
264
 
241
- // Appliquer le favicon
242
- if (appConfig.favicon) {
243
- const existingLink = document.querySelector("link[rel~='icon']")
244
- const link = existingLink || document.createElement('link')
245
- link.setAttribute('rel', 'icon')
246
- link.setAttribute('href', appConfig.favicon)
247
- if (!existingLink) {
248
- document.head.appendChild(link)
249
- }
250
- }
265
+ applyFavicon(appConfig.favicon)
251
266
  }
252
267
  }
253
268
  }
@@ -120,10 +120,11 @@
120
120
  gap: 0.5rem;
121
121
  width: 100%;
122
122
  padding: 0.5rem 0.625rem;
123
- border: 1px solid var(--p-surface-200);
123
+ // Sidebar colours, like SidebarBox: the sidebar is dark whatever the theme (#4171)
124
+ border: 1px solid var(--p-surface-700, #334155);
124
125
  border-radius: $radius-sm;
125
- background: var(--p-surface-0);
126
- color: inherit;
126
+ background: transparent;
127
+ color: var(--p-surface-200, #e2e8f0);
127
128
  font: inherit;
128
129
  font-size: $font-size-sm;
129
130
  cursor: pointer;
@@ -133,7 +134,7 @@
133
134
  }
134
135
 
135
136
  &:hover {
136
- background: var(--p-surface-50);
137
+ background: var(--p-surface-700, #334155);
137
138
  }
138
139
  }
139
140
 
@@ -206,6 +207,11 @@
206
207
  .sidebar--collapsed .qd-task-tray {
207
208
  padding: 0.25rem;
208
209
 
210
+ .qd-task-tray-button {
211
+ justify-content: center;
212
+ padding: 0.5rem 0.25rem;
213
+ }
214
+
209
215
  .qd-task-tray-label {
210
216
  display: none;
211
217
  }
@@ -366,9 +366,10 @@ function createTaskStore() {
366
366
  }
367
367
 
368
368
  /**
369
- * Start a task and follow it. Resolves with the run once the task is
370
- * queued (or null when the confirmation was declined); the run itself
371
- * moves on in the store.
369
+ * Start a task and follow it. Resolves with the run once the task has
370
+ * started (queued), NOT when it ends, or with null when the confirmation
371
+ * was declined. The run moves on in the store: await `run.finished` (or
372
+ * pass `onSettled`) for its outcome.
372
373
  */
373
374
  async function run(options: RunOptions): Promise<TaskRun | null> {
374
375
  const base = options.kind ? kinds.get(options.kind) : undefined
@@ -0,0 +1,76 @@
1
+ /**
2
+ * useTaskNotifications - running tasks in the notification zone (#4171)
3
+ *
4
+ * With the NotificationModule on, each running task is a status item of the
5
+ * notification panel (a click reopens its dialog) and the badge shows its
6
+ * work-in-progress ring until the task ends; the end itself is a toast, kept
7
+ * in the history. TaskHost calls it, so any layout that hosts tasks gets it.
8
+ *
9
+ * `showTray` says whether TaskTray should show too: `tasks.tray` in the
10
+ * Kernel options when set, else only without the notification zone.
11
+ */
12
+ import { computed, inject, onBeforeUnmount, watch, type ComputedRef } from 'vue'
13
+ import { useI18n } from '../i18n/useI18n'
14
+ import { NOTIFICATION_KEY, type NotificationStore } from '../notifications/NotificationStore'
15
+ import { getTaskStore, type TaskRun } from './taskStore'
16
+
17
+ export interface TasksConfig {
18
+ /** Show TaskTray in the sidebar. Default: only when the notification zone is off. */
19
+ tray?: boolean
20
+ }
21
+
22
+ const STATUS_PREFIX = 'task:'
23
+
24
+ /** Whether TaskTray shows, for the current app. */
25
+ export function useTaskTrayVisible(): ComputedRef<boolean> {
26
+ const notifications = inject<NotificationStore | null>(NOTIFICATION_KEY, null)
27
+ const config = inject<TasksConfig>('qdadmTasksConfig', {})
28
+ return computed(() => config.tray ?? !notifications)
29
+ }
30
+
31
+ export function useTaskNotifications(): void {
32
+ const notifications = inject<NotificationStore | null>(NOTIFICATION_KEY, null)
33
+ if (!notifications) return
34
+ const store = getTaskStore()
35
+ const { t } = useI18n()
36
+ const tracked = new Set<string>()
37
+ const shown = new Set<string>()
38
+
39
+ const stateText = (run: TaskRun): string =>
40
+ run.progress !== null ? `${Math.round(run.progress)} %` : t(`core.task.status.${run.status}`)
41
+
42
+ const stop = watch(
43
+ () => store.active.value.map((r) => ({ run: r, label: r.label, status: r.status, progress: r.progress })),
44
+ (entries) => {
45
+ const ids = new Set<string>()
46
+ for (const { run } of entries) {
47
+ const id = STATUS_PREFIX + run.id
48
+ ids.add(id)
49
+ notifications.registerStatus({
50
+ id,
51
+ label: `${run.label} — ${stateText(run)}`,
52
+ severity: 'nominal',
53
+ icon: 'pi pi-spin pi-spinner',
54
+ onClick: () => store.open(run.id),
55
+ })
56
+ shown.add(id)
57
+ if (!tracked.has(run.id)) {
58
+ tracked.add(run.id)
59
+ void notifications.track(run.finished).finally(() => tracked.delete(run.id))
60
+ }
61
+ }
62
+ for (const id of [...shown]) {
63
+ if (ids.has(id)) continue
64
+ notifications.removeStatus(id)
65
+ shown.delete(id)
66
+ }
67
+ },
68
+ { immediate: true }
69
+ )
70
+
71
+ onBeforeUnmount(() => {
72
+ stop()
73
+ for (const id of shown) notifications.removeStatus(id)
74
+ shown.clear()
75
+ })
76
+ }
@@ -3,7 +3,9 @@
3
3
  *
4
4
  * ```ts
5
5
  * const tasks = useTaskRunner()
6
- * tasks.run({
6
+ * // run() resolves once the task has STARTED (queued), not when it ends;
7
+ * // it resolves with null when the user declines the confirmation.
8
+ * const run = await tasks.run({
7
9
  * label: `Create box ${name}`,
8
10
  * start: () => api.post('/boxes', { name }).then((r) => r.data), // → { task_id }
9
11
  * task: { entity: 'tasks' }, // follow the task record
@@ -11,6 +13,12 @@
11
13
  * cancel: (id) => api.post(`/tasks/${id}/cancel`),
12
14
  * to: (id) => ({ name: 'task-show', params: { id } }),
13
15
  * })
16
+ * // The end: run.finished settles with the final run, whatever the outcome
17
+ * const end = await run?.finished
18
+ * if (end?.status === 'failed') console.warn(end.error)
19
+ *
20
+ * // Or react to the end without awaiting it (also fires after a reload resume)
21
+ * tasks.run({ label: 'Refresh db', start, task: { entity: 'tasks' }, onSettled: () => list.refresh() })
14
22
  *
15
23
  * // As a row action, with a typed confirmation
16
24
  * list.addAction('destroy', {
@@ -34,6 +42,7 @@ export function useTaskRunner() {
34
42
  signals: inject('qdadmSignals', null),
35
43
  })
36
44
  return {
45
+ /** Start a task. Resolves once it has started (or null when declined); await `run.finished` for its end. */
37
46
  run: store.run,
38
47
  cancel: store.cancel,
39
48
  dismiss: store.dismiss,