@paris-ias/list 1.0.58 → 1.0.60
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
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
icon
|
|
10
10
|
class="ml-auto"
|
|
11
11
|
v-bind="tooltip"
|
|
12
|
-
@click="rootStore.resetState()"
|
|
12
|
+
@click="rootStore.resetState(type)"
|
|
13
13
|
>
|
|
14
14
|
<v-icon>mdi-restore</v-icon>
|
|
15
15
|
</v-btn>
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
</template>
|
|
20
20
|
|
|
21
21
|
<script setup>
|
|
22
|
-
import { useNuxtApp } from "#imports";
|
|
22
|
+
import { useNuxtApp, onMounted } from "#imports";
|
|
23
23
|
import { useRootStore } from "../../../stores/root";
|
|
24
24
|
const { $stores } = useNuxtApp();
|
|
25
25
|
const rootStore = useRootStore();
|
|
@@ -8,7 +8,7 @@ export declare const useRootStore: import("pinia").StoreDefinition<"rootStore",
|
|
|
8
8
|
setBlankFilterLoad(type: string): void;
|
|
9
9
|
setDefaults(): void;
|
|
10
10
|
updateRouteQuery(type: string): void;
|
|
11
|
-
resetState(): void;
|
|
11
|
+
resetState(type: string): void;
|
|
12
12
|
updateSort({ value, type }: {
|
|
13
13
|
value: number[] | string[];
|
|
14
14
|
type: string;
|
|
@@ -20,31 +20,31 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
20
20
|
}
|
|
21
21
|
}),
|
|
22
22
|
actions: {
|
|
23
|
-
setLoading(value,
|
|
23
|
+
setLoading(value, type = "") {
|
|
24
24
|
const { $stores } = useNuxtApp();
|
|
25
25
|
this.loading = value;
|
|
26
|
-
if (
|
|
26
|
+
if (type.length) $stores[type].loading = value;
|
|
27
27
|
},
|
|
28
28
|
setScrolled() {
|
|
29
29
|
if (import.meta.browser) {
|
|
30
30
|
this.scrolled = window.scrollY > 0;
|
|
31
31
|
}
|
|
32
32
|
},
|
|
33
|
-
saveFiltersToLocalStorage(
|
|
33
|
+
saveFiltersToLocalStorage(type) {
|
|
34
34
|
const { $stores } = useNuxtApp();
|
|
35
|
-
const filters = $stores[
|
|
35
|
+
const filters = $stores[type].filters ?? {};
|
|
36
36
|
const values = Object.fromEntries(
|
|
37
37
|
Object.entries(filters).map(([key, filter]) => [key, filter.value])
|
|
38
38
|
);
|
|
39
39
|
const local = JSON.parse(localStorage.getItem("PARIS_IAS") || "{}");
|
|
40
|
-
local[`${
|
|
40
|
+
local[`${type}_filters`] = values;
|
|
41
41
|
localStorage.setItem("PARIS_IAS", JSON.stringify(local));
|
|
42
42
|
},
|
|
43
|
-
loadRouteQuery(
|
|
43
|
+
loadRouteQuery(type) {
|
|
44
44
|
const { $stores } = useNuxtApp();
|
|
45
45
|
const { currentRoute } = useRouter();
|
|
46
46
|
const query = currentRoute.value.query;
|
|
47
|
-
const filters = $stores[
|
|
47
|
+
const filters = $stores[type].filters;
|
|
48
48
|
if (Object.keys(query)?.length) {
|
|
49
49
|
Object.keys(query).forEach((filter) => {
|
|
50
50
|
if (filter in filters) {
|
|
@@ -53,48 +53,48 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
53
53
|
});
|
|
54
54
|
}
|
|
55
55
|
console.log("query loaded");
|
|
56
|
-
this.setFiltersCount(
|
|
56
|
+
this.setFiltersCount(type);
|
|
57
57
|
},
|
|
58
|
-
loadFiltersFromLocalStorage(
|
|
58
|
+
loadFiltersFromLocalStorage(type) {
|
|
59
59
|
const { $stores } = useNuxtApp();
|
|
60
60
|
const local = JSON.parse(localStorage.getItem("PARIS_IAS") || "{}");
|
|
61
|
-
const saved = local[`${
|
|
61
|
+
const saved = local[`${type}_filters`] ?? null;
|
|
62
62
|
if (!saved) {
|
|
63
|
-
console.log(`[${
|
|
63
|
+
console.log(`[${type}] Aucune donn\xE9e \xE0 restaurer.`);
|
|
64
64
|
return;
|
|
65
65
|
}
|
|
66
|
-
const filters = $stores[
|
|
66
|
+
const filters = $stores[type].filters ?? {};
|
|
67
67
|
for (const [key, value] of Object.entries(saved)) {
|
|
68
68
|
if (filters[key]) {
|
|
69
69
|
filters[key].value = value;
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
-
this.setFiltersCount(
|
|
73
|
-
this.updateRouteQuery(
|
|
74
|
-
console.log(`[${
|
|
72
|
+
this.setFiltersCount(type);
|
|
73
|
+
this.updateRouteQuery(type);
|
|
74
|
+
console.log(`[${type}] Filtres restaur\xE9s depuis localStorage`, saved);
|
|
75
75
|
},
|
|
76
|
-
setFiltersCount(
|
|
76
|
+
setFiltersCount(type) {
|
|
77
77
|
const { $stores } = useNuxtApp();
|
|
78
|
-
const filters = $stores[
|
|
78
|
+
const filters = $stores[type].filters ?? {};
|
|
79
79
|
const count = Object.values(filters).reduce((acc, filter) => {
|
|
80
80
|
const value = filter?.value;
|
|
81
81
|
const isEmpty = value === void 0 || value === null || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "";
|
|
82
82
|
return isEmpty ? acc : acc + 1;
|
|
83
83
|
}, 0);
|
|
84
|
-
$stores[
|
|
84
|
+
$stores[type].filtersCount = count;
|
|
85
85
|
},
|
|
86
|
-
setBlankFilterLoad(
|
|
86
|
+
setBlankFilterLoad(type) {
|
|
87
87
|
},
|
|
88
88
|
setDefaults() {
|
|
89
89
|
const lang = localStorage.getItem("lang");
|
|
90
90
|
},
|
|
91
|
-
updateRouteQuery(
|
|
91
|
+
updateRouteQuery(type) {
|
|
92
92
|
const router = useRouter();
|
|
93
93
|
const { $stores } = useNuxtApp();
|
|
94
94
|
const routeQuery = {
|
|
95
95
|
...this.search ? { search: this.search } : {},
|
|
96
96
|
...this.page > 1 ? { page: this.page.toString() } : {},
|
|
97
|
-
...Object.entries($stores[
|
|
97
|
+
...Object.entries($stores[type].filters).reduce(
|
|
98
98
|
(acc, [key, filter]) => {
|
|
99
99
|
const value = filter?.value;
|
|
100
100
|
console.log("valueStore", value);
|
|
@@ -110,7 +110,7 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
110
110
|
};
|
|
111
111
|
router.replace({ query: routeQuery });
|
|
112
112
|
},
|
|
113
|
-
resetState() {
|
|
113
|
+
resetState(type) {
|
|
114
114
|
const { $stores } = useNuxtApp();
|
|
115
115
|
$stores[type].$reset();
|
|
116
116
|
console.log("resetState");
|
|
@@ -122,68 +122,68 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
122
122
|
this.skip = 0;
|
|
123
123
|
this.numberOfPages = 0;
|
|
124
124
|
},
|
|
125
|
-
updateSort({ value, type
|
|
125
|
+
updateSort({ value, type }) {
|
|
126
126
|
const { $stores } = useNuxtApp();
|
|
127
|
-
$stores[
|
|
128
|
-
$stores[
|
|
127
|
+
$stores[type].sortBy = [value[0]];
|
|
128
|
+
$stores[type].sortDesc = [value[1]];
|
|
129
129
|
this.page = 1;
|
|
130
|
-
this.updateLocalStorage(
|
|
131
|
-
this.update(
|
|
130
|
+
this.updateLocalStorage(type + "_sort", value.join("_"));
|
|
131
|
+
this.update(type);
|
|
132
132
|
},
|
|
133
|
-
updateView({ value, type
|
|
133
|
+
updateView({ value, type }) {
|
|
134
134
|
const { $stores } = useNuxtApp();
|
|
135
|
-
$stores[
|
|
136
|
-
...$stores[
|
|
135
|
+
$stores[type].view = {
|
|
136
|
+
...$stores[type].views[value],
|
|
137
137
|
name: value
|
|
138
138
|
};
|
|
139
|
-
this.updateLocalStorage(
|
|
140
|
-
this.update(
|
|
139
|
+
this.updateLocalStorage(type + "_view", value);
|
|
140
|
+
this.update(type);
|
|
141
141
|
},
|
|
142
142
|
updateLocalStorage(key, value) {
|
|
143
143
|
const local = JSON.parse(localStorage.getItem("PARIS_IAS")) || {};
|
|
144
144
|
local[key] = value;
|
|
145
145
|
localStorage.setItem("PARIS_IAS", JSON.stringify(local));
|
|
146
146
|
},
|
|
147
|
-
updateFilter(key, val,
|
|
147
|
+
updateFilter(key, val, type) {
|
|
148
148
|
const { $stores } = useNuxtApp();
|
|
149
|
-
console.log("update filter: ", { key, val, type
|
|
150
|
-
$stores[
|
|
151
|
-
this.setFiltersCount(
|
|
152
|
-
this.saveFiltersToLocalStorage(
|
|
153
|
-
this.updateRouteQuery(
|
|
149
|
+
console.log("update filter: ", { key, val, type });
|
|
150
|
+
$stores[type].filters[key].value = val;
|
|
151
|
+
this.setFiltersCount(type);
|
|
152
|
+
this.saveFiltersToLocalStorage(type);
|
|
153
|
+
this.updateRouteQuery(type);
|
|
154
154
|
this.page = 1;
|
|
155
|
-
this.update(
|
|
155
|
+
this.update(type);
|
|
156
156
|
},
|
|
157
|
-
updateItemsPerPage({ value, type
|
|
157
|
+
updateItemsPerPage({ value, type }) {
|
|
158
158
|
const { $stores } = useNuxtApp();
|
|
159
159
|
this.page = 1;
|
|
160
|
-
$stores[
|
|
161
|
-
this.update(
|
|
160
|
+
$stores[type].itemsPerPage = value;
|
|
161
|
+
this.update(type);
|
|
162
162
|
},
|
|
163
|
-
updatePage({ page, type
|
|
163
|
+
updatePage({ page, type }) {
|
|
164
164
|
this.page = page;
|
|
165
|
-
this.update(
|
|
165
|
+
this.update(type);
|
|
166
166
|
},
|
|
167
167
|
async updateSearch({
|
|
168
|
-
type
|
|
168
|
+
type = "all",
|
|
169
169
|
search = "",
|
|
170
170
|
lang = "en"
|
|
171
171
|
}) {
|
|
172
172
|
this.search = search;
|
|
173
173
|
this.setLoading(true);
|
|
174
|
-
await this.update(
|
|
174
|
+
await this.update(type, lang);
|
|
175
175
|
},
|
|
176
|
-
async update(
|
|
176
|
+
async update(type, lang = "en") {
|
|
177
177
|
const { $stores } = useNuxtApp();
|
|
178
178
|
this.setLoading(true);
|
|
179
|
-
if (
|
|
180
|
-
$stores[
|
|
179
|
+
if (type !== "all") {
|
|
180
|
+
$stores[type].loading = true;
|
|
181
181
|
}
|
|
182
|
-
const itemsPerPage =
|
|
182
|
+
const itemsPerPage = type === "all" ? 3 : $stores[type]?.itemsPerPage;
|
|
183
183
|
const filters = {};
|
|
184
|
-
if (
|
|
185
|
-
for (const filter in $stores[
|
|
186
|
-
const filterValue = $stores[
|
|
184
|
+
if (type !== "all") {
|
|
185
|
+
for (const filter in $stores[type].filters) {
|
|
186
|
+
const filterValue = $stores[type].filters[filter]?.value;
|
|
187
187
|
if (typeof filterValue !== "undefined" && filterValue?.length) {
|
|
188
188
|
filters[filter] = filterValue;
|
|
189
189
|
}
|
|
@@ -197,14 +197,14 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
197
197
|
// limit
|
|
198
198
|
limit: itemsPerPage,
|
|
199
199
|
// sort, array of keys and array of directions - to have x tie breakers if necessary
|
|
200
|
-
sortBy:
|
|
201
|
-
sortDesc:
|
|
200
|
+
sortBy: type === "all" ? "searchScore" : $stores[type].sortBy,
|
|
201
|
+
sortDesc: type === "all" ? -1 : $stores[type].sortDesc > 0 ? true : false,
|
|
202
202
|
// search (if set)
|
|
203
|
-
...this.search?.length &&
|
|
203
|
+
...this.search?.length && type !== "all" && { search: this.search },
|
|
204
204
|
// add the store module filters
|
|
205
205
|
filters
|
|
206
206
|
},
|
|
207
|
-
...this.search?.length &&
|
|
207
|
+
...this.search?.length && type === "all" && { search: this.search },
|
|
208
208
|
appId: "iea",
|
|
209
209
|
lang
|
|
210
210
|
})
|
|
@@ -212,15 +212,15 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
212
212
|
args.options.filters = JSON.stringify(args.options.filters);
|
|
213
213
|
let result = {};
|
|
214
214
|
console.log("args: ", args);
|
|
215
|
-
console.log(`Fetching ${
|
|
215
|
+
console.log(`Fetching ${type}`);
|
|
216
216
|
const { $queries } = useNuxtApp();
|
|
217
217
|
const { data, error } = await useAsyncQuery(
|
|
218
|
-
|
|
218
|
+
type === "all" ? SEARCH : $queries[type].list,
|
|
219
219
|
args
|
|
220
220
|
);
|
|
221
221
|
if (error.value) console.log(error.value);
|
|
222
|
-
const key =
|
|
223
|
-
if (
|
|
222
|
+
const key = type === "all" ? "search" : "list" + type.charAt(0).toUpperCase() + type.slice(1);
|
|
223
|
+
if (type === "all") {
|
|
224
224
|
this.results = data?.value?.[key];
|
|
225
225
|
} else {
|
|
226
226
|
const items = data?.value?.[key]?.items ?? [];
|
|
@@ -232,13 +232,13 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
232
232
|
_path: `/${id}`
|
|
233
233
|
}))
|
|
234
234
|
};
|
|
235
|
-
$stores[
|
|
235
|
+
$stores[type].items = result["items"];
|
|
236
236
|
const lastPage = Math.ceil(result.total / itemsPerPage);
|
|
237
|
-
this.setFiltersCount(
|
|
238
|
-
this.setBlankFilterLoad(
|
|
239
|
-
$stores[
|
|
237
|
+
this.setFiltersCount(type);
|
|
238
|
+
this.setBlankFilterLoad(type);
|
|
239
|
+
$stores[type].numberOfPages = lastPage;
|
|
240
240
|
}
|
|
241
|
-
this.setLoading(false,
|
|
241
|
+
this.setLoading(false, type);
|
|
242
242
|
return true;
|
|
243
243
|
}
|
|
244
244
|
}
|