@quazardous/qdadm 2.47.0 → 2.49.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 (35) hide show
  1. package/dist/styles/qdadm.css +1 -1
  2. package/package.json +1 -1
  3. package/src/chain/StackHydrator.ts +82 -0
  4. package/src/components/index.ts +3 -0
  5. package/src/components/layout/EntityItemLayout.vue +120 -0
  6. package/src/components/layout/PageNav.vue +24 -2
  7. package/src/components/tasks/TaskDialog.vue +13 -157
  8. package/src/components/tasks/TaskHost.vue +15 -2
  9. package/src/components/tasks/TaskRunView.vue +197 -0
  10. package/src/components/tasks/TaskSequenceDialog.vue +157 -0
  11. package/src/components/tasks/TaskTray.vue +33 -13
  12. package/src/composables/useLiveEntity.ts +3 -1
  13. package/src/composables/useNavigation.ts +3 -4
  14. package/src/entity/EntityManager.cache.ts +49 -8
  15. package/src/entity/EntityManager.interface.ts +6 -0
  16. package/src/entity/EntityManager.ts +8 -0
  17. package/src/i18n/defaults/core.en.generated.ts +13 -0
  18. package/src/i18n/defaults/core.en.yml +13 -0
  19. package/src/i18n/defaults/core.fr.generated.ts +13 -0
  20. package/src/i18n/defaults/core.fr.yml +13 -0
  21. package/src/index.ts +7 -0
  22. package/src/kernel/Kernel.routing.ts +22 -31
  23. package/src/kernel/KernelContext.routing.ts +9 -0
  24. package/src/kernel/KernelContext.ts +3 -0
  25. package/src/kernel/KernelContext.types.ts +6 -0
  26. package/src/kernel/itemTabs.ts +99 -0
  27. package/src/module/moduleRegistry.ts +26 -0
  28. package/src/security/index.ts +1 -0
  29. package/src/security/routeAccess.ts +94 -0
  30. package/src/styles/_item-tabs.scss +52 -0
  31. package/src/styles/_tasks.scss +102 -0
  32. package/src/styles/index.scss +1 -0
  33. package/src/tasks/taskStore.ts +503 -14
  34. package/src/tasks/useTaskNotifications.ts +6 -2
  35. package/src/tasks/useTaskRunner.ts +15 -1
@@ -35,6 +35,7 @@
35
35
  * ```
36
36
  */
37
37
 
38
+ import type { ItemTabsOptions } from '../module/moduleRegistry'
38
39
  import type { App, Component } from 'vue'
39
40
  import type { Router, RouteRecordRaw } from 'vue-router'
40
41
  import type { ListenerOptions } from '@quazardous/quarkernel'
@@ -207,6 +208,8 @@ export interface KernelContext {
207
208
  routeFamily(base: string, prefixes: string[]): this
208
209
  crud(entity: string, pages: CrudPages, options?: CrudOptions): this
209
210
  childPage(parentRouteName: string, pageName: string, options: ChildPageOptions): this
211
+ /** Show an entity's item as tabs: its header, a tab per page of the item, the page below (#4963) */
212
+ itemTabs(entity: string, options?: ItemTabsOptions): this
210
213
 
211
214
  // Zones / Vue (KernelContext.zones.ts)
212
215
  zone(name: string, options?: ZoneOptions): this
@@ -183,6 +183,12 @@ export interface ChildPageOptions {
183
183
  meta?: Record<string, unknown>
184
184
  /** Explicit URL param name for the parent id (see CrudOptions.parentParam). */
185
185
  parentParam?: string
186
+ /**
187
+ * Required on top of reading the parent item, which every child page needs
188
+ * (#4962): `'entity:instances:update'` for a page that acts. Same as
189
+ * `meta.permission`.
190
+ */
191
+ permission?: string | string[]
186
192
  }
187
193
 
188
194
  /** User entity options */
@@ -0,0 +1,99 @@
1
+ /**
2
+ * A tabbed item (#4963): the pages of an item become children of one frame
3
+ * route, whose component (EntityItemLayout) shows the item's header, a tab per
4
+ * page and, in its `router-view`, the page.
5
+ *
6
+ * books/:bookId (frame, no name) EntityItemLayout
7
+ * '' book-show the item's own page, "Details"
8
+ * info book-info a childPage
9
+ * loans loan a child crud list
10
+ * loans/create loan-create …and its forms
11
+ *
12
+ * Route names, full paths and every route's own meta are unchanged; the frame
13
+ * adds only `meta.itemTabs`, which the guard, the breadcrumb and the active
14
+ * stack do not read. The pages of the item are those whose `meta.parent` is the
15
+ * entity, under the same item path, plus the entity's show route when it sits
16
+ * on that path.
17
+ */
18
+ import type { RouteRecordRaw } from 'vue-router'
19
+ import type { ItemTabsOptions } from '../module/moduleRegistry'
20
+
21
+ /** What the frame route carries in `meta.itemTabs` */
22
+ export interface ItemTabsMeta extends ItemTabsOptions {
23
+ entity: string
24
+ /** The route param carrying the item's id */
25
+ param: string
26
+ }
27
+
28
+ type Route = RouteRecordRaw & { meta?: Record<string, unknown>; name?: string | symbol }
29
+
30
+ const EntityItemLayout = () => import('../components/layout/EntityItemLayout.vue')
31
+
32
+ /** Nest the pages of each tabbed entity under a frame route. Routes of other entities pass through, in order. */
33
+ export function nestItemTabs(routes: RouteRecordRaw[], frames: Map<string, ItemTabsOptions>): RouteRecordRaw[] {
34
+ let result = routes as Route[]
35
+ for (const [entity, options] of frames) {
36
+ result = nestOne(result, entity, options)
37
+ }
38
+ return result
39
+ }
40
+
41
+ function parentOf(route: Route): { entity?: string; param?: string } | undefined {
42
+ return route.meta?.parent as { entity?: string; param?: string } | undefined
43
+ }
44
+
45
+ function nestOne(routes: Route[], entity: string, options: ItemTabsOptions): Route[] {
46
+ const first = routes.find((r) => parentOf(r)?.entity === entity && parentOf(r)?.param)
47
+ if (!first) {
48
+ console.warn(`[qdadm] itemTabs('${entity}'): no page of an item of '${entity}' (childPage or child crud) — nothing to show as tabs`)
49
+ return routes
50
+ }
51
+ const param = parentOf(first)!.param!
52
+ const marker = `:${param}`
53
+ const at = first.path.indexOf(`/${marker}`)
54
+ if (at < 0) return routes
55
+ const framePath = first.path.slice(0, at + marker.length + 1)
56
+
57
+ const inFrame = (r: Route): boolean => {
58
+ if (parentOf(r)?.entity === entity) return r.path.startsWith(`${framePath}/`)
59
+ // The item's own page, when it sits on the frame's path
60
+ return r.meta?.entity === entity && r.path === framePath && typeof r.name === 'string' && /-show$/.test(r.name)
61
+ }
62
+ const pages = routes.filter(inFrame)
63
+ // A page of the item whose parent param differs (a child crud namespaces it,
64
+ // a childPage keeps the id field) cannot share the frame: say so
65
+ const apart = routes.filter((r) => parentOf(r)?.entity === entity && !inFrame(r)).map((r) => String(r.name ?? r.path))
66
+ if (apart.length) {
67
+ console.warn(
68
+ `[qdadm] itemTabs('${entity}'): ${apart.join(', ')} not in the tabs — their parent param is not ':${param}'. ` +
69
+ `Give them parentParam: '${param}'.`
70
+ )
71
+ }
72
+ const show = pages.find((r) => r.path === framePath)
73
+
74
+ const children: RouteRecordRaw[] = pages.map((r) => ({ ...r, path: r.path === framePath ? '' : r.path.slice(framePath.length + 1) }) as RouteRecordRaw)
75
+ if (!show) {
76
+ // No page of its own: the item opens on its first tab
77
+ const firstTab = pages.find((r) => typeof r.name === 'string' && !/-(create|edit|new|show)$/.test(r.name) && !r.path.slice(framePath.length + 1).includes(':'))
78
+ if (firstTab) children.unshift({ path: '', redirect: (to) => ({ name: firstTab.name as string, params: to.params }) })
79
+ }
80
+
81
+ const frame: Route = {
82
+ path: framePath,
83
+ component: (options.component as RouteRecordRaw['component']) ?? EntityItemLayout,
84
+ meta: { itemTabs: { ...options, entity, param } satisfies ItemTabsMeta },
85
+ children,
86
+ } as Route
87
+
88
+ const out: Route[] = []
89
+ let placed = false
90
+ for (const r of routes) {
91
+ if (!inFrame(r)) {
92
+ out.push(r)
93
+ } else if (!placed) {
94
+ out.push(frame)
95
+ placed = true
96
+ }
97
+ }
98
+ return out
99
+ }
@@ -169,6 +169,21 @@ const navItems: NavItemWithSection[] = []
169
169
  const routeFamilies: Record<string, string[]> = {}
170
170
  const navSections = new Map<string, NavItem[]>()
171
171
  const entityConfigs = new Map<string, EntityConfig>()
172
+ /** Entities shown as a tabbed item (#4963), by entity name */
173
+ const itemTabs = new Map<string, ItemTabsOptions>()
174
+
175
+ /**
176
+ * A tabbed item (#4963): the item's header, one tab per page of the item, and
177
+ * the page below. Declared by entity: `ctx.itemTabs('instances', { header })`.
178
+ */
179
+ export interface ItemTabsOptions {
180
+ /** The header, given `{ item, manager, loading, id }`. Default: the entity's label and the item's. */
181
+ header?: unknown
182
+ /** The item's own page as the first tab: `false` to leave it out, or its label. Default: shown, "Details". */
183
+ details?: boolean | string
184
+ /** The frame itself, instead of EntityItemLayout */
185
+ component?: unknown
186
+ }
172
187
 
173
188
  // Configurable section order (set via setSectionOrder or bootstrap)
174
189
  let sectionOrder: string[] = []
@@ -262,6 +277,16 @@ const registry = {
262
277
  addEntity(name: string, config: EntityConfig): void {
263
278
  entityConfigs.set(name, config)
264
279
  },
280
+
281
+ /** Show an entity's item as tabs (#4963) */
282
+ addItemTabs(entity: string, options: ItemTabsOptions = {}): void {
283
+ itemTabs.set(entity, options)
284
+ },
285
+ }
286
+
287
+ /** The entities shown as a tabbed item (#4963) */
288
+ export function getItemTabs(): Map<string, ItemTabsOptions> {
289
+ return itemTabs
265
290
  }
266
291
 
267
292
  /**
@@ -519,6 +544,7 @@ export function resetRegistry(): void {
519
544
  Object.keys(routeFamilies).forEach((key) => delete routeFamilies[key])
520
545
  navSections.clear()
521
546
  entityConfigs.clear()
547
+ itemTabs.clear()
522
548
  sectionOrder = []
523
549
  alteredNavSections = null
524
550
  alterationPromise = null
@@ -93,3 +93,4 @@ export {
93
93
  * Used by PermissionRegistry.registerEntity()
94
94
  */
95
95
  export const ENTITY_ACTIONS = ['read', 'list', 'create', 'update', 'delete'] as const
96
+ export { canOpenRoute, routeDenial, type RouteDenial, type RouteAccessDeps, type RouteLike } from './routeAccess'
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Who may open a route: one rule for the router guard, the menu and PageNav
3
+ * (#4962), so the three cannot drift apart.
4
+ *
5
+ * - Every matched record's `meta.permission` must be granted (#4332): a
6
+ * parent's covers its children.
7
+ * - The route's entity must allow the action it declares: `list` for a list
8
+ * route, `read` for anything else (#2497). The entity is `meta.entity`, or,
9
+ * for a child page that has none of its own, the parent's
10
+ * (`meta.parent.entity`): a page on an item is governed by that item.
11
+ *
12
+ * An app without a security checker checks no permission; an entity that is
13
+ * not registered (yet) is not checked.
14
+ */
15
+
16
+ /** The part of a resolved route this reads */
17
+ export interface RouteLike {
18
+ meta?: Record<string, unknown>
19
+ matched?: Array<{ meta?: Record<string, unknown> }>
20
+ }
21
+
22
+ export interface RouteAccessDeps {
23
+ orchestrator?: {
24
+ isRegistered?: (name: string) => boolean
25
+ get: (name: string) => unknown
26
+ } | null
27
+ checker?: { isGranted: (attribute: string, subject?: unknown) => boolean } | null
28
+ }
29
+
30
+ interface ManagerAccess {
31
+ canList?: () => boolean
32
+ canRead?: () => boolean
33
+ labelPlural?: string
34
+ }
35
+
36
+ /** Why a route is refused, or null when it may be opened */
37
+ export type RouteDenial =
38
+ | { kind: 'permission'; permission: string }
39
+ | { kind: 'entity'; entity: string; action: 'list' | 'read'; manager: ManagerAccess }
40
+
41
+ /** Every permission the route's matched records require */
42
+ export function routePermissions(route: RouteLike): string[] {
43
+ const records = route.matched?.length ? route.matched : [{ meta: route.meta }]
44
+ return records.flatMap((record) => {
45
+ const p = record.meta?.permission
46
+ return (Array.isArray(p) ? p : [p]).filter((x): x is string => typeof x === 'string' && x !== '')
47
+ })
48
+ }
49
+
50
+ /** The entity governing the route: its own, else its parent item's */
51
+ export function routeEntity(route: RouteLike): string | undefined {
52
+ const own = route.meta?.entity
53
+ if (typeof own === 'string' && own) return own
54
+ const parent = (route.meta?.parent as { entity?: unknown } | undefined)?.entity
55
+ return typeof parent === 'string' && parent ? parent : undefined
56
+ }
57
+
58
+ /** The action the route performs: `list` when it declares it, `read` otherwise */
59
+ export function routeAction(route: RouteLike): 'list' | 'read' {
60
+ // A child page runs on an item: `read` of the parent, whatever it declares
61
+ if (!route.meta?.entity) return 'read'
62
+ return route.meta?.entityAction === 'list' ? 'list' : 'read'
63
+ }
64
+
65
+ /** The permission check alone: the first one missing, or null */
66
+ export function missingPermission(route: RouteLike, deps: RouteAccessDeps): string | null {
67
+ if (!deps.checker) return null
68
+ return routePermissions(route).find((p) => !deps.checker!.isGranted(p)) ?? null
69
+ }
70
+
71
+ /** The entity check alone: the denial, or null */
72
+ export function entityDenial(route: RouteLike, deps: RouteAccessDeps): Extract<RouteDenial, { kind: 'entity' }> | null {
73
+ const entity = routeEntity(route)
74
+ const orchestrator = deps.orchestrator
75
+ if (!entity || !orchestrator) return null
76
+ if (orchestrator.isRegistered && !orchestrator.isRegistered(entity)) return null
77
+ const manager = orchestrator.get(entity) as ManagerAccess | null | undefined
78
+ if (!manager) return null
79
+ const action = routeAction(route)
80
+ const allowed = action === 'list' && manager.canList ? manager.canList() : manager.canRead ? manager.canRead() : true
81
+ return allowed ? null : { kind: 'entity', entity, action, manager }
82
+ }
83
+
84
+ /** Why the route is refused, or null when it may be opened */
85
+ export function routeDenial(route: RouteLike, deps: RouteAccessDeps): RouteDenial | null {
86
+ const permission = missingPermission(route, deps)
87
+ if (permission !== null) return { kind: 'permission', permission }
88
+ return entityDenial(route, deps)
89
+ }
90
+
91
+ /** Whether the route may be opened */
92
+ export function canOpenRoute(route: RouteLike, deps: RouteAccessDeps): boolean {
93
+ return routeDenial(route, deps) === null
94
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A tabbed item (#4963): EntityItemLayout's header and tab bar
3
+ */
4
+
5
+ @use 'variables' as *;
6
+
7
+ .qd-item-tabs-header {
8
+ display: flex;
9
+ flex-direction: column;
10
+ gap: $space-2xs;
11
+ margin-bottom: $space-md;
12
+ }
13
+
14
+ .qd-item-tabs-entity {
15
+ font-size: $font-size-xs;
16
+ text-transform: uppercase;
17
+ letter-spacing: 0.04em;
18
+ color: var(--p-text-muted-color);
19
+ }
20
+
21
+ .qd-item-tabs-title {
22
+ margin: 0;
23
+ font-size: $font-size-2xl;
24
+ font-weight: 600;
25
+ }
26
+
27
+ .qd-item-tabs-bar {
28
+ display: flex;
29
+ flex-wrap: wrap;
30
+ gap: $space-xs;
31
+ margin-bottom: $space-lg;
32
+ border-bottom: 1px solid var(--p-content-border-color);
33
+ }
34
+
35
+ .qd-item-tabs-tab {
36
+ padding: $space-sm $space-md;
37
+ margin-bottom: -1px;
38
+ border-bottom: 2px solid transparent;
39
+ color: var(--p-text-muted-color);
40
+ text-decoration: none;
41
+ font-size: $font-size-sm;
42
+
43
+ &:hover {
44
+ color: var(--p-text-color);
45
+ }
46
+
47
+ &--active {
48
+ color: var(--p-primary-color);
49
+ border-bottom-color: var(--p-primary-color);
50
+ font-weight: 600;
51
+ }
52
+ }
@@ -72,6 +72,108 @@
72
72
  }
73
73
  }
74
74
 
75
+ // TaskRunView fills the window like the content did (#4934)
76
+ .qd-task-run-view {
77
+ display: flex;
78
+ flex-direction: column;
79
+ flex: 1 1 auto;
80
+ min-height: 0;
81
+ }
82
+
83
+ // The sequence window: the list of steps (#4934)
84
+ .qd-task-sequence-header {
85
+ display: flex;
86
+ align-items: center;
87
+ gap: 0.75rem;
88
+ }
89
+
90
+ .qd-task-sequence-list {
91
+ list-style: none;
92
+ margin: 0;
93
+ padding: 0;
94
+ display: flex;
95
+ flex-direction: column;
96
+ gap: 0.25rem;
97
+ }
98
+
99
+ .qd-task-sequence-step {
100
+ display: flex;
101
+ align-items: center;
102
+ gap: 0.75rem;
103
+ width: 100%;
104
+ padding: 0.5rem 0.75rem;
105
+ border: 1px solid var(--p-content-border-color);
106
+ border-radius: $radius-sm;
107
+ background: transparent;
108
+ color: inherit;
109
+ font: inherit;
110
+ text-align: left;
111
+ cursor: pointer;
112
+
113
+ &:hover:not(:disabled) { background: var(--p-content-hover-background); }
114
+ &:disabled { cursor: default; }
115
+ &:focus-visible { outline: 2px solid var(--p-primary-color); outline-offset: 1px; }
116
+
117
+ &--current {
118
+ border-color: var(--qd-task-running-color, var(--p-orange-500));
119
+ box-shadow: inset 3px 0 0 var(--qd-task-running-color, var(--p-orange-500));
120
+ }
121
+ &--pending,
122
+ &--skipped { color: var(--p-text-muted-color); }
123
+ &--succeeded .qd-task-sequence-icon { color: var(--qd-task-done-color, var(--p-green-600)); }
124
+ &--failed .qd-task-sequence-icon { color: var(--p-red-600); }
125
+ &--running .qd-task-sequence-icon,
126
+ &--queued .qd-task-sequence-icon,
127
+ &--starting .qd-task-sequence-icon { color: var(--qd-task-running-color, var(--p-orange-500)); }
128
+ }
129
+
130
+ .qd-task-sequence-main {
131
+ flex: 1;
132
+ min-width: 0;
133
+ display: flex;
134
+ flex-direction: column;
135
+ gap: 0.125rem;
136
+ }
137
+
138
+ .qd-task-sequence-label { font-weight: 600; }
139
+
140
+ .qd-task-sequence-recap {
141
+ font-size: $font-size-sm;
142
+ color: var(--p-text-muted-color);
143
+ overflow-wrap: anywhere;
144
+
145
+ .qd-task-sequence-step--failed & { color: var(--p-red-700); }
146
+ }
147
+
148
+ .qd-task-sequence-progress {
149
+ height: 0.375rem;
150
+ margin-top: 0.25rem;
151
+ }
152
+
153
+ .qd-task-sequence-state,
154
+ .qd-task-sequence-duration {
155
+ font-size: $font-size-sm;
156
+ color: var(--p-text-muted-color);
157
+ white-space: nowrap;
158
+ }
159
+
160
+ .qd-task-sequence-duration {
161
+ min-width: 4rem;
162
+ text-align: right;
163
+ font-variant-numeric: tabular-nums;
164
+ }
165
+
166
+ .qd-task-sequence-detail-title {
167
+ margin-bottom: 0.75rem;
168
+ font-weight: 600;
169
+ }
170
+
171
+ .qd-task-sequence-detail-index {
172
+ margin-right: 0.5rem;
173
+ color: var(--p-text-muted-color);
174
+ font-variant-numeric: tabular-nums;
175
+ }
176
+
75
177
  .qd-task-before-log,
76
178
  .qd-task-after-log {
77
179
  margin-top: 0.75rem;
@@ -37,6 +37,7 @@
37
37
  @use './sessions';
38
38
  @use './email';
39
39
  @use './tasks';
40
+ @use './item-tabs';
40
41
  @use './pending';
41
42
  @use './dialogs';
42
43
  @use './markdown';