@firestitch/filter 18.2.21 → 18.2.23
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/app/consts/index.d.ts +0 -1
- package/app/helpers/compare.d.ts +2 -0
- package/app/helpers/create-filter-item.d.ts +1 -1
- package/app/helpers/encode-query-parm.d.ts +1 -0
- package/app/helpers/find-value.d.ts +1 -0
- package/app/helpers/index.d.ts +9 -0
- package/app/models/items/checkbox-item.d.ts +0 -1
- package/esm2022/app/consts/index.mjs +1 -2
- package/esm2022/app/helpers/compare.mjs +38 -0
- package/esm2022/app/helpers/encode-query-parm.mjs +6 -0
- package/esm2022/app/helpers/find-value.mjs +13 -0
- package/esm2022/app/helpers/index.mjs +10 -0
- package/esm2022/app/helpers/parse-item-value-from-stored.mjs +5 -3
- package/esm2022/app/helpers/query-param-transformers.mjs +3 -4
- package/esm2022/app/models/items/autocomplete-chips-item.mjs +6 -2
- package/esm2022/app/models/items/checkbox-item.mjs +2 -9
- package/esm2022/app/models/items/chips-item.mjs +3 -2
- package/esm2022/app/services/query-param-controller.service.mjs +4 -3
- package/esm2022/public_api.mjs +1 -3
- package/fesm2022/firestitch-filter.mjs +548 -494
- package/fesm2022/firestitch-filter.mjs.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +0 -1
- package/app/consts/query-param-delimiter.d.ts +0 -1
- package/esm2022/app/consts/query-param-delimiter.mjs +0 -2
|
@@ -24,9 +24,9 @@ import * as i6 from '@firestitch/file';
|
|
|
24
24
|
import { FsFileModule } from '@firestitch/file';
|
|
25
25
|
import * as i1$2 from '@firestitch/chip';
|
|
26
26
|
import { FsChipModule } from '@firestitch/chip';
|
|
27
|
-
import { isFunction, clone, toString
|
|
28
|
-
import { iso8601, format } from '@firestitch/date';
|
|
27
|
+
import { isObject, isFunction, clone, toString } from 'lodash-es';
|
|
29
28
|
import { isDate, isValid, parseISO } from 'date-fns';
|
|
29
|
+
import { iso8601, format } from '@firestitch/date';
|
|
30
30
|
import * as i3$2 from '@firestitch/datepicker';
|
|
31
31
|
import { formatPeriodObject, FsDatePickerModule } from '@firestitch/datepicker';
|
|
32
32
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
|
@@ -640,6 +640,155 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
|
|
|
640
640
|
type: Input
|
|
641
641
|
}] } });
|
|
642
642
|
|
|
643
|
+
function objectsAreEquals(obj1, obj2) {
|
|
644
|
+
const oldKeys = Object.keys(obj1);
|
|
645
|
+
const currKeys = Object.keys(obj2);
|
|
646
|
+
if (oldKeys.length !== currKeys.length) {
|
|
647
|
+
return false;
|
|
648
|
+
}
|
|
649
|
+
for (const key in obj1) {
|
|
650
|
+
if (obj1.hasOwnProperty(key)) {
|
|
651
|
+
const oldItem = obj1[key];
|
|
652
|
+
const currItem = obj2[key];
|
|
653
|
+
const isArrays = Array.isArray(oldItem) && Array.isArray(currItem);
|
|
654
|
+
const isObjects = isObject(oldItem) && isObject(currItem);
|
|
655
|
+
if (isArrays && !arraysAreEquals(oldItem, currItem)) {
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
else if (isObjects && !objectsAreEquals(oldItem, currItem)) {
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
else if (!isArrays && !isObjects && oldItem !== currItem) {
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
return true;
|
|
667
|
+
}
|
|
668
|
+
function arraysAreEquals(arr1, arr2) {
|
|
669
|
+
if (arr1?.length !== arr2.length) {
|
|
670
|
+
return false;
|
|
671
|
+
}
|
|
672
|
+
for (const el of arr1) {
|
|
673
|
+
if (arr2.indexOf(el) === -1) {
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
return true;
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
function encodeQueryParam(value) {
|
|
681
|
+
return value
|
|
682
|
+
.replace(/,/g, '\\,')
|
|
683
|
+
.replace(/:/g, '\\:');
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
function findValue(values, value, children) {
|
|
687
|
+
for (let i = 0; i < values.length; i++) {
|
|
688
|
+
const val = values[i];
|
|
689
|
+
if (val[children]) {
|
|
690
|
+
return findValue(val[children], value, children);
|
|
691
|
+
}
|
|
692
|
+
if (val.value === value) {
|
|
693
|
+
return val;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
return undefined;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
function getRangeName(name, range) {
|
|
700
|
+
return name.concat(range.charAt(0).toUpperCase()).concat(range.slice(1));
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
function parseDate(value) {
|
|
704
|
+
if (value && (!isDate(value) || !isValid(value))) {
|
|
705
|
+
return parseISO(value);
|
|
706
|
+
}
|
|
707
|
+
return value;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
function filterToQueryParam(value, name) {
|
|
711
|
+
return `${encodeURIComponent(value)}:${encodeURIComponent(name)}`;
|
|
712
|
+
}
|
|
713
|
+
function filterFromQueryParam(param) {
|
|
714
|
+
const parts = param.split(/(?<!\\):/);
|
|
715
|
+
return [decodeURIComponent(parts[0]), decodeURIComponent(parts[1])];
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
function parseItemValueFromStored(item, params) {
|
|
719
|
+
const param = params[item.name];
|
|
720
|
+
switch (item.type) {
|
|
721
|
+
case ItemType.Range: {
|
|
722
|
+
const min = params[getRangeName(item.name, 'min')];
|
|
723
|
+
const max = params[getRangeName(item.name, 'max')];
|
|
724
|
+
return { min: min, max: max };
|
|
725
|
+
}
|
|
726
|
+
case ItemType.DateRange:
|
|
727
|
+
case ItemType.DateTimeRange: {
|
|
728
|
+
const from = params[getRangeName(item.name, 'from')];
|
|
729
|
+
const to = params[getRangeName(item.name, 'to')];
|
|
730
|
+
return { from: from, to: to };
|
|
731
|
+
}
|
|
732
|
+
case ItemType.Week: {
|
|
733
|
+
const from = params[getRangeName(item.name, 'from')];
|
|
734
|
+
const to = params[getRangeName(item.name, 'to')];
|
|
735
|
+
const period = params[`${item.name}Period`];
|
|
736
|
+
return { from, to, period };
|
|
737
|
+
}
|
|
738
|
+
case ItemType.Select: {
|
|
739
|
+
return itemTypeSelect(item, param);
|
|
740
|
+
}
|
|
741
|
+
case ItemType.Checkbox: {
|
|
742
|
+
return param === 'true' || param === true;
|
|
743
|
+
}
|
|
744
|
+
case ItemType.AutoComplete: {
|
|
745
|
+
const filterParts = filterFromQueryParam(param);
|
|
746
|
+
return {
|
|
747
|
+
name: filterParts[1],
|
|
748
|
+
value: filterParts[0],
|
|
749
|
+
};
|
|
750
|
+
}
|
|
751
|
+
case ItemType.AutoCompleteChips:
|
|
752
|
+
case ItemType.Chips: {
|
|
753
|
+
const filterParts = param.split(/(?<!\\),/);
|
|
754
|
+
return filterParts.reduce((arry, value) => {
|
|
755
|
+
const chipParts = filterFromQueryParam(value);
|
|
756
|
+
arry.push({
|
|
757
|
+
name: chipParts[1]
|
|
758
|
+
.replace(/\\,/g, ',')
|
|
759
|
+
.replace(/\\:/g, ':'),
|
|
760
|
+
value: chipParts[0],
|
|
761
|
+
});
|
|
762
|
+
return arry;
|
|
763
|
+
}, []);
|
|
764
|
+
}
|
|
765
|
+
default: {
|
|
766
|
+
return param;
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
function itemTypeSelect(item, param) {
|
|
771
|
+
if (!param) {
|
|
772
|
+
return [];
|
|
773
|
+
}
|
|
774
|
+
const values = param.split(',');
|
|
775
|
+
if (item.isolate) {
|
|
776
|
+
const isolatedValue = item.isolateValues;
|
|
777
|
+
item.isolate = arraysHaveSameElements(isolatedValue, values);
|
|
778
|
+
return item.isolate
|
|
779
|
+
? isolatedValue
|
|
780
|
+
: values;
|
|
781
|
+
}
|
|
782
|
+
return values;
|
|
783
|
+
}
|
|
784
|
+
function arraysHaveSameElements(arr1, arr2) {
|
|
785
|
+
arr1 = [...arr1].sort();
|
|
786
|
+
arr2 = [...arr2].sort();
|
|
787
|
+
return arr1.some((item) => {
|
|
788
|
+
return arr2.includes(item);
|
|
789
|
+
});
|
|
790
|
+
}
|
|
791
|
+
|
|
643
792
|
class BaseItem {
|
|
644
793
|
_additionalConfig;
|
|
645
794
|
_filter;
|
|
@@ -850,101 +999,380 @@ class BaseItem {
|
|
|
850
999
|
}
|
|
851
1000
|
}
|
|
852
1001
|
|
|
853
|
-
class
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
search;
|
|
857
|
-
get valuesFn() {
|
|
858
|
-
return this._valuesFn;
|
|
1002
|
+
class BaseDateRangeItem extends BaseItem {
|
|
1003
|
+
get isTypeDateRange() {
|
|
1004
|
+
return this.type === ItemType.DateRange;
|
|
859
1005
|
}
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
this._additionalConfig = _additionalConfig;
|
|
863
|
-
this._filter = _filter;
|
|
864
|
-
this.fetchOnFocus = itemConfig.fetchOnFocus ?? true;
|
|
1006
|
+
get isTypeDateTimeRange() {
|
|
1007
|
+
return this.type === ItemType.DateTimeRange;
|
|
865
1008
|
}
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
class AutocompleteChipsItem extends BaseAutocompleteItem {
|
|
869
|
-
_additionalConfig;
|
|
870
|
-
_filter;
|
|
871
|
-
constructor(itemConfig, _additionalConfig, _filter) {
|
|
872
|
-
super(itemConfig, _additionalConfig, _filter);
|
|
873
|
-
this._additionalConfig = _additionalConfig;
|
|
874
|
-
this._filter = _filter;
|
|
875
|
-
this.chipImage = itemConfig.chipImage ?? 'image';
|
|
876
|
-
this.chipIcon = itemConfig.chipIcon;
|
|
877
|
-
this.chipIconColor = itemConfig.chipIconColor;
|
|
878
|
-
this.chipColor = itemConfig.chipColor;
|
|
879
|
-
this.chipBackground = itemConfig.chipBackground;
|
|
880
|
-
this.chipClass = itemConfig.chipClass;
|
|
881
|
-
this.panelActions = itemConfig.panelActions || [];
|
|
1009
|
+
get hasValue() {
|
|
1010
|
+
return this.value?.from instanceof Date || this.value?.to instanceof Date;
|
|
882
1011
|
}
|
|
883
|
-
|
|
884
|
-
|
|
1012
|
+
setValue(value, emitChange = true) {
|
|
1013
|
+
let from = value?.from;
|
|
1014
|
+
let to = value?.to;
|
|
1015
|
+
if (value) {
|
|
1016
|
+
if (from && (!isDate(from) || !isValid(from))) {
|
|
1017
|
+
from = parseISO(from);
|
|
1018
|
+
}
|
|
1019
|
+
if (to && (!isDate(to) || !isValid(to))) {
|
|
1020
|
+
to = parseISO(to);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
super.setValue({ from, to }, emitChange);
|
|
885
1024
|
}
|
|
886
1025
|
get queryParam() {
|
|
887
1026
|
if (!this.hasValue) {
|
|
888
1027
|
return {};
|
|
889
1028
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
1029
|
+
const value = {};
|
|
1030
|
+
const paramFromName = getRangeName(this.name, 'from');
|
|
1031
|
+
const paramToName = getRangeName(this.name, 'to');
|
|
1032
|
+
if (this.value.from) {
|
|
1033
|
+
value[paramFromName] = iso8601(this.value.from);
|
|
1034
|
+
}
|
|
1035
|
+
if (this.value.to) {
|
|
1036
|
+
value[paramToName] = iso8601(this.value.to);
|
|
1037
|
+
}
|
|
1038
|
+
return value;
|
|
895
1039
|
}
|
|
896
1040
|
get query() {
|
|
897
1041
|
if (!this.hasValue) {
|
|
898
1042
|
return {};
|
|
899
1043
|
}
|
|
900
|
-
const value =
|
|
901
|
-
const
|
|
902
|
-
const
|
|
903
|
-
if (
|
|
904
|
-
|
|
905
|
-
.filter((item) => !!item.value)
|
|
906
|
-
.map((item) => item.value)
|
|
907
|
-
.join(',');
|
|
1044
|
+
const value = {};
|
|
1045
|
+
const paramFromName = getRangeName(this.name, 'from');
|
|
1046
|
+
const paramToName = getRangeName(this.name, 'to');
|
|
1047
|
+
if (this.value.from) {
|
|
1048
|
+
value[paramFromName] = this.value.from;
|
|
908
1049
|
}
|
|
909
|
-
|
|
910
|
-
|
|
1050
|
+
if (this.value.to) {
|
|
1051
|
+
value[paramToName] = this.value.to;
|
|
911
1052
|
}
|
|
912
|
-
return
|
|
1053
|
+
return value;
|
|
913
1054
|
}
|
|
914
1055
|
get chips() {
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
1056
|
+
const dateFormat = this.type === ItemType.DateRange ? 'date' : 'date-time';
|
|
1057
|
+
const chips = [];
|
|
1058
|
+
if (this.value?.from) {
|
|
1059
|
+
chips.push({
|
|
1060
|
+
name: 'from',
|
|
1061
|
+
value: format(this.value.from, dateFormat),
|
|
1062
|
+
label: this.label[0],
|
|
1063
|
+
});
|
|
1064
|
+
}
|
|
1065
|
+
if (this.value?.to) {
|
|
1066
|
+
chips.push({
|
|
1067
|
+
name: 'to',
|
|
1068
|
+
value: format(this.value.to, dateFormat),
|
|
1069
|
+
label: this.label[1],
|
|
1070
|
+
});
|
|
1071
|
+
}
|
|
1072
|
+
return chips;
|
|
929
1073
|
}
|
|
930
|
-
|
|
931
|
-
|
|
1074
|
+
clear(name = null) {
|
|
1075
|
+
if (name === 'from') {
|
|
1076
|
+
delete this.value.from;
|
|
1077
|
+
if (this.defaultValue?.from) {
|
|
1078
|
+
this.value.from = this.defaultValue.from;
|
|
1079
|
+
}
|
|
1080
|
+
this.value = { ...this.value };
|
|
1081
|
+
}
|
|
1082
|
+
else if (name === 'to') {
|
|
1083
|
+
delete this.value.to;
|
|
1084
|
+
if (this.defaultValue?.to) {
|
|
1085
|
+
this.value.to = this.defaultValue.to;
|
|
1086
|
+
}
|
|
1087
|
+
this.value = { ...this.value };
|
|
1088
|
+
}
|
|
1089
|
+
else {
|
|
1090
|
+
this.value = this.defaultValue ? { ...this.defaultValue } : {};
|
|
1091
|
+
}
|
|
932
1092
|
}
|
|
933
1093
|
}
|
|
934
1094
|
|
|
935
|
-
class
|
|
1095
|
+
class DateRangeItem extends BaseDateRangeItem {
|
|
936
1096
|
static create(config, filter) {
|
|
937
|
-
return new
|
|
1097
|
+
return new DateRangeItem(config, null, filter);
|
|
938
1098
|
}
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
value = super.value.value;
|
|
945
|
-
return value;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
class DateTimeRangeItem extends BaseDateRangeItem {
|
|
1102
|
+
static create(config, filter) {
|
|
1103
|
+
return new DateTimeRangeItem(config, null, filter);
|
|
946
1104
|
}
|
|
947
|
-
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
class RangeItem extends BaseItem {
|
|
1108
|
+
_additionalConfig;
|
|
1109
|
+
_filter;
|
|
1110
|
+
constructor(itemConfig, _additionalConfig, _filter) {
|
|
1111
|
+
super(itemConfig, _additionalConfig, _filter);
|
|
1112
|
+
this._additionalConfig = _additionalConfig;
|
|
1113
|
+
this._filter = _filter;
|
|
1114
|
+
this.options = itemConfig.options;
|
|
1115
|
+
this.prefix = itemConfig.prefix;
|
|
1116
|
+
this.suffix = itemConfig.suffix;
|
|
1117
|
+
}
|
|
1118
|
+
static create(config, additionalConfig, filter) {
|
|
1119
|
+
return new RangeItem(config, additionalConfig, filter);
|
|
1120
|
+
}
|
|
1121
|
+
get query() {
|
|
1122
|
+
const value = this.value;
|
|
1123
|
+
const name = this.name;
|
|
1124
|
+
const params = {};
|
|
1125
|
+
const paramMinName = getRangeName(name, 'min');
|
|
1126
|
+
const paramMaxName = getRangeName(name, 'max');
|
|
1127
|
+
if (isObject(value)) {
|
|
1128
|
+
params[paramMinName] = value.min || undefined;
|
|
1129
|
+
params[paramMaxName] = value.max || undefined;
|
|
1130
|
+
}
|
|
1131
|
+
else {
|
|
1132
|
+
params[paramMinName] = undefined;
|
|
1133
|
+
params[paramMaxName] = undefined;
|
|
1134
|
+
}
|
|
1135
|
+
return params;
|
|
1136
|
+
}
|
|
1137
|
+
get chips() {
|
|
1138
|
+
const chips = [];
|
|
1139
|
+
if (this.value.min) {
|
|
1140
|
+
chips.push({
|
|
1141
|
+
name: 'min',
|
|
1142
|
+
label: this.label[0],
|
|
1143
|
+
value: this.value.min,
|
|
1144
|
+
});
|
|
1145
|
+
}
|
|
1146
|
+
if (this.value.max) {
|
|
1147
|
+
chips.push({
|
|
1148
|
+
name: 'max',
|
|
1149
|
+
label: this.label[1],
|
|
1150
|
+
value: this.value.max,
|
|
1151
|
+
});
|
|
1152
|
+
}
|
|
1153
|
+
return chips;
|
|
1154
|
+
}
|
|
1155
|
+
clear(name = null) {
|
|
1156
|
+
let value = this.value;
|
|
1157
|
+
if (name === 'min') {
|
|
1158
|
+
value.min = this.defaultValue?.min;
|
|
1159
|
+
}
|
|
1160
|
+
else if (name === 'max') {
|
|
1161
|
+
value.max = this.defaultValue?.max;
|
|
1162
|
+
}
|
|
1163
|
+
else {
|
|
1164
|
+
value = this.defaultValue ? { ...this.defaultValue } : {};
|
|
1165
|
+
}
|
|
1166
|
+
this.value = { ...value };
|
|
1167
|
+
}
|
|
1168
|
+
get hasValue() {
|
|
1169
|
+
return this.value?.min !== undefined || super.value?.max !== undefined;
|
|
1170
|
+
}
|
|
1171
|
+
setValue(value, emitChange = true) {
|
|
1172
|
+
super.setValue({
|
|
1173
|
+
min: value?.min,
|
|
1174
|
+
max: value?.max,
|
|
1175
|
+
}, emitChange);
|
|
1176
|
+
}
|
|
1177
|
+
init(value) {
|
|
1178
|
+
return super.init(value)
|
|
1179
|
+
.pipe(tap$1(() => {
|
|
1180
|
+
if (!this.label) {
|
|
1181
|
+
this.label = ['Min', 'Max'];
|
|
1182
|
+
}
|
|
1183
|
+
if (!this.value) {
|
|
1184
|
+
this.value = this.defaultValue || {};
|
|
1185
|
+
}
|
|
1186
|
+
}));
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
class WeekItem extends BaseItem {
|
|
1191
|
+
_additionalConfig;
|
|
1192
|
+
_filter;
|
|
1193
|
+
constructor(itemConfig, _additionalConfig, _filter) {
|
|
1194
|
+
super(itemConfig, _additionalConfig, _filter);
|
|
1195
|
+
this._additionalConfig = _additionalConfig;
|
|
1196
|
+
this._filter = _filter;
|
|
1197
|
+
this.seedDate = itemConfig.seedDate;
|
|
1198
|
+
}
|
|
1199
|
+
static create(config, filter) {
|
|
1200
|
+
return new WeekItem(config, null, filter);
|
|
1201
|
+
}
|
|
1202
|
+
setValue(value, emitChange = true) {
|
|
1203
|
+
if (value) {
|
|
1204
|
+
value.from = parseDate(value.from);
|
|
1205
|
+
value.to = parseDate(value.to);
|
|
1206
|
+
value.period = parseInt(value.period, 10) || undefined;
|
|
1207
|
+
}
|
|
1208
|
+
super.setValue(value, emitChange);
|
|
1209
|
+
}
|
|
1210
|
+
get query() {
|
|
1211
|
+
const value = this.value;
|
|
1212
|
+
const name = this.name;
|
|
1213
|
+
const paramFromName = getRangeName(name, 'from');
|
|
1214
|
+
const paramToName = getRangeName(name, 'to');
|
|
1215
|
+
const paramPeriodName = `${name}Period`;
|
|
1216
|
+
return {
|
|
1217
|
+
[paramFromName]: value?.from || undefined,
|
|
1218
|
+
[paramToName]: value?.to || undefined,
|
|
1219
|
+
[paramPeriodName]: value?.period || undefined,
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
get chips() {
|
|
1223
|
+
if (!this.hasValue) {
|
|
1224
|
+
return [];
|
|
1225
|
+
}
|
|
1226
|
+
return [
|
|
1227
|
+
{
|
|
1228
|
+
value: formatPeriodObject(this.value),
|
|
1229
|
+
label: this.label,
|
|
1230
|
+
},
|
|
1231
|
+
];
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
/**
|
|
1236
|
+
* We need this function because when we store persisted/query/remote filter values
|
|
1237
|
+
* it stores with different format, ex.: Range will be stored as RangeFrom && RangeTo
|
|
1238
|
+
* and in this case we don't know how to restroe those values.
|
|
1239
|
+
*
|
|
1240
|
+
* This function do convertation for those kinds of stored values
|
|
1241
|
+
*
|
|
1242
|
+
* @param params
|
|
1243
|
+
* @param items
|
|
1244
|
+
* @param paramsCase
|
|
1245
|
+
*/
|
|
1246
|
+
function restoreItems(params, items) {
|
|
1247
|
+
const result = {};
|
|
1248
|
+
Object.keys(params)
|
|
1249
|
+
.forEach((name) => {
|
|
1250
|
+
const item = findItemWidthName(items, name);
|
|
1251
|
+
if (item) {
|
|
1252
|
+
result[item.name] = parseItemValueFromStored(item, params);
|
|
1253
|
+
}
|
|
1254
|
+
});
|
|
1255
|
+
return result;
|
|
1256
|
+
}
|
|
1257
|
+
function findItemWidthName(items, name) {
|
|
1258
|
+
return items
|
|
1259
|
+
.find((filterItem) => {
|
|
1260
|
+
if (filterItem instanceof RangeItem) {
|
|
1261
|
+
return name === getRangeName(filterItem.name, 'min') ||
|
|
1262
|
+
name === getRangeName(filterItem.name, 'max') ||
|
|
1263
|
+
name === filterItem.name;
|
|
1264
|
+
}
|
|
1265
|
+
else if (filterItem instanceof DateRangeItem || filterItem instanceof DateTimeRangeItem) {
|
|
1266
|
+
return name === getRangeName(filterItem.name, 'from') ||
|
|
1267
|
+
name === getRangeName(filterItem.name, 'to');
|
|
1268
|
+
}
|
|
1269
|
+
else if (filterItem instanceof WeekItem) {
|
|
1270
|
+
return name === getRangeName(filterItem.name, 'from')
|
|
1271
|
+
|| name === getRangeName(filterItem.name, 'to')
|
|
1272
|
+
|| name === `${filterItem.name}Period`;
|
|
1273
|
+
}
|
|
1274
|
+
return filterItem.name === name;
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
1277
|
+
|
|
1278
|
+
class BaseAutocompleteItem extends BaseItem {
|
|
1279
|
+
_additionalConfig;
|
|
1280
|
+
_filter;
|
|
1281
|
+
search;
|
|
1282
|
+
get valuesFn() {
|
|
1283
|
+
return this._valuesFn;
|
|
1284
|
+
}
|
|
1285
|
+
constructor(itemConfig, _additionalConfig, _filter) {
|
|
1286
|
+
super(itemConfig, _additionalConfig, _filter);
|
|
1287
|
+
this._additionalConfig = _additionalConfig;
|
|
1288
|
+
this._filter = _filter;
|
|
1289
|
+
this.fetchOnFocus = itemConfig.fetchOnFocus ?? true;
|
|
1290
|
+
}
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
class AutocompleteChipsItem extends BaseAutocompleteItem {
|
|
1294
|
+
_additionalConfig;
|
|
1295
|
+
_filter;
|
|
1296
|
+
constructor(itemConfig, _additionalConfig, _filter) {
|
|
1297
|
+
super(itemConfig, _additionalConfig, _filter);
|
|
1298
|
+
this._additionalConfig = _additionalConfig;
|
|
1299
|
+
this._filter = _filter;
|
|
1300
|
+
this.chipImage = itemConfig.chipImage ?? 'image';
|
|
1301
|
+
this.chipIcon = itemConfig.chipIcon;
|
|
1302
|
+
this.chipIconColor = itemConfig.chipIconColor;
|
|
1303
|
+
this.chipColor = itemConfig.chipColor;
|
|
1304
|
+
this.chipBackground = itemConfig.chipBackground;
|
|
1305
|
+
this.chipClass = itemConfig.chipClass;
|
|
1306
|
+
this.panelActions = itemConfig.panelActions || [];
|
|
1307
|
+
}
|
|
1308
|
+
static create(config, filter) {
|
|
1309
|
+
return new AutocompleteChipsItem(config, null, filter);
|
|
1310
|
+
}
|
|
1311
|
+
get queryParam() {
|
|
1312
|
+
if (!this.hasValue) {
|
|
1313
|
+
return {};
|
|
1314
|
+
}
|
|
1315
|
+
return {
|
|
1316
|
+
[this.name]: this.value
|
|
1317
|
+
.filter((item) => !!item.value)
|
|
1318
|
+
.map((item) => {
|
|
1319
|
+
return `${item.value}:${encodeQueryParam(item.name)}`;
|
|
1320
|
+
})
|
|
1321
|
+
.join(','),
|
|
1322
|
+
};
|
|
1323
|
+
}
|
|
1324
|
+
get query() {
|
|
1325
|
+
if (!this.hasValue) {
|
|
1326
|
+
return {};
|
|
1327
|
+
}
|
|
1328
|
+
const value = this.value;
|
|
1329
|
+
const name = this.name;
|
|
1330
|
+
const params = {};
|
|
1331
|
+
if (Array.isArray(value)) {
|
|
1332
|
+
params[this.name] = value
|
|
1333
|
+
.filter((item) => !!item.value)
|
|
1334
|
+
.map((item) => item.value)
|
|
1335
|
+
.join(',');
|
|
1336
|
+
}
|
|
1337
|
+
else {
|
|
1338
|
+
params[name] = value;
|
|
1339
|
+
}
|
|
1340
|
+
return params;
|
|
1341
|
+
}
|
|
1342
|
+
get chips() {
|
|
1343
|
+
return this.hasValue ? [
|
|
1344
|
+
{
|
|
1345
|
+
value: super.value
|
|
1346
|
+
.reduce((acc, i) => {
|
|
1347
|
+
acc.push((`${i.name}`).trim());
|
|
1348
|
+
return acc;
|
|
1349
|
+
}, [])
|
|
1350
|
+
.join(', '),
|
|
1351
|
+
label: this.label,
|
|
1352
|
+
},
|
|
1353
|
+
] : [];
|
|
1354
|
+
}
|
|
1355
|
+
get hasValue() {
|
|
1356
|
+
return Array.isArray(super.value) && super.value.length > 0;
|
|
1357
|
+
}
|
|
1358
|
+
setValue(value, emitChange = true) {
|
|
1359
|
+
super.setValue(Array.isArray(value) ? value : [], emitChange);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
class AutocompleteItem extends BaseAutocompleteItem {
|
|
1364
|
+
static create(config, filter) {
|
|
1365
|
+
return new AutocompleteItem(config, null, filter);
|
|
1366
|
+
}
|
|
1367
|
+
get value() {
|
|
1368
|
+
let value = clone(super.value);
|
|
1369
|
+
if (!super.value || super.value.value === undefined) {
|
|
1370
|
+
return undefined;
|
|
1371
|
+
}
|
|
1372
|
+
value = super.value.value;
|
|
1373
|
+
return value;
|
|
1374
|
+
}
|
|
1375
|
+
get query() {
|
|
948
1376
|
const value = this.value;
|
|
949
1377
|
const name = this.name;
|
|
950
1378
|
const params = {};
|
|
@@ -972,12 +1400,6 @@ class CheckboxItem extends BaseItem {
|
|
|
972
1400
|
this._unchecked = itemConfig.unchecked ? toString(itemConfig.unchecked) : undefined;
|
|
973
1401
|
this.defaultValue = itemConfig.default;
|
|
974
1402
|
}
|
|
975
|
-
init(value) {
|
|
976
|
-
return super.init(value)
|
|
977
|
-
.pipe(tap(() => {
|
|
978
|
-
this.value = value === 'true' || value === true;
|
|
979
|
-
}));
|
|
980
|
-
}
|
|
981
1403
|
get checked() {
|
|
982
1404
|
return this._checked;
|
|
983
1405
|
}
|
|
@@ -1011,7 +1433,7 @@ class CheckboxItem extends BaseItem {
|
|
|
1011
1433
|
return {};
|
|
1012
1434
|
}
|
|
1013
1435
|
return {
|
|
1014
|
-
[this.name]:
|
|
1436
|
+
[this.name]: 'true',
|
|
1015
1437
|
};
|
|
1016
1438
|
}
|
|
1017
1439
|
clear() {
|
|
@@ -1040,7 +1462,7 @@ class ChipsItem extends BaseItem {
|
|
|
1040
1462
|
}
|
|
1041
1463
|
return {
|
|
1042
1464
|
[this.name]: this.value
|
|
1043
|
-
.map((item) => `${item.value}:${item.name}`)
|
|
1465
|
+
.map((item) => `${item.value}:${encodeQueryParam(item.name)}`)
|
|
1044
1466
|
.join(','),
|
|
1045
1467
|
};
|
|
1046
1468
|
}
|
|
@@ -1085,247 +1507,55 @@ class BaseDateItem extends BaseItem {
|
|
|
1085
1507
|
constructor(itemConfig, _additionalConfig, _filter) {
|
|
1086
1508
|
super(itemConfig, _additionalConfig, _filter);
|
|
1087
1509
|
this._additionalConfig = _additionalConfig;
|
|
1088
|
-
this._filter = _filter;
|
|
1089
|
-
this.maxYear = itemConfig.maxYear;
|
|
1090
|
-
this.mode = itemConfig.mode || ItemDateMode.Calendar;
|
|
1091
|
-
}
|
|
1092
|
-
setValue(value, emitChange = true) {
|
|
1093
|
-
if (value) {
|
|
1094
|
-
if (!isDate(value) || !isValid(value)) {
|
|
1095
|
-
value = parseISO(value);
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1098
|
-
super.setValue(value, emitChange);
|
|
1099
|
-
}
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
class DateItem extends BaseDateItem {
|
|
1103
|
-
static create(config, filter) {
|
|
1104
|
-
return new DateItem(config, null, filter);
|
|
1105
|
-
}
|
|
1106
|
-
get queryParam() {
|
|
1107
|
-
if (!this.hasValue) {
|
|
1108
|
-
return {};
|
|
1109
|
-
}
|
|
1110
|
-
return {
|
|
1111
|
-
[this.name]: iso8601(super.value),
|
|
1112
|
-
};
|
|
1113
|
-
}
|
|
1114
|
-
get chips() {
|
|
1115
|
-
if (!this.hasValue) {
|
|
1116
|
-
return [];
|
|
1117
|
-
}
|
|
1118
|
-
let dateFormat = 'date';
|
|
1119
|
-
if (this.mode === ItemDateMode.ScrollMonthYear) {
|
|
1120
|
-
dateFormat = 'full-date-dayless';
|
|
1121
|
-
}
|
|
1122
|
-
return [
|
|
1123
|
-
{
|
|
1124
|
-
value: format(super.value, dateFormat),
|
|
1125
|
-
label: this.label,
|
|
1126
|
-
},
|
|
1127
|
-
];
|
|
1128
|
-
}
|
|
1129
|
-
}
|
|
1130
|
-
|
|
1131
|
-
function getRangeName(name, range) {
|
|
1132
|
-
return name.concat(range.charAt(0).toUpperCase()).concat(range.slice(1));
|
|
1133
|
-
}
|
|
1134
|
-
|
|
1135
|
-
class BaseDateRangeItem extends BaseItem {
|
|
1136
|
-
get isTypeDateRange() {
|
|
1137
|
-
return this.type === ItemType.DateRange;
|
|
1138
|
-
}
|
|
1139
|
-
get isTypeDateTimeRange() {
|
|
1140
|
-
return this.type === ItemType.DateTimeRange;
|
|
1141
|
-
}
|
|
1142
|
-
get hasValue() {
|
|
1143
|
-
return this.value?.from instanceof Date || this.value?.to instanceof Date;
|
|
1144
|
-
}
|
|
1145
|
-
setValue(value, emitChange = true) {
|
|
1146
|
-
let from = value?.from;
|
|
1147
|
-
let to = value?.to;
|
|
1148
|
-
if (value) {
|
|
1149
|
-
if (from && (!isDate(from) || !isValid(from))) {
|
|
1150
|
-
from = parseISO(from);
|
|
1151
|
-
}
|
|
1152
|
-
if (to && (!isDate(to) || !isValid(to))) {
|
|
1153
|
-
to = parseISO(to);
|
|
1154
|
-
}
|
|
1155
|
-
}
|
|
1156
|
-
super.setValue({ from, to }, emitChange);
|
|
1157
|
-
}
|
|
1158
|
-
get queryParam() {
|
|
1159
|
-
if (!this.hasValue) {
|
|
1160
|
-
return {};
|
|
1161
|
-
}
|
|
1162
|
-
const value = {};
|
|
1163
|
-
const paramFromName = getRangeName(this.name, 'from');
|
|
1164
|
-
const paramToName = getRangeName(this.name, 'to');
|
|
1165
|
-
if (this.value.from) {
|
|
1166
|
-
value[paramFromName] = iso8601(this.value.from);
|
|
1167
|
-
}
|
|
1168
|
-
if (this.value.to) {
|
|
1169
|
-
value[paramToName] = iso8601(this.value.to);
|
|
1170
|
-
}
|
|
1171
|
-
return value;
|
|
1172
|
-
}
|
|
1173
|
-
get query() {
|
|
1174
|
-
if (!this.hasValue) {
|
|
1175
|
-
return {};
|
|
1176
|
-
}
|
|
1177
|
-
const value = {};
|
|
1178
|
-
const paramFromName = getRangeName(this.name, 'from');
|
|
1179
|
-
const paramToName = getRangeName(this.name, 'to');
|
|
1180
|
-
if (this.value.from) {
|
|
1181
|
-
value[paramFromName] = this.value.from;
|
|
1182
|
-
}
|
|
1183
|
-
if (this.value.to) {
|
|
1184
|
-
value[paramToName] = this.value.to;
|
|
1185
|
-
}
|
|
1186
|
-
return value;
|
|
1187
|
-
}
|
|
1188
|
-
get chips() {
|
|
1189
|
-
const dateFormat = this.type === ItemType.DateRange ? 'date' : 'date-time';
|
|
1190
|
-
const chips = [];
|
|
1191
|
-
if (this.value?.from) {
|
|
1192
|
-
chips.push({
|
|
1193
|
-
name: 'from',
|
|
1194
|
-
value: format(this.value.from, dateFormat),
|
|
1195
|
-
label: this.label[0],
|
|
1196
|
-
});
|
|
1197
|
-
}
|
|
1198
|
-
if (this.value?.to) {
|
|
1199
|
-
chips.push({
|
|
1200
|
-
name: 'to',
|
|
1201
|
-
value: format(this.value.to, dateFormat),
|
|
1202
|
-
label: this.label[1],
|
|
1203
|
-
});
|
|
1204
|
-
}
|
|
1205
|
-
return chips;
|
|
1206
|
-
}
|
|
1207
|
-
clear(name = null) {
|
|
1208
|
-
if (name === 'from') {
|
|
1209
|
-
delete this.value.from;
|
|
1210
|
-
if (this.defaultValue?.from) {
|
|
1211
|
-
this.value.from = this.defaultValue.from;
|
|
1212
|
-
}
|
|
1213
|
-
this.value = { ...this.value };
|
|
1214
|
-
}
|
|
1215
|
-
else if (name === 'to') {
|
|
1216
|
-
delete this.value.to;
|
|
1217
|
-
if (this.defaultValue?.to) {
|
|
1218
|
-
this.value.to = this.defaultValue.to;
|
|
1219
|
-
}
|
|
1220
|
-
this.value = { ...this.value };
|
|
1221
|
-
}
|
|
1222
|
-
else {
|
|
1223
|
-
this.value = this.defaultValue ? { ...this.defaultValue } : {};
|
|
1224
|
-
}
|
|
1225
|
-
}
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1228
|
-
class DateRangeItem extends BaseDateRangeItem {
|
|
1229
|
-
static create(config, filter) {
|
|
1230
|
-
return new DateRangeItem(config, null, filter);
|
|
1231
|
-
}
|
|
1232
|
-
}
|
|
1233
|
-
|
|
1234
|
-
class DateTimeItem extends BaseDateItem {
|
|
1235
|
-
static create(config, filter) {
|
|
1236
|
-
return new DateTimeItem(config, null, filter);
|
|
1237
|
-
}
|
|
1238
|
-
get chips() {
|
|
1239
|
-
return [];
|
|
1240
|
-
}
|
|
1241
|
-
}
|
|
1242
|
-
|
|
1243
|
-
class DateTimeRangeItem extends BaseDateRangeItem {
|
|
1244
|
-
static create(config, filter) {
|
|
1245
|
-
return new DateTimeRangeItem(config, null, filter);
|
|
1246
|
-
}
|
|
1247
|
-
}
|
|
1248
|
-
|
|
1249
|
-
class RangeItem extends BaseItem {
|
|
1250
|
-
_additionalConfig;
|
|
1251
|
-
_filter;
|
|
1252
|
-
constructor(itemConfig, _additionalConfig, _filter) {
|
|
1253
|
-
super(itemConfig, _additionalConfig, _filter);
|
|
1254
|
-
this._additionalConfig = _additionalConfig;
|
|
1255
|
-
this._filter = _filter;
|
|
1256
|
-
this.options = itemConfig.options;
|
|
1257
|
-
this.prefix = itemConfig.prefix;
|
|
1258
|
-
this.suffix = itemConfig.suffix;
|
|
1259
|
-
}
|
|
1260
|
-
static create(config, additionalConfig, filter) {
|
|
1261
|
-
return new RangeItem(config, additionalConfig, filter);
|
|
1262
|
-
}
|
|
1263
|
-
get query() {
|
|
1264
|
-
const value = this.value;
|
|
1265
|
-
const name = this.name;
|
|
1266
|
-
const params = {};
|
|
1267
|
-
const paramMinName = getRangeName(name, 'min');
|
|
1268
|
-
const paramMaxName = getRangeName(name, 'max');
|
|
1269
|
-
if (isObject(value)) {
|
|
1270
|
-
params[paramMinName] = value.min || undefined;
|
|
1271
|
-
params[paramMaxName] = value.max || undefined;
|
|
1272
|
-
}
|
|
1273
|
-
else {
|
|
1274
|
-
params[paramMinName] = undefined;
|
|
1275
|
-
params[paramMaxName] = undefined;
|
|
1276
|
-
}
|
|
1277
|
-
return params;
|
|
1510
|
+
this._filter = _filter;
|
|
1511
|
+
this.maxYear = itemConfig.maxYear;
|
|
1512
|
+
this.mode = itemConfig.mode || ItemDateMode.Calendar;
|
|
1278
1513
|
}
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
label: this.label[0],
|
|
1285
|
-
value: this.value.min,
|
|
1286
|
-
});
|
|
1287
|
-
}
|
|
1288
|
-
if (this.value.max) {
|
|
1289
|
-
chips.push({
|
|
1290
|
-
name: 'max',
|
|
1291
|
-
label: this.label[1],
|
|
1292
|
-
value: this.value.max,
|
|
1293
|
-
});
|
|
1514
|
+
setValue(value, emitChange = true) {
|
|
1515
|
+
if (value) {
|
|
1516
|
+
if (!isDate(value) || !isValid(value)) {
|
|
1517
|
+
value = parseISO(value);
|
|
1518
|
+
}
|
|
1294
1519
|
}
|
|
1295
|
-
|
|
1520
|
+
super.setValue(value, emitChange);
|
|
1296
1521
|
}
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
class DateItem extends BaseDateItem {
|
|
1525
|
+
static create(config, filter) {
|
|
1526
|
+
return new DateItem(config, null, filter);
|
|
1527
|
+
}
|
|
1528
|
+
get queryParam() {
|
|
1529
|
+
if (!this.hasValue) {
|
|
1530
|
+
return {};
|
|
1301
1531
|
}
|
|
1302
|
-
|
|
1303
|
-
|
|
1532
|
+
return {
|
|
1533
|
+
[this.name]: iso8601(super.value),
|
|
1534
|
+
};
|
|
1535
|
+
}
|
|
1536
|
+
get chips() {
|
|
1537
|
+
if (!this.hasValue) {
|
|
1538
|
+
return [];
|
|
1304
1539
|
}
|
|
1305
|
-
|
|
1306
|
-
|
|
1540
|
+
let dateFormat = 'date';
|
|
1541
|
+
if (this.mode === ItemDateMode.ScrollMonthYear) {
|
|
1542
|
+
dateFormat = 'full-date-dayless';
|
|
1307
1543
|
}
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1544
|
+
return [
|
|
1545
|
+
{
|
|
1546
|
+
value: format(super.value, dateFormat),
|
|
1547
|
+
label: this.label,
|
|
1548
|
+
},
|
|
1549
|
+
];
|
|
1312
1550
|
}
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1551
|
+
}
|
|
1552
|
+
|
|
1553
|
+
class DateTimeItem extends BaseDateItem {
|
|
1554
|
+
static create(config, filter) {
|
|
1555
|
+
return new DateTimeItem(config, null, filter);
|
|
1318
1556
|
}
|
|
1319
|
-
|
|
1320
|
-
return
|
|
1321
|
-
.pipe(tap$1(() => {
|
|
1322
|
-
if (!this.label) {
|
|
1323
|
-
this.label = ['Min', 'Max'];
|
|
1324
|
-
}
|
|
1325
|
-
if (!this.value) {
|
|
1326
|
-
this.value = this.defaultValue || {};
|
|
1327
|
-
}
|
|
1328
|
-
}));
|
|
1557
|
+
get chips() {
|
|
1558
|
+
return [];
|
|
1329
1559
|
}
|
|
1330
1560
|
}
|
|
1331
1561
|
|
|
@@ -1456,58 +1686,6 @@ class TextItem extends BaseItem {
|
|
|
1456
1686
|
}
|
|
1457
1687
|
}
|
|
1458
1688
|
|
|
1459
|
-
function parseDate(value) {
|
|
1460
|
-
if (value && (!isDate(value) || !isValid(value))) {
|
|
1461
|
-
return parseISO(value);
|
|
1462
|
-
}
|
|
1463
|
-
return value;
|
|
1464
|
-
}
|
|
1465
|
-
|
|
1466
|
-
class WeekItem extends BaseItem {
|
|
1467
|
-
_additionalConfig;
|
|
1468
|
-
_filter;
|
|
1469
|
-
constructor(itemConfig, _additionalConfig, _filter) {
|
|
1470
|
-
super(itemConfig, _additionalConfig, _filter);
|
|
1471
|
-
this._additionalConfig = _additionalConfig;
|
|
1472
|
-
this._filter = _filter;
|
|
1473
|
-
this.seedDate = itemConfig.seedDate;
|
|
1474
|
-
}
|
|
1475
|
-
static create(config, filter) {
|
|
1476
|
-
return new WeekItem(config, null, filter);
|
|
1477
|
-
}
|
|
1478
|
-
setValue(value, emitChange = true) {
|
|
1479
|
-
if (value) {
|
|
1480
|
-
value.from = parseDate(value.from);
|
|
1481
|
-
value.to = parseDate(value.to);
|
|
1482
|
-
value.period = parseInt(value.period, 10) || undefined;
|
|
1483
|
-
}
|
|
1484
|
-
super.setValue(value, emitChange);
|
|
1485
|
-
}
|
|
1486
|
-
get query() {
|
|
1487
|
-
const value = this.value;
|
|
1488
|
-
const name = this.name;
|
|
1489
|
-
const paramFromName = getRangeName(name, 'from');
|
|
1490
|
-
const paramToName = getRangeName(name, 'to');
|
|
1491
|
-
const paramPeriodName = `${name}Period`;
|
|
1492
|
-
return {
|
|
1493
|
-
[paramFromName]: value?.from || undefined,
|
|
1494
|
-
[paramToName]: value?.to || undefined,
|
|
1495
|
-
[paramPeriodName]: value?.period || undefined,
|
|
1496
|
-
};
|
|
1497
|
-
}
|
|
1498
|
-
get chips() {
|
|
1499
|
-
if (!this.hasValue) {
|
|
1500
|
-
return [];
|
|
1501
|
-
}
|
|
1502
|
-
return [
|
|
1503
|
-
{
|
|
1504
|
-
value: formatPeriodObject(this.value),
|
|
1505
|
-
label: this.label,
|
|
1506
|
-
},
|
|
1507
|
-
];
|
|
1508
|
-
}
|
|
1509
|
-
}
|
|
1510
|
-
|
|
1511
1689
|
function createFilterItem(item, config, filter) {
|
|
1512
1690
|
switch (item.type) {
|
|
1513
1691
|
case ItemType.Select: {
|
|
@@ -1668,131 +1846,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
|
|
|
1668
1846
|
type: Injectable
|
|
1669
1847
|
}] });
|
|
1670
1848
|
|
|
1671
|
-
const QUERY_PARAM_DELIMITER = ':';
|
|
1672
|
-
|
|
1673
|
-
function filterToQueryParam(value, name) {
|
|
1674
|
-
return `${encodeURIComponent(value)}${QUERY_PARAM_DELIMITER}${encodeURIComponent(name)}`;
|
|
1675
|
-
}
|
|
1676
|
-
function filterFromQueryParam(param) {
|
|
1677
|
-
const parts = param.split(QUERY_PARAM_DELIMITER);
|
|
1678
|
-
return [decodeURIComponent(parts[0]), decodeURIComponent(parts[1])];
|
|
1679
|
-
}
|
|
1680
|
-
|
|
1681
|
-
function parseItemValueFromStored(item, params) {
|
|
1682
|
-
const param = params[item.name];
|
|
1683
|
-
switch (item.type) {
|
|
1684
|
-
case ItemType.Range: {
|
|
1685
|
-
const min = params[getRangeName(item.name, 'min')];
|
|
1686
|
-
const max = params[getRangeName(item.name, 'max')];
|
|
1687
|
-
return { min: min, max: max };
|
|
1688
|
-
}
|
|
1689
|
-
case ItemType.DateRange:
|
|
1690
|
-
case ItemType.DateTimeRange: {
|
|
1691
|
-
const from = params[getRangeName(item.name, 'from')];
|
|
1692
|
-
const to = params[getRangeName(item.name, 'to')];
|
|
1693
|
-
return { from: from, to: to };
|
|
1694
|
-
}
|
|
1695
|
-
case ItemType.Week: {
|
|
1696
|
-
const from = params[getRangeName(item.name, 'from')];
|
|
1697
|
-
const to = params[getRangeName(item.name, 'to')];
|
|
1698
|
-
const period = params[`${item.name}Period`];
|
|
1699
|
-
return { from, to, period };
|
|
1700
|
-
}
|
|
1701
|
-
case ItemType.Select: {
|
|
1702
|
-
return itemTypeSelect(item, param);
|
|
1703
|
-
}
|
|
1704
|
-
case ItemType.Checkbox: {
|
|
1705
|
-
return param === 'true' || param === true;
|
|
1706
|
-
}
|
|
1707
|
-
case ItemType.AutoComplete: {
|
|
1708
|
-
const filterParts = filterFromQueryParam(param);
|
|
1709
|
-
return {
|
|
1710
|
-
name: filterParts[1],
|
|
1711
|
-
value: filterParts[0],
|
|
1712
|
-
};
|
|
1713
|
-
}
|
|
1714
|
-
case ItemType.AutoCompleteChips:
|
|
1715
|
-
case ItemType.Chips: {
|
|
1716
|
-
const filterParts = param.split(',');
|
|
1717
|
-
return filterParts.reduce((arry, value) => {
|
|
1718
|
-
const chipParts = filterFromQueryParam(value);
|
|
1719
|
-
arry.push({
|
|
1720
|
-
name: chipParts[1],
|
|
1721
|
-
value: chipParts[0],
|
|
1722
|
-
});
|
|
1723
|
-
return arry;
|
|
1724
|
-
}, []);
|
|
1725
|
-
}
|
|
1726
|
-
default: {
|
|
1727
|
-
return param;
|
|
1728
|
-
}
|
|
1729
|
-
}
|
|
1730
|
-
}
|
|
1731
|
-
function itemTypeSelect(item, param) {
|
|
1732
|
-
if (!param) {
|
|
1733
|
-
return [];
|
|
1734
|
-
}
|
|
1735
|
-
const values = param.split(',');
|
|
1736
|
-
if (item.isolate) {
|
|
1737
|
-
const isolatedValue = item.isolateValues;
|
|
1738
|
-
item.isolate = arraysHaveSameElements(isolatedValue, values);
|
|
1739
|
-
return item.isolate
|
|
1740
|
-
? isolatedValue
|
|
1741
|
-
: values;
|
|
1742
|
-
}
|
|
1743
|
-
return values;
|
|
1744
|
-
}
|
|
1745
|
-
function arraysHaveSameElements(arr1, arr2) {
|
|
1746
|
-
arr1 = [...arr1].sort();
|
|
1747
|
-
arr2 = [...arr2].sort();
|
|
1748
|
-
return arr1.some((item) => {
|
|
1749
|
-
return arr2.includes(item);
|
|
1750
|
-
});
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
/**
|
|
1754
|
-
* We need this function because when we store persisted/query/remote filter values
|
|
1755
|
-
* it stores with different format, ex.: Range will be stored as RangeFrom && RangeTo
|
|
1756
|
-
* and in this case we don't know how to restroe those values.
|
|
1757
|
-
*
|
|
1758
|
-
* This function do convertation for those kinds of stored values
|
|
1759
|
-
*
|
|
1760
|
-
* @param params
|
|
1761
|
-
* @param items
|
|
1762
|
-
* @param paramsCase
|
|
1763
|
-
*/
|
|
1764
|
-
function restoreItems(params, items) {
|
|
1765
|
-
const result = {};
|
|
1766
|
-
Object.keys(params)
|
|
1767
|
-
.forEach((name) => {
|
|
1768
|
-
const item = findItemWidthName(items, name);
|
|
1769
|
-
if (item) {
|
|
1770
|
-
result[item.name] = parseItemValueFromStored(item, params);
|
|
1771
|
-
}
|
|
1772
|
-
});
|
|
1773
|
-
return result;
|
|
1774
|
-
}
|
|
1775
|
-
function findItemWidthName(items, name) {
|
|
1776
|
-
return items
|
|
1777
|
-
.find((filterItem) => {
|
|
1778
|
-
if (filterItem instanceof RangeItem) {
|
|
1779
|
-
return name === getRangeName(filterItem.name, 'min') ||
|
|
1780
|
-
name === getRangeName(filterItem.name, 'max') ||
|
|
1781
|
-
name === filterItem.name;
|
|
1782
|
-
}
|
|
1783
|
-
else if (filterItem instanceof DateRangeItem || filterItem instanceof DateTimeRangeItem) {
|
|
1784
|
-
return name === getRangeName(filterItem.name, 'from') ||
|
|
1785
|
-
name === getRangeName(filterItem.name, 'to');
|
|
1786
|
-
}
|
|
1787
|
-
else if (filterItem instanceof WeekItem) {
|
|
1788
|
-
return name === getRangeName(filterItem.name, 'from')
|
|
1789
|
-
|| name === getRangeName(filterItem.name, 'to')
|
|
1790
|
-
|| name === `${filterItem.name}Period`;
|
|
1791
|
-
}
|
|
1792
|
-
return filterItem.name === name;
|
|
1793
|
-
});
|
|
1794
|
-
}
|
|
1795
|
-
|
|
1796
1849
|
class SortController {
|
|
1797
1850
|
_name = null;
|
|
1798
1851
|
_direction = null;
|
|
@@ -1903,11 +1956,12 @@ class QueryParamController {
|
|
|
1903
1956
|
const url = new URL(window.location.href);
|
|
1904
1957
|
Object.keys(data)
|
|
1905
1958
|
.forEach((name) => {
|
|
1906
|
-
|
|
1959
|
+
const value = data[name];
|
|
1960
|
+
if (value === undefined || value === null) {
|
|
1907
1961
|
url.searchParams.delete(name);
|
|
1908
1962
|
}
|
|
1909
1963
|
else {
|
|
1910
|
-
url.searchParams.set(name,
|
|
1964
|
+
url.searchParams.set(name, value);
|
|
1911
1965
|
}
|
|
1912
1966
|
});
|
|
1913
1967
|
history.replaceState({}, null, url.pathname + decodeURIComponent(url.search));
|
|
@@ -4110,5 +4164,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
|
|
|
4110
4164
|
* Generated bundle index. Do not edit.
|
|
4111
4165
|
*/
|
|
4112
4166
|
|
|
4113
|
-
export { ActionMode, AutocompleteChipsItem, AutocompleteItem, BaseItem, ButtonStyle, CheckboxItem, ChipsItem, DateItem, DateRangeItem, DateTimeItem, DateTimeRangeItem, FS_FILTER_CONFIG, FilterComponent, FilterItemComponent, FilterStatusBarDirective, FsFilterModule, ItemDateMode, ItemType, MenuActionMode,
|
|
4167
|
+
export { ActionMode, AutocompleteChipsItem, AutocompleteItem, BaseItem, ButtonStyle, CheckboxItem, ChipsItem, DateItem, DateRangeItem, DateTimeItem, DateTimeRangeItem, FS_FILTER_CONFIG, FilterComponent, FilterItemComponent, FilterStatusBarDirective, FsFilterModule, ItemDateMode, ItemType, MenuActionMode, RangeItem, SavedFilterController, SelectItem, TextItem, filterFromQueryParam, filterToQueryParam };
|
|
4114
4168
|
//# sourceMappingURL=firestitch-filter.mjs.map
|