@monoui/vuejs 1.1.15 → 1.1.16

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@monoui/vuejs",
3
- "version": "1.1.15",
3
+ "version": "1.1.16",
4
4
  "description": "This project will contain MonoFor UI Framework",
5
5
  "main": "./dist/main.js",
6
6
  "repository": "git@gitlab.com:monoui/vuejs.git",
@@ -79,7 +79,7 @@
79
79
  </slot>
80
80
  </tr>
81
81
  <template v-if="filterable">
82
- <tr v-if="filterable.length !== 0">
82
+ <tr>
83
83
  <th
84
84
  class="p-0 p-t-1 p-b-1"
85
85
  :colspan="Object.keys(columns).length"
@@ -187,59 +187,66 @@
187
187
  <slot name="pagination">
188
188
  <div class="d-flex justify-content-between align-items-center mt-2">
189
189
  <slot name="pagination-filters">
190
- <div v-show="!isDataEmpty">
191
- <span>Show</span>
192
- <b-dropdown
193
- :text="itemPerPageText"
194
- class="m-md-2"
195
- size="sm"
196
- variant="light"
197
- >
198
- <template v-for="perPage in filteredPerPageValues">
199
- <b-dropdown-item
200
- :key="'per-page-' + perPage"
201
- @click="changeItemPerPage(perPage)"
190
+ <div>
191
+ <div v-show="!isDataEmpty">
192
+ <span>Show</span>
193
+ <b-dropdown
194
+ :text="itemPerPageText"
195
+ class="m-md-2"
196
+ size="sm"
197
+ variant="light"
198
+ >
199
+ <template
200
+ v-for="perPage in filteredPerPageValues"
202
201
  >
203
- {{ perPage }}
204
- </b-dropdown-item>
205
- </template>
206
- <b-dropdown-divider
207
- v-if="
208
- filteredPerPageValues &&
209
- filteredPerPageValues.length &&
210
- inLimit()
211
- "
212
- ></b-dropdown-divider>
213
-
214
- <template>
215
- <b-dropdown-item
216
- v-if="inLimit()"
217
- @click="
218
- changeItemPerPage(
219
- settings.totalItemCount
220
- )
202
+ <b-dropdown-item
203
+ :key="'per-page-' + perPage"
204
+ @click="changeItemPerPage(perPage)"
205
+ >
206
+ {{ perPage }}
207
+ </b-dropdown-item>
208
+ </template>
209
+ <b-dropdown-divider
210
+ v-if="
211
+ filteredPerPageValues &&
212
+ filteredPerPageValues.length &&
213
+ inLimit()
221
214
  "
222
- >
223
- All ({{ settings.totalItemCount }})
224
- </b-dropdown-item>
225
- </template>
226
- </b-dropdown>
215
+ />
216
+ <template>
217
+ <b-dropdown-item
218
+ v-if="inLimit()"
219
+ @click="
220
+ changeItemPerPage(
221
+ settings.totalItemCount
222
+ )
223
+ "
224
+ >
225
+ All ({{ settings.totalItemCount }})
226
+ </b-dropdown-item>
227
+ </template>
228
+ </b-dropdown>
229
+ </div>
227
230
  </div>
228
231
  </slot>
229
232
  <slot name="pagination-center" v-bind="settings">
230
- <span v-show="!isDataEmpty">
231
- {{ settings.totalItemCount }} rows
232
- </span>
233
+ <div>
234
+ <span v-show="!isDataEmpty">
235
+ {{ settings.totalItemCount }} rows
236
+ </span>
237
+ </div>
233
238
  </slot>
234
239
  <slot name="pagination-buttons">
235
- <b-pagination
236
- v-if="settings.pageCount > 1"
237
- v-model="settings.currentPage"
238
- :total-rows="settings.totalItemCount"
239
- :per-page="settings.itemPerPage"
240
- @change="changePage"
241
- v-bind="pagination"
242
- />
240
+ <div>
241
+ <b-pagination
242
+ v-if="settings.pageCount > 1"
243
+ v-model="settings.currentPage"
244
+ :total-rows="settings.totalItemCount"
245
+ :per-page="settings.itemPerPage"
246
+ @change="changePage"
247
+ v-bind="pagination"
248
+ />
249
+ </div>
243
250
  </slot>
244
251
  </div>
245
252
  </slot>
@@ -271,6 +278,23 @@ export default {
271
278
  IconSortingArrows
272
279
  },
273
280
  props: {
281
+ history: {
282
+ type: Boolean,
283
+ required: false,
284
+ default: false
285
+ },
286
+ /// <summary>
287
+ /// Keep the table navigation history on options: 'query', 'cookie', 'session', 'local', 'hash'.
288
+ /// </summary>
289
+ historyStorage: {
290
+ type: String,
291
+ required: false,
292
+ default: "query"
293
+ },
294
+ historyName: {
295
+ type: String,
296
+ default: ""
297
+ },
274
298
  columns: {
275
299
  type: Object,
276
300
  required: false
@@ -289,8 +313,9 @@ export default {
289
313
  required: false
290
314
  },
291
315
  filterable: {
292
- type: Array,
293
- required: false
316
+ type: Boolean,
317
+ required: false,
318
+ default: false
294
319
  },
295
320
  headerClass: {
296
321
  type: String,
@@ -368,6 +393,21 @@ export default {
368
393
  type: String,
369
394
  required: false,
370
395
  default: "icon-arrow-down-long"
396
+ },
397
+ searchColumn: {
398
+ type: String,
399
+ required: false,
400
+ default: ""
401
+ },
402
+ searchWordMinLength: {
403
+ type: Number,
404
+ required: false,
405
+ default: 2
406
+ },
407
+ searchDebounce: {
408
+ type: Number,
409
+ required: false,
410
+ default: 300
371
411
  }
372
412
  },
373
413
  watch: {
@@ -387,7 +427,8 @@ export default {
387
427
  searchWord: null,
388
428
  isDataEmpty: false,
389
429
  isLoading: false,
390
- limit: 250
430
+ limit: 250,
431
+ searchDebounceTimeout: null
391
432
  };
392
433
  },
393
434
  computed: {
@@ -411,6 +452,22 @@ export default {
411
452
  }
412
453
  },
413
454
  async mounted() {
455
+ this.settings.currentPage = this.getHistoryParameter(
456
+ "page",
457
+ this.settings.currentPage
458
+ );
459
+ this.settings.itemPerPage = this.getHistoryParameter(
460
+ "limit",
461
+ this.settings.itemPerPage
462
+ );
463
+ if (this.searchColumn) {
464
+ this.searchWord = this.getHistoryParameter(
465
+ `f-${this.searchColumn}`,
466
+ this.searchWord
467
+ );
468
+ }
469
+ this.loadHistoryFilters();
470
+ this.loadHistorySorting();
414
471
  if (this.autoLoad) await this.getValues();
415
472
  },
416
473
  created() {},
@@ -436,9 +493,8 @@ export default {
436
493
  return this.sorting.some(x => x.Column === column);
437
494
  },
438
495
  async toggleSort(column) {
439
- if (!this.isSortable(column)) {
440
- return;
441
- }
496
+ if (!this.isSortable(column)) return;
497
+
442
498
  let currentSort = this.sorting.find(x => x.Column === column);
443
499
  if (!currentSort) {
444
500
  currentSort = { Column: column, Asc: true };
@@ -471,6 +527,16 @@ export default {
471
527
  this.$emit("loading", this.isLoading);
472
528
  const { currentPage, itemPerPage } = this.settings;
473
529
 
530
+ this.clearHistoryParameters("f-");
531
+ for (const filter of this.filters) {
532
+ this.addHistoryParameter(`f-${filter.Column}`, filter.Value);
533
+ }
534
+
535
+ this.clearHistoryParameters("s-");
536
+ for (const sort of this.sorting) {
537
+ this.addHistoryParameter(`s-${sort.Column}`, sort.Asc ? 1 : 0);
538
+ }
539
+
474
540
  let result = await this.requestFunction(
475
541
  this.filters,
476
542
  this.sorting,
@@ -513,16 +579,22 @@ export default {
513
579
  ) {
514
580
  this.settings.pageCount = 1;
515
581
  }
582
+ if (this.settings.currentPage > this.settings.pageCount) {
583
+ this.settings.currentPage = this.settings.pageCount;
584
+ this.changePage(this.settings.currentPage);
585
+ return;
586
+ }
516
587
  this.isLoading = false;
517
588
  this.$emit("loading", this.isLoading);
518
589
  },
519
590
  changePage(page) {
520
591
  this.settings.currentPage = page;
521
-
592
+ this.addHistoryParameter("page", page);
522
593
  this.getValues();
523
594
  },
524
595
  changeItemPerPage(value) {
525
596
  this.settings.itemPerPage = value;
597
+ this.addHistoryParameter("limit", value);
526
598
  this.getValues();
527
599
  },
528
600
  isLessThanTotalItemCount(val) {
@@ -533,15 +605,359 @@ export default {
533
605
  this.getValues();
534
606
  },
535
607
  addFilter(word) {
536
- if (!word || word.length < 3) {
608
+ if (!this.searchColumn) return;
609
+ clearTimeout(this.searchDebounceTimeout);
610
+ this.searchDebounceTimeout = setTimeout(
611
+ () =>
612
+ this.searchColumnValue(
613
+ this.searchColumn,
614
+ word,
615
+ this.searchWordMinLength
616
+ ),
617
+ this.searchDebounce
618
+ );
619
+ },
620
+ searchColumnValue(column, value, limit = -1) {
621
+ let filter = this.filters.find(x => x.Column === column);
622
+
623
+ if (filter && (!value || value.length < limit)) {
624
+ this.filters.splice(this.filters.indexOf(filter), 1);
537
625
  this.getValues();
538
626
  return;
539
627
  }
540
628
 
629
+ if (filter) filter.Value = value;
630
+ else
631
+ this.filters.push({
632
+ Column: column,
633
+ Value: value
634
+ });
541
635
  this.getValues();
542
636
  },
543
637
  inLimit() {
544
638
  return this.settings.totalItemCount <= this.limit;
639
+ },
640
+ getHistoryName(name, seperator = "-") {
641
+ if (!name) name = "";
642
+ if (!this.historyName) return name;
643
+ return `${this.historyName}${seperator}${name}`;
644
+ },
645
+ clearHistoryParameters(
646
+ startsWith = null,
647
+ storage = this.historyStorage
648
+ ) {
649
+ if (!startsWith || !storage) return;
650
+
651
+ try {
652
+ const startsWithName = this.getHistoryName(startsWith);
653
+
654
+ if (storage === "query") {
655
+ const url = new URL(window.location);
656
+ for (const searchParam of url.searchParams) {
657
+ if (searchParam[0].startsWith(startsWithName)) {
658
+ url.searchParams.delete(searchParam[0]);
659
+ }
660
+ }
661
+ window.history.pushState({}, "", url);
662
+ return;
663
+ }
664
+
665
+ if (storage === "local") {
666
+ const keys = Object.keys(localStorage);
667
+ for (const key of keys) {
668
+ if (!key.startsWith(startsWithName)) continue;
669
+ localStorage.removeItem(key);
670
+ }
671
+ return;
672
+ }
673
+
674
+ if (storage === "session") {
675
+ const keys = Object.keys(sessionStorage);
676
+ for (const key of keys) {
677
+ if (!key.startsWith(startsWithName)) continue;
678
+ sessionStorage.removeItem(key);
679
+ }
680
+ return;
681
+ }
682
+
683
+ if (storage === "cookie") {
684
+ var pairs = document.cookie.split(";");
685
+ var cookies = {};
686
+ for (var i = 0; i < pairs.length; i++) {
687
+ var pair = pairs[i].split("=");
688
+ cookies[(pair[0] + "").trim()] = unescape(
689
+ pair.slice(1).join("=")
690
+ );
691
+ }
692
+ const keys = Object.keys(cookies);
693
+ for (const key of keys) {
694
+ if (!key.startsWith(startsWithName)) continue;
695
+ document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC;`;
696
+ }
697
+ return;
698
+ }
699
+
700
+ if (storage === "hash") {
701
+ if (!window.location.hash) return;
702
+ const hash = window.location.hash.substr(1);
703
+ hash.split("&").reduce(function(_, item) {
704
+ var parts = item.split("=");
705
+ if (!parts[0].startsWith(startsWithName)) return;
706
+ window.location.hash = window.location.hash.replace(
707
+ `${item}`,
708
+ ""
709
+ );
710
+ }, {});
711
+ return;
712
+ }
713
+ } catch (error) {
714
+ console.error(error);
715
+ }
716
+ },
717
+ getHistoryParameters(startsWith = null, storage = this.historyStorage) {
718
+ if (!storage) return;
719
+
720
+ try {
721
+ const startsWithName = this.getHistoryName(startsWith);
722
+ let returnParameters = {};
723
+
724
+ if (storage === "query") {
725
+ const url = new URL(window.location);
726
+ for (const searchParam of url.searchParams) {
727
+ if (!searchParam[0].startsWith(startsWithName))
728
+ continue;
729
+ returnParameters[searchParam[0]] = searchParam[1];
730
+ }
731
+ }
732
+
733
+ if (storage === "local") {
734
+ const keys = Object.keys(localStorage);
735
+ for (const key of keys) {
736
+ if (!key.startsWith(startsWithName)) continue;
737
+ returnParameters[key] = localStorage.getItem(key);
738
+ }
739
+ }
740
+
741
+ if (storage === "session") {
742
+ const keys = Object.keys(sessionStorage);
743
+ for (const key of keys) {
744
+ if (!key.startsWith(startsWithName)) continue;
745
+ returnParameters[key] = sessionStorage.getItem(key);
746
+ }
747
+ }
748
+
749
+ if (storage === "cookie") {
750
+ var pairs = document.cookie.split(";");
751
+ var cookies = {};
752
+ for (var i = 0; i < pairs.length; i++) {
753
+ var pair = pairs[i].split("=");
754
+ cookies[(pair[0] + "").trim()] = unescape(
755
+ pair.slice(1).join("=")
756
+ );
757
+ }
758
+ const keys = Object.keys(cookies);
759
+ for (const key of keys) {
760
+ if (startsWithName && !key.startsWith(startsWithName))
761
+ continue;
762
+ returnParameters[key] = cookies[key];
763
+ }
764
+ }
765
+
766
+ if (storage === "hash") {
767
+ if (window.location.hash) {
768
+ const hash = window.location.hash.substr(1);
769
+ hash.split("&").reduce(function(_, item) {
770
+ var parts = item.split("=");
771
+ if (
772
+ startsWithName &&
773
+ !parts[0].startsWith(startsWithName)
774
+ )
775
+ return;
776
+ returnParameters[parts[0]] = parts[1];
777
+ }, {});
778
+ }
779
+ }
780
+
781
+ return returnParameters;
782
+ } catch (error) {
783
+ console.error(error);
784
+ }
785
+ },
786
+ loadHistoryFilters() {
787
+ const parameters = this.getHistoryParameters("f-");
788
+ const trimName = this.getHistoryName("f-");
789
+ const names = Object.keys(parameters);
790
+ for (const paramName of names) {
791
+ const value = parameters[paramName];
792
+ const column = paramName.replace(trimName, "");
793
+
794
+ let filter = this.filters.find(x => x.Column === column);
795
+
796
+ if (filter && !value) {
797
+ this.filters.splice(this.filters.indexOf(filter), 1);
798
+ } else if (filter) {
799
+ filter.Value = value;
800
+ } else {
801
+ this.filters.push({
802
+ Column: column,
803
+ Value: value
804
+ });
805
+ }
806
+ }
807
+ },
808
+ loadHistorySorting() {
809
+ const parameters = this.getHistoryParameters("s-");
810
+ const trimName = this.getHistoryName("s-");
811
+ const names = Object.keys(parameters);
812
+ for (const paramName of names) {
813
+ const value = parameters[paramName] ? true : false;
814
+ const column = paramName.replace(trimName, "");
815
+
816
+ let sort = this.sorting.find(x => x.Column === column);
817
+
818
+ if (sort) {
819
+ sort.Value = value;
820
+ } else {
821
+ this.sorting.push({ Column: column, Asc: value });
822
+ }
823
+ }
824
+ },
825
+ addHistoryParameter(name, value, storage = this.historyStorage) {
826
+ if (!this.history || !name || !storage) return;
827
+
828
+ try {
829
+ if (storage === "query") {
830
+ const url = new URL(window.location);
831
+ const historyName = this.getHistoryName(name);
832
+ url.searchParams.set(historyName, value);
833
+ window.history.pushState({}, "", url);
834
+ return;
835
+ }
836
+
837
+ if (storage === "local") {
838
+ const historyName = this.getHistoryName(name);
839
+ localStorage.setItem(historyName, value);
840
+ return;
841
+ }
842
+
843
+ if (storage === "session") {
844
+ const historyName = this.getHistoryName(name);
845
+ sessionStorage.setItem(historyName, value);
846
+ return;
847
+ }
848
+
849
+ if (storage === "cookie") {
850
+ const historyName = this.getHistoryName(name);
851
+ document.cookie = `${historyName}=${value}`;
852
+ return;
853
+ }
854
+
855
+ if (storage === "hash") {
856
+ const historyName = this.getHistoryName(name);
857
+ const curretParameters = this.getHistoryParameters();
858
+ const newParameters = {
859
+ ...curretParameters,
860
+ [historyName]: value
861
+ };
862
+ const newHash = Object.keys(newParameters)
863
+ .map(key => `${key}=${newParameters[key]}`)
864
+ .join("&");
865
+ window.location.hash = newHash;
866
+ return;
867
+ }
868
+ } catch (error) {
869
+ console.error(error);
870
+ }
871
+ },
872
+ getHistoryParameter(
873
+ name,
874
+ defaultValue = null,
875
+ storage = this.historyStorage
876
+ ) {
877
+ if (!this.history || !name || !storage) return defaultValue;
878
+
879
+ try {
880
+ if (storage === "query") {
881
+ const url = new URL(window.location);
882
+ const historyName = this.getHistoryName(name);
883
+ return url.searchParams.get(historyName) || defaultValue;
884
+ }
885
+
886
+ if (storage === "local") {
887
+ const historyName = this.getHistoryName(name);
888
+ return localStorage.getItem(historyName) || defaultValue;
889
+ }
890
+
891
+ if (storage === "session") {
892
+ const historyName = this.getHistoryName(name);
893
+ return sessionStorage.getItem(historyName) || defaultValue;
894
+ }
895
+
896
+ if (storage === "cookie") {
897
+ const historyName = this.getHistoryName(name);
898
+ const cookie = document.cookie
899
+ .split(";")
900
+ .find(c => c.trim().startsWith(`${historyName}=`));
901
+ if (!cookie) return defaultValue;
902
+ return cookie.split("=")[1] || defaultValue;
903
+ }
904
+
905
+ if (storage === "hash") {
906
+ const historyName = this.getHistoryName(name);
907
+ const hash = window.location.hash
908
+ .split("#")
909
+ .find(c => c.trim().startsWith(`${historyName}=`));
910
+ if (!hash) return defaultValue;
911
+ return hash.split("=")[1] || defaultValue;
912
+ }
913
+ } catch (error) {
914
+ console.error(error);
915
+ }
916
+
917
+ return defaultValue;
918
+ },
919
+ removeHistoryParameter(name, storage = this.historyStorage) {
920
+ if (!this.history || !name || !storage) return;
921
+
922
+ try {
923
+ const historyName = this.getHistoryName(name);
924
+ if (storage === "query") {
925
+ const url = new URL(window.location);
926
+ url.searchParams.delete(historyName);
927
+ window.history.pushState({}, "", url);
928
+ return;
929
+ }
930
+
931
+ if (storage === "local") {
932
+ localStorage.removeItem(historyName);
933
+ return;
934
+ }
935
+
936
+ if (storage === "session") {
937
+ sessionStorage.removeItem(historyName);
938
+ return;
939
+ }
940
+
941
+ if (storage === "cookie") {
942
+ document.cookie = `${historyName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC;`;
943
+ return;
944
+ }
945
+
946
+ if (storage === "hash") {
947
+ if (!window.location.hash) return;
948
+ const hash = window.location.hash.substr(1);
949
+ hash.split("&").reduce(function(_, item) {
950
+ var parts = item.split("=");
951
+ if (!parts[0].startsWith(historyName)) return;
952
+ window.location.hash = window.location.hash.replace(
953
+ `${item}`,
954
+ ""
955
+ );
956
+ }, {});
957
+ }
958
+ } catch (error) {
959
+ console.error(error);
960
+ }
545
961
  }
546
962
  }
547
963
  };