@paris-ias/list 1.0.137 → 1.0.138

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.
Files changed (46) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/actions/DenseItem.vue +64 -0
  3. package/dist/runtime/components/actions/ExpandedItem.vue +17 -14
  4. package/dist/runtime/components/actions/RowsItem.vue +56 -10
  5. package/dist/runtime/components/actions/View.vue +5 -17
  6. package/dist/runtime/components/affiliation/DenseItem.vue +26 -10
  7. package/dist/runtime/components/affiliation/RowsItem.vue +26 -10
  8. package/dist/runtime/components/apps/DenseItem.vue +26 -10
  9. package/dist/runtime/components/apps/RowsItem.vue +26 -10
  10. package/dist/runtime/components/disciplines/DenseItem.vue +26 -10
  11. package/dist/runtime/components/disciplines/RowsItem.vue +26 -10
  12. package/dist/runtime/components/events/DenseItem.vue +12 -3
  13. package/dist/runtime/components/events/RowsItem.vue +12 -5
  14. package/dist/runtime/components/fellowships/DenseItem.vue +14 -0
  15. package/dist/runtime/components/fellowships/RowsItem.vue +16 -2
  16. package/dist/runtime/components/fellowships/View.vue +2 -2
  17. package/dist/runtime/components/files/DenseItem.vue +25 -10
  18. package/dist/runtime/components/files/RowsItem.vue +26 -10
  19. package/dist/runtime/components/list/atoms/FiltersMenu.vue +9 -0
  20. package/dist/runtime/components/list/atoms/PerPage.vue +3 -2
  21. package/dist/runtime/components/list/atoms/ResetButton.vue +5 -1
  22. package/dist/runtime/components/list/atoms/SearchInput.vue +15 -2
  23. package/dist/runtime/components/list/atoms/SearchString.vue +169 -133
  24. package/dist/runtime/components/list/atoms/SortMenu.vue +22 -18
  25. package/dist/runtime/components/list/atoms/ViewMenu.vue +26 -14
  26. package/dist/runtime/components/list/molecules/Filters.vue +4 -4
  27. package/dist/runtime/components/list/molecules/Header.vue +10 -19
  28. package/dist/runtime/components/list/molecules/Pagination.vue +51 -48
  29. package/dist/runtime/components/list/organisms/List.vue +93 -73
  30. package/dist/runtime/components/mailing/RowsItem.vue +26 -10
  31. package/dist/runtime/components/news/DenseItem.vue +59 -45
  32. package/dist/runtime/components/news/RowsItem.vue +11 -7
  33. package/dist/runtime/components/people/DenseItem.vue +10 -8
  34. package/dist/runtime/components/people/RowsItem.vue +11 -2
  35. package/dist/runtime/components/projects/DenseItem.vue +11 -4
  36. package/dist/runtime/components/projects/RowsItem.vue +10 -3
  37. package/dist/runtime/components/publications/DenseItem.vue +12 -8
  38. package/dist/runtime/components/publications/RowsItem.vue +12 -4
  39. package/dist/runtime/components/tags/RowsItem.vue +23 -10
  40. package/dist/runtime/components/users/DenseItem.vue +24 -10
  41. package/dist/runtime/components/users/RowsItem.vue +24 -10
  42. package/dist/runtime/composables/useUtils.js +1 -1
  43. package/dist/runtime/plugins/pinia.js +5 -2
  44. package/dist/runtime/stores/root.d.ts +10 -9
  45. package/dist/runtime/stores/root.js +82 -117
  46. package/package.json +1 -1
@@ -28,33 +28,34 @@ export declare const useRootStore: import("pinia").StoreDefinition<"rootStore",
28
28
  loadRouteQuery(type: string): void;
29
29
  setFiltersCount(type: string): void;
30
30
  updateRouteQuery(type: string): void;
31
- resetState(type: string, lang?: string): Promise<void>;
32
- updateSort({ value, type, lang, }: {
31
+ resetState(type: string, lang?: string): void;
32
+ updateSort({ value, type, }: {
33
33
  value: (number | string)[];
34
34
  type: string;
35
35
  lang?: string;
36
- }): Promise<void>;
36
+ }): void;
37
37
  updateView({ value, type, lang, }: {
38
38
  value: string;
39
39
  type: string;
40
40
  lang?: string;
41
- }): Promise<void>;
42
- updateFilter(key: string, val: unknown, type: string, lang: string): Promise<void>;
41
+ }): void;
42
+ updateFilter(key: string, val: unknown, type: string, lang: string): void;
43
43
  updateItemsPerPage({ value, type, lang, }: {
44
44
  value: number;
45
45
  type: string;
46
46
  lang?: string;
47
- }): Promise<void>;
47
+ }): void;
48
48
  updatePage({ page, type, lang, }: {
49
49
  page: number;
50
50
  type: string;
51
51
  lang?: string;
52
- }): Promise<void>;
52
+ }): void;
53
53
  updateSearch({ type, search, lang, }: {
54
54
  type: string;
55
55
  search: string;
56
56
  lang: string;
57
- }): Promise<void>;
58
- update(type: string, lang?: string): Promise<boolean>;
57
+ }): void;
58
+ buildListVariables(type: string, lang?: string): any;
59
+ applyListResult(type: string, data: Record<string, any>, itemsPerPageOverride?: number): void;
59
60
  }>;
60
61
  export {};
@@ -1,10 +1,9 @@
1
1
  import { defineStore } from "pinia";
2
- import SEARCH from "../graphql/list/search.gql";
3
2
  import { useNuxtApp, useRouter } from "#imports";
4
3
  export const useRootStore = defineStore("rootStore", {
5
4
  state: () => ({
6
5
  scrolled: typeof window !== "undefined" ? window.scrollY > 0 : false,
7
- loading: false,
6
+ loading: true,
8
7
  total: 0,
9
8
  skip: 0,
10
9
  page: 1,
@@ -27,11 +26,12 @@ export const useRootStore = defineStore("rootStore", {
27
26
  }),
28
27
  actions: {
29
28
  setLoading(value, type = "") {
30
- console.log("setLoading", { value, type });
29
+ console.log("X - setLoading", { value, type });
31
30
  const { $stores } = useNuxtApp();
32
- this.loading = value;
33
- if (type.length && type !== "all" && $stores[type]) {
31
+ if (type.length && $stores[type]) {
34
32
  $stores[type].loading = value;
33
+ } else {
34
+ this.loading = value;
35
35
  }
36
36
  },
37
37
  setScrolled() {
@@ -40,28 +40,27 @@ export const useRootStore = defineStore("rootStore", {
40
40
  }
41
41
  },
42
42
  loadRouteQuery(type) {
43
- console.log("loadRouteQuery", type);
44
- const { $stores } = useNuxtApp();
43
+ console.log("0 - loadRouteQuery", type);
45
44
  const { currentRoute } = useRouter();
45
+ const { $stores } = useNuxtApp();
46
46
  const query = currentRoute.value.query;
47
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) {
51
- console.log("filter: ", filter, query[filter]);
52
51
  const queryValue = query[filter];
53
52
  if (typeof queryValue === "string") {
54
53
  filters[filter].value = filters[filter].multiple ? JSON.parse(queryValue) : queryValue;
55
54
  }
56
55
  } else {
57
- console.log("unknown filter: ", filter);
58
56
  }
59
57
  });
60
58
  }
61
- console.log("query loaded");
59
+ if (query.page && query.page > 1)
60
+ $stores[type].page = parseInt(query.page, 10) || 1;
62
61
  },
63
62
  setFiltersCount(type) {
64
- console.log("setFiltersCount", type);
63
+ console.log("6- setFiltersCount", type);
65
64
  const { $stores } = useNuxtApp();
66
65
  const filters = $stores[type]?.filters ?? {};
67
66
  const count = Object.values(filters).reduce((acc, filter) => {
@@ -69,12 +68,10 @@ export const useRootStore = defineStore("rootStore", {
69
68
  const isEmpty = value === void 0 || value === null || Array.isArray(value) && value.length === 0 || typeof value === "string" && value.trim() === "";
70
69
  return isEmpty ? acc : acc + 1;
71
70
  }, 0);
72
- if ($stores[type]) {
73
- $stores[type].filtersCount = count;
74
- }
71
+ $stores[type].filtersCount = count;
75
72
  },
76
73
  updateRouteQuery(type) {
77
- console.log("updateRouteQuery", type);
74
+ console.log("5- updateRouteQuery", type);
78
75
  const router = useRouter();
79
76
  const { $stores } = useNuxtApp();
80
77
  const routeQuery = {
@@ -95,44 +92,19 @@ export const useRootStore = defineStore("rootStore", {
95
92
  };
96
93
  router.replace({ query: routeQuery });
97
94
  },
98
- async resetState(type, lang = "en") {
95
+ resetState(type, lang = "en") {
96
+ console.log("Y - resetState", { type, lang });
99
97
  const { $stores, $models } = useNuxtApp();
100
- const moduleState = $stores[type];
101
- const model = $models[type];
102
- if (moduleState && model) {
103
- const clone = (o) => typeof structuredClone === "function" ? structuredClone(o) : JSON.parse(JSON.stringify(o));
104
- moduleState.search = "";
105
- moduleState.filters = clone(model.filters ?? {});
106
- moduleState.view = model.views ? {
107
- ...clone(model.views[Object.keys(model.views)[0]]),
108
- name: Object.keys(model.views)[0]
109
- } : void 0;
110
- moduleState.sortBy = clone(model.sortBy ?? ["date"]);
111
- moduleState.sortDesc = clone(model.sortDesc ?? [0]);
112
- moduleState.itemsPerPage = model.itemsPerPage ?? 10;
113
- moduleState.items = [];
114
- moduleState.total = 0;
115
- moduleState.numberOfPages = 0;
116
- moduleState.loading = false;
117
- }
118
- this.$patch({
119
- search: "",
120
- page: 1,
121
- scrolled: false,
122
- loading: false,
123
- total: 0,
124
- skip: 0,
125
- numberOfPages: 0
126
- });
127
- this.updateRouteQuery(type);
128
- await this.update(type, lang);
98
+ const model = structuredClone($models[type]);
99
+ $stores[type].filters = model?.filters;
100
+ $stores[type].search = "";
101
+ $stores[type].page = 1;
129
102
  },
130
- async updateSort({
103
+ updateSort({
131
104
  value,
132
- type,
133
- lang = "en"
105
+ type
134
106
  }) {
135
- console.log("updateSort", {
107
+ console.log("Z - updateSort", {
136
108
  value,
137
109
  type
138
110
  });
@@ -142,97 +114,100 @@ export const useRootStore = defineStore("rootStore", {
142
114
  $stores[type].sortDesc = [Number(value[1])];
143
115
  }
144
116
  this.page = 1;
145
- await this.update(type, lang);
117
+ $stores[type].loading = true;
118
+ this.updateRouteQuery(type);
146
119
  },
147
- async updateView({
120
+ updateView({
148
121
  value,
149
122
  type,
150
123
  lang
151
124
  }) {
152
- console.log("updateView", { value, type });
125
+ console.log("W - updateView", { value, type });
153
126
  const { $stores } = useNuxtApp();
154
127
  if ($stores[type]?.views?.[value]) {
155
128
  $stores[type].view = {
156
129
  ...$stores[type].views[value],
157
130
  name: value
158
131
  };
132
+ $stores[type].loading = true;
159
133
  }
160
- await this.update(type, lang);
134
+ this.updateRouteQuery(type);
161
135
  },
162
136
  /* updateLocalStorage(key: string, value: string): void {
163
137
  const local = JSON.parse(localStorage.getItem("PARIS_IAS") || "{}")
164
138
  local[key] = value
165
139
  localStorage.setItem("PARIS_IAS", JSON.stringify(local))
166
140
  }, */
167
- async updateFilter(key, val, type, lang) {
141
+ updateFilter(key, val, type, lang) {
168
142
  const { $stores } = useNuxtApp();
169
- console.log("update filter: ", { key, val, type });
143
+ console.log("R - update filter: ", { key, val, type });
170
144
  if ($stores[type]?.filters?.[key]) {
171
145
  $stores[type].filters[key].value = val;
172
146
  }
173
147
  this.page = 1;
174
- await this.update(type, lang);
148
+ $stores[type].loading = true;
149
+ this.setFiltersCount(type);
150
+ this.updateRouteQuery(type);
175
151
  },
176
- async updateItemsPerPage({
152
+ updateItemsPerPage({
177
153
  value,
178
154
  type,
179
155
  lang
180
156
  }) {
181
- console.log("updateItemsPerPage", { value, type });
157
+ console.log("H - updateItemsPerPage", { value, type });
182
158
  const { $stores } = useNuxtApp();
183
159
  this.page = 1;
184
- if ($stores[type]) {
185
- $stores[type].itemsPerPage = value;
186
- }
187
- await this.update(type, lang);
160
+ $stores[type].itemsPerPage = value;
161
+ $stores[type].loading = true;
162
+ this.updateRouteQuery(type);
188
163
  },
189
- async updatePage({
164
+ updatePage({
190
165
  page,
191
166
  type,
192
167
  lang = "en"
193
168
  }) {
194
- console.log("updatePage", { page, type });
169
+ console.log("update page: ", page);
195
170
  const router = useRouter();
196
171
  const currentQuery = router.currentRoute.value.query;
197
172
  const newQuery = { ...currentQuery };
173
+ if (type !== "all") {
174
+ const { $stores } = useNuxtApp();
175
+ $stores[type].page = page;
176
+ $stores[type].loading = true;
177
+ } else {
178
+ this.page = page;
179
+ }
198
180
  if (page > 1) {
199
181
  newQuery.page = page.toString();
200
182
  } else {
201
183
  delete newQuery.page;
202
184
  }
203
- this.page = page;
204
- await this.update(type, lang);
185
+ router.replace({ query: newQuery });
205
186
  },
206
- /*
207
- initializePageFromRoute(): void {
208
- const { query } = useRouter().currentRoute.value
209
- const page = Number.parseInt(query.page as string, 10)
210
- this.page = isNaN(page) || page < 1 ? 1 : page
211
- }, */
212
- async updateSearch({
187
+ updateSearch({
213
188
  type = "all",
214
189
  search = "",
215
190
  lang = "en"
216
191
  }) {
217
- const { $stores } = useNuxtApp();
218
- console.log("updateSearch", { type, search, lang });
219
192
  if (type === "all") {
220
193
  this.search = search;
221
194
  } else {
195
+ const { $stores } = useNuxtApp();
222
196
  if ($stores[type]) {
223
- $stores[type].$patch({ search });
197
+ ;
198
+ $stores[type].search = search;
199
+ $stores[type].loading = true;
224
200
  }
225
201
  }
226
- await this.update(type, lang);
202
+ this.page = 1;
203
+ this.updateRouteQuery(type);
227
204
  },
228
- async update(type, lang = "en") {
229
- const { $stores, $queries } = useNuxtApp();
230
- console.log("update", { type, lang });
231
- this.setLoading(true);
232
- if (type !== "all" && $stores[type]) {
233
- $stores[type].loading = true;
234
- }
205
+ buildListVariables(type, lang = "en") {
206
+ const { $stores } = useNuxtApp();
235
207
  const itemsPerPage = type === "all" ? 3 : $stores[type]?.itemsPerPage || 10;
208
+ const _viewName = $stores[type]?.view && $stores[type].view.name;
209
+ const _sortByName = $stores[type]?.sortBy && $stores[type].sortBy;
210
+ const _sortDescName = $stores[type]?.sortDesc && $stores[type].sortDesc;
236
211
  const filters = {};
237
212
  if (type !== "all") {
238
213
  const storeFilters = $stores[type]?.filters ?? {};
@@ -246,16 +221,11 @@ export const useRootStore = defineStore("rootStore", {
246
221
  const args = JSON.parse(
247
222
  JSON.stringify({
248
223
  options: {
249
- // skip
250
- skip: +this.page === 1 ? 0 : (+this.page - 1) * itemsPerPage,
251
- // limit
224
+ skip: +$stores[type]?.page === 1 ? 0 : (+$stores[type]?.page - 1) * itemsPerPage,
252
225
  limit: itemsPerPage,
253
- // sort, array of keys and array of directions - to have x tie breakers if necessary
254
226
  sortBy: type === "all" ? "searchScore" : $stores[type]?.sortBy || ["created"],
255
227
  sortDesc: type === "all" ? -1 : ($stores[type]?.sortDesc?.[0] || 0) > 0 ? true : false,
256
- // search (if set)
257
228
  ...this.search?.length && type !== "all" && { search: this.search },
258
- // add the store module filters
259
229
  filters
260
230
  },
261
231
  ...type === "all" && this.search?.length && { search: this.search },
@@ -267,36 +237,31 @@ export const useRootStore = defineStore("rootStore", {
267
237
  })
268
238
  );
269
239
  args.options.filters = JSON.stringify(args.options.filters);
270
- console.log("args: ", args);
271
- const { data, error } = await useAsyncQuery(
272
- type === "all" ? SEARCH : $queries[type]?.list,
273
- args
274
- );
275
- console.log("data: ", data);
276
- if (error.value) console.log(error.value);
240
+ return args;
241
+ },
242
+ applyListResult(type, data, itemsPerPageOverride) {
243
+ const { $stores } = useNuxtApp();
277
244
  const key = type === "all" ? "search" : "list" + type.charAt(0).toUpperCase() + type.slice(1);
278
245
  if (type === "all") {
279
- this.results = data?.value?.[key] || this.results;
280
- } else {
281
- const items = data?.value?.[key]?.items ?? [];
282
- if ($stores[type]) {
283
- $stores[type].total = data?.value?.[key]?.total || 0;
284
- const result = {
285
- ...data?.value?.[key],
286
- items: items.map(({ id, ...rest }) => ({
287
- ...rest,
288
- _path: `/${id}`
289
- }))
290
- };
291
- $stores[type].items = result.items;
292
- const lastPage = Math.ceil((result.total || 0) / itemsPerPage);
293
- this.setFiltersCount(type);
294
- $stores[type].numberOfPages = lastPage;
295
- }
246
+ this.results = data?.[key] || this.results;
247
+ return;
248
+ }
249
+ const items = data?.[key]?.items ?? [];
250
+ if ($stores[type]) {
251
+ const itemsPerPage = itemsPerPageOverride || $stores[type].itemsPerPage || 10;
252
+ $stores[type].total = data?.[key]?.total || 0;
253
+ const result = {
254
+ ...data?.[key],
255
+ items: items.map(({ id, ...rest }) => ({
256
+ ...rest,
257
+ _path: `/${id}`
258
+ }))
259
+ };
260
+ $stores[type].items = result.items;
261
+ const lastPage = Math.ceil((result.total || 0) / itemsPerPage);
262
+ this.setFiltersCount(type);
263
+ $stores[type].numberOfPages = lastPage;
296
264
  }
297
- this.updateRouteQuery(type);
298
- this.setLoading(false, type);
299
- return true;
300
265
  }
301
266
  }
302
267
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "license": "AGPL-3.0-only",
3
3
  "main": "./dist/module.mjs",
4
- "version": "1.0.137",
4
+ "version": "1.0.138",
5
5
  "name": "@paris-ias/list",
6
6
  "repository": {
7
7
  "url": "git+https://github.com/IEA-Paris/list.git",