@paris-ias/list 1.0.59 → 1.0.61
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
|
@@ -50,6 +50,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
50
50
|
};
|
|
51
51
|
const stores = {};
|
|
52
52
|
const queries = {};
|
|
53
|
+
const models = {};
|
|
53
54
|
console.log("INITIALIZING STORES");
|
|
54
55
|
await Promise.all(
|
|
55
56
|
appConfig.list.modules.map(async (type) => {
|
|
@@ -60,6 +61,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
60
61
|
list: (await imports.queries.list).default,
|
|
61
62
|
get: (await imports.queries.get).default
|
|
62
63
|
};
|
|
64
|
+
models[type] = model;
|
|
63
65
|
stores[type] = createDynamicStore(type, model)();
|
|
64
66
|
} catch (error) {
|
|
65
67
|
console.error(`Failed to initialize ${type} store:`, error);
|
|
@@ -67,6 +69,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
67
69
|
})
|
|
68
70
|
);
|
|
69
71
|
const rootStore = useRootStore();
|
|
72
|
+
nuxtApp.provide("models", models);
|
|
70
73
|
nuxtApp.provide("rootStore", rootStore);
|
|
71
74
|
nuxtApp.provide("stores", stores);
|
|
72
75
|
nuxtApp.provide("queries", queries);
|
|
@@ -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,9 +110,10 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
110
110
|
};
|
|
111
111
|
router.replace({ query: routeQuery });
|
|
112
112
|
},
|
|
113
|
-
resetState() {
|
|
114
|
-
const { $stores } = useNuxtApp();
|
|
115
|
-
$
|
|
113
|
+
resetState(type) {
|
|
114
|
+
const { $stores, $models } = useNuxtApp();
|
|
115
|
+
console.log("$models[type]: ", $models[type]);
|
|
116
|
+
$stores[type] = $models[type].default();
|
|
116
117
|
console.log("resetState");
|
|
117
118
|
this.search = "";
|
|
118
119
|
this.page = 1;
|
|
@@ -122,68 +123,68 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
122
123
|
this.skip = 0;
|
|
123
124
|
this.numberOfPages = 0;
|
|
124
125
|
},
|
|
125
|
-
updateSort({ value, type
|
|
126
|
+
updateSort({ value, type }) {
|
|
126
127
|
const { $stores } = useNuxtApp();
|
|
127
|
-
$stores[
|
|
128
|
-
$stores[
|
|
128
|
+
$stores[type].sortBy = [value[0]];
|
|
129
|
+
$stores[type].sortDesc = [value[1]];
|
|
129
130
|
this.page = 1;
|
|
130
|
-
this.updateLocalStorage(
|
|
131
|
-
this.update(
|
|
131
|
+
this.updateLocalStorage(type + "_sort", value.join("_"));
|
|
132
|
+
this.update(type);
|
|
132
133
|
},
|
|
133
|
-
updateView({ value, type
|
|
134
|
+
updateView({ value, type }) {
|
|
134
135
|
const { $stores } = useNuxtApp();
|
|
135
|
-
$stores[
|
|
136
|
-
...$stores[
|
|
136
|
+
$stores[type].view = {
|
|
137
|
+
...$stores[type].views[value],
|
|
137
138
|
name: value
|
|
138
139
|
};
|
|
139
|
-
this.updateLocalStorage(
|
|
140
|
-
this.update(
|
|
140
|
+
this.updateLocalStorage(type + "_view", value);
|
|
141
|
+
this.update(type);
|
|
141
142
|
},
|
|
142
143
|
updateLocalStorage(key, value) {
|
|
143
144
|
const local = JSON.parse(localStorage.getItem("PARIS_IAS")) || {};
|
|
144
145
|
local[key] = value;
|
|
145
146
|
localStorage.setItem("PARIS_IAS", JSON.stringify(local));
|
|
146
147
|
},
|
|
147
|
-
updateFilter(key, val,
|
|
148
|
+
updateFilter(key, val, type) {
|
|
148
149
|
const { $stores } = useNuxtApp();
|
|
149
|
-
console.log("update filter: ", { key, val, type
|
|
150
|
-
$stores[
|
|
151
|
-
this.setFiltersCount(
|
|
152
|
-
this.saveFiltersToLocalStorage(
|
|
153
|
-
this.updateRouteQuery(
|
|
150
|
+
console.log("update filter: ", { key, val, type });
|
|
151
|
+
$stores[type].filters[key].value = val;
|
|
152
|
+
this.setFiltersCount(type);
|
|
153
|
+
this.saveFiltersToLocalStorage(type);
|
|
154
|
+
this.updateRouteQuery(type);
|
|
154
155
|
this.page = 1;
|
|
155
|
-
this.update(
|
|
156
|
+
this.update(type);
|
|
156
157
|
},
|
|
157
|
-
updateItemsPerPage({ value, type
|
|
158
|
+
updateItemsPerPage({ value, type }) {
|
|
158
159
|
const { $stores } = useNuxtApp();
|
|
159
160
|
this.page = 1;
|
|
160
|
-
$stores[
|
|
161
|
-
this.update(
|
|
161
|
+
$stores[type].itemsPerPage = value;
|
|
162
|
+
this.update(type);
|
|
162
163
|
},
|
|
163
|
-
updatePage({ page, type
|
|
164
|
+
updatePage({ page, type }) {
|
|
164
165
|
this.page = page;
|
|
165
|
-
this.update(
|
|
166
|
+
this.update(type);
|
|
166
167
|
},
|
|
167
168
|
async updateSearch({
|
|
168
|
-
type
|
|
169
|
+
type = "all",
|
|
169
170
|
search = "",
|
|
170
171
|
lang = "en"
|
|
171
172
|
}) {
|
|
172
173
|
this.search = search;
|
|
173
174
|
this.setLoading(true);
|
|
174
|
-
await this.update(
|
|
175
|
+
await this.update(type, lang);
|
|
175
176
|
},
|
|
176
|
-
async update(
|
|
177
|
+
async update(type, lang = "en") {
|
|
177
178
|
const { $stores } = useNuxtApp();
|
|
178
179
|
this.setLoading(true);
|
|
179
|
-
if (
|
|
180
|
-
$stores[
|
|
180
|
+
if (type !== "all") {
|
|
181
|
+
$stores[type].loading = true;
|
|
181
182
|
}
|
|
182
|
-
const itemsPerPage =
|
|
183
|
+
const itemsPerPage = type === "all" ? 3 : $stores[type]?.itemsPerPage;
|
|
183
184
|
const filters = {};
|
|
184
|
-
if (
|
|
185
|
-
for (const filter in $stores[
|
|
186
|
-
const filterValue = $stores[
|
|
185
|
+
if (type !== "all") {
|
|
186
|
+
for (const filter in $stores[type].filters) {
|
|
187
|
+
const filterValue = $stores[type].filters[filter]?.value;
|
|
187
188
|
if (typeof filterValue !== "undefined" && filterValue?.length) {
|
|
188
189
|
filters[filter] = filterValue;
|
|
189
190
|
}
|
|
@@ -197,14 +198,14 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
197
198
|
// limit
|
|
198
199
|
limit: itemsPerPage,
|
|
199
200
|
// sort, array of keys and array of directions - to have x tie breakers if necessary
|
|
200
|
-
sortBy:
|
|
201
|
-
sortDesc:
|
|
201
|
+
sortBy: type === "all" ? "searchScore" : $stores[type].sortBy,
|
|
202
|
+
sortDesc: type === "all" ? -1 : $stores[type].sortDesc > 0 ? true : false,
|
|
202
203
|
// search (if set)
|
|
203
|
-
...this.search?.length &&
|
|
204
|
+
...this.search?.length && type !== "all" && { search: this.search },
|
|
204
205
|
// add the store module filters
|
|
205
206
|
filters
|
|
206
207
|
},
|
|
207
|
-
...this.search?.length &&
|
|
208
|
+
...this.search?.length && type === "all" && { search: this.search },
|
|
208
209
|
appId: "iea",
|
|
209
210
|
lang
|
|
210
211
|
})
|
|
@@ -212,15 +213,15 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
212
213
|
args.options.filters = JSON.stringify(args.options.filters);
|
|
213
214
|
let result = {};
|
|
214
215
|
console.log("args: ", args);
|
|
215
|
-
console.log(`Fetching ${
|
|
216
|
+
console.log(`Fetching ${type}`);
|
|
216
217
|
const { $queries } = useNuxtApp();
|
|
217
218
|
const { data, error } = await useAsyncQuery(
|
|
218
|
-
|
|
219
|
+
type === "all" ? SEARCH : $queries[type].list,
|
|
219
220
|
args
|
|
220
221
|
);
|
|
221
222
|
if (error.value) console.log(error.value);
|
|
222
|
-
const key =
|
|
223
|
-
if (
|
|
223
|
+
const key = type === "all" ? "search" : "list" + type.charAt(0).toUpperCase() + type.slice(1);
|
|
224
|
+
if (type === "all") {
|
|
224
225
|
this.results = data?.value?.[key];
|
|
225
226
|
} else {
|
|
226
227
|
const items = data?.value?.[key]?.items ?? [];
|
|
@@ -232,13 +233,13 @@ export const useRootStore = defineStore("rootStore", {
|
|
|
232
233
|
_path: `/${id}`
|
|
233
234
|
}))
|
|
234
235
|
};
|
|
235
|
-
$stores[
|
|
236
|
+
$stores[type].items = result["items"];
|
|
236
237
|
const lastPage = Math.ceil(result.total / itemsPerPage);
|
|
237
|
-
this.setFiltersCount(
|
|
238
|
-
this.setBlankFilterLoad(
|
|
239
|
-
$stores[
|
|
238
|
+
this.setFiltersCount(type);
|
|
239
|
+
this.setBlankFilterLoad(type);
|
|
240
|
+
$stores[type].numberOfPages = lastPage;
|
|
240
241
|
}
|
|
241
|
-
this.setLoading(false,
|
|
242
|
+
this.setLoading(false, type);
|
|
242
243
|
return true;
|
|
243
244
|
}
|
|
244
245
|
}
|