@tekkare/romulus 0.1.319 → 0.1.320
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/module.json +1 -1
- package/dist/runtime/components/Dashboard.vue +125 -2
- package/dist/runtime/components/DashboardWidget.vue +10 -1
- package/dist/runtime/components/ProjectOverview.vue +36 -2
- package/dist/runtime/composables/useRmDashboard.js +11 -1
- package/dist/runtime/utils/dashboard.d.ts +33 -0
- package/dist/runtime/utils/dashboard.js +6 -0
- package/layer/app/components/project/Dashboard.vue +102 -37
- package/layer/app/components/project/Page.vue +83 -12
- package/layer/app/composables/useProjectDashboard.ts +26 -7
- package/layer/app/oip-defaults/dashboardWidgets.ts +6 -0
- package/layer/app/oip-defaults/projects.ts +282 -17
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -10,6 +10,11 @@
|
|
|
10
10
|
ne bouge qu'en mode edition : en lecture, un glisser sur un graphe ne doit
|
|
11
11
|
pas deplacer la carte.
|
|
12
12
|
|
|
13
|
+
Le tiroir d'ajout ne propose que les entrees qui auront quelque chose a
|
|
14
|
+
montrer (rmAddableWidgets) ; un widget deja pose d'une entree devenue vide
|
|
15
|
+
reste sur la grille, avec sa note. Le menu « Modeles » remplace le tableau
|
|
16
|
+
par un jeu de widgets (`templates`), apres confirmation s'il y en a deja.
|
|
17
|
+
|
|
13
18
|
Ce que le paquet ne sait pas :
|
|
14
19
|
- la source de chaque entree (`sourceOf`), que l'app lit ou elle veut
|
|
15
20
|
(Directus dans les apps OIP) ;
|
|
@@ -24,10 +29,12 @@ import { computed, reactive, ref } from 'vue'
|
|
|
24
29
|
import { rmGridBottom } from '../utils/dashboardGrid'
|
|
25
30
|
import {
|
|
26
31
|
RM_WIDGET_MIN,
|
|
32
|
+
rmAddableWidgets,
|
|
27
33
|
rmDashboardExportSheets,
|
|
28
34
|
rmNewWidgetId,
|
|
29
35
|
rmWidgetKind,
|
|
30
36
|
type RmDashboardLang,
|
|
37
|
+
type RmDashboardTemplate,
|
|
31
38
|
type RmDashboardWidget,
|
|
32
39
|
type RmWidgetContext,
|
|
33
40
|
type RmWidgetData,
|
|
@@ -58,6 +65,8 @@ const props = withDefaults(defineProps<{
|
|
|
58
65
|
scopeLabel?: string
|
|
59
66
|
/** Ce que disent les widgets et l'editeur quand le contexte n'a aucune marque. */
|
|
60
67
|
noBrandsText?: string
|
|
68
|
+
/** Les jeux de widgets du menu « Modeles ». Vide : pas de menu. */
|
|
69
|
+
templates?: RmDashboardTemplate[]
|
|
61
70
|
}>(), {
|
|
62
71
|
loading: false,
|
|
63
72
|
failed: false,
|
|
@@ -70,6 +79,7 @@ const props = withDefaults(defineProps<{
|
|
|
70
79
|
emptyText: undefined,
|
|
71
80
|
scopeLabel: undefined,
|
|
72
81
|
noBrandsText: undefined,
|
|
82
|
+
templates: () => [],
|
|
73
83
|
})
|
|
74
84
|
|
|
75
85
|
const emit = defineEmits<{
|
|
@@ -97,6 +107,13 @@ const T = computed(() => props.lang === 'en'
|
|
|
97
107
|
loadFailed: 'The dashboard could not be loaded.',
|
|
98
108
|
emptyTitle: 'An empty dashboard',
|
|
99
109
|
emptyText: 'Add charts, tables or key figures from the catalogue.',
|
|
110
|
+
templates: 'Templates',
|
|
111
|
+
templatesLabel: 'Dashboard templates',
|
|
112
|
+
replaceTitle: 'Replace the dashboard?',
|
|
113
|
+
replaceText: (n: number) => `The ${n} current widget${n > 1 ? 's' : ''} will be replaced by the template.`,
|
|
114
|
+
replace: 'Replace',
|
|
115
|
+
cancel: 'Cancel',
|
|
116
|
+
templateEmpty: 'This template has nothing to put here.',
|
|
100
117
|
}
|
|
101
118
|
: {
|
|
102
119
|
notSaved: 'Non enregistré.',
|
|
@@ -109,6 +126,13 @@ const T = computed(() => props.lang === 'en'
|
|
|
109
126
|
loadFailed: 'Le tableau de bord n\'a pas pu être chargé.',
|
|
110
127
|
emptyTitle: 'Un tableau de bord vide',
|
|
111
128
|
emptyText: 'Ajoutez des graphiques, des tableaux ou des chiffres clés tirés du catalogue.',
|
|
129
|
+
templates: 'Modèles',
|
|
130
|
+
templatesLabel: 'Modèles de tableau de bord',
|
|
131
|
+
replaceTitle: 'Remplacer le tableau de bord ?',
|
|
132
|
+
replaceText: (n: number) => `${n > 1 ? `Les ${n} widgets en place seront remplacés` : 'Le widget en place sera remplacé'} par le modèle.`,
|
|
133
|
+
replace: 'Remplacer',
|
|
134
|
+
cancel: 'Annuler',
|
|
135
|
+
templateEmpty: 'Ce modèle n\'a rien à poser ici.',
|
|
112
136
|
})
|
|
113
137
|
|
|
114
138
|
/** Tete (titre, contexte) et pied (source) de la carte, autour du graphe. */
|
|
@@ -147,6 +171,67 @@ function move(next: { id: string, x: number, y: number, w: number, h: number }[]
|
|
|
147
171
|
const editorOpen = ref(false)
|
|
148
172
|
const editedId = ref('')
|
|
149
173
|
|
|
174
|
+
/**
|
|
175
|
+
* Le catalogue du tiroir : les entrees qui auront quelque chose a montrer,
|
|
176
|
+
* plus celle du widget qu'on regle, meme devenue vide, pour que ses reglages
|
|
177
|
+
* s'ouvrent encore.
|
|
178
|
+
*/
|
|
179
|
+
const addable = computed(() => {
|
|
180
|
+
const list = rmAddableWidgets(props.catalog, props.context)
|
|
181
|
+
const edited = editedId.value ? byId.value[editedId.value] : undefined
|
|
182
|
+
const kept = edited ? props.catalog.find(e => e.kind === edited.kind) : undefined
|
|
183
|
+
return kept && !list.includes(kept) ? [...list, kept] : list
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
// --- Modeles ------------------------------------------------------------------
|
|
187
|
+
|
|
188
|
+
const templatesOpen = ref(false)
|
|
189
|
+
const templatesAnchor = ref<HTMLElement | null>(null)
|
|
190
|
+
const templateBusy = ref('')
|
|
191
|
+
const templateNote = ref('')
|
|
192
|
+
/** Le modele choisi, en attente de confirmation parce que la grille n'est pas vide. */
|
|
193
|
+
const pendingTemplate = ref<RmDashboardTemplate | null>(null)
|
|
194
|
+
|
|
195
|
+
const templateGroups = computed(() => {
|
|
196
|
+
const out: { label: string, entries: RmDashboardTemplate[] }[] = []
|
|
197
|
+
for (const entry of props.templates) {
|
|
198
|
+
const label = entry.group ?? T.value.templates
|
|
199
|
+
let group = out.find(g => g.label === label)
|
|
200
|
+
if (!group) out.push((group = { label, entries: [] }))
|
|
201
|
+
group.entries.push(entry)
|
|
202
|
+
}
|
|
203
|
+
return out
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
function pickTemplate(template: RmDashboardTemplate) {
|
|
207
|
+
templateNote.value = ''
|
|
208
|
+
if (props.widgets.length) {
|
|
209
|
+
pendingTemplate.value = template
|
|
210
|
+
templatesOpen.value = false
|
|
211
|
+
return
|
|
212
|
+
}
|
|
213
|
+
applyTemplate(template)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
async function applyTemplate(template: RmDashboardTemplate) {
|
|
217
|
+
pendingTemplate.value = null
|
|
218
|
+
templateBusy.value = template.id
|
|
219
|
+
try {
|
|
220
|
+
const widgets = await template.widgets()
|
|
221
|
+
if (!widgets?.length) {
|
|
222
|
+
templateNote.value = T.value.templateEmpty
|
|
223
|
+
return
|
|
224
|
+
}
|
|
225
|
+
// Des identifiants neufs : le tableau copie d'un autre projet garde les siens.
|
|
226
|
+
emit('update:widgets', widgets.map(w => ({ ...w, id: rmNewWidgetId() })))
|
|
227
|
+
for (const id of Object.keys(loaded)) delete loaded[id]
|
|
228
|
+
templatesOpen.value = false
|
|
229
|
+
}
|
|
230
|
+
finally {
|
|
231
|
+
templateBusy.value = ''
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
150
235
|
function openAdd() {
|
|
151
236
|
editedId.value = ''
|
|
152
237
|
editorOpen.value = true
|
|
@@ -204,6 +289,11 @@ defineExpose({
|
|
|
204
289
|
<template v-else-if="editing">{{ T.editingHint }}</template>
|
|
205
290
|
</p>
|
|
206
291
|
<div class="rm-dashboard__actions">
|
|
292
|
+
<span v-if="templates.length" ref="templatesAnchor">
|
|
293
|
+
<RmButton variant="tertiary" prefix-icon="Layout" suffix-icon="CaretDown" :disabled="loading || failed" @click="templatesOpen = !templatesOpen">
|
|
294
|
+
{{ T.templates }}
|
|
295
|
+
</RmButton>
|
|
296
|
+
</span>
|
|
207
297
|
<RmButton variant="tertiary" prefix-icon="Plus" :disabled="loading || failed" @click="openAdd">
|
|
208
298
|
{{ T.add }}
|
|
209
299
|
</RmButton>
|
|
@@ -267,10 +357,43 @@ defineExpose({
|
|
|
267
357
|
</template>
|
|
268
358
|
</RmDashboardGrid>
|
|
269
359
|
|
|
360
|
+
<RmPopover v-if="templates.length" v-model="templatesOpen" :anchor="templatesAnchor" :label="T.templatesLabel" width="320px" align="end">
|
|
361
|
+
<div class="rm-dashboard__templates">
|
|
362
|
+
<section v-for="group in templateGroups" :key="group.label" class="rm-dashboard__template-group">
|
|
363
|
+
<p class="rm-dashboard__template-label">{{ group.label }}</p>
|
|
364
|
+
<button
|
|
365
|
+
v-for="item in group.entries"
|
|
366
|
+
:key="item.id"
|
|
367
|
+
type="button"
|
|
368
|
+
class="rm-dashboard__template"
|
|
369
|
+
:disabled="!!templateBusy"
|
|
370
|
+
@click="pickTemplate(item)"
|
|
371
|
+
>
|
|
372
|
+
<span class="rm-dashboard__template-title">{{ item.title }}</span>
|
|
373
|
+
<span v-if="item.description" class="rm-dashboard__template-desc">{{ item.description }}</span>
|
|
374
|
+
</button>
|
|
375
|
+
</section>
|
|
376
|
+
<p v-if="templateNote" class="rm-dashboard__template-note">{{ templateNote }}</p>
|
|
377
|
+
</div>
|
|
378
|
+
</RmPopover>
|
|
379
|
+
|
|
380
|
+
<RmModal :model-value="!!pendingTemplate" size="sm" mode="free" :label="T.replaceTitle" @update:model-value="pendingTemplate = null">
|
|
381
|
+
<template #header>
|
|
382
|
+
<p class="rm-dashboard__confirm-title">{{ T.replaceTitle }}</p>
|
|
383
|
+
</template>
|
|
384
|
+
<p class="rm-dashboard__confirm-text">{{ T.replaceText(widgets.length) }}</p>
|
|
385
|
+
<template #footer>
|
|
386
|
+
<div class="rm-dashboard__confirm-actions">
|
|
387
|
+
<RmButton variant="tertiary" @click="pendingTemplate = null">{{ T.cancel }}</RmButton>
|
|
388
|
+
<RmButton variant="primary" :loading="!!templateBusy" @click="pendingTemplate && applyTemplate(pendingTemplate)">{{ T.replace }}</RmButton>
|
|
389
|
+
</div>
|
|
390
|
+
</template>
|
|
391
|
+
</RmModal>
|
|
392
|
+
|
|
270
393
|
<RmDashboardWidgetEditor
|
|
271
394
|
v-model="editorOpen"
|
|
272
395
|
:widget="editedId ? byId[editedId] ?? null : null"
|
|
273
|
-
:catalog="
|
|
396
|
+
:catalog="addable"
|
|
274
397
|
:context="context"
|
|
275
398
|
:source-of="sourceOf"
|
|
276
399
|
:lang="lang"
|
|
@@ -286,5 +409,5 @@ defineExpose({
|
|
|
286
409
|
</template>
|
|
287
410
|
|
|
288
411
|
<style scoped>
|
|
289
|
-
.rm-dashboard{display:flex;flex-direction:column;gap:16px}.rm-dashboard__bar{align-items:center;display:flex;flex-wrap:wrap;gap:12px;justify-content:space-between}.rm-dashboard__status{align-items:center;color:var(--text-secondary);display:inline-flex;font-size:.8125rem;gap:4px;margin:0;min-height:1.25rem}.rm-dashboard__actions{display:flex;gap:8px;margin-left:auto}.rm-dashboard__link{background:none;color:var(--color-primary);cursor:pointer;padding:0;text-decoration:underline}
|
|
412
|
+
.rm-dashboard{display:flex;flex-direction:column;gap:16px}.rm-dashboard__bar{align-items:center;display:flex;flex-wrap:wrap;gap:12px;justify-content:space-between}.rm-dashboard__status{align-items:center;color:var(--text-secondary);display:inline-flex;font-size:.8125rem;gap:4px;margin:0;min-height:1.25rem}.rm-dashboard__actions{display:flex;gap:8px;margin-left:auto}.rm-dashboard__link{background:none;color:var(--color-primary);cursor:pointer;padding:0;text-decoration:underline}.rm-dashboard__templates{display:flex;flex-direction:column;gap:12px;padding:4px}.rm-dashboard__template-group{display:flex;flex-direction:column;gap:6px}.rm-dashboard__template-label{color:var(--text-muted);font-size:var(--font-11);font-weight:var(--weight-semibold);letter-spacing:.06em;margin:0 4px;text-transform:uppercase}.rm-dashboard__template{background:var(--bg-surface);border:1px solid var(--border-soft);border-radius:var(--radius-md);color:var(--text-primary);cursor:pointer;display:flex;flex-direction:column;gap:2px;padding:10px 12px;text-align:left;transition:border-color var(--duration-fast) var(--ease-out),box-shadow var(--duration-fast) var(--ease-out);width:100%}.rm-dashboard__template:hover:not(:disabled){border-color:var(--border-default);box-shadow:var(--shadow-xs)}.rm-dashboard__template:focus-visible{box-shadow:var(--shadow-focus);outline:none}.rm-dashboard__template:disabled{cursor:default;opacity:.6}.rm-dashboard__template-title{font-size:var(--font-13);font-weight:var(--weight-semibold);line-height:18px}.rm-dashboard__template-desc{color:var(--text-secondary);font-size:var(--font-12);line-height:16px}.rm-dashboard__template-note{color:var(--text-secondary);font-size:var(--font-12);margin:0 4px}.rm-dashboard__confirm-title{font-size:var(--font-15,15px);font-weight:var(--weight-bold);margin:0}.rm-dashboard__confirm-text{color:var(--text-secondary);font-size:var(--font-13);margin:0}.rm-dashboard__confirm-actions{display:flex;gap:8px;justify-content:flex-end}
|
|
290
413
|
</style>
|
|
@@ -151,8 +151,17 @@ async function run() {
|
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
|
|
154
|
+
// Une seule chaine : un tableau neuf a chaque lecture relancerait le widget
|
|
155
|
+
// des qu'une dependance bouge sans changer (les lignes du projet recalculees
|
|
156
|
+
// au changement d'onglet, par exemple).
|
|
154
157
|
watch(
|
|
155
|
-
() => [
|
|
158
|
+
() => [
|
|
159
|
+
props.widget.kind,
|
|
160
|
+
JSON.stringify(params.value),
|
|
161
|
+
brands.value.join('|'),
|
|
162
|
+
props.lang,
|
|
163
|
+
JSON.stringify(props.kind.deps ? props.kind.deps(props.context) : props.context),
|
|
164
|
+
].join('\u0001'),
|
|
156
165
|
run,
|
|
157
166
|
{ immediate: true },
|
|
158
167
|
)
|
|
@@ -6,7 +6,9 @@
|
|
|
6
6
|
ecrivent, et les rangees que l'app deduit de ses ressources : marques,
|
|
7
7
|
maladies, pays...) avec les informations du projet en pied ; a droite les
|
|
8
8
|
facons d'avancer (`steps`, un lien par onglet) et la repartition par
|
|
9
|
-
famille
|
|
9
|
+
famille, avec un apercu du tableau de bord (`dashboard` : ses chiffres
|
|
10
|
+
cles ou ses premiers widgets, et le lien vers l'onglet) ; en bas, les
|
|
11
|
+
derniers ajouts.
|
|
10
12
|
|
|
11
13
|
La description s'edite sur place : `describe` part avec le texte, l'app
|
|
12
14
|
l'enregistre et repasse `saving` a faux. Sans `saveError`, l'editeur se
|
|
@@ -33,6 +35,12 @@ const props = withDefaults(
|
|
|
33
35
|
documentsCount?: number | null
|
|
34
36
|
scopeRows?: RmProjectScopeRow[]
|
|
35
37
|
steps?: RmProjectStep[]
|
|
38
|
+
/**
|
|
39
|
+
* L'apercu du tableau de bord : combien de widgets, et un ou deux
|
|
40
|
+
* chiffres cles (ou, a defaut, les titres des premiers widgets).
|
|
41
|
+
* `null` : pas encore lu, la carte attend ; absent : pas de carte.
|
|
42
|
+
*/
|
|
43
|
+
dashboard?: { count: number, figures: { label: string, value: string | number }[] } | null
|
|
36
44
|
/** Le lecteur peut modifier la description. */
|
|
37
45
|
editable?: boolean
|
|
38
46
|
loading?: boolean
|
|
@@ -47,6 +55,7 @@ const props = withDefaults(
|
|
|
47
55
|
documentsCount: null,
|
|
48
56
|
scopeRows: () => [],
|
|
49
57
|
steps: () => [],
|
|
58
|
+
dashboard: undefined,
|
|
50
59
|
editable: true,
|
|
51
60
|
loading: false,
|
|
52
61
|
saving: false,
|
|
@@ -74,6 +83,8 @@ const WORDS = {
|
|
|
74
83
|
breakdown: 'Répartition par famille', nothing: 'Rien n\'est encore rangé.',
|
|
75
84
|
latest: 'Derniers ajouts', all: 'Toutes les ressources', unknown: 'Élément inconnu',
|
|
76
85
|
empty: 'Parcourez les pages et utilisez le bouton Projet d\'une carte pour la ranger ici.',
|
|
86
|
+
dashboard: 'Tableau de bord', widgets: (n: number) => `${n} widget${n > 1 ? 's' : ''}`, noWidgets: 'Aucun widget pour l\'instant.',
|
|
87
|
+
openDashboard: 'Ouvrir',
|
|
77
88
|
},
|
|
78
89
|
en: {
|
|
79
90
|
resources: 'Resources', families: 'Families', documents: 'Documents', comments: 'Comments',
|
|
@@ -86,6 +97,8 @@ const WORDS = {
|
|
|
86
97
|
breakdown: 'Breakdown by family', nothing: 'Nothing filed yet.',
|
|
87
98
|
latest: 'Latest additions', all: 'All resources', unknown: 'Unknown item',
|
|
88
99
|
empty: 'Browse the pages and use the Project button on a card to file it here.',
|
|
100
|
+
dashboard: 'Dashboard', widgets: (n: number) => `${n} widget${n > 1 ? 's' : ''}`, noWidgets: 'No widget yet.',
|
|
101
|
+
openDashboard: 'Open',
|
|
89
102
|
},
|
|
90
103
|
}
|
|
91
104
|
const T = computed(() => WORDS[props.lang] ?? WORDS.fr)
|
|
@@ -267,6 +280,27 @@ function onLatest(event: MouseEvent, row: RmProjectResource) {
|
|
|
267
280
|
</ol>
|
|
268
281
|
</RmCard>
|
|
269
282
|
|
|
283
|
+
<RmSectionCard v-if="dashboard !== undefined" class="rm-project-ov__card">
|
|
284
|
+
<template #header>
|
|
285
|
+
<div class="rm-project-ov__head">
|
|
286
|
+
<span>{{ T.dashboard }}</span>
|
|
287
|
+
<RmButton variant="text" size="sm" suffix-icon="ArrowRight" @click="emit('tab', 'dashboard')">
|
|
288
|
+
{{ T.openDashboard }}
|
|
289
|
+
</RmButton>
|
|
290
|
+
</div>
|
|
291
|
+
</template>
|
|
292
|
+
<RmSkeleton v-if="dashboard === null" width="100%" :height="56" radius="8px" />
|
|
293
|
+
<template v-else>
|
|
294
|
+
<p class="rm-project-ov__context">{{ dashboard.count ? T.widgets(dashboard.count) : T.noWidgets }}</p>
|
|
295
|
+
<dl v-if="dashboard.figures.length" class="rm-project-ov__figures">
|
|
296
|
+
<div v-for="figure in dashboard.figures" :key="figure.label" class="rm-project-ov__figure">
|
|
297
|
+
<dt>{{ figure.label }}</dt>
|
|
298
|
+
<dd>{{ typeof figure.value === 'number' ? figure.value.toLocaleString(lang === 'en' ? 'en-GB' : 'fr-FR') : figure.value }}</dd>
|
|
299
|
+
</div>
|
|
300
|
+
</dl>
|
|
301
|
+
</template>
|
|
302
|
+
</RmSectionCard>
|
|
303
|
+
|
|
270
304
|
<RmSectionCard class="rm-project-ov__card">
|
|
271
305
|
<template #header>{{ T.breakdown }}</template>
|
|
272
306
|
<RmDonutChart v-if="breakdown.length" :data="breakdown" :height="240" hide-legend />
|
|
@@ -299,5 +333,5 @@ function onLatest(event: MouseEvent, row: RmProjectResource) {
|
|
|
299
333
|
</template>
|
|
300
334
|
|
|
301
335
|
<style scoped>
|
|
302
|
-
.rm-project-ov{display:flex;flex-direction:column;gap:16px}.rm-project-ov__top{align-items:stretch;display:grid;gap:16px;grid-template-columns:minmax(0,3fr) minmax(0,2fr)}@media (max-width:1100px){.rm-project-ov__top{grid-template-columns:1fr}}.rm-project-ov__card{min-width:0}.rm-project-ov__card.is-scope,.rm-project-ov__card.is-scope :deep(.r-card__body){display:flex;flex-direction:column}.rm-project-ov__card.is-scope{height:100%}.rm-project-ov__card.is-scope :deep(.r-card__body){flex:1}.rm-project-ov__card-head{align-items:flex-start;display:flex;gap:12px;justify-content:space-between}.rm-project-ov__titles{display:flex;flex-direction:column;gap:4px;margin-bottom:12px}.rm-project-ov__title{color:var(--text-primary);font-size:15px;font-weight:var(--weight-bold);margin:0}.rm-project-ov__context{color:var(--text-muted);font-size:12px;margin:0}.rm-project-ov__scope{display:flex;flex-direction:column;list-style:none;margin:0 0 16px;padding:0}.rm-project-ov__scope-row{align-items:flex-start;border-bottom:1px solid var(--border-soft,var(--border-default));display:flex;gap:12px;padding:8px 0}.rm-project-ov__scope-icon{color:var(--color-secondary);flex:none;margin-top:1px}.rm-project-ov__scope-body{flex:1;min-width:0}.rm-project-ov__scope-key{color:var(--text-muted);font-size:10.5px;font-weight:700;letter-spacing:.08em;margin:0 0 4px;text-transform:uppercase}.rm-project-ov__scope-value{color:var(--text-primary);font-size:13px;font-weight:600;margin:0;white-space:pre-line}.rm-project-ov__tags{display:flex;flex-wrap:wrap;gap:6px}.rm-project-ov__tag{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rm-project-ov__scope-none{color:var(--text-muted);font-size:13px;font-style:italic;margin:0}.rm-project-ov__more{font-size:13px;margin:0;padding-left:16px}.rm-project-ov__placeholder{background:none;border:none;color:var(--text-muted);cursor:pointer;font:inherit;font-size:13px;font-style:italic;margin:0;padding:0}.rm-project-ov__placeholder:hover{text-decoration:underline}.rm-project-ov__edit-actions{display:flex;gap:8px;justify-content:flex-end;margin:8px 0 12px}.rm-project-ov__meta{border-top:1px solid var(--border-default);display:grid;gap:12px;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));margin:auto 0 0;padding-top:16px}.rm-project-ov__meta dt{color:var(--text-secondary);font-size:12px}.rm-project-ov__meta dd{font-size:14px;font-weight:500;margin:2px 0 0}.rm-project-ov__side{display:flex;flex-direction:column;gap:16px;min-width:0}.rm-project-ov__side>:last-child{flex:1}.rm-project-ov__start{display:flex;flex-direction:column;gap:8px;list-style:none;margin:0;padding:0}.rm-project-ov__start-item{align-items:center;background:var(--bg-surface);border:1px solid var(--border-default);border-radius:var(--radius-xl,12px);color:inherit;cursor:pointer;display:flex;font:inherit;gap:12px;padding:10px 12px;text-align:left;transition:border-color .15s,background .15s,box-shadow .15s;width:100%}.rm-project-ov__start-item:hover{background:var(--bg-hover,var(--bg-surface-2));border-color:var(--color-secondary);box-shadow:var(--shadow-sm)}.rm-project-ov__start-item:focus-visible{outline:2px solid var(--color-primary);outline-offset:2px}.rm-project-ov__start-icon{align-items:center;background:var(--bg-hover,var(--bg-surface-2));border-radius:var(--radius-lg,8px);color:var(--color-secondary);display:flex;flex:none;height:34px;justify-content:center;width:34px}.rm-project-ov__start-text{display:flex;flex:1;flex-direction:column;gap:2px;min-width:0}.rm-project-ov__start-title{color:var(--text-primary);font-size:13px;font-weight:700}.rm-project-ov__start-desc{color:var(--text-muted);font-size:11px;line-height:1.45}.rm-project-ov__start-arrow{color:var(--text-muted);flex:none}.rm-project-ov__start-item.is-disabled{cursor:not-allowed;opacity:.55}.rm-project-ov__start-item.is-disabled:hover{background:var(--bg-surface);border-color:var(--border-default);box-shadow:none}.rm-project-ov__start-tag{border:1px solid;border-radius:var(--radius-pill);color:var(--text-muted);display:inline-block;font-size:10px;font-weight:600;letter-spacing:.02em;margin-left:6px;padding:0 6px;vertical-align:1px}.rm-project-ov__head{align-items:center;display:flex;justify-content:space-between;width:100%}.rm-project-ov__empty{color:var(--text-secondary);font-size:14px;margin:0}.rm-project-ov__list{display:flex;flex-direction:column;list-style:none;margin:0;padding:0}.rm-project-ov__row{align-items:center;border-bottom:1px solid var(--border-default);display:flex;font-size:14px;gap:10px;padding:8px 0}.rm-project-ov__row:last-child{border-bottom:none}.rm-project-ov__row-icon{color:var(--text-secondary);flex:none}.rm-project-ov__row-title{color:var(--text-primary);flex:1;min-width:0;overflow:hidden;text-decoration:none;text-overflow:ellipsis;white-space:nowrap}a.rm-project-ov__row-title{color:var(--color-primary)}a.rm-project-ov__row-title:hover{text-decoration:underline}.rm-project-ov__row-date,.rm-project-ov__row-family{color:var(--text-muted);flex:none;font-size:12px}
|
|
336
|
+
.rm-project-ov{display:flex;flex-direction:column;gap:16px}.rm-project-ov__top{align-items:stretch;display:grid;gap:16px;grid-template-columns:minmax(0,3fr) minmax(0,2fr)}@media (max-width:1100px){.rm-project-ov__top{grid-template-columns:1fr}}.rm-project-ov__card{min-width:0}.rm-project-ov__card.is-scope,.rm-project-ov__card.is-scope :deep(.r-card__body){display:flex;flex-direction:column}.rm-project-ov__card.is-scope{height:100%}.rm-project-ov__card.is-scope :deep(.r-card__body){flex:1}.rm-project-ov__card-head{align-items:flex-start;display:flex;gap:12px;justify-content:space-between}.rm-project-ov__titles{display:flex;flex-direction:column;gap:4px;margin-bottom:12px}.rm-project-ov__title{color:var(--text-primary);font-size:15px;font-weight:var(--weight-bold);margin:0}.rm-project-ov__context{color:var(--text-muted);font-size:12px;margin:0}.rm-project-ov__scope{display:flex;flex-direction:column;list-style:none;margin:0 0 16px;padding:0}.rm-project-ov__scope-row{align-items:flex-start;border-bottom:1px solid var(--border-soft,var(--border-default));display:flex;gap:12px;padding:8px 0}.rm-project-ov__scope-icon{color:var(--color-secondary);flex:none;margin-top:1px}.rm-project-ov__scope-body{flex:1;min-width:0}.rm-project-ov__scope-key{color:var(--text-muted);font-size:10.5px;font-weight:700;letter-spacing:.08em;margin:0 0 4px;text-transform:uppercase}.rm-project-ov__scope-value{color:var(--text-primary);font-size:13px;font-weight:600;margin:0;white-space:pre-line}.rm-project-ov__tags{display:flex;flex-wrap:wrap;gap:6px}.rm-project-ov__tag{display:block;max-width:100%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.rm-project-ov__scope-none{color:var(--text-muted);font-size:13px;font-style:italic;margin:0}.rm-project-ov__more{font-size:13px;margin:0;padding-left:16px}.rm-project-ov__placeholder{background:none;border:none;color:var(--text-muted);cursor:pointer;font:inherit;font-size:13px;font-style:italic;margin:0;padding:0}.rm-project-ov__placeholder:hover{text-decoration:underline}.rm-project-ov__edit-actions{display:flex;gap:8px;justify-content:flex-end;margin:8px 0 12px}.rm-project-ov__meta{border-top:1px solid var(--border-default);display:grid;gap:12px;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));margin:auto 0 0;padding-top:16px}.rm-project-ov__meta dt{color:var(--text-secondary);font-size:12px}.rm-project-ov__meta dd{font-size:14px;font-weight:500;margin:2px 0 0}.rm-project-ov__side{display:flex;flex-direction:column;gap:16px;min-width:0}.rm-project-ov__side>:last-child{flex:1}.rm-project-ov__start{display:flex;flex-direction:column;gap:8px;list-style:none;margin:0;padding:0}.rm-project-ov__start-item{align-items:center;background:var(--bg-surface);border:1px solid var(--border-default);border-radius:var(--radius-xl,12px);color:inherit;cursor:pointer;display:flex;font:inherit;gap:12px;padding:10px 12px;text-align:left;transition:border-color .15s,background .15s,box-shadow .15s;width:100%}.rm-project-ov__start-item:hover{background:var(--bg-hover,var(--bg-surface-2));border-color:var(--color-secondary);box-shadow:var(--shadow-sm)}.rm-project-ov__start-item:focus-visible{outline:2px solid var(--color-primary);outline-offset:2px}.rm-project-ov__start-icon{align-items:center;background:var(--bg-hover,var(--bg-surface-2));border-radius:var(--radius-lg,8px);color:var(--color-secondary);display:flex;flex:none;height:34px;justify-content:center;width:34px}.rm-project-ov__start-text{display:flex;flex:1;flex-direction:column;gap:2px;min-width:0}.rm-project-ov__start-title{color:var(--text-primary);font-size:13px;font-weight:700}.rm-project-ov__start-desc{color:var(--text-muted);font-size:11px;line-height:1.45}.rm-project-ov__start-arrow{color:var(--text-muted);flex:none}.rm-project-ov__start-item.is-disabled{cursor:not-allowed;opacity:.55}.rm-project-ov__start-item.is-disabled:hover{background:var(--bg-surface);border-color:var(--border-default);box-shadow:none}.rm-project-ov__start-tag{border:1px solid;border-radius:var(--radius-pill);color:var(--text-muted);display:inline-block;font-size:10px;font-weight:600;letter-spacing:.02em;margin-left:6px;padding:0 6px;vertical-align:1px}.rm-project-ov__head{align-items:center;display:flex;justify-content:space-between;width:100%}.rm-project-ov__empty{color:var(--text-secondary);font-size:14px;margin:0}.rm-project-ov__figures{display:grid;gap:12px;grid-template-columns:repeat(auto-fit,minmax(120px,1fr));margin:12px 0 0}.rm-project-ov__figure dt{color:var(--text-muted);font-size:12px}.rm-project-ov__figure dd{color:var(--text-primary);font-size:20px;font-weight:var(--weight-bold);line-height:1.2;margin:2px 0 0}.rm-project-ov__list{display:flex;flex-direction:column;list-style:none;margin:0;padding:0}.rm-project-ov__row{align-items:center;border-bottom:1px solid var(--border-default);display:flex;font-size:14px;gap:10px;padding:8px 0}.rm-project-ov__row:last-child{border-bottom:none}.rm-project-ov__row-icon{color:var(--text-secondary);flex:none}.rm-project-ov__row-title{color:var(--text-primary);flex:1;min-width:0;overflow:hidden;text-decoration:none;text-overflow:ellipsis;white-space:nowrap}a.rm-project-ov__row-title{color:var(--color-primary)}a.rm-project-ov__row-title:hover{text-decoration:underline}.rm-project-ov__row-date,.rm-project-ov__row-family{color:var(--text-muted);flex:none;font-size:12px}
|
|
303
337
|
</style>
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { computed, onBeforeUnmount, ref, unref } from "vue";
|
|
2
2
|
export function useRmDashboard(options) {
|
|
3
3
|
const stored = ref(null);
|
|
4
|
-
|
|
4
|
+
let lastFallback = null;
|
|
5
|
+
const fallback = computed(() => {
|
|
6
|
+
const next = options.defaults();
|
|
7
|
+
const previous = lastFallback;
|
|
8
|
+
const widgets2 = next.widgets.map((widget, index) => {
|
|
9
|
+
const before = previous?.widgets[index];
|
|
10
|
+
return before && before.kind === widget.kind ? { ...widget, id: before.id } : widget;
|
|
11
|
+
});
|
|
12
|
+
lastFallback = { ...next, widgets: widgets2 };
|
|
13
|
+
return lastFallback;
|
|
14
|
+
});
|
|
5
15
|
const loading = ref(true);
|
|
6
16
|
const failed = ref(false);
|
|
7
17
|
const saving = ref(false);
|
|
@@ -133,6 +133,18 @@ export interface RmWidgetKind<C extends RmWidgetContext = RmWidgetContext> {
|
|
|
133
133
|
viz: RmDashboardViz[];
|
|
134
134
|
/** Le widget lit les marques : il propose le choix des marques. */
|
|
135
135
|
usesBrands: boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Le widget aura-t-il quelque chose a montrer pour ce contexte ? Faux :
|
|
138
|
+
* l'entree est cachee du catalogue (un projet sans cancer, sans pays...).
|
|
139
|
+
* Un widget `usesBrands` sans marque l'est deja, sans rien declarer.
|
|
140
|
+
*/
|
|
141
|
+
available?: (context: C) => boolean;
|
|
142
|
+
/**
|
|
143
|
+
* La part du contexte que le widget lit (ses lignes, son Inbox...) : il ne
|
|
144
|
+
* se recharge que quand elle change. Absent : tout le contexte, et un
|
|
145
|
+
* widget se recharge des qu'une autre part bouge.
|
|
146
|
+
*/
|
|
147
|
+
deps?: (context: C) => unknown;
|
|
136
148
|
params: RmWidgetParam[];
|
|
137
149
|
/** Taille de depart dans la grille de 12 colonnes. */
|
|
138
150
|
size: {
|
|
@@ -152,6 +164,27 @@ export interface RmWidgetSource {
|
|
|
152
164
|
verified: string | Date | number;
|
|
153
165
|
export?: RmExportSource[];
|
|
154
166
|
}
|
|
167
|
+
/**
|
|
168
|
+
* Un modele de tableau : un jeu de widgets a poser d'un coup, propose dans
|
|
169
|
+
* le menu « Modeles » de RmDashboard a la place du tableau en place. Les
|
|
170
|
+
* widgets se calculent a l'appel (le contexte a pu changer), et peuvent
|
|
171
|
+
* venir de loin (le tableau d'un autre projet) : `null` quand il n'y a rien.
|
|
172
|
+
*/
|
|
173
|
+
export interface RmDashboardTemplate {
|
|
174
|
+
id: string;
|
|
175
|
+
title: string;
|
|
176
|
+
description?: string;
|
|
177
|
+
/** Groupe du menu (« Modeles », « Copier depuis un projet »). */
|
|
178
|
+
group?: string;
|
|
179
|
+
widgets: () => RmDashboardWidget[] | null | Promise<RmDashboardWidget[] | null>;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Les entrees du catalogue qu'on peut ajouter dans ce contexte : celles qui
|
|
183
|
+
* auront quelque chose a montrer. Un widget `usesBrands` sans marque et une
|
|
184
|
+
* entree dont `available` dit non sont cachees, pas grisees : une entree
|
|
185
|
+
* qui ne rend rien n'a rien a faire dans le tiroir.
|
|
186
|
+
*/
|
|
187
|
+
export declare function rmAddableWidgets<C extends RmWidgetContext>(catalog: RmWidgetKind<C>[], context: C): RmWidgetKind<C>[];
|
|
155
188
|
export declare const RM_VIZ_LABELS: Record<RmDashboardViz, Record<RmDashboardLang, string>>;
|
|
156
189
|
/** L'icone d'une visualisation, pour le catalogue. */
|
|
157
190
|
export declare const RM_VIZ_ICONS: Record<RmDashboardViz, string>;
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
export function rmAddableWidgets(catalog, context) {
|
|
2
|
+
return catalog.filter((entry) => {
|
|
3
|
+
if (entry.usesBrands && !context.brands.length) return false;
|
|
4
|
+
return entry.available ? entry.available(context) : true;
|
|
5
|
+
});
|
|
6
|
+
}
|
|
1
7
|
export const RM_VIZ_LABELS = {
|
|
2
8
|
line: { fr: "Courbe", en: "Line" },
|
|
3
9
|
bar: { fr: "Barres", en: "Bars" },
|
|
@@ -1,78 +1,143 @@
|
|
|
1
1
|
<!--
|
|
2
2
|
L'onglet « Tableau de bord » d'un projet : RmDashboard branche sur le
|
|
3
|
-
catalogue
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
catalogue (les widgets du layer, puis ceux de l'app, cf. PROJECT_CATALOG)
|
|
4
|
+
et sur l'API des projets (useProjectDashboard, porte par la page : la vue
|
|
5
|
+
d'ensemble en lit l'apercu, et l'onglet garde ses widgets charges quand on
|
|
6
|
+
le quitte, KeepAlive). Repris de France Augmented Science et d'OIP Case
|
|
7
|
+
Atlas.
|
|
6
8
|
|
|
7
|
-
Les widgets decrivent ce que le projet range, a partir
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
- la source de chaque entree
|
|
9
|
+
Les widgets decrivent ce que le projet range, a partir de ce que la page a
|
|
10
|
+
deja relu (`context` : lignes, documents, Inbox, marques de l'app). Ce que
|
|
11
|
+
le layer ajoute au paquet :
|
|
12
|
+
- la source de chaque entree, lue dans le referentiel Directus des jeux
|
|
13
|
+
qu'elle declare (`sources`), le meme que le panneau Sources et les pieds
|
|
14
|
+
de carte des pages ; le contenu du projet, sans producteur public, est le
|
|
15
|
+
projet lu a l'instant ;
|
|
16
|
+
- les modeles du menu « Modeles » : ceux du layer et de l'app
|
|
17
|
+
(PROJECT_DASHBOARD_TEMPLATES), puis les tableaux des autres projets de
|
|
18
|
+
l'utilisateur, a copier ;
|
|
11
19
|
- l'export de l'onglet (tuile Export du rail, rapport PDF) : un onglet de
|
|
12
|
-
classeur par widget, avec ses nombres bruts.
|
|
20
|
+
classeur par widget, avec ses nombres bruts et les memes sources.
|
|
13
21
|
-->
|
|
14
22
|
<template>
|
|
15
23
|
<RmDashboard
|
|
16
|
-
ref="
|
|
17
|
-
:widgets="widgets"
|
|
18
|
-
:catalog="
|
|
24
|
+
ref="grid"
|
|
25
|
+
:widgets="board.widgets.value"
|
|
26
|
+
:catalog="PROJECT_CATALOG"
|
|
19
27
|
:context="context"
|
|
20
28
|
:source-of="sourceOf"
|
|
21
|
-
:loading="loading"
|
|
22
|
-
:failed="failed"
|
|
23
|
-
:saving="saving"
|
|
24
|
-
:save-failed="saveFailed"
|
|
29
|
+
:loading="board.loading.value"
|
|
30
|
+
:failed="board.failed.value"
|
|
31
|
+
:saving="board.saving.value"
|
|
32
|
+
:save-failed="board.saveFailed.value"
|
|
25
33
|
:lang="lang"
|
|
26
34
|
:empty-text="PROJECT_WORDING.dashboard[lang]"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
:scope-label="en ? 'The project\'s brands' : 'Celles du projet'"
|
|
36
|
+
:no-brands-text="noBrandsText"
|
|
37
|
+
:templates="templates"
|
|
38
|
+
@update:widgets="board.update"
|
|
39
|
+
@load="board.load"
|
|
40
|
+
@retry-save="board.retrySave"
|
|
30
41
|
/>
|
|
31
42
|
</template>
|
|
32
43
|
|
|
33
44
|
<script setup lang="ts">
|
|
34
45
|
import type { RmExportSheet } from "@tekkare/romulus/utils/export";
|
|
35
|
-
import type { RmWidgetSource } from "@tekkare/romulus/utils/dashboard";
|
|
36
|
-
import {
|
|
37
|
-
import
|
|
46
|
+
import type { RmDashboardTemplate, RmWidgetKind, RmWidgetSource } from "@tekkare/romulus/utils/dashboard";
|
|
47
|
+
import { useOipApi } from "#oip-app/api";
|
|
48
|
+
import { PROJECT_DASHBOARD_TEMPLATES, PROJECT_WORDING } from "#oip-projects";
|
|
49
|
+
import { PROJECT_LAYER_TEMPLATES, type OipProjectWidgetContext as WidgetContext } from "../../oip-defaults/projects";
|
|
50
|
+
import { PROJECT_CATALOG, type ProjectBoard } from "../../composables/useProjectDashboard";
|
|
38
51
|
import { visibleExportCharts } from "../../utils/exportPage";
|
|
52
|
+
import useDirectusSources, { PENDING } from "../../oip-drugs/composables/useDirectusSources";
|
|
39
53
|
|
|
40
54
|
type Lang = "fr" | "en";
|
|
41
55
|
|
|
42
56
|
const props = defineProps<{
|
|
43
57
|
projectId: string;
|
|
44
58
|
projectTitle: string;
|
|
45
|
-
|
|
46
|
-
|
|
59
|
+
context: WidgetContext;
|
|
60
|
+
board: ProjectBoard;
|
|
47
61
|
lang: Lang;
|
|
48
62
|
}>();
|
|
49
63
|
|
|
50
64
|
const en = computed(() => props.lang === "en");
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
66
|
+
/** Le mot de l'app pour un projet sans marque ; les contrats d'avant ce mot n'ont pas la cle. */
|
|
67
|
+
const noBrandsText = computed(() => (PROJECT_WORDING as { noBrands?: Record<Lang, string> }).noBrands?.[props.lang]);
|
|
54
68
|
|
|
55
|
-
|
|
56
|
-
brands: projectBrands(props.docs),
|
|
57
|
-
lang: props.lang,
|
|
58
|
-
groups: props.groups,
|
|
59
|
-
docs: props.docs,
|
|
60
|
-
}));
|
|
69
|
+
// --- Sources ----------------------------------------------------------------------
|
|
61
70
|
|
|
62
|
-
/** Le
|
|
63
|
-
|
|
71
|
+
/** Le referentiel Directus des jeux du catalogue : une requete groupee pour tout l'onglet. */
|
|
72
|
+
const directus = useDirectusSources();
|
|
73
|
+
onMounted(() => directus.load(PROJECT_CATALOG.flatMap((entry) => entry.sources)));
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Le pied de carte d'un widget cite les jeux qu'il declare, lus dans le meme
|
|
77
|
+
* referentiel que le panneau Sources ; plusieurs jeux : leurs noms, et la
|
|
78
|
+
* date la plus ancienne. Tant que Directus n'a pas repondu, le pied reste
|
|
79
|
+
* muet (« … ») plutot que faux. Le contenu du projet n'a pas de producteur
|
|
80
|
+
* public : c'est le projet, lu a l'instant.
|
|
81
|
+
*/
|
|
82
|
+
function sourceOf(kind: RmWidgetKind<any>): RmWidgetSource {
|
|
83
|
+
const uuids = [...new Set(kind.sources)];
|
|
84
|
+
if (!uuids.length) {
|
|
85
|
+
return {
|
|
86
|
+
name: en.value ? "Project content" : "Contenu du projet",
|
|
87
|
+
verified: new Date().toISOString().slice(0, 10),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const names = [...new Set(uuids.map((uuid) => directus.metaByUuid(uuid, props.lang).name))];
|
|
91
|
+
const dates = uuids.map((uuid) => directus.verifiedRaw(uuid)).filter((date): date is string => !!date).sort();
|
|
64
92
|
return {
|
|
65
|
-
name:
|
|
66
|
-
verified:
|
|
93
|
+
name: names.join(", "),
|
|
94
|
+
verified: dates[0] ?? PENDING,
|
|
95
|
+
export: directus.exportSources(uuids, props.lang),
|
|
67
96
|
};
|
|
68
97
|
}
|
|
69
98
|
|
|
99
|
+
// --- Modeles ----------------------------------------------------------------------
|
|
100
|
+
|
|
101
|
+
const api = useOipApi();
|
|
102
|
+
const projects = useProjects();
|
|
103
|
+
onMounted(() => projects.load());
|
|
104
|
+
|
|
105
|
+
/** Les modeles du layer et de l'app (un `id` d'app l'emporte), puis les autres projets de l'utilisateur, les dix plus recents. */
|
|
106
|
+
const templates = computed<RmDashboardTemplate[]>(() => {
|
|
107
|
+
const own = PROJECT_DASHBOARD_TEMPLATES;
|
|
108
|
+
const models = [...PROJECT_LAYER_TEMPLATES.filter((entry) => !own.some((item) => item.id === entry.id)), ...own];
|
|
109
|
+
const others = projects.projects.value
|
|
110
|
+
.filter((project) => project.id !== props.projectId && !project.href)
|
|
111
|
+
.sort((a, b) => String(b.createdAt ?? "").localeCompare(String(a.createdAt ?? "")))
|
|
112
|
+
.slice(0, 10);
|
|
113
|
+
return [
|
|
114
|
+
...models.map((entry) => ({
|
|
115
|
+
id: `template:${entry.id}`,
|
|
116
|
+
title: entry.title[props.lang],
|
|
117
|
+
description: entry.description?.[props.lang],
|
|
118
|
+
group: en.value ? "Templates" : "Modèles",
|
|
119
|
+
widgets: () => entry.build(props.context).widgets,
|
|
120
|
+
})),
|
|
121
|
+
...others.map((project) => ({
|
|
122
|
+
id: `copy:${project.id}`,
|
|
123
|
+
title: project.title,
|
|
124
|
+
description: project.resourcesCount
|
|
125
|
+
? en.value
|
|
126
|
+
? `${project.resourcesCount} resource${project.resourcesCount > 1 ? "s" : ""}`
|
|
127
|
+
: `${project.resourcesCount} ressource${project.resourcesCount > 1 ? "s" : ""}`
|
|
128
|
+
: undefined,
|
|
129
|
+
group: en.value ? "Copy from a project" : "Copier depuis un projet",
|
|
130
|
+
widgets: async () => (await api.projects.getDashboard(project.id))?.dashboard?.widgets ?? null,
|
|
131
|
+
})),
|
|
132
|
+
];
|
|
133
|
+
});
|
|
134
|
+
|
|
70
135
|
// --- Export -----------------------------------------------------------------------
|
|
71
136
|
|
|
72
|
-
const
|
|
137
|
+
const grid = ref<{ exportSheets: () => RmExportSheet[] } | null>(null);
|
|
73
138
|
|
|
74
139
|
useExportSource().declare(() => {
|
|
75
|
-
const sheets =
|
|
140
|
+
const sheets = grid.value?.exportSheets() ?? [];
|
|
76
141
|
if (!sheets.length) return null;
|
|
77
142
|
const title = `${props.projectTitle}, ${en.value ? "dashboard" : "tableau de bord"}`;
|
|
78
143
|
return {
|
|
@@ -15,7 +15,9 @@
|
|
|
15
15
|
|
|
16
16
|
Les onglets, dans le meme ordre partout : Vue d'ensemble, Tableau de bord,
|
|
17
17
|
Ressources, Documents, Notes, Agent IA (grise, pas encore branche) et
|
|
18
|
-
Inbox.
|
|
18
|
+
Inbox. Le tableau de bord est porte par la page (useProjectDashboard) : la
|
|
19
|
+
vue d'ensemble en montre l'apercu, et l'onglet, garde en vie (KeepAlive),
|
|
20
|
+
ne recharge ni l'API ni ses widgets a chaque retour. En tete, le suivi du projet (une alerte sur ses fiches, quand l'app
|
|
19
21
|
en declare) ; la page declare l'inventaire du projet a la tuile Export,
|
|
20
22
|
sauf sur le tableau de bord, qui declare le sien.
|
|
21
23
|
|
|
@@ -61,6 +63,7 @@
|
|
|
61
63
|
:scope-rows="scopeRows"
|
|
62
64
|
:documents-count="documentsCount"
|
|
63
65
|
:steps="steps"
|
|
66
|
+
:dashboard="dashboardPreview"
|
|
64
67
|
:loading="loading"
|
|
65
68
|
:saving="describing"
|
|
66
69
|
:save-error="describeError"
|
|
@@ -82,17 +85,19 @@
|
|
|
82
85
|
@remove="removeRow"
|
|
83
86
|
/>
|
|
84
87
|
|
|
85
|
-
<
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
88
|
+
<KeepAlive>
|
|
89
|
+
<ProjectDashboard
|
|
90
|
+
v-if="tab === 'dashboard' && !failed && !loading && project"
|
|
91
|
+
:project-id="projectId"
|
|
92
|
+
:project-title="project.title"
|
|
93
|
+
:context="widgetContext"
|
|
94
|
+
:board="board"
|
|
95
|
+
:lang="lang"
|
|
96
|
+
/>
|
|
97
|
+
</KeepAlive>
|
|
93
98
|
|
|
94
99
|
<ProjectDocuments
|
|
95
|
-
v-
|
|
100
|
+
v-if="tab === 'documents'"
|
|
96
101
|
:project-id="projectId"
|
|
97
102
|
:open-id="documentToOpen"
|
|
98
103
|
@changed="loadDocumentsCount"
|
|
@@ -100,7 +105,7 @@
|
|
|
100
105
|
/>
|
|
101
106
|
|
|
102
107
|
<ProjectNotes
|
|
103
|
-
v-
|
|
108
|
+
v-if="tab === 'notes'"
|
|
104
109
|
:project-id="projectId"
|
|
105
110
|
:users="projectUsers"
|
|
106
111
|
:resources="citableResources"
|
|
@@ -108,7 +113,7 @@
|
|
|
108
113
|
/>
|
|
109
114
|
|
|
110
115
|
<ProjectInbox
|
|
111
|
-
v-
|
|
116
|
+
v-if="tab === 'inbox'"
|
|
112
117
|
:project-id="projectId"
|
|
113
118
|
:items="inboxItems"
|
|
114
119
|
:loading="inboxLoading"
|
|
@@ -194,6 +199,7 @@ import {
|
|
|
194
199
|
PROJECTS_UPSELL,
|
|
195
200
|
PROJECT_WORDING,
|
|
196
201
|
WATCHABLE_PROJECT_TYPES,
|
|
202
|
+
projectBrands,
|
|
197
203
|
projectExternalHref,
|
|
198
204
|
useProjectScopeRows,
|
|
199
205
|
useProjectSuggestions,
|
|
@@ -201,6 +207,9 @@ import {
|
|
|
201
207
|
} from "#oip-projects";
|
|
202
208
|
import type { ProjectItem } from "../../composables/useProjects";
|
|
203
209
|
import { oipProjectHydrate, useOipProjectKinds } from "../../composables/useOipProjectKinds";
|
|
210
|
+
import { PROJECT_CATALOG, useProjectDashboard } from "../../composables/useProjectDashboard";
|
|
211
|
+
import type { OipProjectWidgetContext } from "../../oip-defaults/projects";
|
|
212
|
+
import { rmWidgetBrands, rmWidgetKind, rmWidgetParams } from "@tekkare/romulus/utils/dashboard";
|
|
204
213
|
import type {
|
|
205
214
|
ProjectInboxChange,
|
|
206
215
|
ProjectInboxItem,
|
|
@@ -574,6 +583,7 @@ const dashboardDocs = computed(() =>
|
|
|
574
583
|
rows.value.filter((row) => row.known && row.source).map((row) => ({ type: row.type, source: row.source as Record<string, any> })),
|
|
575
584
|
);
|
|
576
585
|
|
|
586
|
+
|
|
577
587
|
// ----------------------------------------------------------------- l'Inbox
|
|
578
588
|
|
|
579
589
|
/**
|
|
@@ -641,6 +651,67 @@ const inboxItems = computed<ProjectInboxItem[]>(() => {
|
|
|
641
651
|
];
|
|
642
652
|
});
|
|
643
653
|
|
|
654
|
+
// ----------------------------------------------------- le tableau de bord, suite
|
|
655
|
+
// (apres l'Inbox : le contexte des widgets la lit, et le tableau de depart se calcule des le montage)
|
|
656
|
+
|
|
657
|
+
/** Ce que le projet donne a ses widgets : ce que la page a deja relu, et le client de l'app. */
|
|
658
|
+
const widgetApi = useOipApi();
|
|
659
|
+
const widgetContext = computed<OipProjectWidgetContext>(() => ({
|
|
660
|
+
brands: projectBrands(dashboardDocs.value),
|
|
661
|
+
lang: lang.value,
|
|
662
|
+
groups: dashboardGroups.value,
|
|
663
|
+
docs: dashboardDocs.value,
|
|
664
|
+
projectId,
|
|
665
|
+
rows: rows.value,
|
|
666
|
+
inbox: inboxItems.value,
|
|
667
|
+
api: widgetApi,
|
|
668
|
+
}));
|
|
669
|
+
|
|
670
|
+
const board = useProjectDashboard(projectId, () => widgetContext.value);
|
|
671
|
+
onMounted(board.load);
|
|
672
|
+
|
|
673
|
+
/**
|
|
674
|
+
* L'apercu de la vue d'ensemble : combien de widgets, et les chiffres du
|
|
675
|
+
* premier widget en chiffres cles (deux au plus). `null` tant que le tableau
|
|
676
|
+
* n'est pas lu.
|
|
677
|
+
*/
|
|
678
|
+
const dashboardFigures = ref<{ label: string; value: string | number }[]>([]);
|
|
679
|
+
let figuresRun = 0;
|
|
680
|
+
watch(
|
|
681
|
+
[board.widgets, widgetContext, () => board.loading.value],
|
|
682
|
+
async ([widgets, context, pending]) => {
|
|
683
|
+
const run = ++figuresRun;
|
|
684
|
+
if (pending) return;
|
|
685
|
+
const first = widgets.find((widget) => widget.viz === "kpi");
|
|
686
|
+
const entry = first ? rmWidgetKind(PROJECT_CATALOG, first.kind) : undefined;
|
|
687
|
+
if (!first || !entry) {
|
|
688
|
+
dashboardFigures.value = [];
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
const brands = rmWidgetBrands(first, context.brands);
|
|
692
|
+
if (entry.usesBrands && !brands.length) {
|
|
693
|
+
dashboardFigures.value = [];
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
try {
|
|
697
|
+
const data = await entry.fetch(rmWidgetParams(entry, first.params), { ...context, brands });
|
|
698
|
+
if (run !== figuresRun) return;
|
|
699
|
+
dashboardFigures.value =
|
|
700
|
+
data.type === "kpi"
|
|
701
|
+
? data.items.slice(0, 2).map((item) => ({ label: item.label, value: item.value }))
|
|
702
|
+
: data.type === "parts"
|
|
703
|
+
? data.parts.slice(0, 2).map((part) => ({ label: part.name, value: part.value }))
|
|
704
|
+
: [];
|
|
705
|
+
} catch {
|
|
706
|
+
if (run === figuresRun) dashboardFigures.value = [];
|
|
707
|
+
}
|
|
708
|
+
},
|
|
709
|
+
{ immediate: true },
|
|
710
|
+
);
|
|
711
|
+
const dashboardPreview = computed(() =>
|
|
712
|
+
board.loading.value ? null : { count: board.widgets.value.length, figures: dashboardFigures.value },
|
|
713
|
+
);
|
|
714
|
+
|
|
644
715
|
const isLocal = (item: ProjectInboxItem) => item.id === LOCAL_WELCOME || item.id === LOCAL_SUGGESTIONS;
|
|
645
716
|
|
|
646
717
|
function patchInboxItem(id: string, change: Partial<ProjectInboxItem>) {
|
|
@@ -2,21 +2,40 @@
|
|
|
2
2
|
* Le tableau de bord d'un projet et son branchement sur l'API
|
|
3
3
|
* (`projects.dashboard`, un par projet, commun aux membres et aux apps).
|
|
4
4
|
* Le catalogue et le tableau de depart viennent de l'app
|
|
5
|
-
* (#oip-app/projects), sinon
|
|
5
|
+
* (#oip-app/projects), sinon ceux du layer.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
7
|
+
* Le tableau de depart se calcule sur le contexte du projet (ses lignes, ses
|
|
8
|
+
* marques, son Inbox) et perd les widgets qui n'auraient rien a montrer
|
|
9
|
+
* (oipPruneDashboard) ; il se recalcule quand le contexte change, tant que
|
|
10
|
+
* rien n'est enregistre. Tout le reste (sauvegarde temporisee, kinds
|
|
11
|
+
* inconnus conserves) est a useRmDashboard, dans Romulus.
|
|
9
12
|
*/
|
|
10
13
|
|
|
11
14
|
import { useOipApi } from "#oip-app/api";
|
|
12
|
-
import { PROJECT_DASHBOARD_WIDGETS, defaultProjectDashboard } from "#oip-projects";
|
|
15
|
+
import { PROJECT_DASHBOARD_WIDGETS, defaultProjectDashboard, oipPruneDashboard } from "#oip-projects";
|
|
16
|
+
import { PROJECT_LAYER_WIDGETS, type OipProjectWidgetContext } from "../oip-defaults/projects";
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Le catalogue de l'onglet : les widgets du layer, puis ceux de l'app. Une
|
|
20
|
+
* app qui redeclare un `kind` du layer l'emporte ; une app d'avant ces
|
|
21
|
+
* widgets les recoit sans rien changer.
|
|
22
|
+
*/
|
|
23
|
+
export const PROJECT_CATALOG = [
|
|
24
|
+
...PROJECT_LAYER_WIDGETS.filter((entry) => !PROJECT_DASHBOARD_WIDGETS.some((own) => own.kind === entry.kind)),
|
|
25
|
+
...PROJECT_DASHBOARD_WIDGETS,
|
|
26
|
+
];
|
|
27
|
+
|
|
28
|
+
export function useProjectDashboard(projectId: string, context: () => OipProjectWidgetContext) {
|
|
15
29
|
const api = useOipApi();
|
|
16
30
|
return useRmDashboard({
|
|
17
|
-
catalog:
|
|
31
|
+
catalog: PROJECT_CATALOG,
|
|
18
32
|
load: async () => (await api.projects.getDashboard(projectId))?.dashboard ?? null,
|
|
19
33
|
save: (dashboard) => api.projects.saveDashboard(projectId, dashboard),
|
|
20
|
-
defaults:
|
|
34
|
+
defaults: () => {
|
|
35
|
+
const current = context();
|
|
36
|
+
return oipPruneDashboard(defaultProjectDashboard(current), PROJECT_CATALOG, current);
|
|
37
|
+
},
|
|
21
38
|
});
|
|
22
39
|
}
|
|
40
|
+
|
|
41
|
+
export type ProjectBoard = ReturnType<typeof useProjectDashboard>;
|
|
@@ -21,6 +21,12 @@ import { OIP_SCIENCE_DASHBOARD_WIDGETS } from "../oip-science/dashboardWidgets";
|
|
|
21
21
|
import { OIP_DRUG_DASHBOARD_WIDGETS } from "../oip-drugs/dashboardWidgets";
|
|
22
22
|
|
|
23
23
|
export { OIP_SCIENCE_DASHBOARD_WIDGETS, OIP_DRUG_DASHBOARD_WIDGETS };
|
|
24
|
+
/**
|
|
25
|
+
* Les marques que les widgets medicament lisent, a exporter sous le nom
|
|
26
|
+
* `projectBrands` par toute app qui prend ces widgets (`usesBrands`) :
|
|
27
|
+
*
|
|
28
|
+
* export { oipProjectBrands as projectBrands } from "@tekkare/romulus/layer-defaults/dashboardWidgets";
|
|
29
|
+
*/
|
|
24
30
|
export { oipProjectBrands } from "../oip-drugs/dashboardWidgets";
|
|
25
31
|
|
|
26
32
|
export const OIP_DASHBOARD_WIDGETS: RmWidgetKind<OipProjectWidgetContext>[] = [
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
import { computed, ref, type Component, type ComputedRef, type Ref } from "vue";
|
|
17
17
|
import type { RmProjectKind, RmProjectResource, RmProjectScopeRow } from "@tekkare/romulus/utils/projects";
|
|
18
18
|
import type { RmExportSheet } from "@tekkare/romulus/utils/export";
|
|
19
|
-
import type { RmDashboardModel, RmWidgetContext, RmWidgetKind } from "@tekkare/romulus/utils/dashboard";
|
|
20
|
-
import { rmNewWidgetId } from "@tekkare/romulus/utils/dashboard";
|
|
21
|
-
import type { ProjectSuggestion } from "../types/projects";
|
|
19
|
+
import type { RmDashboardModel, RmDashboardWidget, RmWidgetContext, RmWidgetKind } from "@tekkare/romulus/utils/dashboard";
|
|
20
|
+
import { rmAddableWidgets, rmNewWidgetId } from "@tekkare/romulus/utils/dashboard";
|
|
21
|
+
import type { ProjectInboxItem, ProjectSuggestion } from "../types/projects";
|
|
22
22
|
|
|
23
23
|
type Lang = "fr" | "en";
|
|
24
24
|
type Text = { fr: string; en: string };
|
|
@@ -77,6 +77,12 @@ export const PROJECT_WORDING: {
|
|
|
77
77
|
dashboard: Text;
|
|
78
78
|
/** Ce que suit l'alerte d'un projet (« un statut, une phase... »). */
|
|
79
79
|
watch: Text;
|
|
80
|
+
/**
|
|
81
|
+
* Ce que dit un widget `usesBrands` quand le projet ne range aucune marque
|
|
82
|
+
* (« ajoutez des actes AIFA depuis Italy One... »). Absent : le mot neutre
|
|
83
|
+
* de RmDashboard, « Aucune marque sélectionnée ».
|
|
84
|
+
*/
|
|
85
|
+
noBrands?: Text;
|
|
80
86
|
} = {
|
|
81
87
|
empty: {
|
|
82
88
|
fr: "Un projet rassemble ce que vous mettez de côté au fil des pages.",
|
|
@@ -147,20 +153,47 @@ export interface OipProjectWidgetContext extends RmWidgetContext {
|
|
|
147
153
|
groups: { label: string; count: number }[];
|
|
148
154
|
/** Les documents des elements ranges, deja relus par la page. */
|
|
149
155
|
docs: { type: string; source: Record<string, any> }[];
|
|
156
|
+
/** Le projet, pour les widgets qui relisent l'API (notes, documents). */
|
|
157
|
+
projectId: string;
|
|
158
|
+
/** Les lignes du projet telles que la page les affiche : titre, famille, pays, date d'ajout. */
|
|
159
|
+
rows: RmProjectResource[];
|
|
160
|
+
/** Les messages de l'Inbox, deja lus par la page : ce qui a bouge, ce qui a ete ajoute. */
|
|
161
|
+
inbox: ProjectInboxItem[];
|
|
162
|
+
/** Le client de l'app (`useOipApi()`), capture au montage : un widget ne peut pas l'appeler lui-meme apres un `await`. */
|
|
163
|
+
api: any;
|
|
150
164
|
}
|
|
151
165
|
|
|
152
166
|
/**
|
|
153
167
|
* Les marques du projet, que les widgets `usesBrands` lisent : l'app les tire
|
|
154
|
-
* des documents ranges (`code` des ventes, marques des avis...). Aucune par
|
|
168
|
+
* des documents ranges (`code` des ventes, marques des avis...). Aucune par
|
|
169
|
+
* defaut. Une app qui prend les widgets medicament du layer exporte
|
|
170
|
+
* `oipProjectBrands` sous ce nom (cf. oip-defaults/dashboardWidgets.ts) :
|
|
171
|
+
* sans marque, RmDashboardWidget coupe avant le `fetch`.
|
|
155
172
|
*/
|
|
156
173
|
export function projectBrands(_docs: OipProjectWidgetContext["docs"]): string[] {
|
|
157
174
|
return [];
|
|
158
175
|
}
|
|
159
176
|
|
|
177
|
+
type WidgetKind = RmWidgetKind<OipProjectWidgetContext>;
|
|
178
|
+
|
|
179
|
+
const PROJECT_GROUP = { fr: "Projet", en: "Project" };
|
|
180
|
+
const T = (lang: Lang, fr: string, en: string) => (lang === "en" ? en : fr);
|
|
181
|
+
const day = (value: unknown) => String(value ?? "").slice(0, 10);
|
|
182
|
+
|
|
183
|
+
/** Le nom d'un pays dans la langue lue ; le code tel quel si le navigateur ne le connait pas. */
|
|
184
|
+
function countryName(code: string, lang: Lang): string {
|
|
185
|
+
try {
|
|
186
|
+
return new Intl.DisplayNames([lang === "en" ? "en" : "fr"], { type: "region" }).of(code.toUpperCase()) ?? code;
|
|
187
|
+
} catch {
|
|
188
|
+
return code;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
160
192
|
/** Le widget que toute app sait remplir : le contenu du projet, par famille. */
|
|
161
|
-
export const PROJECT_RESOURCES_WIDGET:
|
|
193
|
+
export const PROJECT_RESOURCES_WIDGET: WidgetKind = {
|
|
162
194
|
kind: "project.resources",
|
|
163
|
-
|
|
195
|
+
deps: ({ groups }) => groups,
|
|
196
|
+
group: PROJECT_GROUP,
|
|
164
197
|
title: { fr: "Contenu du projet", en: "Project content" },
|
|
165
198
|
description: { fr: "Les éléments rangés dans le projet, par famille.", en: "What the project holds, per family." },
|
|
166
199
|
viz: ["donut", "bar", "table", "kpi"],
|
|
@@ -173,21 +206,253 @@ export const PROJECT_RESOURCES_WIDGET: RmWidgetKind<OipProjectWidgetContext> = {
|
|
|
173
206
|
},
|
|
174
207
|
};
|
|
175
208
|
|
|
176
|
-
/**
|
|
177
|
-
|
|
209
|
+
/**
|
|
210
|
+
* Les widgets que le layer remplit sans connaitre la famille : ce que la page
|
|
211
|
+
* a deja relu (lignes, Inbox) et ce que l'API sait du projet (notes,
|
|
212
|
+
* documents). Ils font le tableau de depart de toute app, catalogue ou pas.
|
|
213
|
+
*/
|
|
214
|
+
|
|
215
|
+
/** Les derniers elements ranges, du plus recent au plus ancien. */
|
|
216
|
+
export const PROJECT_RECENT_WIDGET: WidgetKind = {
|
|
217
|
+
kind: "project.recent",
|
|
218
|
+
deps: ({ rows }) => rows.map((row) => [row.type, row.id, row.createdAt]),
|
|
219
|
+
group: PROJECT_GROUP,
|
|
220
|
+
title: { fr: "Derniers ajouts", en: "Latest additions" },
|
|
221
|
+
description: { fr: "Les éléments rangés dans le projet, du plus récent au plus ancien.", en: "What was filed in the project, newest first." },
|
|
222
|
+
viz: ["table"],
|
|
223
|
+
sources: [],
|
|
224
|
+
usesBrands: false,
|
|
225
|
+
params: [],
|
|
226
|
+
size: { w: 8, h: 5 },
|
|
227
|
+
async fetch(_params, { rows, lang }) {
|
|
228
|
+
const sorted = [...rows].sort((a, b) => String(b.createdAt ?? "").localeCompare(String(a.createdAt ?? "")));
|
|
229
|
+
return {
|
|
230
|
+
type: "rows",
|
|
231
|
+
columns: [
|
|
232
|
+
{ key: "date", label: T(lang, "Ajouté le", "Added on"), date: true },
|
|
233
|
+
{ key: "title", label: T(lang, "Élément", "Item"), long: true },
|
|
234
|
+
{ key: "family", label: T(lang, "Famille", "Family") },
|
|
235
|
+
{ key: "country", label: T(lang, "Pays", "Country"), optional: true },
|
|
236
|
+
],
|
|
237
|
+
rows: sorted.map((row) => ({
|
|
238
|
+
date: day(row.createdAt),
|
|
239
|
+
title: row.title || T(lang, "Élément inconnu", "Unknown item"),
|
|
240
|
+
family: row.family,
|
|
241
|
+
country: row.country ? countryName(row.country, lang) : null,
|
|
242
|
+
})),
|
|
243
|
+
};
|
|
244
|
+
},
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/** Les elements par pays de leur donnee. Cache tant qu'aucune ligne n'en porte un. */
|
|
248
|
+
export const PROJECT_COUNTRIES_WIDGET: WidgetKind = {
|
|
249
|
+
kind: "project.byCountry",
|
|
250
|
+
deps: ({ rows }) => rows.map((row) => row.country ?? ""),
|
|
251
|
+
group: PROJECT_GROUP,
|
|
252
|
+
title: { fr: "Éléments par pays", en: "Items per country" },
|
|
253
|
+
description: { fr: "Les éléments du projet, comptés par pays de leur donnée.", en: "The project's items, counted by the country of their data." },
|
|
254
|
+
viz: ["donut", "bar", "table"],
|
|
255
|
+
sources: [],
|
|
256
|
+
usesBrands: false,
|
|
257
|
+
params: [],
|
|
258
|
+
size: { w: 4, h: 5 },
|
|
259
|
+
available: ({ rows }) => rows.some((row) => !!row.country),
|
|
260
|
+
async fetch(_params, { rows, lang }) {
|
|
261
|
+
const counts = new Map<string, number>();
|
|
262
|
+
for (const row of rows) {
|
|
263
|
+
const name = row.country ? countryName(row.country, lang) : T(lang, "Sans pays", "No country");
|
|
264
|
+
counts.set(name, (counts.get(name) ?? 0) + 1);
|
|
265
|
+
}
|
|
266
|
+
return { type: "parts", parts: [...counts].map(([name, value]) => ({ name, value })).sort((a, b) => b.value - a.value) };
|
|
267
|
+
},
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
const CHANGE_LABELS: Record<string, Text> = {
|
|
271
|
+
appeared: { fr: "Apparu", en: "Appeared" },
|
|
272
|
+
changed: { fr: "Modifié", en: "Changed" },
|
|
273
|
+
disappeared: { fr: "Disparu", en: "Disappeared" },
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
/** Les changements detectes sur les fiches du projet, lus dans l'Inbox. Cache tant que l'Inbox n'en a aucun. */
|
|
277
|
+
export const PROJECT_CHANGES_WIDGET: WidgetKind = {
|
|
278
|
+
kind: "project.changes",
|
|
279
|
+
deps: ({ inbox }) => inbox.map((item) => [item.id, item.readAt]),
|
|
280
|
+
group: PROJECT_GROUP,
|
|
281
|
+
title: { fr: "Ce qui a bougé", en: "What changed" },
|
|
282
|
+
description: {
|
|
283
|
+
fr: "Les fiches du projet apparues, modifiées ou disparues, telles que l'Inbox les a vues.",
|
|
284
|
+
en: "The project's records that appeared, changed or disappeared, as the Inbox saw them.",
|
|
285
|
+
},
|
|
286
|
+
viz: ["kpi", "table"],
|
|
287
|
+
sources: [],
|
|
288
|
+
usesBrands: false,
|
|
289
|
+
params: [
|
|
290
|
+
{
|
|
291
|
+
key: "scope",
|
|
292
|
+
label: { fr: "Période", en: "Scope" },
|
|
293
|
+
options: [
|
|
294
|
+
{ value: "unread", label: { fr: "Depuis ma dernière visite", en: "Since my last visit" } },
|
|
295
|
+
{ value: "all", label: { fr: "Tout l'historique", en: "Whole history" } },
|
|
296
|
+
],
|
|
297
|
+
},
|
|
298
|
+
],
|
|
299
|
+
size: { w: 8, h: 5 },
|
|
300
|
+
available: ({ inbox }) => inbox.some((item) => item.kind === "changes" && item.payload?.events?.length),
|
|
301
|
+
async fetch(params, { inbox, lang }) {
|
|
302
|
+
const items = inbox.filter((item) => item.kind === "changes" && (params.scope === "all" || !item.readAt));
|
|
303
|
+
const events = items.flatMap((item) => item.payload?.events ?? []);
|
|
304
|
+
const period = params.scope === "all" ? T(lang, "tout l'historique", "whole history") : T(lang, "depuis ma dernière visite", "since my last visit");
|
|
305
|
+
const count = (kind: string) => events.filter((event) => event.kind === kind).length;
|
|
306
|
+
return {
|
|
307
|
+
type: "kpi",
|
|
308
|
+
period,
|
|
309
|
+
items: (["appeared", "changed", "disappeared"] as const).map((kind) => ({
|
|
310
|
+
label: CHANGE_LABELS[kind]![lang],
|
|
311
|
+
value: count(kind),
|
|
312
|
+
previous: null,
|
|
313
|
+
})),
|
|
314
|
+
note: events.length ? undefined : T(lang, "Rien n'a bougé sur cette période.", "Nothing changed over this period."),
|
|
315
|
+
};
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
/** Les notes et documents du projet, du plus recent au plus ancien. */
|
|
320
|
+
export const PROJECT_ACTIVITY_WIDGET: WidgetKind = {
|
|
321
|
+
kind: "project.activity",
|
|
322
|
+
deps: ({ projectId }) => projectId,
|
|
323
|
+
group: PROJECT_GROUP,
|
|
324
|
+
title: { fr: "Notes et documents récents", en: "Recent notes and documents" },
|
|
325
|
+
description: { fr: "Les dernières notes écrites et les derniers documents déposés dans le projet.", en: "The latest notes written and documents dropped in the project." },
|
|
326
|
+
viz: ["table"],
|
|
327
|
+
sources: [],
|
|
328
|
+
usesBrands: false,
|
|
329
|
+
params: [],
|
|
330
|
+
size: { w: 4, h: 5 },
|
|
331
|
+
async fetch(_params, { api, projectId, lang }) {
|
|
332
|
+
const [notes, documents] = await Promise.all([
|
|
333
|
+
api.projectNotes.list(projectId).then((r: any) => r?.notes ?? []).catch(() => []),
|
|
334
|
+
api.projectDocuments.list(projectId).then((r: any) => r?.documents ?? []).catch(() => []),
|
|
335
|
+
]);
|
|
336
|
+
const rows = [
|
|
337
|
+
...notes.map((note: any) => ({
|
|
338
|
+
date: day(note.updatedAt ?? note.createdAt),
|
|
339
|
+
kind: T(lang, "Note", "Note"),
|
|
340
|
+
title: String(note.title || T(lang, "Sans titre", "Untitled")),
|
|
341
|
+
})),
|
|
342
|
+
...documents.map((document: any) => ({
|
|
343
|
+
date: day(document.createdAt),
|
|
344
|
+
kind: T(lang, "Document", "Document"),
|
|
345
|
+
title: String(document.title || document.filename || ""),
|
|
346
|
+
})),
|
|
347
|
+
].sort((a, b) => b.date.localeCompare(a.date));
|
|
348
|
+
return {
|
|
349
|
+
type: "rows",
|
|
350
|
+
columns: [
|
|
351
|
+
{ key: "date", label: T(lang, "Date", "Date"), date: true },
|
|
352
|
+
{ key: "kind", label: T(lang, "Type", "Type") },
|
|
353
|
+
{ key: "title", label: T(lang, "Titre", "Title"), long: true },
|
|
354
|
+
],
|
|
355
|
+
rows,
|
|
356
|
+
note: rows.length ? undefined : T(lang, "Aucune note ni document pour l'instant.", "No note or document yet."),
|
|
357
|
+
};
|
|
358
|
+
},
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/** Les widgets du layer, que toute app propose avant les siens. */
|
|
362
|
+
export const PROJECT_LAYER_WIDGETS: WidgetKind[] = [
|
|
363
|
+
PROJECT_RESOURCES_WIDGET,
|
|
364
|
+
PROJECT_RECENT_WIDGET,
|
|
365
|
+
PROJECT_COUNTRIES_WIDGET,
|
|
366
|
+
PROJECT_CHANGES_WIDGET,
|
|
367
|
+
PROJECT_ACTIVITY_WIDGET,
|
|
368
|
+
];
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* Catalogue des widgets du tableau de bord. Une app y met les siens apres
|
|
372
|
+
* ceux du layer : `[...PROJECT_LAYER_WIDGETS, ...widgets]`.
|
|
373
|
+
*/
|
|
374
|
+
export const PROJECT_DASHBOARD_WIDGETS: WidgetKind[] = PROJECT_LAYER_WIDGETS;
|
|
178
375
|
|
|
179
|
-
/**
|
|
180
|
-
export function
|
|
376
|
+
/** Un widget pose a une place, avec sa taille de catalogue. */
|
|
377
|
+
export function oipPlaceWidget(
|
|
378
|
+
catalog: WidgetKind[],
|
|
379
|
+
kind: string,
|
|
380
|
+
viz: RmDashboardWidget["viz"],
|
|
381
|
+
x: number,
|
|
382
|
+
y: number,
|
|
383
|
+
size?: { w: number; h: number },
|
|
384
|
+
): RmDashboardWidget {
|
|
385
|
+
const entry = catalog.find((item) => item.kind === kind);
|
|
386
|
+
return { id: rmNewWidgetId(), kind, viz, params: {}, layout: { x, y, ...(size ?? entry?.size ?? { w: 4, h: 5 }) } };
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
/**
|
|
390
|
+
* Le tableau d'un projet reduit a ce qui a quelque chose a montrer : les
|
|
391
|
+
* widgets d'une entree cachee du catalogue (sans marque, `available` faux)
|
|
392
|
+
* ne sont pas poses. Pour un tableau de depart ou un modele ; un tableau
|
|
393
|
+
* enregistre garde les siens.
|
|
394
|
+
*/
|
|
395
|
+
export function oipPruneDashboard(model: RmDashboardModel, catalog: WidgetKind[], context: OipProjectWidgetContext): RmDashboardModel {
|
|
396
|
+
const addable = new Set(rmAddableWidgets(catalog, context).map((entry) => entry.kind));
|
|
397
|
+
return { ...model, widgets: model.widgets.filter((widget) => addable.has(widget.kind)) };
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Le tableau de depart d'un projet qui n'en a pas encore enregistre : le
|
|
402
|
+
* contenu, les derniers ajouts, les pays, ce qui a bouge, les notes et
|
|
403
|
+
* documents. Sans contexte (contrat d'avant), le seul contenu du projet.
|
|
404
|
+
* Une app pose les siens ; les widgets sans donnee sont retires a l'affichage
|
|
405
|
+
* (oipPruneDashboard), elle n'a pas a le faire elle-meme.
|
|
406
|
+
*/
|
|
407
|
+
export function defaultProjectDashboard(context?: OipProjectWidgetContext): RmDashboardModel {
|
|
408
|
+
const place = (kind: string, viz: RmDashboardWidget["viz"], x: number, y: number, size?: { w: number; h: number }) =>
|
|
409
|
+
oipPlaceWidget(PROJECT_LAYER_WIDGETS, kind, viz, x, y, size);
|
|
410
|
+
if (!context) return { version: 1, widgets: [place("project.resources", "donut", 0, 0)] };
|
|
181
411
|
return {
|
|
182
412
|
version: 1,
|
|
183
413
|
widgets: [
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
layout: { x: 0, y: 0, ...PROJECT_RESOURCES_WIDGET.size },
|
|
190
|
-
},
|
|
414
|
+
place("project.resources", "donut", 0, 0),
|
|
415
|
+
place("project.recent", "table", 4, 0),
|
|
416
|
+
place("project.byCountry", "donut", 0, 5),
|
|
417
|
+
place("project.changes", "kpi", 4, 5),
|
|
418
|
+
place("project.activity", "table", 0, 10, { w: 12, h: 5 }),
|
|
191
419
|
],
|
|
192
420
|
};
|
|
193
421
|
}
|
|
422
|
+
|
|
423
|
+
/** Un modele de tableau : un jeu de widgets a poser d'un coup, propose dans le menu « Modeles ». */
|
|
424
|
+
export interface OipProjectDashboardTemplate {
|
|
425
|
+
id: string;
|
|
426
|
+
title: Text;
|
|
427
|
+
description?: Text;
|
|
428
|
+
build: (context: OipProjectWidgetContext) => RmDashboardModel;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Les modeles du menu « Modeles » de l'onglet, apres lesquels viennent les
|
|
433
|
+
* tableaux des autres projets de l'utilisateur (« Copier depuis un projet »).
|
|
434
|
+
* Une app ajoute les siens : `[...PROJECT_LAYER_TEMPLATES, ...]`.
|
|
435
|
+
*/
|
|
436
|
+
export const PROJECT_LAYER_TEMPLATES: OipProjectDashboardTemplate[] = [
|
|
437
|
+
{
|
|
438
|
+
id: "overview",
|
|
439
|
+
title: { fr: "Vue d'ensemble", en: "Overview" },
|
|
440
|
+
description: { fr: "Le contenu, les derniers ajouts, les pays, ce qui a bougé.", en: "The content, latest additions, countries, what changed." },
|
|
441
|
+
build: (context) => defaultProjectDashboard(context),
|
|
442
|
+
},
|
|
443
|
+
{
|
|
444
|
+
id: "activity",
|
|
445
|
+
title: { fr: "Activité", en: "Activity" },
|
|
446
|
+
description: { fr: "Ce qui a bougé, les derniers ajouts, les notes et documents.", en: "What changed, latest additions, notes and documents." },
|
|
447
|
+
build: () => ({
|
|
448
|
+
version: 1,
|
|
449
|
+
widgets: [
|
|
450
|
+
oipPlaceWidget(PROJECT_LAYER_WIDGETS, "project.changes", "kpi", 0, 0, { w: 12, h: 4 }),
|
|
451
|
+
oipPlaceWidget(PROJECT_LAYER_WIDGETS, "project.recent", "table", 0, 4, { w: 8, h: 6 }),
|
|
452
|
+
oipPlaceWidget(PROJECT_LAYER_WIDGETS, "project.activity", "table", 8, 4, { w: 4, h: 6 }),
|
|
453
|
+
],
|
|
454
|
+
}),
|
|
455
|
+
},
|
|
456
|
+
];
|
|
457
|
+
|
|
458
|
+
export const PROJECT_DASHBOARD_TEMPLATES: OipProjectDashboardTemplate[] = PROJECT_LAYER_TEMPLATES;
|