@quazardous/qdadm 2.51.0 → 2.53.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 (129) hide show
  1. package/dist/node/cards/tools/cardsTool.d.ts +32 -0
  2. package/dist/node/cards/tools/cardsTool.js +151 -0
  3. package/dist/node/cards/tools/cli.d.ts +2 -0
  4. package/dist/node/cards/tools/cli.js +38 -0
  5. package/dist/node/cards/validate.d.ts +35 -0
  6. package/dist/node/cards/validate.js +94 -0
  7. package/dist/styles/qdadm.css +1 -1
  8. package/package.json +7 -2
  9. package/src/board/QdBoardBlock.vue +67 -0
  10. package/src/board/QdDomainBoard.vue +64 -0
  11. package/src/board/blocks/BreakdownBlock.vue +44 -0
  12. package/src/board/blocks/KpiBlock.vue +31 -0
  13. package/src/board/blocks/TimelineBlock.vue +63 -0
  14. package/src/board/blocks/TopBlock.vue +57 -0
  15. package/src/board/blocks/schemas.ts +107 -0
  16. package/src/board/index.ts +31 -0
  17. package/src/board/registry.ts +33 -0
  18. package/src/board/types.ts +32 -0
  19. package/src/cards/QdCard.vue +175 -0
  20. package/src/cards/QdCardView.vue +53 -0
  21. package/src/cards/QdCardsGallery.vue +103 -0
  22. package/src/cards/QdFavoritesCard.vue +50 -0
  23. package/src/cards/QdRecentCard.vue +44 -0
  24. package/src/cards/builtin/agenda/AgendaCard.vue +37 -0
  25. package/src/cards/builtin/agenda/meta.json +60 -0
  26. package/src/cards/builtin/agenda/schema.json +48 -0
  27. package/src/cards/builtin/bullet/BulletCard.vue +76 -0
  28. package/src/cards/builtin/bullet/meta.json +38 -0
  29. package/src/cards/builtin/bullet/schema.json +18 -0
  30. package/src/cards/builtin/cards-index.json +1694 -0
  31. package/src/cards/builtin/compare/CompareCard.vue +47 -0
  32. package/src/cards/builtin/compare/meta.json +79 -0
  33. package/src/cards/builtin/compare/schema.json +40 -0
  34. package/src/cards/builtin/favorites/FavoritesCard.vue +50 -0
  35. package/src/cards/builtin/favorites/meta.json +33 -0
  36. package/src/cards/builtin/favorites/schema.json +20 -0
  37. package/src/cards/builtin/feed/FeedCard.vue +39 -0
  38. package/src/cards/builtin/feed/meta.json +64 -0
  39. package/src/cards/builtin/feed/schema.json +54 -0
  40. package/src/cards/builtin/funnel/FunnelCard.vue +44 -0
  41. package/src/cards/builtin/funnel/meta.json +53 -0
  42. package/src/cards/builtin/funnel/schema.json +37 -0
  43. package/src/cards/builtin/goal/GoalCard.vue +73 -0
  44. package/src/cards/builtin/goal/meta.json +43 -0
  45. package/src/cards/builtin/goal/schema.json +12 -0
  46. package/src/cards/builtin/heat/HeatCard.vue +46 -0
  47. package/src/cards/builtin/heat/meta.json +101 -0
  48. package/src/cards/builtin/heat/schema.json +39 -0
  49. package/src/cards/builtin/index.ts +71 -0
  50. package/src/cards/builtin/metric/MetricCard.vue +82 -0
  51. package/src/cards/builtin/metric/meta.json +109 -0
  52. package/src/cards/builtin/metric/schema.json +35 -0
  53. package/src/cards/builtin/pills.ts +36 -0
  54. package/src/cards/builtin/queue/QueueCard.vue +65 -0
  55. package/src/cards/builtin/queue/meta.json +47 -0
  56. package/src/cards/builtin/queue/schema.json +32 -0
  57. package/src/cards/builtin/ranking/RankingCard.vue +37 -0
  58. package/src/cards/builtin/ranking/meta.json +71 -0
  59. package/src/cards/builtin/ranking/schema.json +35 -0
  60. package/src/cards/builtin/recent/RecentCard.vue +41 -0
  61. package/src/cards/builtin/recent/meta.json +32 -0
  62. package/src/cards/builtin/recent/schema.json +21 -0
  63. package/src/cards/builtin/shared.ts +83 -0
  64. package/src/cards/builtin/split/SplitCard.vue +52 -0
  65. package/src/cards/builtin/split/meta.json +72 -0
  66. package/src/cards/builtin/split/schema.json +40 -0
  67. package/src/cards/builtin/trend/TrendCard.vue +75 -0
  68. package/src/cards/builtin/trend/meta.json +81 -0
  69. package/src/cards/builtin/trend/schema.json +58 -0
  70. package/src/cards/index.ts +29 -0
  71. package/src/cards/registry.ts +57 -0
  72. package/src/cards/tools/cardsTool.ts +181 -0
  73. package/src/cards/tools/cli.ts +35 -0
  74. package/src/cards/types.ts +111 -0
  75. package/src/cards/validate.ts +111 -0
  76. package/src/components/edit/FormActions.vue +9 -5
  77. package/src/components/edit/FormPage.vue +17 -2
  78. package/src/components/layout/AppLayout.vue +4 -0
  79. package/src/components/layout/BaseLayout.vue +4 -0
  80. package/src/components/layout/CardParamsForm.vue +157 -0
  81. package/src/components/layout/CardsDashboard.vue +276 -57
  82. package/src/components/layout/PageHeader.vue +22 -1
  83. package/src/components/layout/QdFavoriteStar.vue +71 -0
  84. package/src/components/layout/Zone.vue +2 -1
  85. package/src/components/lists/ListPage.vue +9 -1
  86. package/src/components/lists/QdSaveSearch.vue +79 -0
  87. package/src/components/pages/NotFoundPage.vue +5 -2
  88. package/src/components/run/QdRunBar.vue +99 -0
  89. package/src/components/show/ShowPage.vue +10 -1
  90. package/src/composables/useBreadcrumb.ts +1 -1
  91. package/src/composables/useCardsArrangement.ts +297 -27
  92. package/src/composables/useEntityItemFormPage.ts +39 -3
  93. package/src/composables/useEntityItemFormPage.types.ts +8 -0
  94. package/src/composables/useEntityItemShowPage.ts +22 -0
  95. package/src/composables/useListPage.ts +71 -0
  96. package/src/composables/useListPage.types.ts +6 -0
  97. package/src/composables/useUnsavedChangesGuard.ts +17 -1
  98. package/src/domain/QdBadge.vue +36 -0
  99. package/src/domain/QdDomainBar.vue +213 -0
  100. package/src/domain/QdDomainBarZone.vue +19 -0
  101. package/src/domain/index.ts +6 -0
  102. package/src/domain/registry.ts +122 -0
  103. package/src/favorites/index.ts +7 -0
  104. package/src/favorites/store.ts +172 -0
  105. package/src/favorites/useFavorites.ts +217 -0
  106. package/src/i18n/defaults/core.en.generated.ts +132 -0
  107. package/src/i18n/defaults/core.en.yml +132 -0
  108. package/src/i18n/defaults/core.fr.generated.ts +132 -0
  109. package/src/i18n/defaults/core.fr.yml +132 -0
  110. package/src/index.ts +23 -0
  111. package/src/kernel/Kernel.routing.ts +4 -15
  112. package/src/kernel/Kernel.types.ts +5 -1
  113. package/src/kernel/Kernel.vue.ts +2 -2
  114. package/src/kernel/KernelContext.routing.ts +10 -1
  115. package/src/kernel/KernelContext.ts +7 -0
  116. package/src/kernel/KernelContext.types.ts +2 -0
  117. package/src/kernel/homeRoute.ts +45 -0
  118. package/src/module/moduleRegistry.ts +4 -0
  119. package/src/run/index.ts +6 -0
  120. package/src/run/run.ts +162 -0
  121. package/src/run/useRun.ts +207 -0
  122. package/src/styles/_cards-dashboard.scss +190 -0
  123. package/src/styles/_qd-board.scss +359 -0
  124. package/src/styles/_qd-cards.scss +1197 -0
  125. package/src/styles/_qd-domain-bar.scss +159 -0
  126. package/src/styles/_qd-run.scss +135 -0
  127. package/src/styles/index.scss +4 -0
  128. package/src/zones/ZoneRegistry.ts +16 -0
  129. package/src/zones/index.ts +1 -0
@@ -0,0 +1,47 @@
1
+ {
2
+ "type": "queue",
3
+ "title": "Queue",
4
+ "question": "What do I have to do?",
5
+ "readings": [
6
+ "the big number: how many are waiting, with a short note (\"1 expires tomorrow\")",
7
+ "each line: one item to process, with its own gesture",
8
+ "the background that advances under a line: its age against the promised delay",
9
+ "its warmth: how urgent it is (cool, warm, overdue), doubled by the age written on the right"
10
+ ],
11
+ "strengths": [
12
+ "the only card whose lines each carry a gesture",
13
+ "the oldest and the overdue stand out without reading the numbers",
14
+ "the main action opens the first one, and the run bar takes over from there"
15
+ ],
16
+ "avoid": [
17
+ "when nobody acts on the items: use metric with hot lines",
18
+ "for more than a handful of lines: link to the list instead"
19
+ ],
20
+ "sizes": ["s", "m", "l"],
21
+ "options": {
22
+ "ageUnit": { "type": "string", "enum": ["min", "h", "d"], "default": "d", "description": "The unit of `age` and `due`" },
23
+ "maxItems": { "type": "integer", "minimum": 1, "maximum": 8, "default": 3, "description": "How many lines to show" }
24
+ },
25
+ "action": "mode next: open the first item to process, with the run bar over the whole queue (\"Process the 1st\")",
26
+ "example": {
27
+ "envelope": {
28
+ "title": "Open returns",
29
+ "status": "watch",
30
+ "source": "after-sales",
31
+ "freshness": "2026-11-19T09:40:00Z",
32
+ "to": "/returns",
33
+ "action": { "verb": "Process the oldest", "count": 3, "mode": "next", "to": "/returns/8812" },
34
+ "size": "s"
35
+ },
36
+ "data": {
37
+ "total": 3,
38
+ "note": "1 overdue",
39
+ "items": [
40
+ { "label": "Return 8812 · broken screen", "age": 11, "due": 10, "to": "/returns/8812" },
41
+ { "label": "Return 8840 · wrong series", "age": 7, "due": 10, "to": "/returns/8840" },
42
+ { "label": "Return 8857 · withdrawal", "age": 3, "due": 14, "to": "/returns/8857", "action": { "verb": "Remind", "to": "/returns/8857/remind" } }
43
+ ]
44
+ },
45
+ "options": { "ageUnit": "d", "maxItems": 3 }
46
+ }
47
+ }
@@ -0,0 +1,32 @@
1
+ {
2
+ "type": "object",
3
+ "required": ["items"],
4
+ "additionalProperties": false,
5
+ "properties": {
6
+ "total": { "type": "integer", "minimum": 0, "description": "How many are waiting (the lines show only the first ones)" },
7
+ "note": { "type": "string", "description": "A short note after the number: \"1 expires tomorrow\"" },
8
+ "items": {
9
+ "type": "array",
10
+ "items": {
11
+ "type": "object",
12
+ "required": ["label"],
13
+ "additionalProperties": false,
14
+ "properties": {
15
+ "label": { "type": "string" },
16
+ "age": { "type": "number", "minimum": 0, "description": "How long it has waited, in the ageUnit option" },
17
+ "due": { "type": "number", "minimum": 0, "description": "The promised delay, in the same unit: the background reaches the end there" },
18
+ "to": { "type": ["string", "object"], "description": "The item's route" },
19
+ "action": {
20
+ "type": "object",
21
+ "required": ["verb", "to"],
22
+ "additionalProperties": false,
23
+ "properties": {
24
+ "verb": { "type": "string", "description": "The line's gesture: \"Remind\"" },
25
+ "to": { "type": ["string", "object"] }
26
+ }
27
+ }
28
+ }
29
+ }
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,37 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * ranking - what works? (#5355)
4
+ *
5
+ * The first N, ranked, with their values; a bar per line when asked, scaled
6
+ * to the first. Each line opens its item. See meta.json for the sheet.
7
+ */
8
+ import { computed } from 'vue'
9
+ import { RouterLink, type RouteLocationRaw } from 'vue-router'
10
+ import { useI18n } from '../../../i18n/useI18n'
11
+ import { formatNumber } from '../shared'
12
+ import type { CardSize } from '../../types'
13
+
14
+ const props = defineProps<{
15
+ data: { items: Array<{ label: string; value: number; to?: RouteLocationRaw }> }
16
+ options: { maxItems?: number; unit?: string; bars?: boolean }
17
+ size: CardSize
18
+ }>()
19
+ const { locale } = useI18n()
20
+
21
+ const lines = computed(() => {
22
+ const items = [...props.data.items].sort((a, b) => b.value - a.value).slice(0, props.options.maxItems ?? 5)
23
+ const max = Math.max(0, ...items.map((i) => i.value))
24
+ return items.map((item, i) => ({ ...item, rank: i + 1, share: max ? (item.value / max) * 100 : 0, text: formatNumber(item.value, locale.value, { unit: props.options.unit }) }))
25
+ })
26
+ </script>
27
+
28
+ <template>
29
+ <ol class="qd-ranking">
30
+ <li v-for="line in lines" :key="line.rank" class="qd-ranking-item">
31
+ <span class="qd-ranking-rank">{{ line.rank }}</span>
32
+ <component :is="line.to ? RouterLink : 'span'" :to="line.to" class="qd-ranking-label">{{ line.label }}</component>
33
+ <span class="qd-ranking-value">{{ line.text }}</span>
34
+ <span v-if="options.bars" class="qd-ranking-track" aria-hidden="true"><span class="qd-ranking-bar" :style="{ width: `${line.share}%` }"></span></span>
35
+ </li>
36
+ </ol>
37
+ </template>
@@ -0,0 +1,71 @@
1
+ {
2
+ "type": "ranking",
3
+ "title": "Ranking",
4
+ "question": "What works?",
5
+ "readings": [
6
+ "the rank, the name, the value: the first ones of a list",
7
+ "the bar, when asked: each value against the first"
8
+ ],
9
+ "strengths": [
10
+ "the few that count, in order",
11
+ "each line opens its item"
12
+ ],
13
+ "avoid": [
14
+ "when the items are to process: use queue",
15
+ "for shares of a whole: use split"
16
+ ],
17
+ "sizes": [
18
+ "s",
19
+ "m"
20
+ ],
21
+ "options": {
22
+ "maxItems": {
23
+ "type": "integer",
24
+ "minimum": 1,
25
+ "maximum": 10,
26
+ "default": 5,
27
+ "description": "How many lines"
28
+ },
29
+ "unit": {
30
+ "type": "string",
31
+ "description": "Written after each value"
32
+ },
33
+ "bars": {
34
+ "type": "boolean",
35
+ "default": false,
36
+ "description": "Draw a bar per line, scaled to the first"
37
+ }
38
+ },
39
+ "action": "mode list: the whole ranking",
40
+ "example": {
41
+ "envelope": {
42
+ "title": "Best sellers (7 d)",
43
+ "status": "info",
44
+ "source": "catalogue",
45
+ "to": "/products",
46
+ "size": "s"
47
+ },
48
+ "data": {
49
+ "items": [
50
+ {
51
+ "label": "iiyama ProLite 27\" screen",
52
+ "value": 142,
53
+ "to": "/products/1"
54
+ },
55
+ {
56
+ "label": "Brother MFC-J5345DW",
57
+ "value": 97,
58
+ "to": "/products/2"
59
+ },
60
+ {
61
+ "label": "Samsung 24\" S3",
62
+ "value": 88,
63
+ "to": "/products/3"
64
+ }
65
+ ]
66
+ },
67
+ "options": {
68
+ "maxItems": 5
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,35 @@
1
+ {
2
+ "type": "object",
3
+ "required": [
4
+ "items"
5
+ ],
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "items": {
9
+ "type": "array",
10
+ "items": {
11
+ "type": "object",
12
+ "required": [
13
+ "label",
14
+ "value"
15
+ ],
16
+ "additionalProperties": false,
17
+ "properties": {
18
+ "label": {
19
+ "type": "string"
20
+ },
21
+ "value": {
22
+ "type": "number"
23
+ },
24
+ "to": {
25
+ "type": [
26
+ "string",
27
+ "object"
28
+ ],
29
+ "description": "Where it opens"
30
+ }
31
+ }
32
+ }
33
+ }
34
+ }
35
+ }
@@ -0,0 +1,41 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * recent - what was I just looking at? (#5349)
4
+ *
5
+ * The last records opened, the last one first, with what each one is and
6
+ * when it was seen. QdRecentCard feeds it live from useRecent.
7
+ * See meta.json for the sheet.
8
+ */
9
+ import { computed } from 'vue'
10
+ import { RouterLink, type RouteLocationRaw } from 'vue-router'
11
+ import { useI18n } from '../../../i18n/useI18n'
12
+ import { relativeTime } from '../shared'
13
+ import type { CardSize } from '../../types'
14
+
15
+ interface RecentData {
16
+ items: Array<{ label: string; to: RouteLocationRaw; at?: string | number; note?: string }>
17
+ }
18
+
19
+ const props = defineProps<{ data: RecentData; options: { maxItems?: number }; size: CardSize }>()
20
+ const { locale } = useI18n()
21
+
22
+ const lines = computed(() =>
23
+ props.data.items.slice(0, props.options.maxItems ?? 5).map((item) => ({
24
+ ...item,
25
+ when: item.at === undefined ? null : relativeTime(item.at, locale.value),
26
+ whenTitle: item.at === undefined ? undefined : new Date(item.at).toLocaleString(locale.value),
27
+ }))
28
+ )
29
+ </script>
30
+
31
+ <template>
32
+ <ul class="qd-recent">
33
+ <li v-for="(line, i) in lines" :key="i" class="qd-recent-item">
34
+ <RouterLink :to="line.to" class="qd-recent-link">
35
+ <span class="qd-recent-label">{{ line.label }}</span>
36
+ <span v-if="line.note" class="qd-recent-note">{{ line.note }}</span>
37
+ </RouterLink>
38
+ <time v-if="line.when" class="qd-recent-when" :datetime="new Date(line.at!).toISOString()" :title="line.whenTitle">{{ line.when }}</time>
39
+ </li>
40
+ </ul>
41
+ </template>
@@ -0,0 +1,32 @@
1
+ {
2
+ "type": "recent",
3
+ "title": "Recent",
4
+ "question": "What was I just looking at?",
5
+ "readings": [
6
+ "the last records the person opened, the last one first",
7
+ "what each one is, and when it was seen"
8
+ ],
9
+ "strengths": [
10
+ "finds again what someone was working on, without searching",
11
+ "filled on its own: nothing to set up"
12
+ ],
13
+ "avoid": [
14
+ "as a history of changes: it says what was seen, not what was done"
15
+ ],
16
+ "sizes": ["s", "m"],
17
+ "options": {
18
+ "maxItems": { "type": "integer", "minimum": 1, "maximum": 20, "default": 5, "description": "How many lines to show" }
19
+ },
20
+ "action": "none: each line opens its record",
21
+ "example": {
22
+ "envelope": { "title": "Recent", "status": "info", "size": "s" },
23
+ "data": {
24
+ "items": [
25
+ { "label": "Order 575806", "to": "/orders/575806", "at": "2026-11-19T09:38:00Z", "note": "Order" },
26
+ { "label": "Mairie de Lyon", "to": "/customers/88", "at": "2026-11-19T08:12:00Z", "note": "Customer" },
27
+ { "label": "Return 8812", "to": "/returns/8812", "at": "2026-11-18T16:40:00Z", "note": "Return" }
28
+ ]
29
+ },
30
+ "options": { "maxItems": 5 }
31
+ }
32
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "type": "object",
3
+ "required": ["items"],
4
+ "additionalProperties": false,
5
+ "properties": {
6
+ "items": {
7
+ "type": "array",
8
+ "items": {
9
+ "type": "object",
10
+ "required": ["label", "to"],
11
+ "additionalProperties": false,
12
+ "properties": {
13
+ "label": { "type": "string" },
14
+ "to": { "type": ["string", "object"], "description": "The page it opens" },
15
+ "at": { "type": ["string", "number"], "description": "When it was seen: an ISO string or a timestamp in ms" },
16
+ "note": { "type": "string", "description": "What it is: \"Book\", \"Order\"" }
17
+ }
18
+ }
19
+ }
20
+ }
21
+ }
@@ -0,0 +1,83 @@
1
+ /**
2
+ * What qdadm's generic cards share (#5339): numbers in the app's language,
3
+ * the line of a series.
4
+ */
5
+ import type { TranslateParams } from '../../i18n/types'
6
+
7
+ /** A number as the app's locale writes it, with a unit when given */
8
+ export function formatNumber(value: number, locale: string, { decimals, unit }: { decimals?: number; unit?: string } = {}): string {
9
+ const text = new Intl.NumberFormat(locale, {
10
+ minimumFractionDigits: decimals ?? 0,
11
+ maximumFractionDigits: decimals ?? 2,
12
+ }).format(value)
13
+ if (!unit) return text
14
+ // "12 %", "412 k€": a narrow no-break space, as French writes it; "%"-led units stay glued in English
15
+ return /^[%‰]$/.test(unit) && locale.startsWith('en') ? `${text}${unit}` : `${text}\u202f${unit}`
16
+ }
17
+
18
+ /** A signed change: "+4", "−1,3" */
19
+ export function formatDelta(value: number, locale: string, decimals?: number): string {
20
+ const text = formatNumber(Math.abs(value), locale, { decimals })
21
+ return value > 0 ? `+${text}` : value < 0 ? `−${text}` : text
22
+ }
23
+
24
+ /** Points of a series in a box of width × height, the y axis going down */
25
+ export function seriesPoints(series: number[], width: number, height: number, pad = 2): Array<[number, number]> {
26
+ if (series.length === 0) return []
27
+ const min = Math.min(...series)
28
+ const max = Math.max(...series)
29
+ const span = max - min || 1
30
+ const step = series.length > 1 ? width / (series.length - 1) : 0
31
+ return series.map((v, i) => [i * step, pad + (height - 2 * pad) * (1 - (v - min) / span)])
32
+ }
33
+
34
+ /** The line and the area under it, as SVG paths */
35
+ export function seriesPaths(series: number[], width: number, height: number): { line: string; area: string } {
36
+ const pts = seriesPoints(series, width, height)
37
+ if (pts.length === 0) return { line: '', area: '' }
38
+ const line = pts.map(([x, y], i) => `${i ? 'L' : 'M'}${x.toFixed(2)},${y.toFixed(2)}`).join(' ')
39
+ const area = `${line} L${pts[pts.length - 1]![0].toFixed(2)},${height} L0,${height} Z`
40
+ return { line, area }
41
+ }
42
+
43
+ /** Whether a change is good news, given which way is better */
44
+ export function deltaTone(value: number, higherIs: 'better' | 'worse' | 'neutral' = 'better'): 'good' | 'critical' | 'neutral' {
45
+ if (value === 0 || higherIs === 'neutral') return 'neutral'
46
+ return (value > 0) === (higherIs === 'better') ? 'good' : 'critical'
47
+ }
48
+
49
+ /** "3 minutes ago", "yesterday": a moment against now, in the app's language */
50
+ export function relativeTime(at: string | number | Date, locale: string, now = Date.now()): string | null {
51
+ const date = at instanceof Date ? at : new Date(at)
52
+ if (Number.isNaN(date.getTime())) return null
53
+ const seconds = Math.round((date.getTime() - now) / 1000)
54
+ const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' })
55
+ const abs = Math.abs(seconds)
56
+ if (abs < 45) return rtf.format(0, 'second')
57
+ if (abs < 3600) return rtf.format(Math.round(seconds / 60), 'minute')
58
+ if (abs < 86400) return rtf.format(Math.round(seconds / 3600), 'hour')
59
+ return rtf.format(Math.round(seconds / 86400), 'day')
60
+ }
61
+
62
+ /**
63
+ * When, in a dated list: a time for today, "tomorrow" / "yesterday", else a
64
+ * short date; `withTime` adds the time to tomorrow's and yesterday's.
65
+ */
66
+ export function dayWords(
67
+ at: Date,
68
+ now: Date,
69
+ locale: string,
70
+ t: (key: string, params?: TranslateParams) => string,
71
+ withTime = true
72
+ ): { when: string; full: string; iso: string } {
73
+ const iso = Number.isNaN(at.getTime()) ? '' : at.toISOString()
74
+ if (!iso) return { when: '', full: '', iso }
75
+ const day = (d: Date) => new Date(d.getFullYear(), d.getMonth(), d.getDate()).getTime()
76
+ const diff = Math.round((day(at) - day(now)) / 86400000)
77
+ const time = at.toLocaleTimeString(locale, { hour: '2-digit', minute: '2-digit' })
78
+ const full = at.toLocaleString(locale)
79
+ if (diff === 0) return { when: withTime ? time : t('core.cards.agenda.today'), full, iso }
80
+ if (diff === 1) return { when: withTime ? t('core.cards.agenda.tomorrowAt', { time }) : t('core.cards.agenda.tomorrow'), full, iso }
81
+ if (diff === -1) return { when: withTime ? t('core.cards.agenda.yesterdayAt', { time }) : t('core.cards.agenda.yesterday'), full, iso }
82
+ return { when: at.toLocaleDateString(locale, { day: 'numeric', month: 'short' }), full, iso }
83
+ }
@@ -0,0 +1,52 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * split - where does it come from? (#5355)
4
+ *
5
+ * The total, one bar split in parts, and the legend with each part's name and
6
+ * value. The colours come from a fixed palette by rank, never from the data;
7
+ * the parts past `maxParts` go into a grey "others". Everything the colour
8
+ * says is also written. See meta.json for the sheet.
9
+ */
10
+ import { computed } from 'vue'
11
+ import { RouterLink, type RouteLocationRaw } from 'vue-router'
12
+ import { useI18n } from '../../../i18n/useI18n'
13
+ import { formatNumber } from '../shared'
14
+ import type { CardSize } from '../../types'
15
+
16
+ interface Part {
17
+ label: string
18
+ value: number
19
+ to?: RouteLocationRaw
20
+ }
21
+ const props = defineProps<{ data: { total?: number; parts: Part[] }; options: { maxParts?: number; unit?: string }; size: CardSize }>()
22
+ const { t, locale } = useI18n()
23
+
24
+ const parts = computed(() => {
25
+ const sorted = [...props.data.parts].sort((a, b) => b.value - a.value)
26
+ const max = props.options.maxParts ?? 4
27
+ const shown: Array<Part & { tone: string }> = sorted.slice(0, max).map((p, i) => ({ ...p, tone: String(i + 1) }))
28
+ const rest = sorted.slice(max)
29
+ if (rest.length) shown.push({ label: t('core.cards.split.others'), value: rest.reduce((s, p) => s + p.value, 0), tone: 'others' })
30
+ return shown
31
+ })
32
+ const sum = computed(() => props.data.parts.reduce((s, p) => s + p.value, 0))
33
+ const total = computed(() => props.data.total ?? sum.value)
34
+ const share = (v: number) => (sum.value ? (v / sum.value) * 100 : 0)
35
+ const fmt = (v: number) => formatNumber(v, locale.value)
36
+ </script>
37
+
38
+ <template>
39
+ <div class="qd-split">
40
+ <span class="qd-card-value">{{ formatNumber(total, locale, { unit: options.unit }) }}</span>
41
+ <div class="qd-split-bar" aria-hidden="true">
42
+ <span v-for="p in parts" :key="p.label" class="qd-split-part" :data-tone="p.tone" :style="{ width: `${share(p.value)}%` }" :title="`${p.label}: ${fmt(p.value)}`"></span>
43
+ </div>
44
+ <ul class="qd-split-legend">
45
+ <li v-for="p in parts" :key="p.label">
46
+ <span class="qd-split-swatch" :data-tone="p.tone" aria-hidden="true"></span>
47
+ <component :is="p.to ? RouterLink : 'span'" :to="p.to" class="qd-split-label">{{ p.label }}</component>
48
+ <span class="qd-split-value">{{ fmt(p.value) }}</span>
49
+ </li>
50
+ </ul>
51
+ </div>
52
+ </template>
@@ -0,0 +1,72 @@
1
+ {
2
+ "type": "split",
3
+ "title": "Split",
4
+ "question": "Where does it come from?",
5
+ "readings": [
6
+ "the total",
7
+ "one bar split in parts, a fixed colour per part",
8
+ "the legend: each part's name and value, written, so colour is never needed"
9
+ ],
10
+ "strengths": [
11
+ "the weight of each source in one line",
12
+ "the biggest parts first, the small ones grouped in \"others\""
13
+ ],
14
+ "avoid": [
15
+ "for more than a handful of parts: use ranking",
16
+ "for a change over time: use trend"
17
+ ],
18
+ "sizes": [
19
+ "s",
20
+ "m"
21
+ ],
22
+ "options": {
23
+ "maxParts": {
24
+ "type": "integer",
25
+ "minimum": 2,
26
+ "maximum": 6,
27
+ "default": 4,
28
+ "description": "Parts drawn; the rest go into \"others\""
29
+ },
30
+ "unit": {
31
+ "type": "string",
32
+ "description": "Written after the total"
33
+ }
34
+ },
35
+ "action": "mode list: the detail by part",
36
+ "example": {
37
+ "envelope": {
38
+ "title": "Today's orders",
39
+ "status": "info",
40
+ "source": "marketplaces",
41
+ "to": "/orders",
42
+ "size": "s"
43
+ },
44
+ "data": {
45
+ "parts": [
46
+ {
47
+ "label": "Amazon FR",
48
+ "value": 82
49
+ },
50
+ {
51
+ "label": "Shop",
52
+ "value": 50
53
+ },
54
+ {
55
+ "label": "Cdiscount",
56
+ "value": 35
57
+ },
58
+ {
59
+ "label": "Fnac",
60
+ "value": 12
61
+ },
62
+ {
63
+ "label": "Rakuten",
64
+ "value": 7
65
+ }
66
+ ]
67
+ },
68
+ "options": {
69
+ "maxParts": 3
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "type": "object",
3
+ "required": [
4
+ "parts"
5
+ ],
6
+ "additionalProperties": false,
7
+ "properties": {
8
+ "total": {
9
+ "type": "number",
10
+ "description": "The total, when the parts do not sum to it"
11
+ },
12
+ "parts": {
13
+ "type": "array",
14
+ "items": {
15
+ "type": "object",
16
+ "required": [
17
+ "label",
18
+ "value"
19
+ ],
20
+ "additionalProperties": false,
21
+ "properties": {
22
+ "label": {
23
+ "type": "string"
24
+ },
25
+ "value": {
26
+ "type": "number",
27
+ "minimum": 0
28
+ },
29
+ "to": {
30
+ "type": [
31
+ "string",
32
+ "object"
33
+ ],
34
+ "description": "Where it opens"
35
+ }
36
+ }
37
+ }
38
+ }
39
+ }
40
+ }
@@ -0,0 +1,75 @@
1
+ <script setup lang="ts">
2
+ /**
3
+ * trend - is this normal? (#5355)
4
+ *
5
+ * The curve, the band of normal (one for the whole curve, or one per point),
6
+ * and the points outside it marked and counted in words. The last value is
7
+ * written. See meta.json for the sheet.
8
+ */
9
+ import { computed } from 'vue'
10
+ import { useI18n } from '../../../i18n/useI18n'
11
+ import { formatNumber } from '../shared'
12
+ import type { CardSize } from '../../types'
13
+
14
+ interface Point {
15
+ value: number
16
+ at?: string | number
17
+ low?: number
18
+ high?: number
19
+ }
20
+ const props = defineProps<{
21
+ data: { series: Point[]; normal?: { low: number; high: number }; label?: string }
22
+ options: { unit?: string; decimals?: number }
23
+ size: CardSize
24
+ }>()
25
+ const { t, locale } = useI18n()
26
+
27
+ const W = 100
28
+ const H = 40
29
+ const PAD = 3
30
+ const bands = computed(() => props.data.series.map((p) => ({ low: p.low ?? props.data.normal?.low, high: p.high ?? props.data.normal?.high })))
31
+ const range = computed(() => {
32
+ const all = props.data.series.flatMap((p, i) => [p.value, bands.value[i]!.low, bands.value[i]!.high]).filter((v): v is number => typeof v === 'number')
33
+ const min = Math.min(...all)
34
+ const max = Math.max(...all)
35
+ return { min, span: max - min || 1 }
36
+ })
37
+ const x = (i: number) => (props.data.series.length > 1 ? (i / (props.data.series.length - 1)) * W : W / 2)
38
+ const y = (v: number) => PAD + (H - 2 * PAD) * (1 - (v - range.value.min) / range.value.span)
39
+ const line = computed(() => props.data.series.map((p, i) => `${i ? 'L' : 'M'}${x(i).toFixed(2)},${y(p.value).toFixed(2)}`).join(' '))
40
+ const band = computed(() => {
41
+ const pts = bands.value.map((b, i) => ({ i, b })).filter(({ b }) => b.low !== undefined && b.high !== undefined)
42
+ if (pts.length < 2) return ''
43
+ const top = pts.map(({ i, b }, k) => `${k ? 'L' : 'M'}${x(i).toFixed(2)},${y(b.high!).toFixed(2)}`).join(' ')
44
+ const bottom = [...pts].reverse().map(({ i, b }) => `L${x(i).toFixed(2)},${y(b.low!).toFixed(2)}`).join(' ')
45
+ return `${top} ${bottom} Z`
46
+ })
47
+ const outside = computed(() =>
48
+ props.data.series
49
+ .map((p, i) => ({ i, p, b: bands.value[i]! }))
50
+ .filter(({ p, b }) => (b.low !== undefined && p.value < b.low) || (b.high !== undefined && p.value > b.high))
51
+ .map(({ i, p }) => ({ left: `${x(i)}%`, top: `${(y(p.value) / H) * 100}%`, value: p.value }))
52
+ )
53
+ const last = computed(() => props.data.series[props.data.series.length - 1])
54
+ const fmt = (v: number) => formatNumber(v, locale.value, { decimals: props.options.decimals, unit: props.options.unit })
55
+ const hasBand = computed(() => bands.value.some((b) => b.low !== undefined && b.high !== undefined))
56
+ </script>
57
+
58
+ <template>
59
+ <div class="qd-trend">
60
+ <div v-if="last" class="qd-metric-line">
61
+ <span class="qd-card-value">{{ fmt(last.value) }}</span>
62
+ <span v-if="data.label" class="qd-card-unit">{{ data.label }}</span>
63
+ </div>
64
+ <div class="qd-trend-chart" aria-hidden="true">
65
+ <svg :viewBox="`0 0 ${W} ${H}`" preserveAspectRatio="none">
66
+ <path v-if="band" :d="band" class="qd-trend-band" />
67
+ <path :d="line" class="qd-spark-line" vector-effect="non-scaling-stroke" />
68
+ </svg>
69
+ <span v-for="(o, i) in outside" :key="i" class="qd-trend-out" :style="{ left: o.left, top: o.top }"></span>
70
+ </div>
71
+ <p v-if="hasBand" class="qd-trend-reading" :class="outside.length ? 'qd-tone-text--watch' : null">
72
+ {{ outside.length ? t('core.cards.trend.outside', { count: outside.length }) : t('core.cards.trend.within') }}
73
+ </p>
74
+ </div>
75
+ </template>