@tekkare/romulus 0.1.318 → 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.
@@ -1,78 +1,143 @@
1
1
  <!--
2
2
  L'onglet « Tableau de bord » d'un projet : RmDashboard branche sur le
3
- catalogue de l'app (`PROJECT_DASHBOARD_WIDGETS` de #oip-app/projects, sinon
4
- le seul contenu du projet) et sur l'API des projets (useProjectDashboard).
5
- Repris de France Augmented Science et d'OIP Case Atlas.
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 des documents que la
8
- page a deja relus ; les marques en viennent aussi (`projectBrands` de
9
- l'app). Ce que le layer ajoute au paquet :
10
- - la source de chaque entree : le contenu du projet, lu a l'instant ;
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="board"
17
- :widgets="widgets"
18
- :catalog="PROJECT_DASHBOARD_WIDGETS"
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
- @update:widgets="update"
28
- @load="load"
29
- @retry-save="retrySave"
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 { PROJECT_DASHBOARD_WIDGETS, PROJECT_WORDING, projectBrands } from "#oip-projects";
37
- import type { OipProjectWidgetContext as WidgetContext } from "../../oip-defaults/projects";
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
- groups: WidgetContext["groups"];
46
- docs: WidgetContext["docs"];
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
- const { widgets, loading, failed, saving, saveFailed, load, update, retrySave } = useProjectDashboard(props.projectId);
53
- onMounted(load);
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
- const context = computed<WidgetContext>(() => ({
56
- brands: projectBrands(props.docs),
57
- lang: props.lang,
58
- groups: props.groups,
59
- docs: props.docs,
60
- }));
69
+ // --- Sources ----------------------------------------------------------------------
61
70
 
62
- /** Le contenu du projet n'a pas de producteur public : c'est le projet, lu a l'instant. */
63
- function sourceOf(): RmWidgetSource {
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: en.value ? "Project content" : "Contenu du projet",
66
- verified: new Date().toISOString().slice(0, 10),
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 board = ref<{ exportSheets: () => RmExportSheet[] } | null>(null);
137
+ const grid = ref<{ exportSheets: () => RmExportSheet[] } | null>(null);
73
138
 
74
139
  useExportSource().declare(() => {
75
- const sheets = board.value?.exportSheets() ?? [];
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. En tete, le suivi du projet (une alerte sur ses fiches, quand l'app
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
- <ProjectDashboard
86
- v-else-if="tab === 'dashboard' && !failed && project"
87
- :project-id="projectId"
88
- :project-title="project.title"
89
- :groups="dashboardGroups"
90
- :docs="dashboardDocs"
91
- :lang="lang"
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-else-if="tab === 'documents'"
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-else-if="tab === 'notes'"
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-else-if="tab === 'inbox'"
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>) {
@@ -77,6 +77,8 @@ const LOADERS: Record<string, Record<string, () => Promise<any>>> = {
77
77
  * `id`, `label`).
78
78
  * - `patients-<famille>` : la fiche d'OIP Case Atlas, que ses pages montent
79
79
  * aussi (props `id`, `tab`, `backTo`).
80
+ * - `oncology-approval` : la carte d'une autorisation de Global Oncology,
81
+ * commune aux cinq agences (props `id`, `type`).
80
82
  */
81
83
  const VIEW_LOADERS: Record<string, () => Promise<any>> = {
82
84
  "science-phrc": () => import("../components/oip-science/resources/Phrc.vue"),
@@ -118,6 +120,7 @@ const VIEW_LOADERS: Record<string, () => Promise<any>> = {
118
120
  "new-zealand-medsafe": () => import("../components/oip-new-zealand/MedsafeProduct.vue"),
119
121
  "new-zealand-price": () => import("../components/oip-new-zealand/NewZealandPrice.vue"),
120
122
  "new-zealand-retail-molecule": () => import("../components/oip-new-zealand/RetailMolecule.vue"),
123
+ "oncology-approval": () => import("../components/oip-oncology/Approval.vue"),
121
124
  };
122
125
 
123
126
  const cache = new Map<string, Component>();
@@ -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 le seul contenu du projet.
5
+ * (#oip-app/projects), sinon ceux du layer.
6
6
  *
7
- * Tout le reste (sauvegarde temporisee, repli tant que rien n'est
8
- * enregistre, kinds inconnus conserves) est a useRmDashboard, dans Romulus.
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
- export function useProjectDashboard(projectId: string) {
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: PROJECT_DASHBOARD_WIDGETS,
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: defaultProjectDashboard,
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>[] = [