@tekkare/romulus 0.1.327 → 0.1.328
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/layer/app/components/OipShell.vue +3 -0
- package/layer/app/components/layout/newsModal.vue +243 -0
- package/layer/app/components/panels/OipPanelTopics.vue +146 -12
- package/layer/app/composables/useOipFavorites.ts +13 -1
- package/layer/app/composables/useOipPageSubject.ts +52 -0
- package/layer/server/api/oip/favorites.post.ts +75 -0
- package/layer/server/api/oip/news.get.ts +106 -0
- package/layer/server/api/oip/subjects.get.ts +40 -0
- package/layer/server/utils/oipFavorites.ts +60 -0
- package/package.json +1 -1
package/dist/module.json
CHANGED
|
@@ -37,6 +37,7 @@ import OipPanelSourceTables from "./panels/OipPanelSourceTables.vue";
|
|
|
37
37
|
import OipPanelStatistics from "./panels/OipPanelStatistics.vue";
|
|
38
38
|
import OipPanelTopics from "./panels/OipPanelTopics.vue";
|
|
39
39
|
import OipPanelTutorials from "./panels/OipPanelTutorials.vue";
|
|
40
|
+
import OipNewsModal from "./layout/newsModal.vue";
|
|
40
41
|
|
|
41
42
|
// Relatif et non `~/` : dans un layer, `~` designe l'app qui l'etend.
|
|
42
43
|
import tekkareLogoRaw from "../assets/tekkare_logo.svg?raw";
|
|
@@ -663,6 +664,8 @@ const tekkareLogo = tekkareLogoRaw.replaceAll('fill="#2100AD"', 'fill="currentCo
|
|
|
663
664
|
|
|
664
665
|
<template #overlay>
|
|
665
666
|
<div ref="chatwootLayer" class="oip-chatwoot-layer" />
|
|
667
|
+
<!-- Nouveautés sur les sujets favoris de cette app, une fois par news. -->
|
|
668
|
+
<OipNewsModal :lang="en ? 'en' : 'fr'" />
|
|
666
669
|
</template>
|
|
667
670
|
</RmAppShell>
|
|
668
671
|
</template>
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
Modale « Nouveautés », montee par OipShell sur toutes les pages.
|
|
3
|
+
|
|
4
|
+
A l'arrivee dans l'app, demande a /api/oip/news les news publiees sur
|
|
5
|
+
OIP 7 (OipNews) qui touchent un sujet de cette app mis en favori. Celles
|
|
6
|
+
que le lecteur n'a pas encore vues ouvrent la modale ; la fermer les marque
|
|
7
|
+
vues (localStorage, par navigateur). Rien a montrer : rien ne s'ouvre.
|
|
8
|
+
-->
|
|
9
|
+
<script setup lang="ts">
|
|
10
|
+
interface NewsItem {
|
|
11
|
+
id: string;
|
|
12
|
+
type: string;
|
|
13
|
+
title: string;
|
|
14
|
+
description: string;
|
|
15
|
+
date: string;
|
|
16
|
+
link: string | null;
|
|
17
|
+
subjects: { id: string; path: string; translations: { languages_code?: string; subject_name?: string }[] }[];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const props = defineProps<{ lang: "fr" | "en" }>();
|
|
21
|
+
const en = computed(() => props.lang === "en");
|
|
22
|
+
|
|
23
|
+
const STORAGE_KEY = "oip-news-seen";
|
|
24
|
+
/** Au-dela, les plus anciens ids sortent : la fenetre serveur est de 30 jours. */
|
|
25
|
+
const MAX_SEEN = 200;
|
|
26
|
+
|
|
27
|
+
/** Memes types que le fil d'OIP 7 (oip7 app/utils/newsShared.ts). */
|
|
28
|
+
const TYPE_EMOJI: Record<string, string> = { announcement: "📣", new_webapp: "🚀", data_update: "🔄" };
|
|
29
|
+
|
|
30
|
+
const open = ref(false);
|
|
31
|
+
const items = ref<NewsItem[]>([]);
|
|
32
|
+
const PLATFORM_URL = useAppConfig().oip.platform.href;
|
|
33
|
+
const { status } = useAuth();
|
|
34
|
+
|
|
35
|
+
function readSeen(): string[] {
|
|
36
|
+
try {
|
|
37
|
+
const value = JSON.parse(localStorage.getItem(STORAGE_KEY) || "[]");
|
|
38
|
+
return Array.isArray(value) ? value : [];
|
|
39
|
+
} catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function markSeen() {
|
|
45
|
+
const seen = [...new Set([...items.value.map((item) => item.id), ...readSeen()])].slice(0, MAX_SEEN);
|
|
46
|
+
try {
|
|
47
|
+
localStorage.setItem(STORAGE_KEY, JSON.stringify(seen));
|
|
48
|
+
} catch {
|
|
49
|
+
// Stockage refuse : la modale reviendra a la prochaine visite.
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let checked = false;
|
|
54
|
+
async function check() {
|
|
55
|
+
if (checked || status.value !== "authenticated") return;
|
|
56
|
+
checked = true;
|
|
57
|
+
try {
|
|
58
|
+
const news = await $fetch<NewsItem[]>("/api/oip/news");
|
|
59
|
+
const seen = new Set(readSeen());
|
|
60
|
+
items.value = news.filter((item) => !seen.has(item.id));
|
|
61
|
+
open.value = items.value.length > 0;
|
|
62
|
+
} catch {
|
|
63
|
+
// Favoris ou news illisibles : la modale ne s'ouvre pas, l'app continue.
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
onMounted(() => watch(status, check, { immediate: true }));
|
|
68
|
+
|
|
69
|
+
watch(open, (value, previous) => {
|
|
70
|
+
if (previous && !value) markSeen();
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/** Une description de news est du HTML (editeur riche d'OIP 7) : ici, un extrait en texte. */
|
|
74
|
+
function excerpt(html: string): string {
|
|
75
|
+
const text = html.replace(/<[^>]*>/g, " ").replace(/ /g, " ").replace(/\s+/g, " ").trim();
|
|
76
|
+
return text.length > 220 ? `${text.slice(0, 220).trimEnd()}…` : text;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function subjectName(subject: NewsItem["subjects"][number]): string {
|
|
80
|
+
const list = subject.translations || [];
|
|
81
|
+
const match = list.find((t) => String(t?.languages_code || "").startsWith(props.lang)) || list[0];
|
|
82
|
+
return match?.subject_name || subject.path;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function formatDate(value: string): string {
|
|
86
|
+
const date = new Date(value);
|
|
87
|
+
if (Number.isNaN(date.getTime())) return "";
|
|
88
|
+
return date.toLocaleDateString(en.value ? "en-GB" : "fr-FR", { day: "numeric", month: "long", year: "numeric" });
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const isExternal = (to: string) => /^https?:\/\//.test(to);
|
|
92
|
+
</script>
|
|
93
|
+
|
|
94
|
+
<template>
|
|
95
|
+
<RmModal v-model="open" size="lg" mode="free" :label="en ? 'What is new' : 'Nouveautés'">
|
|
96
|
+
<template #header>
|
|
97
|
+
<div class="news_head">
|
|
98
|
+
<span class="news_head_icon">✨</span>
|
|
99
|
+
<div>
|
|
100
|
+
<h2 class="news_title">{{ en ? "Something new on your topics!" : "Du nouveau sur vos sujets !" }}</h2>
|
|
101
|
+
<p class="news_subtitle">
|
|
102
|
+
{{
|
|
103
|
+
en
|
|
104
|
+
? "Updates published on the topics you follow in this app."
|
|
105
|
+
: "Les nouveautés publiées sur les sujets que vous suivez dans cette app."
|
|
106
|
+
}}
|
|
107
|
+
</p>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
</template>
|
|
111
|
+
|
|
112
|
+
<ul class="news_list">
|
|
113
|
+
<li v-for="item in items" :key="item.id" class="news_item">
|
|
114
|
+
<div class="news_meta">
|
|
115
|
+
<span>{{ TYPE_EMOJI[item.type] || "📣" }}</span>
|
|
116
|
+
<span>{{ formatDate(item.date) }}</span>
|
|
117
|
+
</div>
|
|
118
|
+
<strong class="news_item_title">{{ item.title }}</strong>
|
|
119
|
+
<p v-if="excerpt(item.description)" class="news_item_text">{{ excerpt(item.description) }}</p>
|
|
120
|
+
<div class="news_links">
|
|
121
|
+
<template v-for="subject in item.subjects" :key="subject.id">
|
|
122
|
+
<NuxtLink class="news_chip" :to="subject.path" @click="open = false">
|
|
123
|
+
<i class="ph ph-star" />
|
|
124
|
+
{{ subjectName(subject) }}
|
|
125
|
+
</NuxtLink>
|
|
126
|
+
</template>
|
|
127
|
+
<a
|
|
128
|
+
v-if="item.link"
|
|
129
|
+
class="news_chip"
|
|
130
|
+
:href="item.link"
|
|
131
|
+
:target="isExternal(item.link) ? '_blank' : undefined"
|
|
132
|
+
rel="noopener noreferrer"
|
|
133
|
+
>
|
|
134
|
+
<i class="ph ph-arrow-square-out" />
|
|
135
|
+
{{ en ? "Learn more" : "En savoir plus" }}
|
|
136
|
+
</a>
|
|
137
|
+
</div>
|
|
138
|
+
</li>
|
|
139
|
+
</ul>
|
|
140
|
+
|
|
141
|
+
<template #footer>
|
|
142
|
+
<a class="news_all" :href="`${PLATFORM_URL.replace(/\/+$/, '')}/news`" target="_blank" rel="noopener noreferrer">
|
|
143
|
+
{{ en ? "All news on OIP Platform" : "Toutes les nouveautés sur OIP Platform" }}
|
|
144
|
+
</a>
|
|
145
|
+
<RmButton @click="open = false">{{ en ? "Got it" : "J'ai compris" }}</RmButton>
|
|
146
|
+
</template>
|
|
147
|
+
</RmModal>
|
|
148
|
+
</template>
|
|
149
|
+
|
|
150
|
+
<style scoped>
|
|
151
|
+
.news_head {
|
|
152
|
+
display: flex;
|
|
153
|
+
align-items: flex-start;
|
|
154
|
+
gap: 12px;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.news_head_icon {
|
|
158
|
+
font-size: 24px;
|
|
159
|
+
line-height: 1;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.news_title {
|
|
163
|
+
margin: 0;
|
|
164
|
+
color: var(--text-primary);
|
|
165
|
+
font-size: var(--font-16);
|
|
166
|
+
font-weight: var(--weight-semibold);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.news_subtitle {
|
|
170
|
+
margin: 4px 0 0;
|
|
171
|
+
color: var(--text-muted);
|
|
172
|
+
font-size: var(--font-12);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.news_list {
|
|
176
|
+
display: flex;
|
|
177
|
+
flex-direction: column;
|
|
178
|
+
gap: 12px;
|
|
179
|
+
margin: 0;
|
|
180
|
+
padding: 0;
|
|
181
|
+
list-style: none;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.news_item {
|
|
185
|
+
display: flex;
|
|
186
|
+
flex-direction: column;
|
|
187
|
+
gap: 6px;
|
|
188
|
+
padding: 12px 14px;
|
|
189
|
+
border: 1px solid var(--border-default);
|
|
190
|
+
border-radius: var(--radius-lg);
|
|
191
|
+
background: var(--bg-surface);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
.news_meta {
|
|
195
|
+
display: flex;
|
|
196
|
+
gap: 8px;
|
|
197
|
+
color: var(--text-muted);
|
|
198
|
+
font-size: var(--font-11);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.news_item_title {
|
|
202
|
+
color: var(--text-primary);
|
|
203
|
+
font-size: var(--font-13);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.news_item_text {
|
|
207
|
+
margin: 0;
|
|
208
|
+
color: var(--text-muted);
|
|
209
|
+
font-size: var(--font-12);
|
|
210
|
+
line-height: 1.5;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.news_links {
|
|
214
|
+
display: flex;
|
|
215
|
+
flex-wrap: wrap;
|
|
216
|
+
gap: 6px;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
.news_chip {
|
|
220
|
+
display: inline-flex;
|
|
221
|
+
align-items: center;
|
|
222
|
+
gap: 4px;
|
|
223
|
+
padding: 3px 8px;
|
|
224
|
+
border-radius: var(--radius-md);
|
|
225
|
+
background: var(--bg-surface-2);
|
|
226
|
+
color: var(--color-secondary);
|
|
227
|
+
font-size: var(--font-11);
|
|
228
|
+
font-weight: var(--weight-semibold);
|
|
229
|
+
text-decoration: none;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.news_chip:hover {
|
|
233
|
+
text-decoration: underline;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.news_all {
|
|
237
|
+
margin-right: auto;
|
|
238
|
+
color: var(--color-secondary);
|
|
239
|
+
font-size: var(--font-12);
|
|
240
|
+
font-weight: var(--weight-semibold);
|
|
241
|
+
text-decoration: none;
|
|
242
|
+
}
|
|
243
|
+
</style>
|
|
@@ -15,11 +15,33 @@
|
|
|
15
15
|
defineProps<{ appKey?: string; superAdmin?: boolean }>();
|
|
16
16
|
|
|
17
17
|
const { locale } = useI18n();
|
|
18
|
-
const { rows, load, pending, unavailable } = useOipFavorites();
|
|
18
|
+
const { rows, load, pending, unavailable, isStarred, toggleSubject } = useOipFavorites();
|
|
19
19
|
/** Le hub de la plateforme, la ou s'allume l'etoile. */
|
|
20
20
|
const PLATFORM_URL = useAppConfig().oip.platform.href;
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
/** Le sujet de la page ouverte, s'il en est un : c'est lui que le bouton etoile. */
|
|
23
|
+
const { subject: pageSubject, load: loadPageSubject } = useOipPageSubject();
|
|
24
|
+
const pageStarred = computed(() => !!pageSubject.value && isStarred(pageSubject.value.id));
|
|
25
|
+
const toggling = ref(false);
|
|
26
|
+
const toggleError = ref(false);
|
|
27
|
+
|
|
28
|
+
async function togglePage() {
|
|
29
|
+
if (!pageSubject.value || toggling.value) return;
|
|
30
|
+
toggling.value = true;
|
|
31
|
+
toggleError.value = false;
|
|
32
|
+
try {
|
|
33
|
+
await toggleSubject(pageSubject.value.id);
|
|
34
|
+
} catch {
|
|
35
|
+
toggleError.value = true;
|
|
36
|
+
} finally {
|
|
37
|
+
toggling.value = false;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
onMounted(() => {
|
|
42
|
+
load();
|
|
43
|
+
loadPageSubject();
|
|
44
|
+
});
|
|
23
45
|
|
|
24
46
|
/** Meme regle que les sources : la traduction Directus qui commence par la langue. */
|
|
25
47
|
const pick = (list: any[] | undefined) =>
|
|
@@ -158,6 +180,26 @@ const isExternal = (to: string) => !!origin.value && !to.startsWith(origin.value
|
|
|
158
180
|
}}
|
|
159
181
|
</p>
|
|
160
182
|
|
|
183
|
+
<button
|
|
184
|
+
v-if="pageSubject"
|
|
185
|
+
type="button"
|
|
186
|
+
class="topics_star"
|
|
187
|
+
:class="{ 'topics_star--on': pageStarred }"
|
|
188
|
+
:disabled="toggling"
|
|
189
|
+
:aria-pressed="pageStarred"
|
|
190
|
+
@click="togglePage"
|
|
191
|
+
>
|
|
192
|
+
<i class="ph" :class="pageStarred ? 'ph-fill ph-star' : 'ph-star'" />
|
|
193
|
+
{{
|
|
194
|
+
pageStarred
|
|
195
|
+
? locale === "en" ? "Remove this page from my topics" : "Retirer cette page de mes sujets"
|
|
196
|
+
: locale === "en" ? "Add this page to my topics" : "Ajouter cette page en favoris"
|
|
197
|
+
}}
|
|
198
|
+
</button>
|
|
199
|
+
<p v-if="toggleError" class="topics_note">
|
|
200
|
+
{{ locale === "en" ? "Your topics could not be updated." : "Vos sujets n'ont pas pu être mis à jour." }}
|
|
201
|
+
</p>
|
|
202
|
+
|
|
161
203
|
<input
|
|
162
204
|
v-if="topics.length >= SEARCHABLE_FROM"
|
|
163
205
|
v-model="search"
|
|
@@ -206,16 +248,42 @@ const isExternal = (to: string) => !!origin.value && !to.startsWith(origin.value
|
|
|
206
248
|
{{ locale === "en" ? "No topic matches that search." : "Aucun sujet ne correspond." }}
|
|
207
249
|
</p>
|
|
208
250
|
|
|
209
|
-
<
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
251
|
+
<div v-else class="topics_empty">
|
|
252
|
+
<i class="ph ph-star topics_empty_icon" />
|
|
253
|
+
<strong class="topics_empty_title">
|
|
254
|
+
{{ locale === "en" ? "Follow the topics that matter to you" : "Suivez les sujets qui comptent pour vous" }}
|
|
255
|
+
</strong>
|
|
256
|
+
<ul class="topics_empty_list">
|
|
257
|
+
<li>
|
|
258
|
+
{{
|
|
259
|
+
locale === "en"
|
|
260
|
+
? "Find them here in one click, from any page of the app."
|
|
261
|
+
: "Retrouvez-les ici en un clic, depuis n'importe quelle page de l'app."
|
|
262
|
+
}}
|
|
263
|
+
</li>
|
|
264
|
+
<li>
|
|
265
|
+
{{
|
|
266
|
+
locale === "en"
|
|
267
|
+
? "Be told when there is something new: a message on arrival in the app, and an email."
|
|
268
|
+
: "Soyez prévenu des nouveautés : un message à l'arrivée dans l'app, et un e-mail."
|
|
269
|
+
}}
|
|
270
|
+
</li>
|
|
271
|
+
</ul>
|
|
272
|
+
<p class="topics_note">
|
|
273
|
+
{{
|
|
274
|
+
pageSubject
|
|
275
|
+
? locale === "en"
|
|
276
|
+
? "Start with this page using the button above, or star rows in the country menus of OIP Platform."
|
|
277
|
+
: "Commencez par cette page avec le bouton ci-dessus, ou cliquez l'étoile d'une ligne dans les menus pays d'OIP Platform."
|
|
278
|
+
: locale === "en"
|
|
279
|
+
? "Open a country menu on OIP Platform and click the star at the end of a row."
|
|
280
|
+
: "Ouvrez le menu d'un pays sur OIP Platform et cliquez l'étoile au bout d'une ligne."
|
|
281
|
+
}}
|
|
282
|
+
<a class="topics_link" :href="PLATFORM_URL" target="_blank" rel="noopener noreferrer">
|
|
283
|
+
{{ locale === "en" ? "Open OIP Platform" : "Ouvrir OIP Platform" }}
|
|
284
|
+
</a>
|
|
285
|
+
</p>
|
|
286
|
+
</div>
|
|
219
287
|
</div>
|
|
220
288
|
</template>
|
|
221
289
|
|
|
@@ -264,6 +332,72 @@ const isExternal = (to: string) => !!origin.value && !to.startsWith(origin.value
|
|
|
264
332
|
text-decoration: none;
|
|
265
333
|
}
|
|
266
334
|
|
|
335
|
+
.topics_star {
|
|
336
|
+
display: inline-flex;
|
|
337
|
+
align-items: center;
|
|
338
|
+
justify-content: center;
|
|
339
|
+
gap: 8px;
|
|
340
|
+
padding: 8px 12px;
|
|
341
|
+
border: 1px solid var(--color-secondary);
|
|
342
|
+
border-radius: var(--radius-md);
|
|
343
|
+
background: transparent;
|
|
344
|
+
color: var(--color-secondary);
|
|
345
|
+
font-family: var(--font-sans);
|
|
346
|
+
font-size: var(--font-13);
|
|
347
|
+
font-weight: var(--weight-semibold);
|
|
348
|
+
cursor: pointer;
|
|
349
|
+
transition: background 0.15s ease-out;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
.topics_star:hover:not(:disabled) {
|
|
353
|
+
background: rgba(var(--brand-rgb), 0.08);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
.topics_star:disabled {
|
|
357
|
+
opacity: 0.6;
|
|
358
|
+
cursor: progress;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
.topics_star--on {
|
|
362
|
+
border-color: var(--border-default);
|
|
363
|
+
color: var(--text-muted);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
.topics_star--on .ph {
|
|
367
|
+
color: var(--color-secondary);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
.topics_empty {
|
|
371
|
+
display: flex;
|
|
372
|
+
flex-direction: column;
|
|
373
|
+
gap: 10px;
|
|
374
|
+
padding: 16px;
|
|
375
|
+
border: 1px dashed var(--border-default);
|
|
376
|
+
border-radius: var(--radius-lg);
|
|
377
|
+
background: var(--bg-surface);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
.topics_empty_icon {
|
|
381
|
+
color: var(--color-secondary);
|
|
382
|
+
font-size: 22px;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.topics_empty_title {
|
|
386
|
+
color: var(--text-primary);
|
|
387
|
+
font-size: var(--font-13);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.topics_empty_list {
|
|
391
|
+
display: flex;
|
|
392
|
+
flex-direction: column;
|
|
393
|
+
gap: 6px;
|
|
394
|
+
margin: 0;
|
|
395
|
+
padding-left: 18px;
|
|
396
|
+
color: var(--text-muted);
|
|
397
|
+
font-size: var(--font-12);
|
|
398
|
+
line-height: 1.5;
|
|
399
|
+
}
|
|
400
|
+
|
|
267
401
|
.topics_list {
|
|
268
402
|
display: flex;
|
|
269
403
|
flex-direction: column;
|
|
@@ -65,5 +65,17 @@ export const useOipFavorites = () => {
|
|
|
65
65
|
return inflight;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
/** Vrai si le sujet est en favori en tant que sujet (pas par une entree de menu). */
|
|
69
|
+
const isStarred = (subjectId: string) => rows.value.some((row) => row.subject?.subject_id === subjectId);
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Bascule le favori d'un sujet (POST /api/oip/favorites), puis relit la
|
|
73
|
+
* liste : la ligne arrive resolue comme les autres.
|
|
74
|
+
*/
|
|
75
|
+
async function toggleSubject(subjectId: string) {
|
|
76
|
+
await $fetch<{ starred: boolean }>("/api/oip/favorites", { method: "POST", body: { subject: subjectId } });
|
|
77
|
+
await load(true);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return { rows, load, pending, loaded, unavailable, isStarred, toggleSubject };
|
|
69
81
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Le sujet Directus (OipSubject) de la page ouverte.
|
|
3
|
+
*
|
|
4
|
+
* Un sujet = une app + un chemin. GET /api/oip/subjects rend les sujets de
|
|
5
|
+
* cette app (reconnue a son prod_url cote serveur) ; ici on garde celui dont
|
|
6
|
+
* `relative_path` est le chemin courant, sinon son plus long prefixe (une
|
|
7
|
+
* fiche /drugs/123 releve du sujet /drugs). Charge une fois par page.
|
|
8
|
+
*/
|
|
9
|
+
export interface OipSubjectRow {
|
|
10
|
+
id: string;
|
|
11
|
+
path: string;
|
|
12
|
+
translations: { languages_code: string; name: string }[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let inflight: Promise<void> | null = null;
|
|
16
|
+
|
|
17
|
+
const trim = (path: string) => (path.length > 1 ? path.replace(/\/+$/, "") : path);
|
|
18
|
+
|
|
19
|
+
export const useOipPageSubject = () => {
|
|
20
|
+
const subjects = useState<OipSubjectRow[] | null>("oip-page-subjects", () => null);
|
|
21
|
+
const route = useRoute();
|
|
22
|
+
const { status } = useAuth();
|
|
23
|
+
|
|
24
|
+
async function load() {
|
|
25
|
+
if (import.meta.server || subjects.value || status.value !== "authenticated") return;
|
|
26
|
+
inflight ??= $fetch<OipSubjectRow[]>("/api/oip/subjects")
|
|
27
|
+
.then((rows) => {
|
|
28
|
+
subjects.value = rows;
|
|
29
|
+
})
|
|
30
|
+
.catch(() => {
|
|
31
|
+
// Pas de sujets lisibles : pas de bouton, rien de casse.
|
|
32
|
+
subjects.value = [];
|
|
33
|
+
})
|
|
34
|
+
.finally(() => {
|
|
35
|
+
inflight = null;
|
|
36
|
+
});
|
|
37
|
+
return inflight;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const subject = computed<OipSubjectRow | null>(() => {
|
|
41
|
+
const current = trim(route.path);
|
|
42
|
+
let best: OipSubjectRow | null = null;
|
|
43
|
+
for (const row of subjects.value ?? []) {
|
|
44
|
+
const path = trim(row.path.startsWith("/") ? row.path : `/${row.path}`);
|
|
45
|
+
const matches = path === "/" || current === path || current.startsWith(`${path}/`);
|
|
46
|
+
if (matches && (!best || path.length > trim(best.path).length)) best = { ...row, path };
|
|
47
|
+
}
|
|
48
|
+
return best;
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return { subject, load };
|
|
52
|
+
};
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { defineEventHandler } from "h3";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { requireOipUserId } from "../../utils/oipAuth";
|
|
4
|
+
import {
|
|
5
|
+
OIP_FAVORITES_COLLECTION,
|
|
6
|
+
OIP_FAVORITE_FIELDS,
|
|
7
|
+
oipFavoritesDirectus,
|
|
8
|
+
oipFavoritesUnavailable,
|
|
9
|
+
oipFreshFilter,
|
|
10
|
+
} from "../../utils/oipFavorites";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* POST /api/oip/favorites, servi par le layer OIP (bouton « Ajouter cette
|
|
14
|
+
* page en favoris » du panneau « Mes sujets »).
|
|
15
|
+
*
|
|
16
|
+
* Bascule le favori d'un sujet pour l'appelant, comme l'etoile d'OIP 7 :
|
|
17
|
+
* etoiler un sujet deja etoile le retire. Idempotent, un double clic ne laisse
|
|
18
|
+
* pas deux lignes (Directus ne sait pas poser l'unicite (user, sujet)).
|
|
19
|
+
*/
|
|
20
|
+
const schema = z.object({ subject: z.string().uuid() });
|
|
21
|
+
|
|
22
|
+
export default defineEventHandler(async (event) => {
|
|
23
|
+
const userId = await requireOipUserId(event);
|
|
24
|
+
const parsed = schema.safeParse(await readBody(event));
|
|
25
|
+
if (!parsed.success) throw createError({ status: 400, message: "Invalid body: { subject: uuid }" });
|
|
26
|
+
const { subject } = parsed.data;
|
|
27
|
+
|
|
28
|
+
const { url, headers, freshHeaders } = oipFavoritesDirectus();
|
|
29
|
+
const F = OIP_FAVORITE_FIELDS;
|
|
30
|
+
|
|
31
|
+
const findRows = () =>
|
|
32
|
+
$fetch<{ data: { id: string }[] }>(`${url}/items/${OIP_FAVORITES_COLLECTION}`, {
|
|
33
|
+
headers: freshHeaders,
|
|
34
|
+
query: {
|
|
35
|
+
limit: -1,
|
|
36
|
+
fields: "id",
|
|
37
|
+
filter: oipFreshFilter({ [F.user]: { _eq: userId } }, { [F.subject]: { _eq: subject } }),
|
|
38
|
+
},
|
|
39
|
+
}).then((response) => response.data ?? []);
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
const rows = await findRows();
|
|
43
|
+
if (rows.length) {
|
|
44
|
+
// Pluriel expres : un doublon deja en base part avec ce clic.
|
|
45
|
+
await Promise.all(
|
|
46
|
+
rows.map((row) =>
|
|
47
|
+
$fetch(`${url}/items/${OIP_FAVORITES_COLLECTION}/${row.id}`, { method: "DELETE", headers }).catch(
|
|
48
|
+
(error) => {
|
|
49
|
+
// Une ligne deja supprimee par un clic concurrent repond 403 aussi.
|
|
50
|
+
const status = error?.response?.status ?? error?.statusCode;
|
|
51
|
+
if (status !== 403 && status !== 404) throw error;
|
|
52
|
+
},
|
|
53
|
+
),
|
|
54
|
+
),
|
|
55
|
+
);
|
|
56
|
+
if ((await findRows()).length) {
|
|
57
|
+
throw createError({
|
|
58
|
+
status: 503,
|
|
59
|
+
message: `Directus refused to delete from "${OIP_FAVORITES_COLLECTION}": DIRECTUS_FAVORITES_TOKEN has no delete on it.`,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
return { starred: false };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
await $fetch(`${url}/items/${OIP_FAVORITES_COLLECTION}`, {
|
|
66
|
+
method: "POST",
|
|
67
|
+
headers,
|
|
68
|
+
// user_id vient de la session, jamais du corps.
|
|
69
|
+
body: { [F.user]: userId, [F.subject]: subject },
|
|
70
|
+
});
|
|
71
|
+
return { starred: true };
|
|
72
|
+
} catch (error: any) {
|
|
73
|
+
throw oipFavoritesUnavailable(error) ?? error;
|
|
74
|
+
}
|
|
75
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { defineEventHandler } from "h3";
|
|
2
|
+
import { requireOipUserId } from "../../utils/oipAuth";
|
|
3
|
+
import { oipAppUrls } from "../../utils/oipGuards";
|
|
4
|
+
import {
|
|
5
|
+
OIP_FAVORITES_COLLECTION,
|
|
6
|
+
OIP_FAVORITE_FIELDS,
|
|
7
|
+
oipFavoritesDirectus,
|
|
8
|
+
oipFavoritesUnavailable,
|
|
9
|
+
oipFreshFilter,
|
|
10
|
+
} from "../../utils/oipFavorites";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* GET /api/oip/news, servi par le layer OIP (modale « Nouveautés »).
|
|
14
|
+
*
|
|
15
|
+
* Les news publiees (OipNews, celles d'OIP 7) des 30 derniers jours qui
|
|
16
|
+
* touchent un sujet de CETTE app que le lecteur a en favori : le sujet
|
|
17
|
+
* lui-meme, ou une entree de menu qui le porte. Meme audience que le mail
|
|
18
|
+
* envoye a la publication (oip7 server/utils/news-notify.ts), restreinte a
|
|
19
|
+
* l'app ouverte. Ce qui a deja ete vu se decide cote navigateur.
|
|
20
|
+
*/
|
|
21
|
+
const WINDOW_DAYS = 30;
|
|
22
|
+
|
|
23
|
+
const norm = (value?: string | null) => (value || "").trim().replace(/\/+$/, "");
|
|
24
|
+
|
|
25
|
+
export default defineEventHandler(async (event) => {
|
|
26
|
+
const userId = await requireOipUserId(event);
|
|
27
|
+
const appUrls = new Set(oipAppUrls());
|
|
28
|
+
const { url, headers, freshHeaders } = oipFavoritesDirectus();
|
|
29
|
+
const F = OIP_FAVORITE_FIELDS;
|
|
30
|
+
|
|
31
|
+
try {
|
|
32
|
+
const favorites = await $fetch<{ data: any[] }>(`${url}/items/${OIP_FAVORITES_COLLECTION}`, {
|
|
33
|
+
headers: freshHeaders,
|
|
34
|
+
query: {
|
|
35
|
+
limit: -1,
|
|
36
|
+
filter: oipFreshFilter({ [F.user]: { _eq: userId } }),
|
|
37
|
+
fields: [
|
|
38
|
+
`${F.subject}.subject_id`,
|
|
39
|
+
`${F.subject}.app.prod_url`,
|
|
40
|
+
`${F.menuItem}.Subjects.OipSubject_subject_id.subject_id`,
|
|
41
|
+
`${F.menuItem}.Subjects.OipSubject_subject_id.app.prod_url`,
|
|
42
|
+
].join(","),
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Les sujets favoris (directs ou par une entree de menu) qui sont de cette app.
|
|
47
|
+
const subjectIds = new Set<string>();
|
|
48
|
+
const keep = (subject: any) => {
|
|
49
|
+
if (subject?.subject_id && appUrls.has(norm(subject.app?.prod_url))) subjectIds.add(subject.subject_id);
|
|
50
|
+
};
|
|
51
|
+
for (const row of favorites.data ?? []) {
|
|
52
|
+
keep(row[F.subject]);
|
|
53
|
+
for (const entry of row[F.menuItem]?.Subjects ?? []) keep(entry?.OipSubject_subject_id);
|
|
54
|
+
}
|
|
55
|
+
if (!subjectIds.size) return [];
|
|
56
|
+
|
|
57
|
+
const since = new Date(Date.now() - WINDOW_DAYS * 86400000).toISOString().slice(0, 10);
|
|
58
|
+
const news = await $fetch<{ data: any[] }>(`${url}/items/OipNews`, {
|
|
59
|
+
headers,
|
|
60
|
+
query: {
|
|
61
|
+
limit: 20,
|
|
62
|
+
sort: "-date",
|
|
63
|
+
filter: JSON.stringify({
|
|
64
|
+
_and: [
|
|
65
|
+
{ status: { _eq: "published" } },
|
|
66
|
+
{ date: { _gte: since } },
|
|
67
|
+
{ subjects: { OipSubject_subject_id: { _in: [...subjectIds] } } },
|
|
68
|
+
],
|
|
69
|
+
}),
|
|
70
|
+
fields: [
|
|
71
|
+
"id",
|
|
72
|
+
"type",
|
|
73
|
+
"title",
|
|
74
|
+
"description",
|
|
75
|
+
"date",
|
|
76
|
+
"custom_link",
|
|
77
|
+
"subjects.OipSubject_subject_id.subject_id",
|
|
78
|
+
"subjects.OipSubject_subject_id.relative_path",
|
|
79
|
+
"subjects.OipSubject_subject_id.translations.languages_code",
|
|
80
|
+
"subjects.OipSubject_subject_id.translations.subject_name",
|
|
81
|
+
].join(","),
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return (news.data ?? []).map((item) => ({
|
|
86
|
+
id: item.id as string,
|
|
87
|
+
type: item.type as string,
|
|
88
|
+
title: item.title as string,
|
|
89
|
+
description: (item.description as string) || "",
|
|
90
|
+
date: item.date as string,
|
|
91
|
+
link: (item.custom_link as string) || null,
|
|
92
|
+
// Seulement les sujets de cette app que le lecteur suit : ce sont eux
|
|
93
|
+
// qu'il peut ouvrir d'ici.
|
|
94
|
+
subjects: (item.subjects ?? [])
|
|
95
|
+
.map((entry: any) => entry?.OipSubject_subject_id)
|
|
96
|
+
.filter((subject: any) => subjectIds.has(subject?.subject_id))
|
|
97
|
+
.map((subject: any) => ({
|
|
98
|
+
id: subject.subject_id as string,
|
|
99
|
+
path: (subject.relative_path as string) || "/",
|
|
100
|
+
translations: subject.translations ?? [],
|
|
101
|
+
})),
|
|
102
|
+
}));
|
|
103
|
+
} catch (error: any) {
|
|
104
|
+
throw oipFavoritesUnavailable(error, "OipNews") ?? error;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defineEventHandler } from "h3";
|
|
2
|
+
import { requireOipSession } from "../../utils/oipAuth";
|
|
3
|
+
import { oipAppUrls } from "../../utils/oipGuards";
|
|
4
|
+
import { oipFavoritesDirectus, oipFavoritesUnavailable } from "../../utils/oipFavorites";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* GET /api/oip/subjects, servi par le layer OIP.
|
|
8
|
+
*
|
|
9
|
+
* Les sujets Directus (`OipSubject`) de cette app : un sujet est une app plus
|
|
10
|
+
* un chemin. L'app se reconnait a son `prod_url` (NUXT_OIP_APP_URL), pas a
|
|
11
|
+
* l'origine du navigateur, qui differe en staging et en local. Le client
|
|
12
|
+
* compare ensuite `relative_path` au chemin courant pour savoir quel sujet
|
|
13
|
+
* est la page ouverte.
|
|
14
|
+
*/
|
|
15
|
+
export default defineEventHandler(async (event) => {
|
|
16
|
+
await requireOipSession(event);
|
|
17
|
+
const appUrls = oipAppUrls();
|
|
18
|
+
const { url, headers } = oipFavoritesDirectus();
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
const response = await $fetch<{ data: any[] }>(`${url}/items/OipSubject`, {
|
|
22
|
+
headers,
|
|
23
|
+
query: {
|
|
24
|
+
limit: -1,
|
|
25
|
+
filter: JSON.stringify({ app: { prod_url: { _in: appUrls } } }),
|
|
26
|
+
fields: ["subject_id", "relative_path", "translations.languages_code", "translations.subject_name"].join(","),
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
return (response.data ?? []).map((row) => ({
|
|
30
|
+
id: row.subject_id as string,
|
|
31
|
+
path: (row.relative_path as string) || "/",
|
|
32
|
+
translations: (row.translations ?? []).map((t: any) => ({
|
|
33
|
+
languages_code: String(t?.languages_code || "").trim(),
|
|
34
|
+
name: t?.subject_name ?? "",
|
|
35
|
+
})),
|
|
36
|
+
}));
|
|
37
|
+
} catch (error: any) {
|
|
38
|
+
throw oipFavoritesUnavailable(error, "OipSubject") ?? error;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ce que les routes favoris et nouveautes du layer savent du cote Directus :
|
|
3
|
+
* un renommage dans le CMS se corrige ici et nulle part ailleurs.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/** Directus affiche « Oip Favorites » pour ce nom brut. Surchargeable par l'env. */
|
|
7
|
+
export const OIP_FAVORITES_COLLECTION = process.env.DIRECTUS_FAVORITES_COLLECTION || "Oip_Favorites";
|
|
8
|
+
|
|
9
|
+
export const OIP_FAVORITE_FIELDS = {
|
|
10
|
+
user: "user_id",
|
|
11
|
+
menuItem: "Menu_item",
|
|
12
|
+
subject: "Subject",
|
|
13
|
+
} as const;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* L'URL et le jeton Directus des favoris. Le jeton lit Oip_Favorites,
|
|
17
|
+
* OipSubject et OipNews, et cree/supprime dans Oip_Favorites (bouton
|
|
18
|
+
* « Ajouter cette page »).
|
|
19
|
+
*/
|
|
20
|
+
export function oipFavoritesDirectus() {
|
|
21
|
+
const config = useRuntimeConfig();
|
|
22
|
+
const url = (config.directusFavoritesUrl as string | undefined)?.replace(/\/+$/, "");
|
|
23
|
+
const token = config.directusFavoritesToken as string | undefined;
|
|
24
|
+
if (!url || !token) {
|
|
25
|
+
throw createError({
|
|
26
|
+
status: 503,
|
|
27
|
+
message:
|
|
28
|
+
"Favourites are not configured: set DIRECTUS_URL and DIRECTUS_FAVORITES_TOKEN. " +
|
|
29
|
+
"The token needs read access on Oip_Favorites, OipSubject and OipNews.",
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
const headers = { Authorization: `Bearer ${token}` };
|
|
33
|
+
return {
|
|
34
|
+
url,
|
|
35
|
+
/** Ecritures. */
|
|
36
|
+
headers,
|
|
37
|
+
/** Lectures qui doivent voir ce qui vient d'etre ecrit. */
|
|
38
|
+
freshHeaders: { ...headers, "Cache-Control": "no-store" },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Un filtre que le cache Directus (cinq minutes, cle = requete normalisee) ne
|
|
44
|
+
* peut pas servir : la clause porte l'instant courant. Elle n'exclut rien, la
|
|
45
|
+
* borne est un jour en avance.
|
|
46
|
+
*/
|
|
47
|
+
export function oipFreshFilter(...conditions: Record<string, any>[]) {
|
|
48
|
+
const horizon = new Date(Date.now() + 86400000).toISOString();
|
|
49
|
+
return JSON.stringify({ _and: [...conditions, { date_created: { _lte: horizon } }] });
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Directus repond 403 pour « pas le droit » comme pour « pas de collection ». */
|
|
53
|
+
export function oipFavoritesUnavailable(error: any, collection = OIP_FAVORITES_COLLECTION) {
|
|
54
|
+
const status = error?.response?.status ?? error?.statusCode;
|
|
55
|
+
if (status !== 403 && status !== 404) return null;
|
|
56
|
+
return createError({
|
|
57
|
+
status: 503,
|
|
58
|
+
message: `Directus collection "${collection}" is unreachable: check DIRECTUS_FAVORITES_TOKEN permissions on it.`,
|
|
59
|
+
});
|
|
60
|
+
}
|