@monoui/vuejs 1.1.15 → 1.1.18

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.18",
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"
@@ -185,62 +185,73 @@
185
185
  </div>
186
186
  <slot name="pagination-seperator" />
187
187
  <slot name="pagination">
188
- <div class="d-flex justify-content-between align-items-center mt-2">
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)"
202
- >
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
- )
221
- "
188
+ <div :class="paginationClass">
189
+ <div
190
+ class="d-flex justify-content-between align-items-center mt-2"
191
+ >
192
+ <slot name="pagination-filters">
193
+ <div>
194
+ <div v-show="!isDataEmpty">
195
+ <span>Show</span>
196
+ <b-dropdown
197
+ :text="itemPerPageText"
198
+ class="m-md-2"
199
+ size="sm"
200
+ variant="light"
222
201
  >
223
- All ({{ settings.totalItemCount }})
224
- </b-dropdown-item>
225
- </template>
226
- </b-dropdown>
227
- </div>
228
- </slot>
229
- <slot name="pagination-center" v-bind="settings">
230
- <span v-show="!isDataEmpty">
231
- {{ settings.totalItemCount }} rows
232
- </span>
233
- </slot>
234
- <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
- />
243
- </slot>
202
+ <template
203
+ v-for="perPage in filteredPerPageValues"
204
+ >
205
+ <b-dropdown-item
206
+ :key="'per-page-' + perPage"
207
+ @click="changeItemPerPage(perPage)"
208
+ >
209
+ {{ perPage }}
210
+ </b-dropdown-item>
211
+ </template>
212
+ <b-dropdown-divider
213
+ v-if="
214
+ filteredPerPageValues &&
215
+ filteredPerPageValues.length &&
216
+ inLimit()
217
+ "
218
+ />
219
+ <template>
220
+ <b-dropdown-item
221
+ v-if="inLimit()"
222
+ @click="
223
+ changeItemPerPage(
224
+ settings.totalItemCount
225
+ )
226
+ "
227
+ >
228
+ All ({{ settings.totalItemCount }})
229
+ </b-dropdown-item>
230
+ </template>
231
+ </b-dropdown>
232
+ </div>
233
+ </div>
234
+ </slot>
235
+ <slot name="pagination-center" v-bind="settings">
236
+ <div>
237
+ <span v-show="!isDataEmpty">
238
+ {{ settings.totalItemCount }} rows
239
+ </span>
240
+ </div>
241
+ </slot>
242
+ <slot name="pagination-buttons">
243
+ <div>
244
+ <b-pagination
245
+ v-if="settings.pageCount > 1"
246
+ v-model="settings.currentPage"
247
+ :total-rows="settings.totalItemCount"
248
+ :per-page="settings.itemPerPage"
249
+ @change="changePage"
250
+ v-bind="pagination"
251
+ />
252
+ </div>
253
+ </slot>
254
+ </div>
244
255
  </div>
245
256
  </slot>
246
257
  <slot name="footer" />
@@ -271,6 +282,23 @@ export default {
271
282
  IconSortingArrows
272
283
  },
273
284
  props: {
285
+ history: {
286
+ type: Boolean,
287
+ required: false,
288
+ default: false
289
+ },
290
+ /// <summary>
291
+ /// Keep the table navigation history on options: 'query', 'cookie', 'session', 'local', 'hash'.
292
+ /// </summary>
293
+ historyStorage: {
294
+ type: String,
295
+ required: false,
296
+ default: "query"
297
+ },
298
+ historyName: {
299
+ type: String,
300
+ default: ""
301
+ },
274
302
  columns: {
275
303
  type: Object,
276
304
  required: false
@@ -289,8 +317,9 @@ export default {
289
317
  required: false
290
318
  },
291
319
  filterable: {
292
- type: Array,
293
- required: false
320
+ type: Boolean,
321
+ required: false,
322
+ default: false
294
323
  },
295
324
  headerClass: {
296
325
  type: String,
@@ -368,6 +397,26 @@ export default {
368
397
  type: String,
369
398
  required: false,
370
399
  default: "icon-arrow-down-long"
400
+ },
401
+ searchColumn: {
402
+ type: String,
403
+ required: false,
404
+ default: ""
405
+ },
406
+ searchWordMinLength: {
407
+ type: Number,
408
+ required: false,
409
+ default: 2
410
+ },
411
+ searchDebounce: {
412
+ type: Number,
413
+ required: false,
414
+ default: 300
415
+ },
416
+ paginationClass: {
417
+ type: String,
418
+ required: false,
419
+ default: ""
371
420
  }
372
421
  },
373
422
  watch: {
@@ -377,6 +426,12 @@ export default {
377
426
  },
378
427
  data() {
379
428
  return {
429
+ defaultSettings: {
430
+ currentPage: 1,
431
+ pageCount: 0,
432
+ itemPerPage: 10,
433
+ totalItemCount: 0
434
+ },
380
435
  settings: {
381
436
  currentPage: 1,
382
437
  pageCount: 0,
@@ -387,7 +442,8 @@ export default {
387
442
  searchWord: null,
388
443
  isDataEmpty: false,
389
444
  isLoading: false,
390
- limit: 250
445
+ limit: 250,
446
+ searchDebounceTimeout: null
391
447
  };
392
448
  },
393
449
  computed: {
@@ -410,11 +466,45 @@ export default {
410
466
  return this.settings.totalItemCount <= 0;
411
467
  }
412
468
  },
469
+ created() {
470
+ this.addPopStateListener();
471
+ },
413
472
  async mounted() {
473
+ this.loadHistory();
414
474
  if (this.autoLoad) await this.getValues();
415
475
  },
416
- created() {},
417
476
  methods: {
477
+ addPopStateListener() {
478
+ window.addEventListener("popstate", this.popStateEvent);
479
+ },
480
+ removePopStateListener() {
481
+ window.removeEventListener("popstate", this.popStateEvent);
482
+ },
483
+ async popStateEvent() {
484
+ this.loadHistory();
485
+ await this.getValues(false);
486
+ },
487
+ loadHistory() {
488
+ this.settings.currentPage = this.getHistoryParameter(
489
+ "page",
490
+ this.defaultSettings.currentPage
491
+ );
492
+ this.settings.itemPerPage = this.getHistoryParameter(
493
+ "limit",
494
+ this.defaultSettings.itemPerPage
495
+ );
496
+ if (this.searchColumn) {
497
+ this.searchWord = this.getHistoryParameter(
498
+ `f-${this.searchColumn}`,
499
+ this.searchWord
500
+ );
501
+ }
502
+ this.loadHistoryFilters();
503
+ this.loadHistorySorting();
504
+ // console.log("loadHistory:settings", this.settings);
505
+ // console.log("loadHistory:filters", this.filters);
506
+ // console.log("loadHistory:sorting", this.sorting);
507
+ },
418
508
  sortableIcon(column) {
419
509
  const currentSort = this.sorting.find(x => x.Column === column);
420
510
  if (!currentSort) {
@@ -436,9 +526,8 @@ export default {
436
526
  return this.sorting.some(x => x.Column === column);
437
527
  },
438
528
  async toggleSort(column) {
439
- if (!this.isSortable(column)) {
440
- return;
441
- }
529
+ if (!this.isSortable(column)) return;
530
+
442
531
  let currentSort = this.sorting.find(x => x.Column === column);
443
532
  if (!currentSort) {
444
533
  currentSort = { Column: column, Asc: true };
@@ -478,6 +567,16 @@ export default {
478
567
  itemPerPage
479
568
  );
480
569
 
570
+ this.clearHistoryParameters("f-");
571
+ for (const filter of this.filters) {
572
+ this.addHistoryParameter(`f-${filter.Column}`, filter.Value);
573
+ }
574
+
575
+ this.clearHistoryParameters("s-");
576
+ for (const sort of this.sorting) {
577
+ this.addHistoryParameter(`s-${sort.Column}`, sort.Asc ? 1 : 0);
578
+ }
579
+
481
580
  if (!result || result.status !== 200) {
482
581
  this.isLoading = false;
483
582
  this.isDataEmpty = true;
@@ -513,16 +612,22 @@ export default {
513
612
  ) {
514
613
  this.settings.pageCount = 1;
515
614
  }
615
+ if (this.settings.currentPage > this.settings.pageCount) {
616
+ this.settings.currentPage = this.settings.pageCount;
617
+ this.changePage(this.settings.currentPage);
618
+ return;
619
+ }
516
620
  this.isLoading = false;
517
621
  this.$emit("loading", this.isLoading);
518
622
  },
519
623
  changePage(page) {
520
624
  this.settings.currentPage = page;
521
-
625
+ this.addHistoryParameter("page", page);
522
626
  this.getValues();
523
627
  },
524
628
  changeItemPerPage(value) {
525
629
  this.settings.itemPerPage = value;
630
+ this.addHistoryParameter("limit", value);
526
631
  this.getValues();
527
632
  },
528
633
  isLessThanTotalItemCount(val) {
@@ -533,15 +638,359 @@ export default {
533
638
  this.getValues();
534
639
  },
535
640
  addFilter(word) {
536
- if (!word || word.length < 3) {
641
+ if (!this.searchColumn) return;
642
+ clearTimeout(this.searchDebounceTimeout);
643
+ this.searchDebounceTimeout = setTimeout(
644
+ () =>
645
+ this.searchColumnValue(
646
+ this.searchColumn,
647
+ word,
648
+ this.searchWordMinLength
649
+ ),
650
+ this.searchDebounce
651
+ );
652
+ },
653
+ searchColumnValue(column, value, limit = -1) {
654
+ let filter = this.filters.find(x => x.Column === column);
655
+
656
+ if (filter && (!value || value.length < limit)) {
657
+ this.filters.splice(this.filters.indexOf(filter), 1);
537
658
  this.getValues();
538
659
  return;
539
660
  }
540
661
 
662
+ if (filter) filter.Value = value;
663
+ else
664
+ this.filters.push({
665
+ Column: column,
666
+ Value: value
667
+ });
541
668
  this.getValues();
542
669
  },
543
670
  inLimit() {
544
671
  return this.settings.totalItemCount <= this.limit;
672
+ },
673
+ getHistoryName(name, seperator = "-") {
674
+ if (!name) name = "";
675
+ if (!this.historyName) return name;
676
+ return `${this.historyName}${seperator}${name}`;
677
+ },
678
+ clearHistoryParameters(
679
+ startsWith = null,
680
+ storage = this.historyStorage
681
+ ) {
682
+ if (!startsWith || !storage) return;
683
+
684
+ try {
685
+ const startsWithName = this.getHistoryName(startsWith);
686
+
687
+ if (storage === "query") {
688
+ const url = new URL(window.location);
689
+ for (const searchParam of url.searchParams) {
690
+ if (searchParam[0].startsWith(startsWithName)) {
691
+ url.searchParams.delete(searchParam[0]);
692
+ }
693
+ }
694
+ window.history.pushState({}, "", url);
695
+ return;
696
+ }
697
+
698
+ if (storage === "local") {
699
+ const keys = Object.keys(localStorage);
700
+ for (const key of keys) {
701
+ if (!key.startsWith(startsWithName)) continue;
702
+ localStorage.removeItem(key);
703
+ }
704
+ return;
705
+ }
706
+
707
+ if (storage === "session") {
708
+ const keys = Object.keys(sessionStorage);
709
+ for (const key of keys) {
710
+ if (!key.startsWith(startsWithName)) continue;
711
+ sessionStorage.removeItem(key);
712
+ }
713
+ return;
714
+ }
715
+
716
+ if (storage === "cookie") {
717
+ var pairs = document.cookie.split(";");
718
+ var cookies = {};
719
+ for (var i = 0; i < pairs.length; i++) {
720
+ var pair = pairs[i].split("=");
721
+ cookies[(pair[0] + "").trim()] = unescape(
722
+ pair.slice(1).join("=")
723
+ );
724
+ }
725
+ const keys = Object.keys(cookies);
726
+ for (const key of keys) {
727
+ if (!key.startsWith(startsWithName)) continue;
728
+ document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:00 UTC;`;
729
+ }
730
+ return;
731
+ }
732
+
733
+ if (storage === "hash") {
734
+ if (!window.location.hash) return;
735
+ const hash = window.location.hash.substr(1);
736
+ hash.split("&").reduce(function(_, item) {
737
+ var parts = item.split("=");
738
+ if (!parts[0].startsWith(startsWithName)) return;
739
+ window.location.hash = window.location.hash.replace(
740
+ `${item}`,
741
+ ""
742
+ );
743
+ }, {});
744
+ return;
745
+ }
746
+ } catch (error) {
747
+ console.error(error);
748
+ }
749
+ },
750
+ getHistoryParameters(startsWith = null, storage = this.historyStorage) {
751
+ if (!storage) return;
752
+
753
+ try {
754
+ const startsWithName = this.getHistoryName(startsWith);
755
+ let returnParameters = {};
756
+
757
+ if (storage === "query") {
758
+ const url = new URL(window.location);
759
+ for (const searchParam of url.searchParams) {
760
+ if (!searchParam[0].startsWith(startsWithName))
761
+ continue;
762
+ returnParameters[searchParam[0]] = searchParam[1];
763
+ }
764
+ }
765
+
766
+ if (storage === "local") {
767
+ const keys = Object.keys(localStorage);
768
+ for (const key of keys) {
769
+ if (!key.startsWith(startsWithName)) continue;
770
+ returnParameters[key] = localStorage.getItem(key);
771
+ }
772
+ }
773
+
774
+ if (storage === "session") {
775
+ const keys = Object.keys(sessionStorage);
776
+ for (const key of keys) {
777
+ if (!key.startsWith(startsWithName)) continue;
778
+ returnParameters[key] = sessionStorage.getItem(key);
779
+ }
780
+ }
781
+
782
+ if (storage === "cookie") {
783
+ var pairs = document.cookie.split(";");
784
+ var cookies = {};
785
+ for (var i = 0; i < pairs.length; i++) {
786
+ var pair = pairs[i].split("=");
787
+ cookies[(pair[0] + "").trim()] = unescape(
788
+ pair.slice(1).join("=")
789
+ );
790
+ }
791
+ const keys = Object.keys(cookies);
792
+ for (const key of keys) {
793
+ if (startsWithName && !key.startsWith(startsWithName))
794
+ continue;
795
+ returnParameters[key] = cookies[key];
796
+ }
797
+ }
798
+
799
+ if (storage === "hash") {
800
+ if (window.location.hash) {
801
+ const hash = window.location.hash.substr(1);
802
+ hash.split("&").reduce(function(_, item) {
803
+ var parts = item.split("=");
804
+ if (
805
+ startsWithName &&
806
+ !parts[0].startsWith(startsWithName)
807
+ )
808
+ return;
809
+ returnParameters[parts[0]] = parts[1];
810
+ }, {});
811
+ }
812
+ }
813
+
814
+ return returnParameters;
815
+ } catch (error) {
816
+ console.error(error);
817
+ }
818
+ },
819
+ loadHistoryFilters() {
820
+ const parameters = this.getHistoryParameters("f-");
821
+ const trimName = this.getHistoryName("f-");
822
+ const names = Object.keys(parameters);
823
+ for (const paramName of names) {
824
+ const value = parameters[paramName];
825
+ const column = paramName.replace(trimName, "");
826
+
827
+ let filter = this.filters.find(x => x.Column === column);
828
+
829
+ if (filter && !value) {
830
+ this.filters.splice(this.filters.indexOf(filter), 1);
831
+ } else if (filter) {
832
+ filter.Value = value;
833
+ } else {
834
+ this.filters.push({
835
+ Column: column,
836
+ Value: value
837
+ });
838
+ }
839
+ }
840
+ },
841
+ loadHistorySorting() {
842
+ const parameters = this.getHistoryParameters("s-");
843
+ const trimName = this.getHistoryName("s-");
844
+ const names = Object.keys(parameters);
845
+ for (const paramName of names) {
846
+ const value = parameters[paramName] ? true : false;
847
+ const column = paramName.replace(trimName, "");
848
+
849
+ let sort = this.sorting.find(x => x.Column === column);
850
+
851
+ if (sort) {
852
+ sort.Value = value;
853
+ } else {
854
+ this.sorting.push({ Column: column, Asc: value });
855
+ }
856
+ }
857
+ },
858
+ addHistoryParameter(name, value, storage = this.historyStorage) {
859
+ if (!this.history || !name || !storage) return;
860
+ // console.log("addHistoryParameter", name, value, storage);
861
+ try {
862
+ if (storage === "query") {
863
+ const url = new URL(window.location);
864
+ const historyName = this.getHistoryName(name);
865
+ url.searchParams.set(historyName, value);
866
+ window.history.pushState(null, "", url);
867
+ return;
868
+ }
869
+
870
+ if (storage === "local") {
871
+ const historyName = this.getHistoryName(name);
872
+ localStorage.setItem(historyName, value);
873
+ return;
874
+ }
875
+
876
+ if (storage === "session") {
877
+ const historyName = this.getHistoryName(name);
878
+ sessionStorage.setItem(historyName, value);
879
+ return;
880
+ }
881
+
882
+ if (storage === "cookie") {
883
+ const historyName = this.getHistoryName(name);
884
+ document.cookie = `${historyName}=${value}`;
885
+ return;
886
+ }
887
+
888
+ if (storage === "hash") {
889
+ const historyName = this.getHistoryName(name);
890
+ const curretParameters = this.getHistoryParameters();
891
+ const newParameters = {
892
+ ...curretParameters,
893
+ [historyName]: value
894
+ };
895
+ const newHash = Object.keys(newParameters)
896
+ .map(key => `${key}=${newParameters[key]}`)
897
+ .join("&");
898
+ window.location.hash = newHash;
899
+ return;
900
+ }
901
+ } catch (error) {
902
+ console.error(error);
903
+ }
904
+ },
905
+ getHistoryParameter(
906
+ name,
907
+ defaultValue = null,
908
+ storage = this.historyStorage
909
+ ) {
910
+ if (!this.history || !name || !storage) return defaultValue;
911
+
912
+ try {
913
+ if (storage === "query") {
914
+ const url = new URL(window.location);
915
+ const historyName = this.getHistoryName(name);
916
+ return url.searchParams.get(historyName) || defaultValue;
917
+ }
918
+
919
+ if (storage === "local") {
920
+ const historyName = this.getHistoryName(name);
921
+ return localStorage.getItem(historyName) || defaultValue;
922
+ }
923
+
924
+ if (storage === "session") {
925
+ const historyName = this.getHistoryName(name);
926
+ return sessionStorage.getItem(historyName) || defaultValue;
927
+ }
928
+
929
+ if (storage === "cookie") {
930
+ const historyName = this.getHistoryName(name);
931
+ const cookie = document.cookie
932
+ .split(";")
933
+ .find(c => c.trim().startsWith(`${historyName}=`));
934
+ if (!cookie) return defaultValue;
935
+ return cookie.split("=")[1] || defaultValue;
936
+ }
937
+
938
+ if (storage === "hash") {
939
+ const historyName = this.getHistoryName(name);
940
+ const hash = window.location.hash
941
+ .split("#")
942
+ .find(c => c.trim().startsWith(`${historyName}=`));
943
+ if (!hash) return defaultValue;
944
+ return hash.split("=")[1] || defaultValue;
945
+ }
946
+ } catch (error) {
947
+ console.error(error);
948
+ }
949
+
950
+ return defaultValue;
951
+ },
952
+ removeHistoryParameter(name, storage = this.historyStorage) {
953
+ if (!this.history || !name || !storage) return;
954
+
955
+ try {
956
+ const historyName = this.getHistoryName(name);
957
+ if (storage === "query") {
958
+ const url = new URL(window.location);
959
+ url.searchParams.delete(historyName);
960
+ window.history.pushState({}, "", url);
961
+ return;
962
+ }
963
+
964
+ if (storage === "local") {
965
+ localStorage.removeItem(historyName);
966
+ return;
967
+ }
968
+
969
+ if (storage === "session") {
970
+ sessionStorage.removeItem(historyName);
971
+ return;
972
+ }
973
+
974
+ if (storage === "cookie") {
975
+ document.cookie = `${historyName}=; expires=Thu, 01 Jan 1970 00:00:00 UTC;`;
976
+ return;
977
+ }
978
+
979
+ if (storage === "hash") {
980
+ if (!window.location.hash) return;
981
+ const hash = window.location.hash.substr(1);
982
+ hash.split("&").reduce(function(_, item) {
983
+ var parts = item.split("=");
984
+ if (!parts[0].startsWith(historyName)) return;
985
+ window.location.hash = window.location.hash.replace(
986
+ `${item}`,
987
+ ""
988
+ );
989
+ }, {});
990
+ }
991
+ } catch (error) {
992
+ console.error(error);
993
+ }
545
994
  }
546
995
  }
547
996
  };