@tekkare/romulus 0.1.261 → 0.1.262

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.
@@ -0,0 +1,205 @@
1
+ <!--
2
+ Ce que la page d'un projet donne au panneau d'export du rail.
3
+
4
+ Ne rend rien : il declare la source (cf. useExportSource). Le classeur est
5
+ l'inventaire du projet, comme dans France Augmented Science, OIP Case Atlas
6
+ et fr_drugs_app : la fiche du projet, ses ressources, les feuilles propres a
7
+ l'app (`projectExportSheets` de #oip-app/projects, par exemple un onglet par
8
+ famille avec les colonnes de l'export de ses listes) et ses commentaires. Les commentaires ne se lisent qu'a l'ouverture du panneau,
9
+ une requete par ressource commentee.
10
+ -->
11
+ <script setup lang="ts">
12
+ import type { RmExportSheet } from "@tekkare/romulus/utils/export";
13
+ import { rmProjectFamilies, type RmProjectResource } from "@tekkare/romulus/utils/projects";
14
+ import { useOipApi } from "#oip-app/api";
15
+ import { projectExportSheets } from "#oip-projects";
16
+ import type { ProjectUser } from "../../types/projects";
17
+
18
+ const props = defineProps<{
19
+ projectId: string;
20
+ project: {
21
+ title: string;
22
+ description: string;
23
+ createdAt?: string;
24
+ isShared?: boolean;
25
+ owner?: { email: string; displayName: string | null };
26
+ } | null;
27
+ rows: RmProjectResource[];
28
+ users: ProjectUser[];
29
+ }>();
30
+
31
+ const { locale } = useI18n();
32
+ const en = computed(() => locale.value === "en");
33
+ const projects = useProjects();
34
+
35
+ const origin = import.meta.client ? window.location.origin : "";
36
+ // Une ressource d'une autre app porte deja l'URL de son app.
37
+ const link = (path?: string) => (!path ? "" : /^https?:/.test(path) ? path : `${origin}${path}`);
38
+
39
+ const text = (column: string, read: (row: any) => any, width = 30) => ({
40
+ column,
41
+ type: String,
42
+ width,
43
+ wrap: true,
44
+ alignVertical: "center",
45
+ value: (row: any) => {
46
+ const value = read(row);
47
+ return value === null || value === undefined ? "" : String(value);
48
+ },
49
+ });
50
+
51
+ const date = (column: string, read: (row: any) => any) => ({
52
+ column: `${column} (${en.value ? "mm/dd/yyyy" : "dd/mm/yyyy"})`,
53
+ type: Date,
54
+ format: en.value ? "mm/dd/yyyy" : "dd/mm/yyyy",
55
+ width: 18,
56
+ alignVertical: "center",
57
+ value: (row: any) => {
58
+ const value = new Date(read(row) ?? "");
59
+ return Number.isNaN(value.getTime()) ? null : value;
60
+ },
61
+ });
62
+
63
+ const number = (column: string, read: (row: any) => any) => ({
64
+ column,
65
+ type: Number,
66
+ width: 14,
67
+ alignVertical: "center",
68
+ value: (row: any) => {
69
+ const value = read(row);
70
+ return typeof value === "number" && Number.isFinite(value) ? value : null;
71
+ },
72
+ });
73
+
74
+ const comments = ref<{ resource: string; family: string; author: string; createdAt: string; text: string }[]>([]);
75
+
76
+ const commentTotal = computed(() => props.rows.reduce((sum, row) => sum + (row.comments ?? 0), 0));
77
+
78
+ function formatDay(value?: string) {
79
+ const day = new Date(value ?? "");
80
+ return Number.isNaN(day.getTime()) ? "" : day.toLocaleDateString(en.value ? "en-GB" : "fr-FR");
81
+ }
82
+
83
+ function personName(user: { displayName?: string | null; firstName?: string | null; lastName?: string | null; email?: string }) {
84
+ const name = user.displayName || [user.firstName, user.lastName].filter(Boolean).join(" ");
85
+ return name ? `${name} (${user.email})` : (user.email ?? "");
86
+ }
87
+
88
+ const projectSheet = computed<RmExportSheet>(() => {
89
+ const p = props.project;
90
+ const visibility = p?.isShared
91
+ ? en.value ? "Whole workspace" : "Tout l'espace de travail"
92
+ : props.users.length > 1
93
+ ? en.value ? "Shared with members" : "Partagé avec des membres"
94
+ : en.value ? "Private" : "Privé";
95
+ const rows = [
96
+ { label: en.value ? "Project" : "Projet", value: p?.title ?? "" },
97
+ { label: "Description", value: p?.description ?? "" },
98
+ { label: en.value ? "Owner" : "Propriétaire", value: p?.owner ? personName(p.owner) : "" },
99
+ { label: en.value ? "Created on" : "Créé le", value: formatDay(p?.createdAt) },
100
+ { label: en.value ? "Visibility" : "Visibilité", value: visibility },
101
+ { label: en.value ? "Members" : "Membres", value: props.users.map(personName).join(", ") },
102
+ { label: en.value ? "Resources" : "Ressources", value: String(props.rows.length) },
103
+ ...rmProjectFamilies(props.rows).map((family) => ({ label: ` ${family.label}`, value: String(family.count) })),
104
+ { label: en.value ? "Comments" : "Commentaires", value: String(commentTotal.value) },
105
+ { label: en.value ? "Link" : "Lien", value: link(projects.pathOf(props.projectId)) },
106
+ ];
107
+ return {
108
+ name: en.value ? "Project" : "Projet",
109
+ titleColumn: en.value ? "Field" : "Rubrique",
110
+ data: rows,
111
+ schema: [
112
+ text(en.value ? "Field" : "Rubrique", (row) => row.label, 26),
113
+ text(en.value ? "Value" : "Valeur", (row) => row.value, 80),
114
+ ],
115
+ } as RmExportSheet;
116
+ });
117
+
118
+ const resourcesSheet = computed<RmExportSheet>(() => ({
119
+ name: en.value ? "Resources" : "Ressources",
120
+ titleColumn: en.value ? "Resource" : "Ressource",
121
+ subtitleColumn: en.value ? "Family" : "Famille",
122
+ data: props.rows,
123
+ schema: [
124
+ text(en.value ? "Resource" : "Ressource", (row) => row.title || row.id, 50),
125
+ text(en.value ? "Details" : "Détail", (row) => row.subtitle, 50),
126
+ text(en.value ? "Family" : "Famille", (row) => row.family, 26),
127
+ text(en.value ? "Section" : "Rubrique", (row) => row.section, 22),
128
+ date(en.value ? "Added on" : "Ajouté le", (row) => row.createdAt),
129
+ number(en.value ? "Comments" : "Commentaires", (row) => row.comments),
130
+ text(en.value ? "Link" : "Lien", (row) => link(row.path), 50),
131
+ text(en.value ? "Identifier" : "Identifiant", (row) => row.id, 30),
132
+ ],
133
+ }) as RmExportSheet);
134
+
135
+ const commentsSheet = computed<RmExportSheet>(() => ({
136
+ name: en.value ? "Comments" : "Commentaires",
137
+ titleColumn: en.value ? "Resource" : "Ressource",
138
+ subtitleColumn: en.value ? "Author" : "Auteur",
139
+ data: comments.value,
140
+ schema: [
141
+ text(en.value ? "Resource" : "Ressource", (row) => row.resource, 45),
142
+ text(en.value ? "Family" : "Famille", (row) => row.family, 24),
143
+ text(en.value ? "Author" : "Auteur", (row) => row.author, 30),
144
+ date("Date", (row) => row.createdAt),
145
+ text(en.value ? "Comment" : "Commentaire", (row) => row.text, 80),
146
+ ],
147
+ }) as RmExportSheet);
148
+
149
+ /** La fiche et les ressources toujours ; les feuilles de l'app et les commentaires quand il y en a. */
150
+ const sheets = computed(() =>
151
+ [
152
+ projectSheet.value,
153
+ resourcesSheet.value,
154
+ ...projectExportSheets(props.rows, en.value ? "en" : "fr"),
155
+ commentsSheet.value,
156
+ ].filter((sheet, index) => index < 2 || sheet.data.length),
157
+ );
158
+
159
+ /** Les commentaires des ressources commentees, relus a l'ouverture du panneau. */
160
+ async function loadComments() {
161
+ const api = useOipApi();
162
+ const commented = props.rows.filter((row) => row.comments);
163
+ const lists = await Promise.all(
164
+ commented.map((row) =>
165
+ api.comments
166
+ .getResourceComments(props.projectId, row.id)
167
+ .then((response) =>
168
+ (response?.data ?? []).map((comment) => ({
169
+ resource: row.title || row.id,
170
+ family: row.family,
171
+ author: [comment.userFirstName, comment.userLastName].filter(Boolean).join(" ") || comment.userEmail || "",
172
+ createdAt: comment.createdAt,
173
+ text: comment.text,
174
+ })),
175
+ )
176
+ .catch(() => []),
177
+ ),
178
+ );
179
+ comments.value = lists.flat();
180
+ }
181
+
182
+ useExportSource().declare(() => {
183
+ if (!props.project) return null;
184
+ const title = props.project.title || (en.value ? "Project" : "Projet");
185
+ return {
186
+ title: en.value ? `Inventory, ${title}` : `Inventaire, ${title}`,
187
+ subtitle: en.value ? `Project, ${props.rows.length} resources` : `Projet, ${props.rows.length} ressources`,
188
+ fileName: rmExportFileName(title, en.value ? "inventory" : "inventaire"),
189
+ sheets: sheets.value,
190
+ kpi: [
191
+ { label: en.value ? "Resources" : "Ressources", value: props.rows.length },
192
+ { label: en.value ? "Families" : "Familles", value: rmProjectFamilies(props.rows).length },
193
+ { label: en.value ? "Comments" : "Commentaires", value: commentTotal.value },
194
+ ],
195
+ layout: "table",
196
+ prepare: loadComments,
197
+ beforeExport: loadComments,
198
+ posthogName: "Project - inventory",
199
+ };
200
+ });
201
+ </script>
202
+
203
+ <template>
204
+ <span hidden />
205
+ </template>