@quazardous/qdadm 2.48.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.
- package/dist/styles/qdadm.css +1 -1
- package/package.json +1 -1
- package/src/chain/StackHydrator.ts +82 -0
- package/src/components/index.ts +1 -0
- package/src/components/layout/EntityItemLayout.vue +120 -0
- package/src/components/layout/PageNav.vue +24 -2
- package/src/composables/useLiveEntity.ts +3 -1
- package/src/composables/useNavigation.ts +3 -4
- package/src/entity/EntityManager.cache.ts +49 -8
- package/src/entity/EntityManager.interface.ts +6 -0
- package/src/entity/EntityManager.ts +8 -0
- package/src/index.ts +2 -0
- package/src/kernel/Kernel.routing.ts +22 -31
- package/src/kernel/KernelContext.routing.ts +9 -0
- package/src/kernel/KernelContext.ts +3 -0
- package/src/kernel/KernelContext.types.ts +6 -0
- package/src/kernel/itemTabs.ts +99 -0
- package/src/module/moduleRegistry.ts +26 -0
- package/src/security/index.ts +1 -0
- package/src/security/routeAccess.ts +94 -0
- package/src/styles/_item-tabs.scss +52 -0
- package/src/styles/index.scss +1 -0
- package/src/tasks/taskStore.ts +92 -2
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* EntityItemLayout - a tabbed item (#4963)
|
|
4
|
+
*
|
|
5
|
+
* The frame of `ctx.itemTabs(entity)`: the item's header, one tab per page of
|
|
6
|
+
* the item (its own page as "Details", its child pages and child lists, in
|
|
7
|
+
* declaration order, those the user may open), and the page in a
|
|
8
|
+
* `router-view`. A tab switch changes only the page: the header stays, and the
|
|
9
|
+
* item comes from the active stack, which reads it again when it is
|
|
10
|
+
* invalidated (#4960).
|
|
11
|
+
*
|
|
12
|
+
* Inside it, `<PageNav/>` stays silent: the tabs are the navigation.
|
|
13
|
+
*/
|
|
14
|
+
import { computed, inject, provide, type Component } from 'vue'
|
|
15
|
+
import { RouterLink, RouterView, useRoute, useRouter, type RouteRecordNormalized, type RouteRecordRaw } from 'vue-router'
|
|
16
|
+
import { useStackHydrator } from '../../chain/useStackHydrator'
|
|
17
|
+
import { useI18n } from '../../i18n/useI18n'
|
|
18
|
+
import { canOpenRoute, type RouteAccessDeps } from '../../security/routeAccess'
|
|
19
|
+
import type { ItemTabsMeta } from '../../kernel/itemTabs'
|
|
20
|
+
|
|
21
|
+
interface ManagerView {
|
|
22
|
+
label?: string
|
|
23
|
+
labelPlural?: string
|
|
24
|
+
getEntityLabel?: (item: unknown) => string | null
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const route = useRoute()
|
|
28
|
+
const router = useRouter()
|
|
29
|
+
const { tOr } = useI18n()
|
|
30
|
+
const hydrator = useStackHydrator()
|
|
31
|
+
const orchestrator = inject<(RouteAccessDeps['orchestrator'] & { get: (name: string) => unknown }) | null>('qdadmOrchestrator', null)
|
|
32
|
+
const checker = inject<RouteAccessDeps['checker']>('qdadmSecurityChecker', null)
|
|
33
|
+
|
|
34
|
+
provide('qdadmItemTabs', true)
|
|
35
|
+
|
|
36
|
+
/** This frame's record: the innermost matched record carrying meta.itemTabs */
|
|
37
|
+
const frame = computed<RouteRecordNormalized | undefined>(() => [...route.matched].reverse().find((r) => r.meta?.itemTabs))
|
|
38
|
+
const config = computed(() => frame.value?.meta.itemTabs as ItemTabsMeta | undefined)
|
|
39
|
+
const manager = computed(() => (config.value ? (orchestrator?.get(config.value.entity) as ManagerView | null) : null))
|
|
40
|
+
const id = computed(() => (config.value ? (route.params[config.value.param] as string | undefined) ?? null : null))
|
|
41
|
+
|
|
42
|
+
// Read through the levels array each time: the stack replaces it on every
|
|
43
|
+
// hydration, while a level object keeps its identity as its data changes
|
|
44
|
+
const findLevel = () =>
|
|
45
|
+
hydrator.levels.value.find((l) => l.entity === config.value?.entity && String(l.id) === String(id.value)) ?? null
|
|
46
|
+
const item = computed(() => findLevel()?.data ?? null)
|
|
47
|
+
const loading = computed(() => !findLevel()?.hydrated)
|
|
48
|
+
const title = computed(() => (item.value ? manager.value?.getEntityLabel?.(item.value) : null) ?? id.value ?? '')
|
|
49
|
+
|
|
50
|
+
interface Tab {
|
|
51
|
+
name: string
|
|
52
|
+
label: string
|
|
53
|
+
href: string
|
|
54
|
+
exact: boolean
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function tabLabel(child: RouteRecordRaw): string {
|
|
58
|
+
if (child.path === '') {
|
|
59
|
+
const details = config.value?.details
|
|
60
|
+
return typeof details === 'string' ? details : tOr('breadcrumb.details', 'Details')
|
|
61
|
+
}
|
|
62
|
+
const meta = (child.meta ?? {}) as { navLabel?: string; entity?: string }
|
|
63
|
+
if (meta.navLabel) return meta.navLabel
|
|
64
|
+
const childManager = meta.entity ? (orchestrator?.get(meta.entity) as ManagerView | null) : null
|
|
65
|
+
return childManager?.labelPlural || String(child.name)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const tabs = computed<Tab[]>(() => {
|
|
69
|
+
const children = (frame.value?.children ?? []) as RouteRecordRaw[]
|
|
70
|
+
const out: Tab[] = []
|
|
71
|
+
for (const child of children) {
|
|
72
|
+
if (typeof child.name !== 'string' || child.redirect) continue
|
|
73
|
+
// Forms and a child's own record are not tabs: they open from the tab's page
|
|
74
|
+
if (/-(create|edit|new|show)$/.test(child.name) && child.path !== '') continue
|
|
75
|
+
if (child.path.includes(':')) continue
|
|
76
|
+
if (child.path === '' && config.value?.details === false) continue
|
|
77
|
+
let resolved
|
|
78
|
+
try {
|
|
79
|
+
resolved = router.resolve({ name: child.name, params: route.params })
|
|
80
|
+
} catch {
|
|
81
|
+
continue
|
|
82
|
+
}
|
|
83
|
+
if (!canOpenRoute(resolved, { orchestrator, checker })) continue
|
|
84
|
+
out.push({ name: child.name, label: tabLabel(child), href: resolved.path, exact: child.path === '' })
|
|
85
|
+
}
|
|
86
|
+
return out
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
const isActive = (tab: Tab): boolean =>
|
|
90
|
+
tab.exact ? route.path === tab.href : route.path === tab.href || route.path.startsWith(`${tab.href}/`)
|
|
91
|
+
|
|
92
|
+
const header = computed(() => config.value?.header as Component | undefined)
|
|
93
|
+
</script>
|
|
94
|
+
|
|
95
|
+
<template>
|
|
96
|
+
<div class="qd-item-tabs">
|
|
97
|
+
<header class="qd-item-tabs-header">
|
|
98
|
+
<component :is="header" v-if="header" :item="item" :manager="manager" :loading="loading" :id="id" />
|
|
99
|
+
<template v-else>
|
|
100
|
+
<span v-if="manager?.label" class="qd-item-tabs-entity">{{ manager.label }}</span>
|
|
101
|
+
<h1 class="qd-item-tabs-title">{{ title }}</h1>
|
|
102
|
+
</template>
|
|
103
|
+
</header>
|
|
104
|
+
<nav v-if="tabs.length > 1" class="qd-item-tabs-bar" :aria-label="title">
|
|
105
|
+
<RouterLink
|
|
106
|
+
v-for="tab in tabs"
|
|
107
|
+
:key="tab.name"
|
|
108
|
+
:to="tab.href"
|
|
109
|
+
class="qd-item-tabs-tab"
|
|
110
|
+
:class="{ 'qd-item-tabs-tab--active': isActive(tab) }"
|
|
111
|
+
:aria-current="isActive(tab) ? 'page' : undefined"
|
|
112
|
+
>
|
|
113
|
+
{{ tab.label }}
|
|
114
|
+
</RouterLink>
|
|
115
|
+
</nav>
|
|
116
|
+
<div class="qd-item-tabs-page">
|
|
117
|
+
<RouterView />
|
|
118
|
+
</div>
|
|
119
|
+
</div>
|
|
120
|
+
</template>
|
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
* Auto-detects from current route:
|
|
13
13
|
* - Navlinks: sibling routes (same parent entity + param) or children routes
|
|
14
14
|
*
|
|
15
|
+
* Links the user cannot open are left out (#4962): the same rule as the
|
|
16
|
+
* router guard and the menu (security/routeAccess).
|
|
17
|
+
*
|
|
15
18
|
* Props:
|
|
16
19
|
* - showDetailsLink: Show "Details" link in navlinks (default: false)
|
|
17
20
|
*/
|
|
@@ -20,6 +23,7 @@ import { useRoute, useRouter } from 'vue-router'
|
|
|
20
23
|
import { getSiblingRoutes, getChildRoutes, routeParamsSatisfied, type ModuleRoute, type ParentConfig } from '../../module/moduleRegistry'
|
|
21
24
|
import { useOrchestrator } from '../../orchestrator/useOrchestrator.js'
|
|
22
25
|
import { useI18n } from '../../i18n/useI18n'
|
|
26
|
+
import { canOpenRoute, type RouteAccessDeps } from '../../security/routeAccess'
|
|
23
27
|
import type { EntityManager } from '../../entity/EntityManager'
|
|
24
28
|
import type { EntityRecord } from '../../types'
|
|
25
29
|
|
|
@@ -41,6 +45,18 @@ const route = useRoute()
|
|
|
41
45
|
const router = useRouter()
|
|
42
46
|
const { getManager } = useOrchestrator()
|
|
43
47
|
const { tOr } = useI18n()
|
|
48
|
+
// null without security: every link shows, as in the menu
|
|
49
|
+
const securityChecker = inject<RouteAccessDeps['checker']>('qdadmSecurityChecker', null)
|
|
50
|
+
const accessOrchestrator = inject<RouteAccessDeps['orchestrator']>('qdadmOrchestrator', null)
|
|
51
|
+
|
|
52
|
+
/** Whether the user may open the link's route (unresolvable: shown, the router decides) */
|
|
53
|
+
function canOpen(link: NavLink): boolean {
|
|
54
|
+
try {
|
|
55
|
+
return canOpenRoute(router.resolve(link.to as never), { orchestrator: accessOrchestrator, checker: securityChecker })
|
|
56
|
+
} catch {
|
|
57
|
+
return true
|
|
58
|
+
}
|
|
59
|
+
}
|
|
44
60
|
|
|
45
61
|
// Parent config from route meta
|
|
46
62
|
const parentConfig = computed<ParentConfig | undefined>(() => route.meta?.parent as ParentConfig | undefined)
|
|
@@ -186,10 +202,16 @@ const allNavlinks = computed<NavLink[]>(() => {
|
|
|
186
202
|
return []
|
|
187
203
|
})
|
|
188
204
|
|
|
205
|
+
// Only what the user may open
|
|
206
|
+
const visibleNavlinks = computed<NavLink[]>(() => allNavlinks.value.filter(canOpen))
|
|
207
|
+
|
|
208
|
+
// Inside a tabbed item (#4963) the tabs are the navigation: no links twice
|
|
209
|
+
const inItemTabs = inject<boolean>('qdadmItemTabs', false)
|
|
210
|
+
|
|
189
211
|
// Sync navlinks to AppLayout via provide/inject
|
|
190
|
-
watch([
|
|
212
|
+
watch([visibleNavlinks, () => route.fullPath], ([links]) => {
|
|
191
213
|
if (navlinksOverride) {
|
|
192
|
-
navlinksOverride.value = links as NavLink[]
|
|
214
|
+
navlinksOverride.value = inItemTabs ? [] : (links as NavLink[])
|
|
193
215
|
}
|
|
194
216
|
}, { immediate: true })
|
|
195
217
|
</script>
|
|
@@ -135,7 +135,9 @@ export function useLiveEntity(
|
|
|
135
135
|
|
|
136
136
|
// Local writes are the manager's own echo: it has already repaired its
|
|
137
137
|
// cache and the page that triggered the write reloads on its own path.
|
|
138
|
-
|
|
138
|
+
// 'app' is the app saying a record changed (`manager.invalidate`, #4959):
|
|
139
|
+
// news to this screen, like a change made elsewhere.
|
|
140
|
+
if (payload.source !== 'remote' && payload.source !== 'app') return
|
|
139
141
|
if (payload.entity !== entityName) return
|
|
140
142
|
|
|
141
143
|
if (options.id) {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* the navigation structure dynamically.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import { routePermissions } from '../security/routeAccess'
|
|
12
13
|
import { computed, inject, ref, onMounted, type ComputedRef, type Ref } from 'vue'
|
|
13
14
|
import { useRoute, useRouter } from 'vue-router'
|
|
14
15
|
import { getNavSections, alterMenuSections, isMenuAltered } from '../module/moduleRegistry'
|
|
@@ -129,10 +130,8 @@ export function useNavigation(): UseNavigationReturn {
|
|
|
129
130
|
|
|
130
131
|
function routePermission(name: string): string | string[] | undefined {
|
|
131
132
|
try {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
return p === undefined ? [] : Array.isArray(p) ? p : [p]
|
|
135
|
-
})
|
|
133
|
+
// The same reading as the router guard and PageNav (#4962)
|
|
134
|
+
return routePermissions(router.resolve({ name }))
|
|
136
135
|
} catch {
|
|
137
136
|
return undefined
|
|
138
137
|
}
|
|
@@ -332,7 +332,7 @@ export function applyCacheMethods(EntityManagerClass: { prototype: any }): void
|
|
|
332
332
|
)
|
|
333
333
|
}
|
|
334
334
|
|
|
335
|
-
// Listen for
|
|
335
|
+
// Listen for changes to this entity that this manager did not make.
|
|
336
336
|
//
|
|
337
337
|
// The invalidation signals were written for local mutations, where the
|
|
338
338
|
// manager that mutates repairs its own cache on the way out. A change that
|
|
@@ -340,27 +340,34 @@ export function applyCacheMethods(EntityManagerClass: { prototype: any }): void
|
|
|
340
340
|
// while claiming to be valid (#1887). Gated on the origin marker: without
|
|
341
341
|
// it, this handler would fire on every local write too and force a refetch
|
|
342
342
|
// of a list the manager is already holding correctly.
|
|
343
|
+
//
|
|
344
|
+
// 'remote' comes from a live stream, 'app' from `invalidate()` (#4959).
|
|
345
|
+
// With an id, only that record's detail entry goes; the list cache goes
|
|
346
|
+
// whole either way, since a changed record can enter or leave a filtered
|
|
347
|
+
// or sorted page, and a complete list cache also answers list() locally.
|
|
343
348
|
cleanups.push(
|
|
344
349
|
signals.on('entity:data-invalidate', (event: { name: string; data: unknown }) => {
|
|
345
|
-
const { entity, source } = (event.data || {}) as {
|
|
350
|
+
const { entity, source, id } = (event.data || {}) as {
|
|
346
351
|
entity?: string
|
|
347
352
|
source?: string
|
|
353
|
+
id?: string | number
|
|
348
354
|
}
|
|
349
|
-
if (source !== 'remote') return
|
|
355
|
+
if (source !== 'remote' && source !== 'app') return
|
|
350
356
|
if (entity !== this.name) return
|
|
351
|
-
this.
|
|
357
|
+
this._dropCaches(id)
|
|
352
358
|
})
|
|
353
359
|
)
|
|
354
360
|
|
|
355
|
-
//
|
|
361
|
+
// Asymmetric detail cache: a write to this entity drops what it touched —
|
|
362
|
+
// that record when the event names it, every record otherwise.
|
|
356
363
|
if (this.isAsymmetric && this.isDetailCacheEnabled) {
|
|
357
364
|
cleanups.push(
|
|
358
365
|
signals.on(
|
|
359
366
|
'entity:data-invalidate',
|
|
360
367
|
(event: { name: string; data: unknown }) => {
|
|
361
|
-
const { entity } = (event.data || {}) as { entity?: string }
|
|
368
|
+
const { entity, id } = (event.data || {}) as { entity?: string; id?: string | number }
|
|
362
369
|
if (entity === this.name) {
|
|
363
|
-
this.
|
|
370
|
+
this._dropDetail(id)
|
|
364
371
|
}
|
|
365
372
|
}
|
|
366
373
|
)
|
|
@@ -415,7 +422,16 @@ export function applyCacheMethods(EntityManagerClass: { prototype: any }): void
|
|
|
415
422
|
this._detailInflight.clear()
|
|
416
423
|
}
|
|
417
424
|
|
|
418
|
-
proto.
|
|
425
|
+
proto._dropDetail = function (this: Self, id?: string | number | null): void {
|
|
426
|
+
if (id === undefined || id === null) {
|
|
427
|
+
this.invalidateDetailCache()
|
|
428
|
+
return
|
|
429
|
+
}
|
|
430
|
+
this._detailCache.items.delete(String(id))
|
|
431
|
+
this._detailInflight.delete(String(id))
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
proto._dropListCache = function (this: Self): void {
|
|
419
435
|
const cache = this._cache
|
|
420
436
|
cache.valid = false
|
|
421
437
|
cache.items = []
|
|
@@ -423,10 +439,35 @@ export function applyCacheMethods(EntityManagerClass: { prototype: any }): void
|
|
|
423
439
|
cache.overflowed = false
|
|
424
440
|
cache.loadedAt = null
|
|
425
441
|
this._cacheLoading = null
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
proto._dropCaches = function (this: Self, id?: string | number | null): void {
|
|
445
|
+
this._dropListCache()
|
|
446
|
+
this._dropDetail(id)
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
proto.invalidateCache = function (this: Self): void {
|
|
450
|
+
this._dropListCache()
|
|
426
451
|
// Also clear detail cache
|
|
427
452
|
this.invalidateDetailCache()
|
|
428
453
|
}
|
|
429
454
|
|
|
455
|
+
/**
|
|
456
|
+
* Say that a record of this entity changed, or the whole entity without an
|
|
457
|
+
* id (#4959). Drops what the caches hold of it, then tells the mounted views
|
|
458
|
+
* (`useLiveEntity`, list and show pages, the active stack) to read it again,
|
|
459
|
+
* with `source: 'app'` — heard like a change made elsewhere.
|
|
460
|
+
*/
|
|
461
|
+
proto.invalidate = function (this: Self, id?: string | number | null): void {
|
|
462
|
+
this._dropCaches(id)
|
|
463
|
+
this._signals?.emit('entity:data-invalidate', {
|
|
464
|
+
entity: this.name,
|
|
465
|
+
action: 'updated',
|
|
466
|
+
...(id !== undefined && id !== null && { id }),
|
|
467
|
+
source: 'app',
|
|
468
|
+
})
|
|
469
|
+
}
|
|
470
|
+
|
|
430
471
|
proto.invalidateDataLayer = function (this: Self): void {
|
|
431
472
|
this.invalidateCache()
|
|
432
473
|
|
|
@@ -81,6 +81,12 @@ export interface EntityManagerRead<T = unknown> extends EntityManagerBase<T>, En
|
|
|
81
81
|
delete: (id: string | number, context?: unknown) => Promise<void>
|
|
82
82
|
request: (method: string, path: string, options?: { data?: unknown }) => Promise<unknown>
|
|
83
83
|
invalidateCache: () => void
|
|
84
|
+
/**
|
|
85
|
+
* A record changed, or the whole entity without an id (#4959): drops it from
|
|
86
|
+
* the caches and has the mounted views read it again. Optional on the
|
|
87
|
+
* structural view so hand-written managers and test doubles stay valid.
|
|
88
|
+
*/
|
|
89
|
+
invalidate?: (id?: string | number | null) => void
|
|
84
90
|
/** Field config lookup — read-side too since list column binding (#1255) */
|
|
85
91
|
getFieldConfig: (name: string) => unknown | null
|
|
86
92
|
/** Config-carrying property: always present on the class, VALUE nullable */
|
|
@@ -1007,6 +1007,14 @@ export interface EntityManager<T extends EntityRecord = EntityRecord> {
|
|
|
1007
1007
|
/** @internal */ _loadCacheInBackground(): void
|
|
1008
1008
|
/** @internal */ _loadCache(): Promise<boolean>
|
|
1009
1009
|
invalidateCache(): void
|
|
1010
|
+
/** @internal */ _dropDetail(id?: string | number | null): void
|
|
1011
|
+
/** @internal */ _dropListCache(): void
|
|
1012
|
+
/** @internal */ _dropCaches(id?: string | number | null): void
|
|
1013
|
+
/**
|
|
1014
|
+
* A record of this entity changed, or the whole entity without an id: drop
|
|
1015
|
+
* what the caches hold of it and have the mounted views read it again.
|
|
1016
|
+
*/
|
|
1017
|
+
invalidate(id?: string | number | null): void
|
|
1010
1018
|
invalidateDataLayer(): void
|
|
1011
1019
|
ensureCache(): Promise<boolean>
|
|
1012
1020
|
warmup(): Promise<boolean | null>
|
package/src/index.ts
CHANGED
|
@@ -483,6 +483,7 @@ export {
|
|
|
483
483
|
type RunOptions,
|
|
484
484
|
type SequenceStep,
|
|
485
485
|
type SequenceOptions,
|
|
486
|
+
type TaskInvalidate,
|
|
486
487
|
type SequenceStepStatus,
|
|
487
488
|
type TaskSequence,
|
|
488
489
|
type TaskSequenceStep,
|
|
@@ -527,6 +528,7 @@ export {
|
|
|
527
528
|
type ModuleInitFunction,
|
|
528
529
|
type InitModulesOptions,
|
|
529
530
|
type MenuAlterContext,
|
|
531
|
+
type ItemTabsOptions,
|
|
530
532
|
// ParentConfig, NavItem, NavSection, ModuleDefinition - already exported
|
|
531
533
|
} from './module/moduleRegistry'
|
|
532
534
|
|
|
@@ -6,8 +6,10 @@ import {
|
|
|
6
6
|
type RouteLocationNormalized,
|
|
7
7
|
type RouteRecordNormalized,
|
|
8
8
|
} from 'vue-router'
|
|
9
|
-
import { getRoutes } from '../module/moduleRegistry'
|
|
9
|
+
import { getRoutes, getItemTabs } from '../module/moduleRegistry'
|
|
10
|
+
import { nestItemTabs } from './itemTabs'
|
|
10
11
|
import { installChunkReload } from './chunkReload'
|
|
12
|
+
import { routeEntity, routePermissions, missingPermission, entityDenial } from '../security/routeAccess'
|
|
11
13
|
import type { Kernel } from './Kernel'
|
|
12
14
|
// #1196 Phase B — this-typing against the real Kernel shape (was Self = any)
|
|
13
15
|
type Self = Kernel
|
|
@@ -72,7 +74,8 @@ export function applyRoutingMethods(KernelClass: { prototype: Kernel }): void {
|
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
|
|
77
|
+
// An entity shown as tabs gets its item's pages nested under one frame route (#4963)
|
|
78
|
+
const moduleRoutes = nestItemTabs(getRoutes() as RouteRecordRaw[], getItemTabs())
|
|
76
79
|
|
|
77
80
|
const publicRoutes = moduleRoutes.filter(
|
|
78
81
|
(r) => r.meta?.public || r.meta?.requiresAuth === false
|
|
@@ -247,32 +250,25 @@ export function applyRoutingMethods(KernelClass: { prototype: Kernel }): void {
|
|
|
247
250
|
return sessionLost ? { name: 'login', query: { session_lost: '1' } } : { name: 'login' }
|
|
248
251
|
}
|
|
249
252
|
|
|
250
|
-
|
|
251
|
-
//
|
|
252
|
-
//
|
|
253
|
-
//
|
|
254
|
-
//
|
|
253
|
+
// Who may open it (#4962): the same rule as the menu and PageNav —
|
|
254
|
+
// every matched record's meta.permission (#4332), and the route's entity
|
|
255
|
+
// (or, for a child page, its parent item's) for the action it declares
|
|
256
|
+
// (#2497). An entity not registered yet is the ONLY pass-through; a
|
|
257
|
+
// failing check fails CLOSED, never silently allows (#1190).
|
|
255
258
|
const orchestrator = this.orchestrator
|
|
256
|
-
const entityToCheck = !!entity && !!orchestrator && orchestrator.isRegistered(entity)
|
|
257
|
-
|
|
258
|
-
// Page permissions (#4332): every matched record's meta.permission, so a
|
|
259
|
-
// parent's covers its children; a list needs every entry. Without a
|
|
260
|
-
// security checker (an app without security) nothing is checked, as for
|
|
261
|
-
// the menu.
|
|
262
|
-
const permissions = to.matched.flatMap((record: RouteRecordNormalized) => {
|
|
263
|
-
const p = record.meta.permission
|
|
264
|
-
return (Array.isArray(p) ? p : [p]).filter((x): x is string => typeof x === 'string' && x !== '')
|
|
265
|
-
})
|
|
266
259
|
const checker = this.securityChecker
|
|
267
|
-
const
|
|
260
|
+
const deps = { orchestrator, checker }
|
|
261
|
+
const entity = routeEntity(to)
|
|
262
|
+
const entityToCheck = !!entity && !!orchestrator && orchestrator.isRegistered(entity)
|
|
263
|
+
const permissionsToCheck = routePermissions(to).length > 0 && !!checker
|
|
268
264
|
|
|
269
265
|
if (!entityToCheck && !permissionsToCheck) return
|
|
270
266
|
|
|
271
267
|
const checkPermissions = (): { path: string } | undefined => {
|
|
272
268
|
if (!permissionsToCheck) return undefined
|
|
273
269
|
try {
|
|
274
|
-
const missing =
|
|
275
|
-
if (missing ===
|
|
270
|
+
const missing = missingPermission(to, deps)
|
|
271
|
+
if (missing === null) return undefined
|
|
276
272
|
console.warn(`[qdadm] Access denied to ${to.path} (permission: ${missing})`)
|
|
277
273
|
orchestrator?.toast.error('Access Denied', "You don't have permission to access this page", 'Kernel')
|
|
278
274
|
this.signals!.emit('auth:access-denied', { path: to.path, permission: missing })
|
|
@@ -283,28 +279,23 @@ export function applyRoutingMethods(KernelClass: { prototype: Kernel }): void {
|
|
|
283
279
|
}
|
|
284
280
|
}
|
|
285
281
|
|
|
286
|
-
// The action the route declares (#2497): a list route is governed by
|
|
287
|
-
// `list`. A route that declares none — any custom page — checks `read`.
|
|
288
|
-
const action = to.meta?.entityAction === 'list' ? 'list' : 'read'
|
|
289
|
-
|
|
290
282
|
const checkEntity = (): { path: string } | undefined => {
|
|
291
283
|
if (!entityToCheck) return undefined
|
|
292
284
|
try {
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
if (manager && !allowed) {
|
|
285
|
+
const denial = entityDenial(to, deps)
|
|
286
|
+
if (denial) {
|
|
296
287
|
console.warn(
|
|
297
|
-
`[qdadm] Access denied to ${to.path} (entity: ${entity}, action: ${action})`
|
|
288
|
+
`[qdadm] Access denied to ${to.path} (entity: ${denial.entity}, action: ${denial.action})`
|
|
298
289
|
)
|
|
299
290
|
orchestrator!.toast.error(
|
|
300
291
|
'Access Denied',
|
|
301
|
-
`You don't have permission to access ${manager.labelPlural || entity}`,
|
|
292
|
+
`You don't have permission to access ${denial.manager.labelPlural || denial.entity}`,
|
|
302
293
|
'Kernel'
|
|
303
294
|
)
|
|
304
295
|
this.signals!.emit('auth:access-denied', {
|
|
305
296
|
path: to.path,
|
|
306
|
-
entity,
|
|
307
|
-
manager,
|
|
297
|
+
entity: denial.entity,
|
|
298
|
+
manager: denial.manager,
|
|
308
299
|
})
|
|
309
300
|
return { path: '/' }
|
|
310
301
|
}
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* framework cannot afford two answers to the same question.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import type { ItemTabsOptions } from '../module/moduleRegistry'
|
|
17
18
|
import type { RouteRecordRaw } from 'vue-router'
|
|
18
19
|
import pluralize from '../utils/pluralize'
|
|
19
20
|
import { registry, getRoutes } from '../module/moduleRegistry'
|
|
@@ -153,6 +154,11 @@ export function applyRoutingMethods(KernelContextClass: { prototype: KernelConte
|
|
|
153
154
|
return this
|
|
154
155
|
}
|
|
155
156
|
|
|
157
|
+
proto.itemTabs = function (this: Self, entity: string, options: ItemTabsOptions = {}): Self {
|
|
158
|
+
registry.addItemTabs(entity, options)
|
|
159
|
+
return this
|
|
160
|
+
}
|
|
161
|
+
|
|
156
162
|
proto.navItem = function (this: Self, item: NavItem): Self {
|
|
157
163
|
registry.addNavItem(item)
|
|
158
164
|
return this
|
|
@@ -389,6 +395,9 @@ export function applyRoutingMethods(KernelContextClass: { prototype: KernelConte
|
|
|
389
395
|
meta: {
|
|
390
396
|
layout: 'page',
|
|
391
397
|
...(options.icon && { icon: options.icon }),
|
|
398
|
+
// On top of the parent item's read right, which the guard checks
|
|
399
|
+
// through meta.parent (#4962)
|
|
400
|
+
...(options.permission !== undefined && { permission: options.permission }),
|
|
392
401
|
...options.meta,
|
|
393
402
|
},
|
|
394
403
|
},
|
|
@@ -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
|
+
}
|