@quazardous/qdadm 2.52.0 → 2.54.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/node/cards/tools/cardsTool.js +2 -1
- package/dist/styles/qdadm.css +1 -1
- package/package.json +1 -1
- package/src/cards/QdCard.vue +4 -0
- package/src/cards/QdCardView.vue +7 -2
- package/src/cards/QdFavoritesCard.vue +73 -14
- package/src/cards/builtin/agenda/meta.json +1 -0
- package/src/cards/builtin/cards-index.json +19 -1
- package/src/cards/builtin/favorites/FavoritesCard.vue +69 -10
- package/src/cards/builtin/favorites/meta.json +4 -2
- package/src/cards/builtin/favorites/schema.json +3 -1
- package/src/cards/builtin/feed/meta.json +1 -0
- package/src/cards/builtin/index.ts +6 -5
- package/src/cards/builtin/pills.ts +36 -0
- package/src/cards/builtin/queue/meta.json +1 -0
- package/src/cards/builtin/recent/meta.json +1 -0
- package/src/cards/index.ts +1 -0
- package/src/cards/tools/cardsTool.ts +2 -1
- package/src/cards/types.ts +16 -0
- package/src/components/edit/FormPage.vue +1 -1
- package/src/components/layout/AppLayout.vue +4 -0
- package/src/components/layout/BaseLayout.vue +4 -0
- package/src/components/layout/PageHeader.vue +8 -0
- package/src/components/show/ShowPage.vue +1 -1
- package/src/domain/QdBadge.vue +36 -0
- package/src/domain/QdDomainBar.vue +213 -0
- package/src/domain/QdDomainBarZone.vue +19 -0
- package/src/domain/index.ts +6 -0
- package/src/domain/registry.ts +122 -0
- package/src/i18n/defaults/core.en.generated.ts +14 -0
- package/src/i18n/defaults/core.en.yml +14 -0
- package/src/i18n/defaults/core.fr.generated.ts +14 -0
- package/src/i18n/defaults/core.fr.yml +14 -0
- package/src/index.ts +1 -0
- package/src/kernel/KernelContext.routing.ts +10 -1
- package/src/kernel/KernelContext.ts +7 -0
- package/src/kernel/KernelContext.types.ts +2 -0
- package/src/module/moduleRegistry.ts +4 -0
- package/src/styles/_qd-cards.scss +93 -0
- package/src/styles/_qd-domain-bar.scss +159 -0
- package/src/styles/index.scss +1 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* QdBadge (#5389): a number on a pill, like a notification count. Its tone
|
|
4
|
+
* comes from how things stand (critical, watch, or none); it hides at zero and
|
|
5
|
+
* says what it counts to screen readers.
|
|
6
|
+
*/
|
|
7
|
+
import { computed } from 'vue'
|
|
8
|
+
import { useI18n } from '../i18n/useI18n'
|
|
9
|
+
|
|
10
|
+
const props = defineProps<{
|
|
11
|
+
count: number | null | undefined
|
|
12
|
+
/** What it counts, for screen readers */
|
|
13
|
+
title?: string
|
|
14
|
+
tone?: 'critical' | 'watch' | null
|
|
15
|
+
}>()
|
|
16
|
+
|
|
17
|
+
const { locale, tOr } = useI18n()
|
|
18
|
+
const shown = computed(() => typeof props.count === 'number' && props.count > 0)
|
|
19
|
+
const text = computed(() => {
|
|
20
|
+
const n = props.count ?? 0
|
|
21
|
+
return n > 99 ? '99+' : new Intl.NumberFormat(locale.value).format(n)
|
|
22
|
+
})
|
|
23
|
+
</script>
|
|
24
|
+
|
|
25
|
+
<template>
|
|
26
|
+
<span
|
|
27
|
+
v-if="shown"
|
|
28
|
+
class="qd-badge"
|
|
29
|
+
:class="tone ? `qd-badge--${tone}` : null"
|
|
30
|
+
:data-tone="tone || 'neutral'"
|
|
31
|
+
:title="title ? tOr('core.domainBar.badge', '{count} — {title}', { count: count!, title }) : undefined"
|
|
32
|
+
>
|
|
33
|
+
<span aria-hidden="true">{{ text }}</span>
|
|
34
|
+
<span class="qd-card-sr">{{ title ? tOr('core.domainBar.badge', '{count} — {title}', { count: count!, title }) : count }}</span>
|
|
35
|
+
</span>
|
|
36
|
+
</template>
|
|
@@ -0,0 +1,213 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* QdDomainBar (#5389): the bar on top of every page of a domain. Its title,
|
|
4
|
+
* its navigation (the current entry marked, a badge on each entry that names
|
|
5
|
+
* an indicator) and its indicators: mini cards, each read from its own source
|
|
6
|
+
* and drawn as a pill whose count is a badge.
|
|
7
|
+
*
|
|
8
|
+
* Compact: one line of icons and badges, on its own once the page scrolls, or
|
|
9
|
+
* by the person's choice, kept per account.
|
|
10
|
+
*/
|
|
11
|
+
import { computed, onBeforeUnmount, onMounted, ref, watch, type Ref } from 'vue'
|
|
12
|
+
import { RouterLink, useRoute, useRouter, type RouteLocationRaw } from 'vue-router'
|
|
13
|
+
import { useI18n } from '../i18n/useI18n'
|
|
14
|
+
import { useAuth } from '../composables/useAuth'
|
|
15
|
+
import { useAsyncRead } from '../composables/useAsyncRead'
|
|
16
|
+
import { getCard, checkCardInput, resolveCardOptions } from '../cards/registry'
|
|
17
|
+
import type { CardStatus } from '../cards/types'
|
|
18
|
+
import QdBadge from './QdBadge.vue'
|
|
19
|
+
import { badgeTone, type DomainDefinition, type DomainIndicator, type DomainNavEntry } from './registry'
|
|
20
|
+
|
|
21
|
+
const props = defineProps<{ domain: DomainDefinition }>()
|
|
22
|
+
|
|
23
|
+
const { locale, tOr } = useI18n()
|
|
24
|
+
const route = useRoute()
|
|
25
|
+
const router = useRouter()
|
|
26
|
+
|
|
27
|
+
// ── The indicators: each its own read, its own state ──────────────────────────
|
|
28
|
+
interface IndicatorView {
|
|
29
|
+
def: DomainIndicator
|
|
30
|
+
/** The value says more than the badge: a unit, a target, no count, or a zero the badge hides */
|
|
31
|
+
showValue: boolean
|
|
32
|
+
state: 'loading' | 'unreachable' | 'invalid' | 'ready'
|
|
33
|
+
value: string
|
|
34
|
+
count: number | null
|
|
35
|
+
status: CardStatus | null
|
|
36
|
+
reason: string | null
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function watchIndicator(def: DomainIndicator): Ref<IndicatorView> {
|
|
40
|
+
const read = def.load ? useAsyncRead(() => def.load!()) : null
|
|
41
|
+
let timer: ReturnType<typeof setInterval> | null = null
|
|
42
|
+
if (read && def.refresh && def.refresh > 0) {
|
|
43
|
+
onMounted(() => (timer = setInterval(() => void read.load(), def.refresh! * 1000)))
|
|
44
|
+
onBeforeUnmount(() => timer && clearInterval(timer))
|
|
45
|
+
}
|
|
46
|
+
return computed<IndicatorView>(() => {
|
|
47
|
+
const base = { def, value: '', count: null, status: null, reason: null, showValue: false }
|
|
48
|
+
if (read && !read.ready.value) {
|
|
49
|
+
return read.error.value ? { ...base, state: 'unreachable', reason: read.error.value } : { ...base, state: 'loading' }
|
|
50
|
+
}
|
|
51
|
+
const data = read ? read.data.value : def.data
|
|
52
|
+
const card = getCard(def.card)
|
|
53
|
+
if (!card?.pill) return { ...base, state: 'invalid', reason: `no card type '${def.card}' with a pill` }
|
|
54
|
+
const problems = checkCardInput(card, data, def.options ?? {})
|
|
55
|
+
if (problems.length) return { ...base, state: 'invalid', reason: problems.map((p) => `${p.path}: ${p.message}`).join('; ') }
|
|
56
|
+
const pill = card.pill(data, resolveCardOptions(card.meta, def.options ?? {}), locale.value)
|
|
57
|
+
const status = typeof def.status === 'function' ? def.status(data) ?? null : def.status ?? null
|
|
58
|
+
const plain = pill.count !== null && pill.count > 0 && pill.value === new Intl.NumberFormat(locale.value).format(pill.count)
|
|
59
|
+
return { ...base, state: 'ready', value: pill.value, count: pill.count, status, showValue: !plain }
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const indicators = (props.domain.indicators ?? []).map(watchIndicator)
|
|
64
|
+
const byId = computed(() => new Map(indicators.map((i) => [i.value.def.id, i.value])))
|
|
65
|
+
|
|
66
|
+
// ── The navigation ────────────────────────────────────────────────────────────
|
|
67
|
+
function targetOf(entry: DomainNavEntry): RouteLocationRaw | null {
|
|
68
|
+
if (entry.to) return entry.to
|
|
69
|
+
if (entry.route && router.hasRoute(entry.route)) return { name: entry.route }
|
|
70
|
+
return null
|
|
71
|
+
}
|
|
72
|
+
const nav = computed(() =>
|
|
73
|
+
(props.domain.nav ?? [])
|
|
74
|
+
.map((entry) => ({ entry, to: targetOf(entry), badge: entry.badge ? byId.value.get(entry.badge) ?? null : null }))
|
|
75
|
+
.filter((n) => n.to !== null)
|
|
76
|
+
)
|
|
77
|
+
/** The current entry: the one whose route is the deepest matched one */
|
|
78
|
+
const current = computed(() => {
|
|
79
|
+
const matched = route.matched.map((r) => r.path)
|
|
80
|
+
let best = -1
|
|
81
|
+
let bestLen = -1
|
|
82
|
+
nav.value.forEach((n, i) => {
|
|
83
|
+
let path: string
|
|
84
|
+
try {
|
|
85
|
+
path = router.resolve(n.to!).matched.at(-1)?.path ?? ''
|
|
86
|
+
} catch {
|
|
87
|
+
return
|
|
88
|
+
}
|
|
89
|
+
if (!path) return
|
|
90
|
+
const hit = matched.some((m) => m === path || m.startsWith(path.endsWith('/') ? path : path + '/'))
|
|
91
|
+
if (hit && path.length > bestLen) {
|
|
92
|
+
best = i
|
|
93
|
+
bestLen = path.length
|
|
94
|
+
}
|
|
95
|
+
})
|
|
96
|
+
return best
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
// ── Compact ───────────────────────────────────────────────────────────────────
|
|
100
|
+
const { user } = useAuth()
|
|
101
|
+
const key = computed(() => {
|
|
102
|
+
const u = user.value as { id?: unknown; username?: unknown } | null
|
|
103
|
+
return `qdadm.domainBar.${props.domain.name}.${String(u?.id ?? u?.username ?? 'anonymous')}.compact`
|
|
104
|
+
})
|
|
105
|
+
function readChoice(): boolean {
|
|
106
|
+
try {
|
|
107
|
+
return globalThis.localStorage?.getItem(key.value) === '1'
|
|
108
|
+
} catch {
|
|
109
|
+
return false
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const chosen = ref(readChoice())
|
|
113
|
+
watch(key, () => (chosen.value = readChoice()))
|
|
114
|
+
function toggle(): void {
|
|
115
|
+
chosen.value = !chosen.value
|
|
116
|
+
try {
|
|
117
|
+
if (chosen.value) globalThis.localStorage?.setItem(key.value, '1')
|
|
118
|
+
else globalThis.localStorage?.removeItem(key.value)
|
|
119
|
+
} catch {
|
|
120
|
+
// Blocked storage: the choice lasts the page
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Scrolled past the top: compact on its own, the person's choice untouched
|
|
125
|
+
const sentinel = ref<HTMLElement | null>(null)
|
|
126
|
+
const scrolled = ref(false)
|
|
127
|
+
let observer: IntersectionObserver | null = null
|
|
128
|
+
onMounted(() => {
|
|
129
|
+
if (typeof IntersectionObserver === 'undefined' || !sentinel.value) return
|
|
130
|
+
observer = new IntersectionObserver(([e]) => (scrolled.value = !!e && !e.isIntersecting))
|
|
131
|
+
observer.observe(sentinel.value)
|
|
132
|
+
})
|
|
133
|
+
onBeforeUnmount(() => observer?.disconnect())
|
|
134
|
+
const compact = computed(() => chosen.value || scrolled.value)
|
|
135
|
+
|
|
136
|
+
const label = computed(() => tOr('core.domainBar.label', '{domain}: its pages and indicators', { domain: props.domain.label }))
|
|
137
|
+
function pillTitle(i: IndicatorView): string {
|
|
138
|
+
const title = i.def.title
|
|
139
|
+
if (i.state === 'unreachable') return tOr('core.domainBar.unreachable', '{title}: unreachable ({error})', { title, error: i.reason ?? '' })
|
|
140
|
+
if (i.state === 'invalid') return tOr('core.domainBar.invalid', '{title}: data that does not fit', { title }) + (i.reason ? ` (${i.reason})` : '')
|
|
141
|
+
if (i.state === 'loading') return tOr('core.domainBar.loading', '{title}: loading', { title })
|
|
142
|
+
return `${title}: ${i.value}`
|
|
143
|
+
}
|
|
144
|
+
</script>
|
|
145
|
+
|
|
146
|
+
<template>
|
|
147
|
+
<div ref="sentinel" class="qd-domain-bar-sentinel" aria-hidden="true"></div>
|
|
148
|
+
<section
|
|
149
|
+
class="qd-domain-bar"
|
|
150
|
+
:class="{ 'qd-domain-bar--compact': compact }"
|
|
151
|
+
:aria-label="label"
|
|
152
|
+
:data-domain="domain.name"
|
|
153
|
+
:data-compact="compact ? (chosen ? 'chosen' : 'scrolled') : undefined"
|
|
154
|
+
>
|
|
155
|
+
<component :is="domain.to ? RouterLink : 'span'" :to="domain.to" class="qd-domain-bar-title">
|
|
156
|
+
<i v-if="domain.icon" :class="domain.icon" aria-hidden="true"></i>
|
|
157
|
+
<span class="qd-domain-bar-name">{{ domain.label }}</span>
|
|
158
|
+
</component>
|
|
159
|
+
|
|
160
|
+
<nav v-if="nav.length" class="qd-domain-bar-nav" :aria-label="tOr('core.domainBar.nav', '{domain} pages', { domain: domain.label })">
|
|
161
|
+
<RouterLink
|
|
162
|
+
v-for="(n, i) in nav"
|
|
163
|
+
:key="n.entry.label"
|
|
164
|
+
:to="n.to!"
|
|
165
|
+
class="qd-domain-bar-entry"
|
|
166
|
+
:class="{ 'qd-domain-bar-entry--current': i === current }"
|
|
167
|
+
:aria-current="i === current ? 'page' : undefined"
|
|
168
|
+
:title="compact ? n.entry.label : undefined"
|
|
169
|
+
data-domain-nav
|
|
170
|
+
>
|
|
171
|
+
<i v-if="n.entry.icon" :class="n.entry.icon" aria-hidden="true"></i>
|
|
172
|
+
<span class="qd-domain-bar-entry-label" :class="{ 'qd-card-sr': compact && n.entry.icon }">{{ n.entry.label }}</span>
|
|
173
|
+
<QdBadge v-if="n.badge && n.badge.state === 'ready'" :count="n.badge.count" :title="n.badge.def.title" :tone="badgeTone(n.badge.status)" />
|
|
174
|
+
</RouterLink>
|
|
175
|
+
</nav>
|
|
176
|
+
|
|
177
|
+
<ul v-if="indicators.length" class="qd-domain-bar-indicators" :aria-label="tOr('core.domainBar.indicators', '{domain} indicators', { domain: domain.label })">
|
|
178
|
+
<li
|
|
179
|
+
v-for="ind in indicators"
|
|
180
|
+
:key="ind.value.def.id"
|
|
181
|
+
class="qd-domain-pill"
|
|
182
|
+
:data-indicator="ind.value.def.id"
|
|
183
|
+
:data-state="ind.value.state"
|
|
184
|
+
:data-status="ind.value.status || undefined"
|
|
185
|
+
:title="pillTitle(ind.value)"
|
|
186
|
+
>
|
|
187
|
+
<component :is="ind.value.def.to ? RouterLink : 'span'" :to="ind.value.def.to" class="qd-domain-pill-body">
|
|
188
|
+
<i v-if="ind.value.def.icon" :class="ind.value.def.icon" aria-hidden="true"></i>
|
|
189
|
+
<span class="qd-domain-pill-title" :class="{ 'qd-card-sr': compact && ind.value.def.icon }">{{ ind.value.def.title }}</span>
|
|
190
|
+
<template v-if="ind.value.state === 'ready'">
|
|
191
|
+
<QdBadge v-if="ind.value.count !== null" :count="ind.value.count" :title="ind.value.def.title" :tone="badgeTone(ind.value.status)" />
|
|
192
|
+
<span v-if="ind.value.showValue" class="qd-domain-pill-value" :class="{ 'qd-domain-pill-value--zero': ind.value.count === 0 }">{{ ind.value.value }}</span>
|
|
193
|
+
</template>
|
|
194
|
+
<i v-else-if="ind.value.state === 'loading'" class="pi pi-spin pi-spinner qd-domain-pill-mark" aria-hidden="true"></i>
|
|
195
|
+
<i v-else class="pi pi-exclamation-triangle qd-domain-pill-mark" aria-hidden="true"></i>
|
|
196
|
+
<span v-if="ind.value.state !== 'ready'" class="qd-card-sr">{{ pillTitle(ind.value) }}</span>
|
|
197
|
+
</component>
|
|
198
|
+
</li>
|
|
199
|
+
</ul>
|
|
200
|
+
|
|
201
|
+
<button
|
|
202
|
+
type="button"
|
|
203
|
+
class="qd-domain-bar-toggle"
|
|
204
|
+
:aria-pressed="chosen ? 'true' : 'false'"
|
|
205
|
+
:aria-label="chosen ? tOr('core.domainBar.expand', 'Full bar') : tOr('core.domainBar.compact', 'Compact bar')"
|
|
206
|
+
:title="chosen ? tOr('core.domainBar.expand', 'Full bar') : tOr('core.domainBar.compact', 'Compact bar')"
|
|
207
|
+
data-domain-toggle
|
|
208
|
+
@click="toggle"
|
|
209
|
+
>
|
|
210
|
+
<i :class="chosen ? 'pi pi-window-maximize' : 'pi pi-window-minimize'" aria-hidden="true"></i>
|
|
211
|
+
</button>
|
|
212
|
+
</section>
|
|
213
|
+
</template>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
/**
|
|
3
|
+
* Where the layouts draw the domain bar (#5389): the `_app:domain-bar` zone,
|
|
4
|
+
* on the pages of a domain only, with QdDomainBar as its default. An app
|
|
5
|
+
* replaces it with a block in that zone; the block receives `domain`.
|
|
6
|
+
*/
|
|
7
|
+
import { computed } from 'vue'
|
|
8
|
+
import { useRoute } from 'vue-router'
|
|
9
|
+
import Zone from '../components/layout/Zone.vue'
|
|
10
|
+
import QdDomainBar from './QdDomainBar.vue'
|
|
11
|
+
import { domainOfRoute } from './registry'
|
|
12
|
+
|
|
13
|
+
const route = useRoute()
|
|
14
|
+
const domain = computed(() => domainOfRoute(route))
|
|
15
|
+
</script>
|
|
16
|
+
|
|
17
|
+
<template>
|
|
18
|
+
<Zone v-if="domain" :key="domain.name" class="qd-domain-bar-zone" name="_app:domain-bar" :default-component="QdDomainBar" :block-props="{ domain }" />
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/** Domains and their bar (#5389) */
|
|
2
|
+
export { default as QdDomainBar } from './QdDomainBar.vue'
|
|
3
|
+
export { default as QdDomainBarZone } from './QdDomainBarZone.vue'
|
|
4
|
+
export { default as QdBadge } from './QdBadge.vue'
|
|
5
|
+
export { registerDomain, getDomain, listDomains, domainOfRoute, badgeTone } from './registry'
|
|
6
|
+
export type { DomainConfig, DomainDefinition, DomainIndicator, DomainNavEntry } from './registry'
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domains (#5389): a part of the app with a bar of its own on top of every
|
|
3
|
+
* one of its pages: its navigation and a row of indicators, mini cards each
|
|
4
|
+
* read from its own source, their counts as badges.
|
|
5
|
+
*
|
|
6
|
+
* A page belongs to a domain:
|
|
7
|
+
* 1. when its route says so (`meta.domain`);
|
|
8
|
+
* 2. when its entity is one the domain lists (`entities`), from any module;
|
|
9
|
+
* 3. when the module that declared the domain declared the route too.
|
|
10
|
+
*/
|
|
11
|
+
import type { RouteLocationNormalizedLoaded, RouteLocationRaw } from 'vue-router'
|
|
12
|
+
import type { CardStatus } from '../cards/types'
|
|
13
|
+
|
|
14
|
+
/** One permanent indicator: a card of a registered type, drawn as a pill */
|
|
15
|
+
export interface DomainIndicator {
|
|
16
|
+
/** Named by the nav entries that show its badge */
|
|
17
|
+
id: string
|
|
18
|
+
/** The card type (metric, queue, goal, compare, split, or one of the app's) */
|
|
19
|
+
card: string
|
|
20
|
+
/** Its name, read beside the pill and by screen readers */
|
|
21
|
+
title: string
|
|
22
|
+
icon?: string
|
|
23
|
+
/** The data, as the card type takes it */
|
|
24
|
+
data?: unknown
|
|
25
|
+
/** Or read it: called at once, then every `refresh` seconds */
|
|
26
|
+
load?: () => unknown | Promise<unknown>
|
|
27
|
+
/** Seconds between two reads (default: none) */
|
|
28
|
+
refresh?: number
|
|
29
|
+
/** The card type's options */
|
|
30
|
+
options?: Record<string, unknown>
|
|
31
|
+
/** How things stand: fixed, or from the data */
|
|
32
|
+
status?: CardStatus | ((data: unknown) => CardStatus | undefined | null)
|
|
33
|
+
/** Where the pill leads */
|
|
34
|
+
to?: RouteLocationRaw
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** One entry of the domain's navigation */
|
|
38
|
+
export interface DomainNavEntry {
|
|
39
|
+
label: string
|
|
40
|
+
icon?: string
|
|
41
|
+
/** A route name, or `to` */
|
|
42
|
+
route?: string
|
|
43
|
+
to?: RouteLocationRaw
|
|
44
|
+
/** The id of the indicator whose count shows as this entry's badge */
|
|
45
|
+
badge?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** What `ctx.domain(name, …)` declares */
|
|
49
|
+
export interface DomainConfig {
|
|
50
|
+
label: string
|
|
51
|
+
icon?: string
|
|
52
|
+
/** Where the domain's title leads (its board) */
|
|
53
|
+
to?: RouteLocationRaw
|
|
54
|
+
nav?: DomainNavEntry[]
|
|
55
|
+
indicators?: DomainIndicator[]
|
|
56
|
+
/** Entities of other modules whose pages join the domain */
|
|
57
|
+
entities?: string[]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export interface DomainDefinition extends DomainConfig {
|
|
61
|
+
name: string
|
|
62
|
+
/** The module that declared it: its routes join the domain */
|
|
63
|
+
module: string | null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const domains = new Map<string, DomainDefinition>()
|
|
67
|
+
|
|
68
|
+
export function registerDomain(name: string, config: DomainConfig, module: string | null = null): void {
|
|
69
|
+
if (!name) throw new Error('[qdadm] domain: a domain needs a name')
|
|
70
|
+
if (domains.has(name)) console.warn(`[qdadm] domain('${name}'): replaces the domain already declared`)
|
|
71
|
+
const ids = new Set<string>()
|
|
72
|
+
for (const i of config.indicators ?? []) {
|
|
73
|
+
if (ids.has(i.id)) console.warn(`[qdadm] domain('${name}'): two indicators are named '${i.id}'`)
|
|
74
|
+
ids.add(i.id)
|
|
75
|
+
}
|
|
76
|
+
for (const n of config.nav ?? []) {
|
|
77
|
+
if (n.badge && !ids.has(n.badge)) console.warn(`[qdadm] domain('${name}'): the entry '${n.label}' shows the badge of '${n.badge}', which no indicator is`)
|
|
78
|
+
}
|
|
79
|
+
domains.set(name, { ...config, name, module })
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getDomain(name: string): DomainDefinition | null {
|
|
83
|
+
return domains.get(name) ?? null
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export function listDomains(): DomainDefinition[] {
|
|
87
|
+
return [...domains.values()]
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** Tests only */
|
|
91
|
+
export function resetDomains(): void {
|
|
92
|
+
domains.clear()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
type RouteLike = Pick<RouteLocationNormalizedLoaded, 'meta' | 'matched'>
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The domain a route belongs to, or null. `meta.domain: false` keeps a page
|
|
99
|
+
* out of its module's domain.
|
|
100
|
+
*/
|
|
101
|
+
export function domainOfRoute(route: RouteLike | null | undefined): DomainDefinition | null {
|
|
102
|
+
if (!route || domains.size === 0) return null
|
|
103
|
+
const meta = route.meta ?? {}
|
|
104
|
+
if (meta.domain === false) return null
|
|
105
|
+
if (typeof meta.domain === 'string') return getDomain(meta.domain)
|
|
106
|
+
const entity = typeof meta.entity === 'string' ? meta.entity : null
|
|
107
|
+
if (entity) {
|
|
108
|
+
for (const d of domains.values()) if (d.entities?.includes(entity)) return d
|
|
109
|
+
}
|
|
110
|
+
// The deepest matched route with a module wins (a frame route's children carry theirs)
|
|
111
|
+
const modules = (route.matched ?? []).map((r) => r.meta?.module).filter((m): m is string => typeof m === 'string')
|
|
112
|
+
const module = modules.at(-1) ?? (typeof meta.module === 'string' ? meta.module : null)
|
|
113
|
+
if (module) {
|
|
114
|
+
for (const d of domains.values()) if (d.module === module) return d
|
|
115
|
+
}
|
|
116
|
+
return null
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The tone of a badge: only bad news is coloured */
|
|
120
|
+
export function badgeTone(status: CardStatus | null | undefined): 'critical' | 'watch' | null {
|
|
121
|
+
return status === 'critical' || status === 'watch' ? status : null
|
|
122
|
+
}
|
|
@@ -487,6 +487,9 @@ export default `core:
|
|
|
487
487
|
favorites:
|
|
488
488
|
add: "Add {label} to favourites"
|
|
489
489
|
remove: "Remove {label} from favourites"
|
|
490
|
+
removed: "{label} removed from favourites"
|
|
491
|
+
undo: Undo
|
|
492
|
+
undoLabel: "Put {label} back in favourites"
|
|
490
493
|
saveSearch: Save this search
|
|
491
494
|
searchSaved: Search saved
|
|
492
495
|
searchName: Name of the search
|
|
@@ -511,6 +514,17 @@ export default `core:
|
|
|
511
514
|
change: "{change} on the period before"
|
|
512
515
|
same: Same as the period before
|
|
513
516
|
timelineBars: "Volume from {from} to {to}"
|
|
517
|
+
# The domain bar (#5389)
|
|
518
|
+
domainBar:
|
|
519
|
+
label: "{domain}: its pages and indicators"
|
|
520
|
+
nav: "{domain} pages"
|
|
521
|
+
indicators: "{domain} indicators"
|
|
522
|
+
compact: Compact bar
|
|
523
|
+
expand: Full bar
|
|
524
|
+
badge: "{count} — {title}"
|
|
525
|
+
unreachable: "{title}: unreachable ({error})"
|
|
526
|
+
invalid: "{title}: data that does not fit"
|
|
527
|
+
loading: "{title}: loading"
|
|
514
528
|
# NotFoundPage
|
|
515
529
|
notFound:
|
|
516
530
|
title: Page not found
|
|
@@ -485,6 +485,9 @@ core:
|
|
|
485
485
|
favorites:
|
|
486
486
|
add: "Add {label} to favourites"
|
|
487
487
|
remove: "Remove {label} from favourites"
|
|
488
|
+
removed: "{label} removed from favourites"
|
|
489
|
+
undo: Undo
|
|
490
|
+
undoLabel: "Put {label} back in favourites"
|
|
488
491
|
saveSearch: Save this search
|
|
489
492
|
searchSaved: Search saved
|
|
490
493
|
searchName: Name of the search
|
|
@@ -509,6 +512,17 @@ core:
|
|
|
509
512
|
change: "{change} on the period before"
|
|
510
513
|
same: Same as the period before
|
|
511
514
|
timelineBars: "Volume from {from} to {to}"
|
|
515
|
+
# The domain bar (#5389)
|
|
516
|
+
domainBar:
|
|
517
|
+
label: "{domain}: its pages and indicators"
|
|
518
|
+
nav: "{domain} pages"
|
|
519
|
+
indicators: "{domain} indicators"
|
|
520
|
+
compact: Compact bar
|
|
521
|
+
expand: Full bar
|
|
522
|
+
badge: "{count} — {title}"
|
|
523
|
+
unreachable: "{title}: unreachable ({error})"
|
|
524
|
+
invalid: "{title}: data that does not fit"
|
|
525
|
+
loading: "{title}: loading"
|
|
512
526
|
# NotFoundPage
|
|
513
527
|
notFound:
|
|
514
528
|
title: Page not found
|
|
@@ -487,6 +487,9 @@ export default `core:
|
|
|
487
487
|
favorites:
|
|
488
488
|
add: "Ajouter {label} aux favoris"
|
|
489
489
|
remove: "Retirer {label} des favoris"
|
|
490
|
+
removed: "{label} retiré des favoris"
|
|
491
|
+
undo: Annuler
|
|
492
|
+
undoLabel: "Remettre {label} dans les favoris"
|
|
490
493
|
saveSearch: Enregistrer cette recherche
|
|
491
494
|
searchSaved: Recherche enregistrée
|
|
492
495
|
searchName: Nom de la recherche
|
|
@@ -511,6 +514,17 @@ export default `core:
|
|
|
511
514
|
change: "{change} sur la période précédente"
|
|
512
515
|
same: Autant que la période précédente
|
|
513
516
|
timelineBars: "Volume du {from} au {to}"
|
|
517
|
+
# Le cartouche de domaine (#5389)
|
|
518
|
+
domainBar:
|
|
519
|
+
label: "{domain} : ses pages et ses indicateurs"
|
|
520
|
+
nav: "Pages de {domain}"
|
|
521
|
+
indicators: "Indicateurs de {domain}"
|
|
522
|
+
compact: Cartouche compact
|
|
523
|
+
expand: Cartouche complet
|
|
524
|
+
badge: "{count} — {title}"
|
|
525
|
+
unreachable: "{title} : injoignable ({error})"
|
|
526
|
+
invalid: "{title} : données qui ne correspondent pas"
|
|
527
|
+
loading: "{title} : chargement"
|
|
514
528
|
# NotFoundPage
|
|
515
529
|
notFound:
|
|
516
530
|
title: Page introuvable
|
|
@@ -485,6 +485,9 @@ core:
|
|
|
485
485
|
favorites:
|
|
486
486
|
add: "Ajouter {label} aux favoris"
|
|
487
487
|
remove: "Retirer {label} des favoris"
|
|
488
|
+
removed: "{label} retiré des favoris"
|
|
489
|
+
undo: Annuler
|
|
490
|
+
undoLabel: "Remettre {label} dans les favoris"
|
|
488
491
|
saveSearch: Enregistrer cette recherche
|
|
489
492
|
searchSaved: Recherche enregistrée
|
|
490
493
|
searchName: Nom de la recherche
|
|
@@ -509,6 +512,17 @@ core:
|
|
|
509
512
|
change: "{change} sur la période précédente"
|
|
510
513
|
same: Autant que la période précédente
|
|
511
514
|
timelineBars: "Volume du {from} au {to}"
|
|
515
|
+
# Le cartouche de domaine (#5389)
|
|
516
|
+
domainBar:
|
|
517
|
+
label: "{domain} : ses pages et ses indicateurs"
|
|
518
|
+
nav: "Pages de {domain}"
|
|
519
|
+
indicators: "Indicateurs de {domain}"
|
|
520
|
+
compact: Cartouche compact
|
|
521
|
+
expand: Cartouche complet
|
|
522
|
+
badge: "{count} — {title}"
|
|
523
|
+
unreachable: "{title} : injoignable ({error})"
|
|
524
|
+
invalid: "{title} : données qui ne correspondent pas"
|
|
525
|
+
loading: "{title} : chargement"
|
|
512
526
|
# NotFoundPage
|
|
513
527
|
notFound:
|
|
514
528
|
title: Page introuvable
|
package/src/index.ts
CHANGED
|
@@ -462,6 +462,7 @@ export * from './cards/index'
|
|
|
462
462
|
export * from './run/index'
|
|
463
463
|
export * from './favorites/index'
|
|
464
464
|
export * from './board/index'
|
|
465
|
+
export * from './domain/index'
|
|
465
466
|
export { useTaskRunner, taskAction } from './tasks/useTaskRunner'
|
|
466
467
|
export { useTaskNotifications, useTaskTrayVisible, type TasksConfig } from './tasks/useTaskNotifications'
|
|
467
468
|
export {
|
|
@@ -18,6 +18,7 @@ import type { ItemTabsOptions } from '../module/moduleRegistry'
|
|
|
18
18
|
import type { RouteRecordRaw } from 'vue-router'
|
|
19
19
|
import pluralize from '../utils/pluralize'
|
|
20
20
|
import { registry, getRoutes } from '../module/moduleRegistry'
|
|
21
|
+
import { registerDomain, type DomainConfig } from '../domain/registry'
|
|
21
22
|
import type {
|
|
22
23
|
ChildPageOptions,
|
|
23
24
|
CrudOptions,
|
|
@@ -150,7 +151,15 @@ export function applyRoutingMethods(KernelContextClass: { prototype: KernelConte
|
|
|
150
151
|
routes: RouteRecordRaw[],
|
|
151
152
|
opts: RouteOptions = {}
|
|
152
153
|
): Self {
|
|
153
|
-
|
|
154
|
+
// Each route knows its module, so a domain the module declares finds its pages (#5389)
|
|
155
|
+
const module = this._module?.name
|
|
156
|
+
const tagged = module ? routes.map((r) => ({ ...r, meta: { module, ...r.meta } }) as RouteRecordRaw) : routes
|
|
157
|
+
registry.addRoutes(basePath, tagged, opts)
|
|
158
|
+
return this
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
proto.domain = function (this: Self, name: string, config: DomainConfig): Self {
|
|
162
|
+
registerDomain(name, config, this._module?.name ?? null)
|
|
154
163
|
return this
|
|
155
164
|
}
|
|
156
165
|
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
*/
|
|
37
37
|
|
|
38
38
|
import type { ItemTabsOptions } from '../module/moduleRegistry'
|
|
39
|
+
import type { DomainConfig } from '../domain/registry'
|
|
39
40
|
import type { App, Component } from 'vue'
|
|
40
41
|
import type { Router, RouteRecordRaw } from 'vue-router'
|
|
41
42
|
import type { ListenerOptions } from '@quazardous/quarkernel'
|
|
@@ -210,6 +211,12 @@ export interface KernelContext {
|
|
|
210
211
|
childPage(parentRouteName: string, pageName: string, options: ChildPageOptions): this
|
|
211
212
|
/** Show an entity's item as tabs: its header, a tab per page of the item, the page below (#4963) */
|
|
212
213
|
itemTabs(entity: string, options?: ItemTabsOptions): this
|
|
214
|
+
/**
|
|
215
|
+
* A domain (#5389): a bar on top of each of its pages, with its navigation
|
|
216
|
+
* and its indicators. Its pages: this module's routes, the pages of the
|
|
217
|
+
* entities it lists, and any route whose `meta.domain` names it.
|
|
218
|
+
*/
|
|
219
|
+
domain(name: string, config: DomainConfig): this
|
|
213
220
|
|
|
214
221
|
// Zones / Vue (KernelContext.zones.ts)
|
|
215
222
|
zone(name: string, options?: ZoneOptions): this
|
|
@@ -28,6 +28,8 @@ import type { RouteParamResolverContext } from './KernelContext.routing'
|
|
|
28
28
|
|
|
29
29
|
/** Extended Module interface with internal cleanup method */
|
|
30
30
|
export interface ModuleWithCleanup {
|
|
31
|
+
/** The module's name (Module.name); routes are tagged with it (#5389) */
|
|
32
|
+
name?: string
|
|
31
33
|
constructor?: { name?: string }
|
|
32
34
|
_addSignalCleanup?: (cleanup: () => void) => void
|
|
33
35
|
}
|
|
@@ -52,6 +52,10 @@ export interface ModuleRouteMeta {
|
|
|
52
52
|
title?: string
|
|
53
53
|
/** Who may open the page (#4332): enforced by the router guard; a list needs every entry */
|
|
54
54
|
permission?: string | string[]
|
|
55
|
+
/** The module that declared the route (#5389), set by ctx.routes() */
|
|
56
|
+
module?: string
|
|
57
|
+
/** The domain whose bar the page shows (#5389); false: none, even its module's */
|
|
58
|
+
domain?: string | false
|
|
55
59
|
[key: string]: unknown
|
|
56
60
|
}
|
|
57
61
|
|