@open-commune/web 0.2.16 → 0.2.18
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,28 +1,47 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<ul class="space-y-
|
|
3
|
-
<li v-for="row in rows" :key="row.name" class="
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
<ul class="space-y-2.5 text-sm">
|
|
3
|
+
<li v-for="row in rows" :key="row.name" class="flex min-w-0 items-center gap-3">
|
|
4
|
+
<NuxtLink
|
|
5
|
+
v-if="row.link"
|
|
6
|
+
:to="row.link"
|
|
7
|
+
class="truncate text-default hover:text-highlighted hover:underline"
|
|
8
|
+
:class="bars ? 'w-36 shrink-0' : 'min-w-0 flex-1'"
|
|
9
|
+
>
|
|
10
10
|
{{ row.name }}
|
|
11
11
|
</NuxtLink>
|
|
12
|
-
<span
|
|
13
|
-
|
|
12
|
+
<span
|
|
13
|
+
v-else
|
|
14
|
+
class="truncate text-default"
|
|
15
|
+
:class="[bars ? 'w-36 shrink-0' : 'min-w-0 flex-1', mono && 'font-mono text-[13px]']"
|
|
16
|
+
>
|
|
17
|
+
{{ row.name }}
|
|
18
|
+
</span>
|
|
19
|
+
<span v-if="bars" class="flex min-w-0 flex-1 items-center gap-2">
|
|
20
|
+
<span
|
|
21
|
+
class="h-1.5 shrink-0 rounded-full"
|
|
22
|
+
:class="row.accent ? 'bg-secondary' : 'bg-(--ui-text-dimmed)'"
|
|
23
|
+
:style="{ width: `${Math.max(3, (row.value / max) * 75)}%` }"
|
|
24
|
+
aria-hidden="true"
|
|
25
|
+
/>
|
|
26
|
+
<span class="whitespace-nowrap tabular-nums text-dimmed">{{ row.label ?? row.value }}</span>
|
|
27
|
+
</span>
|
|
28
|
+
<span v-else class="shrink-0 whitespace-nowrap tabular-nums text-dimmed">{{ row.label ?? row.value }}</span>
|
|
14
29
|
</li>
|
|
15
30
|
</ul>
|
|
16
31
|
</template>
|
|
17
32
|
|
|
18
33
|
<script setup lang="ts">
|
|
19
34
|
/**
|
|
20
|
-
* A
|
|
21
|
-
*
|
|
22
|
-
*
|
|
35
|
+
* A list of the panels: one row per item, its name and its value. With
|
|
36
|
+
* `bars`, a thin bar between them as long as its share of the longest row,
|
|
37
|
+
* the value right after it, and a row marked `accent` drawn in the accent
|
|
38
|
+
* colour. Without, the value is set flush right. `mono` sets the names in a
|
|
39
|
+
* fixed-width face, for the campaigns' codes.
|
|
23
40
|
*/
|
|
24
41
|
const props = defineProps<{
|
|
25
|
-
rows: { name: string; value: number; label?: string; link?: string }[];
|
|
42
|
+
rows: { name: string; value: number; label?: string; link?: string; accent?: boolean }[];
|
|
43
|
+
bars?: boolean;
|
|
44
|
+
mono?: boolean;
|
|
26
45
|
}>();
|
|
27
46
|
|
|
28
47
|
const max = computed(() => Math.max(1, ...props.rows.map((row) => row.value)));
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<section
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
2
|
+
<section
|
|
3
|
+
v-if="visible && state !== 'hidden'"
|
|
4
|
+
class="rounded-lg bg-elevated p-6 shadow-card dark:shadow-none dark:ring dark:ring-[var(--ui-border)] plain:bg-default plain:ring plain:ring-default"
|
|
5
|
+
aria-label="Fréquentation"
|
|
6
|
+
>
|
|
7
|
+
<header class="flex flex-wrap items-center justify-between gap-2">
|
|
8
|
+
<span :class="LABEL">{{ heading }}</span>
|
|
9
|
+
<span class="flex gap-3" role="group" aria-label="Période">
|
|
8
10
|
<button
|
|
9
11
|
v-for="option in PERIODS"
|
|
10
12
|
:key="option"
|
|
11
13
|
type="button"
|
|
12
|
-
class="border-b-2
|
|
13
|
-
:class="option === period ? 'border-primary font-semibold text-highlighted' : 'border-transparent text-
|
|
14
|
+
class="border-b-2 py-0.5 text-sm"
|
|
15
|
+
:class="option === period ? 'border-primary font-semibold text-highlighted' : 'border-transparent text-muted hover:text-highlighted'"
|
|
14
16
|
:aria-pressed="option === period"
|
|
15
17
|
@click="period = option"
|
|
16
18
|
>
|
|
@@ -19,31 +21,30 @@
|
|
|
19
21
|
</span>
|
|
20
22
|
</header>
|
|
21
23
|
|
|
22
|
-
<div v-if="state === 'loading' && !audience" class="space-y-3">
|
|
24
|
+
<div v-if="state === 'loading' && !audience" class="mt-5 space-y-3">
|
|
23
25
|
<USkeleton class="h-10 w-2/3" />
|
|
24
26
|
<USkeleton class="h-24 w-full" />
|
|
25
27
|
</div>
|
|
26
28
|
|
|
27
29
|
<template v-else-if="audience">
|
|
28
|
-
<div class="flex flex-wrap items-baseline gap-x-
|
|
30
|
+
<div class="mt-5 flex flex-wrap items-baseline gap-x-9 gap-y-2">
|
|
29
31
|
<div>
|
|
30
|
-
<span class="font-serif text-
|
|
31
|
-
<span class="ml-1 text-
|
|
32
|
-
<span v-if="trend" class="ml-2 text-xs font-medium" :class="trend.up ? 'text-success' : 'text-error'">{{ trend.label }}</span>
|
|
32
|
+
<span class="font-serif text-[2.125rem] leading-none font-semibold text-highlighted">{{ count(audience.visits) }}</span>
|
|
33
|
+
<span class="ml-1.5 text-sm text-dimmed">{{ collection ? 'pages vues' : 'visites' }}</span>
|
|
33
34
|
</div>
|
|
34
35
|
<div v-if="audience.visitors != null">
|
|
35
|
-
<span class="font-serif text-
|
|
36
|
-
<span class="ml-1 text-
|
|
36
|
+
<span class="font-serif text-xl text-highlighted">{{ count(audience.visitors) }}</span>
|
|
37
|
+
<span class="ml-1.5 text-sm text-dimmed">visiteurs</span>
|
|
37
38
|
</div>
|
|
38
39
|
<div v-if="audience.viewsPerVisit != null">
|
|
39
|
-
<span class="font-serif text-
|
|
40
|
-
<span class="ml-1 text-
|
|
40
|
+
<span class="font-serif text-xl text-highlighted">{{ decimal(audience.viewsPerVisit) }}</span>
|
|
41
|
+
<span class="ml-1.5 text-sm text-dimmed">pages / visite</span>
|
|
41
42
|
</div>
|
|
42
43
|
<div v-if="audience.readingMs != null">
|
|
43
|
-
<span class="font-serif text-
|
|
44
|
-
<span class="ml-1 text-
|
|
44
|
+
<span class="font-serif text-xl text-highlighted">{{ duration(audience.readingMs) }}</span>
|
|
45
|
+
<span class="ml-1.5 text-sm text-dimmed">durée moyenne</span>
|
|
45
46
|
</div>
|
|
46
|
-
<div v-if="audience.rightNow != null" class="ml-auto text-
|
|
47
|
+
<div v-if="audience.rightNow != null" class="ml-auto text-sm whitespace-nowrap text-muted">
|
|
47
48
|
<span class="mr-1.5 inline-block size-1.5 rounded-full bg-success align-middle" aria-hidden="true" />
|
|
48
49
|
<b class="text-highlighted">{{ audience.rightNow }}</b>
|
|
49
50
|
{{ audience.rightNow > 1 ? 'visiteurs' : 'visiteur' }} en ce moment
|
|
@@ -60,50 +61,55 @@
|
|
|
60
61
|
:categories="series"
|
|
61
62
|
:height="140"
|
|
62
63
|
x-axis="day"
|
|
63
|
-
:x-formatter="dayTick"
|
|
64
|
-
:x-num-ticks="4"
|
|
65
|
-
:y-num-ticks="3"
|
|
66
|
-
:y-axes="{ 0: { formatter: (value: number) => count(value) } }"
|
|
67
64
|
:tooltip-title-formatter="(row: { day: string }) => day(row.day)"
|
|
68
|
-
curve-type="
|
|
69
|
-
:padding="{ top: 4, right:
|
|
65
|
+
curve-type="basis"
|
|
66
|
+
:padding="{ top: 4, right: 0, bottom: 0, left: 0 }"
|
|
70
67
|
:gradient-stops="[
|
|
71
|
-
{ offset: '0%', stopOpacity: 0.
|
|
68
|
+
{ offset: '0%', stopOpacity: 0.08 },
|
|
72
69
|
{ offset: '100%', stopOpacity: 0 },
|
|
73
70
|
]"
|
|
71
|
+
hide-x-axis
|
|
72
|
+
hide-y-axis
|
|
74
73
|
hide-legend
|
|
75
74
|
/>
|
|
76
75
|
</div>
|
|
77
76
|
|
|
78
|
-
<div v-if="open" class="mt-5 grid gap-
|
|
77
|
+
<div v-if="open" class="mt-5 grid gap-x-8 gap-y-8 border-t border-default pt-6 sm:grid-cols-3">
|
|
79
78
|
<div v-if="audience.sources?.length">
|
|
80
|
-
<h3 class="
|
|
81
|
-
<audience-bar-list :rows="
|
|
79
|
+
<h3 :class="[LABEL, 'mb-3']">Sources</h3>
|
|
80
|
+
<audience-bar-list :rows="sources" bars />
|
|
82
81
|
</div>
|
|
83
|
-
<div v-if="audience.depth">
|
|
84
|
-
<h3 class="
|
|
85
|
-
<audience-bar-list :rows="shares(depth)" />
|
|
82
|
+
<div v-if="entry && audience.depth">
|
|
83
|
+
<h3 :class="[LABEL, 'mb-3']">Lecture</h3>
|
|
84
|
+
<audience-bar-list :rows="shares(depth)" bars />
|
|
86
85
|
</div>
|
|
87
|
-
<div v-
|
|
88
|
-
<h3 class="
|
|
86
|
+
<div v-if="!entry && audience.top.length">
|
|
87
|
+
<h3 :class="[LABEL, 'mb-3']">Pages les plus vues</h3>
|
|
89
88
|
<audience-bar-list :rows="topPages" />
|
|
90
89
|
</div>
|
|
91
90
|
<div v-if="audience.devices?.length">
|
|
92
|
-
<h3 class="
|
|
93
|
-
<audience-bar-list :rows="shares(devices)" />
|
|
91
|
+
<h3 :class="[LABEL, 'mb-3']">Appareils</h3>
|
|
92
|
+
<audience-bar-list :rows="shares(devices)" bars />
|
|
93
|
+
</div>
|
|
94
|
+
<div v-if="audience.places?.length">
|
|
95
|
+
<h3 :class="[LABEL, 'mb-3']">Provenance géographique</h3>
|
|
96
|
+
<audience-bar-list :rows="shares(audience.places)" />
|
|
94
97
|
</div>
|
|
95
98
|
<div v-if="audience.campaigns?.length">
|
|
96
|
-
<h3 class="
|
|
97
|
-
<audience-bar-list :rows="campaigns" />
|
|
99
|
+
<h3 :class="[LABEL, 'mb-3']">Campagnes (UTM)</h3>
|
|
100
|
+
<audience-bar-list :rows="campaigns" mono />
|
|
98
101
|
</div>
|
|
99
|
-
<p class="flex gap-
|
|
102
|
+
<p class="flex gap-3 rounded-lg border border-default bg-default p-4 text-sm leading-relaxed text-muted sm:col-span-3">
|
|
100
103
|
<svg class="mt-0.5 size-4 shrink-0 text-success" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 22s8-4 8-10V5l-8-3-8 3v7c0 6 8 10 8 10z" /><path d="m9 12 2 2 4-4" /></svg>
|
|
101
|
-
<span
|
|
104
|
+
<span>
|
|
105
|
+
<b class="font-semibold text-highlighted">Conforme RGPD</b> — mesure anonyme et agrégée, sans cookie ni bandeau de consentement.
|
|
106
|
+
<template v-if="audience.places?.length">La provenance géographique est une estimation, agrégée par commune.</template>
|
|
107
|
+
</span>
|
|
102
108
|
</p>
|
|
103
109
|
</div>
|
|
104
110
|
|
|
105
|
-
<div class="mt-
|
|
106
|
-
<button type="button" class="text-
|
|
111
|
+
<div class="mt-4 text-center">
|
|
112
|
+
<button type="button" class="text-sm text-muted hover:text-highlighted" :aria-expanded="open" @click="open = !open">
|
|
107
113
|
{{ open ? 'Replier ⌃' : 'Plus de détails ⌄' }}
|
|
108
114
|
</button>
|
|
109
115
|
</div>
|
|
@@ -115,9 +121,12 @@
|
|
|
115
121
|
/**
|
|
116
122
|
* An audience panel: the site's, a collection's or an entry's, read from the
|
|
117
123
|
* instance's `audience.summary`, which asks the configured audience source.
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
124
|
+
* The session says first whether this user may see it (`useAudience().visible`):
|
|
125
|
+
* if not, nothing renders and nothing is asked. A refusal still means no
|
|
126
|
+
* source is configured, this user is not among its viewers, or the source did
|
|
127
|
+
* not answer: the panel then renders nothing at all. Every block the source
|
|
128
|
+
* leaves out is left out here too. The most read pages are the site's and a
|
|
129
|
+
* collection's; the reading depth, an entry's.
|
|
121
130
|
*/
|
|
122
131
|
import { AUDIENCE_PERIODS } from '@open-commune/core/dtos';
|
|
123
132
|
import AudienceBarList from './audience-bar-list.vue';
|
|
@@ -147,7 +156,8 @@ const DEVICES: Record<string, string> = {
|
|
|
147
156
|
|
|
148
157
|
const period = ref<(typeof PERIODS)[number]>(30);
|
|
149
158
|
const open = ref(false);
|
|
150
|
-
const {
|
|
159
|
+
const { visible, summary } = useAudience();
|
|
160
|
+
const { data, isPending, isError } = summary(
|
|
151
161
|
computed(() => ({
|
|
152
162
|
period: period.value,
|
|
153
163
|
collection: props.collection?.slug,
|
|
@@ -159,12 +169,15 @@ const state = computed(() =>
|
|
|
159
169
|
isError.value ? 'hidden' : isPending.value && !data.value ? 'loading' : 'ready',
|
|
160
170
|
);
|
|
161
171
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
172
|
+
/** A section's title, and the panel's own. */
|
|
173
|
+
const LABEL = 'text-xs font-semibold tracking-[.14em] text-muted uppercase';
|
|
174
|
+
|
|
175
|
+
/** The social networks, whose share the sources draw in the accent colour. */
|
|
176
|
+
const SOCIAL = /(^|\.)(facebook|instagram|linkedin|twitter|x|t|youtube|tiktok|whatsapp|bsky|threads|mastodon)\.[a-z]+$|^réseaux sociaux$/i;
|
|
177
|
+
|
|
178
|
+
const sources = computed(() =>
|
|
179
|
+
shares(audience.value?.sources ?? []).map((row) => ({ ...row, accent: SOCIAL.test(row.name) })),
|
|
180
|
+
);
|
|
168
181
|
|
|
169
182
|
/** How far the readers of an entry went down the page. */
|
|
170
183
|
const depth = computed(() => {
|
|
@@ -221,10 +234,5 @@ const duration = (ms: number) => {
|
|
|
221
234
|
};
|
|
222
235
|
const day = (iso: string) =>
|
|
223
236
|
new Date(`${iso}T12:00:00Z`).toLocaleDateString('fr-FR', { day: 'numeric', month: 'short' });
|
|
224
|
-
/** An x tick of the curve: an index into the days, or the day itself. */
|
|
225
|
-
const dayTick = (tick: number | Date) => {
|
|
226
|
-
const iso = typeof tick === 'number' ? audience.value?.daily[tick]?.day : String(tick);
|
|
227
|
-
return iso ? day(iso) : '';
|
|
228
|
-
};
|
|
229
237
|
|
|
230
238
|
</script>
|
|
@@ -6,12 +6,22 @@ import { computed, toValue, type MaybeRefOrGetter } from 'vue'
|
|
|
6
6
|
* The audience panels' data surface. The instance asks its configured source
|
|
7
7
|
* and keeps the answer a minute itself, so the cache here only spares a
|
|
8
8
|
* screen that comes back. A refusal is final: the panel hides, no retry.
|
|
9
|
+
*
|
|
10
|
+
* `visible` is the session's own answer, decided by the server at auth.me:
|
|
11
|
+
* a source is configured and this user is among its viewers. It is read from
|
|
12
|
+
* the session and not from the `read:audience` ability, which an admin's
|
|
13
|
+
* `manage:all` grants whatever the server said. Nothing is asked while it is
|
|
14
|
+
* false, so a refused user never sees a panel, not even while it loads.
|
|
9
15
|
*/
|
|
10
16
|
export default function useAudience() {
|
|
11
17
|
const trpc = useTrpc()
|
|
18
|
+
const session = useSession()
|
|
19
|
+
|
|
20
|
+
const visible = computed(() => session.user.value?.audience === true)
|
|
12
21
|
|
|
13
22
|
const summary = (ask: MaybeRefOrGetter<AudienceAsk>) =>
|
|
14
23
|
useQuery({
|
|
24
|
+
enabled: visible,
|
|
15
25
|
queryKey: computed(() => {
|
|
16
26
|
const { period, collection, entry } = toValue(ask)
|
|
17
27
|
return ['audience', period, collection ?? null, entry ?? null]
|
|
@@ -22,5 +32,5 @@ export default function useAudience() {
|
|
|
22
32
|
retry: false,
|
|
23
33
|
})
|
|
24
34
|
|
|
25
|
-
return { summary }
|
|
35
|
+
return { visible, summary }
|
|
26
36
|
}
|
package/package.json
CHANGED
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
"@iconify/vue": "^5.0.3",
|
|
20
20
|
"@nuxt/kit": "^4.6.1",
|
|
21
21
|
"@nuxt/ui": "^4.12.0",
|
|
22
|
-
"@open-commune/core": "^0.2.
|
|
23
|
-
"@open-commune/editor": "^0.2.
|
|
22
|
+
"@open-commune/core": "^0.2.18",
|
|
23
|
+
"@open-commune/editor": "^0.2.18",
|
|
24
24
|
"@pinia-orm/nuxt": "^2.0.0",
|
|
25
25
|
"@pinia/nuxt": "^1.0.3",
|
|
26
26
|
"@tanstack/vue-query": "^5.104.3",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
},
|
|
44
44
|
"description": "The Open Commune application: the admin interface and the server, on a single origin.",
|
|
45
45
|
"license": "AGPL-3.0-or-later",
|
|
46
|
-
"version": "0.2.
|
|
46
|
+
"version": "0.2.18",
|
|
47
47
|
"type": "module",
|
|
48
48
|
"main": "./nuxt.config.ts",
|
|
49
49
|
"files": [
|
|
@@ -26,7 +26,9 @@ export const useWorkspaceStore = defineStore('layout/workspace', () => {
|
|
|
26
26
|
const user = $session.user.value
|
|
27
27
|
$abilities.assignAbilities([
|
|
28
28
|
'entrance:self',
|
|
29
|
-
...(ROLES.find(({ id }) => id === user?.role)?.permissions ?? [])
|
|
29
|
+
...(ROLES.find(({ id }) => id === user?.role)?.permissions ?? []),
|
|
30
|
+
// Decided by the server, not by the role (auth.me's `audience`).
|
|
31
|
+
...(user?.audience === true ? ['read:audience'] : [])
|
|
30
32
|
])
|
|
31
33
|
}
|
|
32
34
|
|