@nethserver/ns8-ui-lib 2.0.1 → 2.1.0

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.
@@ -17142,7 +17142,28 @@ var LottieService = {
17142
17142
  GearsLottie: GearsLottie
17143
17143
  };
17144
17144
  }
17145
- };var script$a = {
17145
+ };/*
17146
+ * Copyright (C) 2023 Nethesis S.r.l.
17147
+ * SPDX-License-Identifier: GPL-3.0-or-later
17148
+ */
17149
+
17150
+ var StorageService = {
17151
+ name: "StorageService",
17152
+ methods: {
17153
+ getFromStorage: function getFromStorage(prop) {
17154
+ return JSON.parse(localStorage.getItem(prop));
17155
+ },
17156
+ saveToStorage: function saveToStorage(prop, object) {
17157
+ localStorage.setItem(prop, JSON.stringify(object));
17158
+ },
17159
+ deleteFromStorage: function deleteFromStorage(prop) {
17160
+ localStorage.removeItem(prop);
17161
+ }
17162
+ }
17163
+ };// localStorage entry holding the page sizes chosen by the user, grouped by
17164
+ // page sizes set (e.g. {"10,25,50,100": 50}) or by pageSizeStorageKey prop
17165
+ var PAGE_SIZES_STORAGE_KEY = "nsDataTablePageSizes";
17166
+ var script$a = {
17146
17167
  name: "NsDataTable",
17147
17168
  extends: vue.CvDataTable,
17148
17169
  components: {
@@ -17157,7 +17178,7 @@ var LottieService = {
17157
17178
  ChevronRight16: ChevronRight16__default["default"],
17158
17179
  NsPagination: NsPagination
17159
17180
  },
17160
- mixins: [UtilService, LottieService],
17181
+ mixins: [UtilService, LottieService, StorageService],
17161
17182
  props: {
17162
17183
  actionBarAriaLabel: {
17163
17184
  type: String,
@@ -17193,6 +17214,17 @@ var LottieService = {
17193
17214
  return [10, 25, 50, 100];
17194
17215
  }
17195
17216
  },
17217
+ // remember the page size chosen by the user in localStorage
17218
+ persistPageSize: {
17219
+ type: Boolean,
17220
+ default: true
17221
+ },
17222
+ // key used to store the page size; tables with the same key share the same page size.
17223
+ // If empty, tables are grouped by their page sizes set
17224
+ pageSizeStorageKey: {
17225
+ type: String,
17226
+ default: ""
17227
+ },
17196
17228
  rowSize: {
17197
17229
  type: String,
17198
17230
  default: "standard",
@@ -17318,7 +17350,8 @@ var LottieService = {
17318
17350
  searchFilter: "",
17319
17351
  pageStart: 0,
17320
17352
  pageNumber: 0,
17321
- pageLength: 0
17353
+ pageLength: 0,
17354
+ selectedPageSize: null
17322
17355
  };
17323
17356
  },
17324
17357
  watch: {
@@ -17327,9 +17360,13 @@ var LottieService = {
17327
17360
  },
17328
17361
  filteredRows: function filteredRows() {
17329
17362
  this.$emit("updatePage", this.tablePage);
17363
+ },
17364
+ pageSizeGroup: function pageSizeGroup() {
17365
+ this.selectedPageSize = this.getStoredPageSize();
17330
17366
  }
17331
17367
  },
17332
17368
  created: function created() {
17369
+ this.selectedPageSize = this.getStoredPageSize();
17333
17370
  this.filterRows();
17334
17371
  },
17335
17372
  computed: {
@@ -17337,12 +17374,36 @@ var LottieService = {
17337
17374
  if (this.pageSizes.length) {
17338
17375
  return {
17339
17376
  numberOfItems: this.filteredRows.length,
17340
- pageSizes: this.pageSizes
17377
+ pageSizes: this.paginationPageSizes
17341
17378
  };
17342
17379
  } else {
17343
17380
  return false;
17344
17381
  }
17345
17382
  },
17383
+ isPageSizePersisted: function isPageSizePersisted() {
17384
+ return this.persistPageSize && this.pageSizes.length > 1 && this.pageSizes.every(function (size) {
17385
+ return typeof size === "number";
17386
+ });
17387
+ },
17388
+ pageSizeGroup: function pageSizeGroup() {
17389
+ if (!this.isPageSizePersisted) {
17390
+ return "";
17391
+ }
17392
+ return this.pageSizeStorageKey || this.pageSizes.join(",");
17393
+ },
17394
+ paginationPageSizes: function paginationPageSizes() {
17395
+ var _this = this;
17396
+ if (this.selectedPageSize === null || !this.pageSizes.includes(this.selectedPageSize)) {
17397
+ return this.pageSizes;
17398
+ }
17399
+ // preselect page size in NsPagination
17400
+ return this.pageSizes.map(function (size) {
17401
+ return {
17402
+ value: size,
17403
+ selected: size === _this.selectedPageSize
17404
+ };
17405
+ });
17406
+ },
17346
17407
  tablePage: function tablePage() {
17347
17408
  if (this.pageSizes.length) {
17348
17409
  return this.filteredRows.slice(this.pageStart, this.pageStart + this.pageLength);
@@ -17405,11 +17466,11 @@ var LottieService = {
17405
17466
  }
17406
17467
  },
17407
17468
  searchMatch: function searchMatch(target, cleanRegex, queryText) {
17408
- var _this = this;
17469
+ var _this2 = this;
17409
17470
  if (Array.isArray(target)) {
17410
17471
  // search field is an array (e.g. groups)
17411
17472
  return target.some(function (elem) {
17412
- return _this.searchMatch(elem, cleanRegex, queryText);
17473
+ return _this2.searchMatch(elem, cleanRegex, queryText);
17413
17474
  });
17414
17475
  } else if (typeof target === "string") {
17415
17476
  // search field is a simple string
@@ -17422,12 +17483,12 @@ var LottieService = {
17422
17483
 
17423
17484
  return Object.keys(target).some(function (key) {
17424
17485
  // recursion
17425
- return _this.searchMatch(target[key], cleanRegex, queryText);
17486
+ return _this2.searchMatch(target[key], cleanRegex, queryText);
17426
17487
  });
17427
17488
  }
17428
17489
  },
17429
17490
  defaultFilterRows: function defaultFilterRows() {
17430
- var _this2 = this;
17491
+ var _this3 = this;
17431
17492
  if (!this.searchFilter) {
17432
17493
  return this.allRows;
17433
17494
  } else {
@@ -17436,10 +17497,10 @@ var LottieService = {
17436
17497
  var queryText = this.searchFilter.replace(cleanRegex, "");
17437
17498
  var searchResults = this.allRows.filter(function (option) {
17438
17499
  // compare query text with attributes option
17439
- return _this2.rawColumns.some(function (searchField) {
17500
+ return _this3.rawColumns.some(function (searchField) {
17440
17501
  var target = option[searchField];
17441
17502
  if (target) {
17442
- return _this2.searchMatch(target, cleanRegex, queryText);
17503
+ return _this3.searchMatch(target, cleanRegex, queryText);
17443
17504
  } else {
17444
17505
  return false;
17445
17506
  }
@@ -17448,7 +17509,45 @@ var LottieService = {
17448
17509
  return searchResults;
17449
17510
  }
17450
17511
  },
17512
+ readStoredPageSizes: function readStoredPageSizes() {
17513
+ try {
17514
+ var storedPageSizes = this.getFromStorage(PAGE_SIZES_STORAGE_KEY);
17515
+ if (storedPageSizes && _typeof$1(storedPageSizes) === "object" && !Array.isArray(storedPageSizes)) {
17516
+ return storedPageSizes;
17517
+ }
17518
+ } catch (e) {
17519
+ // corrupted value or storage not available
17520
+ }
17521
+ return {};
17522
+ },
17523
+ getStoredPageSize: function getStoredPageSize() {
17524
+ if (!this.pageSizeGroup) {
17525
+ return null;
17526
+ }
17527
+ var pageSize = this.readStoredPageSizes()[this.pageSizeGroup];
17528
+ if (this.pageSizes.includes(pageSize)) {
17529
+ return pageSize;
17530
+ }
17531
+ return null;
17532
+ },
17533
+ storePageSize: function storePageSize(pageSize) {
17534
+ if (!this.pageSizeGroup) {
17535
+ return;
17536
+ }
17537
+ var storedPageSizes = this.readStoredPageSizes();
17538
+ storedPageSizes[this.pageSizeGroup] = pageSize;
17539
+ try {
17540
+ this.saveToStorage(PAGE_SIZES_STORAGE_KEY, storedPageSizes);
17541
+ } catch (e) {
17542
+ // storage not available or full
17543
+ }
17544
+ },
17451
17545
  paginateTable: function paginateTable(ev) {
17546
+ if (this.isPageSizePersisted && this.pageLength !== 0 && ev.length !== this.pageLength) {
17547
+ // page size changed by the user
17548
+ this.selectedPageSize = ev.length;
17549
+ this.storePageSize(ev.length);
17550
+ }
17452
17551
  this.pageStart = ev.start - 1;
17453
17552
  this.pageNumber = ev.page;
17454
17553
  this.pageLength = ev.length;
@@ -17804,7 +17903,7 @@ var __vue_inject_styles__$p = undefined;
17804
17903
  /* scoped */
17805
17904
  var __vue_scope_id__$p = undefined;
17806
17905
  /* module identifier */
17807
- var __vue_module_identifier__$p = "data-v-3467b887";
17906
+ var __vue_module_identifier__$p = "data-v-34c62134";
17808
17907
  /* functional template */
17809
17908
  var __vue_is_functional_template__$p = false;
17810
17909
  /* style inject */
@@ -24487,24 +24586,6 @@ var queryParam = {
24487
24586
  * Copyright (C) 2023 Nethesis S.r.l.
24488
24587
  * SPDX-License-Identifier: GPL-3.0-or-later
24489
24588
  */
24490
-
24491
- var StorageService = {
24492
- name: "StorageService",
24493
- methods: {
24494
- getFromStorage: function getFromStorage(prop) {
24495
- return JSON.parse(localStorage.getItem(prop));
24496
- },
24497
- saveToStorage: function saveToStorage(prop, object) {
24498
- localStorage.setItem(prop, JSON.stringify(object));
24499
- },
24500
- deleteFromStorage: function deleteFromStorage(prop) {
24501
- localStorage.removeItem(prop);
24502
- }
24503
- }
24504
- };/*
24505
- * Copyright (C) 2023 Nethesis S.r.l.
24506
- * SPDX-License-Identifier: GPL-3.0-or-later
24507
- */
24508
24589
  var task = {
24509
24590
  name: "TaskService",
24510
24591
  mixins: [StorageService, UtilService],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nethserver/ns8-ui-lib",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Vue.js library for NethServer 8 UI",
5
5
  "keywords": [
6
6
  "nethserver",
@@ -313,6 +313,11 @@ import Close16 from "@carbon/icons-vue/es/close/16";
313
313
  import ChevronRight16 from "@carbon/icons-vue/es/chevron--right/16";
314
314
  import UtilService from "../lib-mixins/util.js";
315
315
  import LottieService from "../lib-mixins/lottie.js";
316
+ import StorageService from "../lib-mixins/storage.js";
317
+
318
+ // localStorage entry holding the page sizes chosen by the user, grouped by
319
+ // page sizes set (e.g. {"10,25,50,100": 50}) or by pageSizeStorageKey prop
320
+ const PAGE_SIZES_STORAGE_KEY = "nsDataTablePageSizes";
316
321
 
317
322
  export default {
318
323
  name: "NsDataTable",
@@ -329,7 +334,7 @@ export default {
329
334
  ChevronRight16,
330
335
  NsPagination,
331
336
  },
332
- mixins: [UtilService, LottieService],
337
+ mixins: [UtilService, LottieService, StorageService],
333
338
  props: {
334
339
  actionBarAriaLabel: { type: String, default: "Table Action Bar" },
335
340
  collapseAllAriaLabel: { type: String, default: "Collapse all rows" },
@@ -343,6 +348,11 @@ export default {
343
348
  type: Array,
344
349
  default: () => [10, 25, 50, 100],
345
350
  },
351
+ // remember the page size chosen by the user in localStorage
352
+ persistPageSize: { type: Boolean, default: true },
353
+ // key used to store the page size; tables with the same key share the same page size.
354
+ // If empty, tables are grouped by their page sizes set
355
+ pageSizeStorageKey: { type: String, default: "" },
346
356
  rowSize: {
347
357
  type: String,
348
358
  default: "standard",
@@ -395,6 +405,7 @@ export default {
395
405
  pageStart: 0,
396
406
  pageNumber: 0,
397
407
  pageLength: 0,
408
+ selectedPageSize: null,
398
409
  };
399
410
  },
400
411
  watch: {
@@ -404,8 +415,12 @@ export default {
404
415
  filteredRows: function () {
405
416
  this.$emit("updatePage", this.tablePage);
406
417
  },
418
+ pageSizeGroup: function () {
419
+ this.selectedPageSize = this.getStoredPageSize();
420
+ },
407
421
  },
408
422
  created() {
423
+ this.selectedPageSize = this.getStoredPageSize();
409
424
  this.filterRows();
410
425
  },
411
426
  computed: {
@@ -413,12 +428,38 @@ export default {
413
428
  if (this.pageSizes.length) {
414
429
  return {
415
430
  numberOfItems: this.filteredRows.length,
416
- pageSizes: this.pageSizes,
431
+ pageSizes: this.paginationPageSizes,
417
432
  };
418
433
  } else {
419
434
  return false;
420
435
  }
421
436
  },
437
+ isPageSizePersisted() {
438
+ return (
439
+ this.persistPageSize &&
440
+ this.pageSizes.length > 1 &&
441
+ this.pageSizes.every((size) => typeof size === "number")
442
+ );
443
+ },
444
+ pageSizeGroup() {
445
+ if (!this.isPageSizePersisted) {
446
+ return "";
447
+ }
448
+ return this.pageSizeStorageKey || this.pageSizes.join(",");
449
+ },
450
+ paginationPageSizes() {
451
+ if (
452
+ this.selectedPageSize === null ||
453
+ !this.pageSizes.includes(this.selectedPageSize)
454
+ ) {
455
+ return this.pageSizes;
456
+ }
457
+ // preselect page size in NsPagination
458
+ return this.pageSizes.map((size) => ({
459
+ value: size,
460
+ selected: size === this.selectedPageSize,
461
+ }));
462
+ },
422
463
  tablePage() {
423
464
  if (this.pageSizes.length) {
424
465
  return this.filteredRows.slice(
@@ -526,7 +567,56 @@ export default {
526
567
  return searchResults;
527
568
  }
528
569
  },
570
+ readStoredPageSizes() {
571
+ try {
572
+ const storedPageSizes = this.getFromStorage(PAGE_SIZES_STORAGE_KEY);
573
+
574
+ if (
575
+ storedPageSizes &&
576
+ typeof storedPageSizes === "object" &&
577
+ !Array.isArray(storedPageSizes)
578
+ ) {
579
+ return storedPageSizes;
580
+ }
581
+ } catch (e) {
582
+ // corrupted value or storage not available
583
+ }
584
+ return {};
585
+ },
586
+ getStoredPageSize() {
587
+ if (!this.pageSizeGroup) {
588
+ return null;
589
+ }
590
+ const pageSize = this.readStoredPageSizes()[this.pageSizeGroup];
591
+
592
+ if (this.pageSizes.includes(pageSize)) {
593
+ return pageSize;
594
+ }
595
+ return null;
596
+ },
597
+ storePageSize(pageSize) {
598
+ if (!this.pageSizeGroup) {
599
+ return;
600
+ }
601
+ const storedPageSizes = this.readStoredPageSizes();
602
+ storedPageSizes[this.pageSizeGroup] = pageSize;
603
+
604
+ try {
605
+ this.saveToStorage(PAGE_SIZES_STORAGE_KEY, storedPageSizes);
606
+ } catch (e) {
607
+ // storage not available or full
608
+ }
609
+ },
529
610
  paginateTable(ev) {
611
+ if (
612
+ this.isPageSizePersisted &&
613
+ this.pageLength !== 0 &&
614
+ ev.length !== this.pageLength
615
+ ) {
616
+ // page size changed by the user
617
+ this.selectedPageSize = ev.length;
618
+ this.storePageSize(ev.length);
619
+ }
530
620
  this.pageStart = ev.start - 1;
531
621
  this.pageNumber = ev.page;
532
622
  this.pageLength = ev.length;