@firestitch/filter 18.2.20 → 18.2.22
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/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/base-item.mjs +2 -4
- package/esm2022/app/services/filter-controller.service.mjs +5 -2
- package/esm2022/app/services/query-param-controller.service.mjs +4 -3
- package/esm2022/public_api.mjs +1 -3
- package/fesm2022/firestitch-filter.mjs +546 -485
- 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;
|
|
@@ -784,9 +933,7 @@ class BaseItem {
|
|
|
784
933
|
this.loadDefault(),
|
|
785
934
|
this.loadValues(),
|
|
786
935
|
])
|
|
787
|
-
.pipe(tap(() =>
|
|
788
|
-
this.initValue(value);
|
|
789
|
-
}));
|
|
936
|
+
.pipe(tap(() => this.initValue(value)));
|
|
790
937
|
}
|
|
791
938
|
loadDefault() {
|
|
792
939
|
return this.defaultValueFn()
|
|
@@ -852,98 +999,377 @@ class BaseItem {
|
|
|
852
999
|
}
|
|
853
1000
|
}
|
|
854
1001
|
|
|
855
|
-
class
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
search;
|
|
859
|
-
get valuesFn() {
|
|
860
|
-
return this._valuesFn;
|
|
1002
|
+
class BaseDateRangeItem extends BaseItem {
|
|
1003
|
+
get isTypeDateRange() {
|
|
1004
|
+
return this.type === ItemType.DateRange;
|
|
861
1005
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
this._additionalConfig = _additionalConfig;
|
|
865
|
-
this._filter = _filter;
|
|
866
|
-
this.fetchOnFocus = itemConfig.fetchOnFocus ?? true;
|
|
1006
|
+
get isTypeDateTimeRange() {
|
|
1007
|
+
return this.type === ItemType.DateTimeRange;
|
|
867
1008
|
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
class AutocompleteChipsItem extends BaseAutocompleteItem {
|
|
871
|
-
_additionalConfig;
|
|
872
|
-
_filter;
|
|
873
|
-
constructor(itemConfig, _additionalConfig, _filter) {
|
|
874
|
-
super(itemConfig, _additionalConfig, _filter);
|
|
875
|
-
this._additionalConfig = _additionalConfig;
|
|
876
|
-
this._filter = _filter;
|
|
877
|
-
this.chipImage = itemConfig.chipImage ?? 'image';
|
|
878
|
-
this.chipIcon = itemConfig.chipIcon;
|
|
879
|
-
this.chipIconColor = itemConfig.chipIconColor;
|
|
880
|
-
this.chipColor = itemConfig.chipColor;
|
|
881
|
-
this.chipBackground = itemConfig.chipBackground;
|
|
882
|
-
this.chipClass = itemConfig.chipClass;
|
|
883
|
-
this.panelActions = itemConfig.panelActions || [];
|
|
1009
|
+
get hasValue() {
|
|
1010
|
+
return this.value?.from instanceof Date || this.value?.to instanceof Date;
|
|
884
1011
|
}
|
|
885
|
-
|
|
886
|
-
|
|
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);
|
|
887
1024
|
}
|
|
888
1025
|
get queryParam() {
|
|
889
1026
|
if (!this.hasValue) {
|
|
890
1027
|
return {};
|
|
891
1028
|
}
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
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;
|
|
897
1039
|
}
|
|
898
1040
|
get query() {
|
|
899
1041
|
if (!this.hasValue) {
|
|
900
1042
|
return {};
|
|
901
1043
|
}
|
|
902
|
-
const value =
|
|
903
|
-
const
|
|
904
|
-
const
|
|
905
|
-
if (
|
|
906
|
-
|
|
907
|
-
.filter((item) => !!item.value)
|
|
908
|
-
.map((item) => item.value)
|
|
909
|
-
.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;
|
|
910
1049
|
}
|
|
911
|
-
|
|
912
|
-
|
|
1050
|
+
if (this.value.to) {
|
|
1051
|
+
value[paramToName] = this.value.to;
|
|
913
1052
|
}
|
|
914
|
-
return
|
|
1053
|
+
return value;
|
|
915
1054
|
}
|
|
916
1055
|
get chips() {
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
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;
|
|
928
1073
|
}
|
|
929
|
-
|
|
930
|
-
|
|
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
|
+
}
|
|
931
1092
|
}
|
|
932
|
-
|
|
933
|
-
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
class DateRangeItem extends BaseDateRangeItem {
|
|
1096
|
+
static create(config, filter) {
|
|
1097
|
+
return new DateRangeItem(config, null, filter);
|
|
934
1098
|
}
|
|
935
1099
|
}
|
|
936
1100
|
|
|
937
|
-
class
|
|
1101
|
+
class DateTimeRangeItem extends BaseDateRangeItem {
|
|
938
1102
|
static create(config, filter) {
|
|
939
|
-
return new
|
|
1103
|
+
return new DateTimeRangeItem(config, null, filter);
|
|
940
1104
|
}
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
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;
|
|
947
1373
|
return value;
|
|
948
1374
|
}
|
|
949
1375
|
get query() {
|
|
@@ -1089,245 +1515,53 @@ class BaseDateItem extends BaseItem {
|
|
|
1089
1515
|
this._additionalConfig = _additionalConfig;
|
|
1090
1516
|
this._filter = _filter;
|
|
1091
1517
|
this.maxYear = itemConfig.maxYear;
|
|
1092
|
-
this.mode = itemConfig.mode || ItemDateMode.Calendar;
|
|
1093
|
-
}
|
|
1094
|
-
setValue(value, emitChange = true) {
|
|
1095
|
-
if (value) {
|
|
1096
|
-
if (!isDate(value) || !isValid(value)) {
|
|
1097
|
-
value = parseISO(value);
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
super.setValue(value, emitChange);
|
|
1101
|
-
}
|
|
1102
|
-
}
|
|
1103
|
-
|
|
1104
|
-
class DateItem extends BaseDateItem {
|
|
1105
|
-
static create(config, filter) {
|
|
1106
|
-
return new DateItem(config, null, filter);
|
|
1107
|
-
}
|
|
1108
|
-
get queryParam() {
|
|
1109
|
-
if (!this.hasValue) {
|
|
1110
|
-
return {};
|
|
1111
|
-
}
|
|
1112
|
-
return {
|
|
1113
|
-
[this.name]: iso8601(super.value),
|
|
1114
|
-
};
|
|
1115
|
-
}
|
|
1116
|
-
get chips() {
|
|
1117
|
-
if (!this.hasValue) {
|
|
1118
|
-
return [];
|
|
1119
|
-
}
|
|
1120
|
-
let dateFormat = 'date';
|
|
1121
|
-
if (this.mode === ItemDateMode.ScrollMonthYear) {
|
|
1122
|
-
dateFormat = 'full-date-dayless';
|
|
1123
|
-
}
|
|
1124
|
-
return [
|
|
1125
|
-
{
|
|
1126
|
-
value: format(super.value, dateFormat),
|
|
1127
|
-
label: this.label,
|
|
1128
|
-
},
|
|
1129
|
-
];
|
|
1130
|
-
}
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
function getRangeName(name, range) {
|
|
1134
|
-
return name.concat(range.charAt(0).toUpperCase()).concat(range.slice(1));
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
class BaseDateRangeItem extends BaseItem {
|
|
1138
|
-
get isTypeDateRange() {
|
|
1139
|
-
return this.type === ItemType.DateRange;
|
|
1140
|
-
}
|
|
1141
|
-
get isTypeDateTimeRange() {
|
|
1142
|
-
return this.type === ItemType.DateTimeRange;
|
|
1143
|
-
}
|
|
1144
|
-
get hasValue() {
|
|
1145
|
-
return this.value?.from instanceof Date || this.value?.to instanceof Date;
|
|
1146
|
-
}
|
|
1147
|
-
setValue(value, emitChange = true) {
|
|
1148
|
-
let from = value?.from;
|
|
1149
|
-
let to = value?.to;
|
|
1150
|
-
if (value) {
|
|
1151
|
-
if (from && (!isDate(from) || !isValid(from))) {
|
|
1152
|
-
from = parseISO(from);
|
|
1153
|
-
}
|
|
1154
|
-
if (to && (!isDate(to) || !isValid(to))) {
|
|
1155
|
-
to = parseISO(to);
|
|
1156
|
-
}
|
|
1157
|
-
}
|
|
1158
|
-
super.setValue({ from, to }, emitChange);
|
|
1159
|
-
}
|
|
1160
|
-
get queryParam() {
|
|
1161
|
-
if (!this.hasValue) {
|
|
1162
|
-
return {};
|
|
1163
|
-
}
|
|
1164
|
-
const value = {};
|
|
1165
|
-
const paramFromName = getRangeName(this.name, 'from');
|
|
1166
|
-
const paramToName = getRangeName(this.name, 'to');
|
|
1167
|
-
if (this.value.from) {
|
|
1168
|
-
value[paramFromName] = iso8601(this.value.from);
|
|
1169
|
-
}
|
|
1170
|
-
if (this.value.to) {
|
|
1171
|
-
value[paramToName] = iso8601(this.value.to);
|
|
1172
|
-
}
|
|
1173
|
-
return value;
|
|
1174
|
-
}
|
|
1175
|
-
get query() {
|
|
1176
|
-
if (!this.hasValue) {
|
|
1177
|
-
return {};
|
|
1178
|
-
}
|
|
1179
|
-
const value = {};
|
|
1180
|
-
const paramFromName = getRangeName(this.name, 'from');
|
|
1181
|
-
const paramToName = getRangeName(this.name, 'to');
|
|
1182
|
-
if (this.value.from) {
|
|
1183
|
-
value[paramFromName] = this.value.from;
|
|
1184
|
-
}
|
|
1185
|
-
if (this.value.to) {
|
|
1186
|
-
value[paramToName] = this.value.to;
|
|
1187
|
-
}
|
|
1188
|
-
return value;
|
|
1189
|
-
}
|
|
1190
|
-
get chips() {
|
|
1191
|
-
const dateFormat = this.type === ItemType.DateRange ? 'date' : 'date-time';
|
|
1192
|
-
const chips = [];
|
|
1193
|
-
if (this.value?.from) {
|
|
1194
|
-
chips.push({
|
|
1195
|
-
name: 'from',
|
|
1196
|
-
value: format(this.value.from, dateFormat),
|
|
1197
|
-
label: this.label[0],
|
|
1198
|
-
});
|
|
1199
|
-
}
|
|
1200
|
-
if (this.value?.to) {
|
|
1201
|
-
chips.push({
|
|
1202
|
-
name: 'to',
|
|
1203
|
-
value: format(this.value.to, dateFormat),
|
|
1204
|
-
label: this.label[1],
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
return chips;
|
|
1208
|
-
}
|
|
1209
|
-
clear(name = null) {
|
|
1210
|
-
if (name === 'from') {
|
|
1211
|
-
delete this.value.from;
|
|
1212
|
-
if (this.defaultValue?.from) {
|
|
1213
|
-
this.value.from = this.defaultValue.from;
|
|
1214
|
-
}
|
|
1215
|
-
this.value = { ...this.value };
|
|
1216
|
-
}
|
|
1217
|
-
else if (name === 'to') {
|
|
1218
|
-
delete this.value.to;
|
|
1219
|
-
if (this.defaultValue?.to) {
|
|
1220
|
-
this.value.to = this.defaultValue.to;
|
|
1221
|
-
}
|
|
1222
|
-
this.value = { ...this.value };
|
|
1223
|
-
}
|
|
1224
|
-
else {
|
|
1225
|
-
this.value = this.defaultValue ? { ...this.defaultValue } : {};
|
|
1226
|
-
}
|
|
1227
|
-
}
|
|
1228
|
-
}
|
|
1229
|
-
|
|
1230
|
-
class DateRangeItem extends BaseDateRangeItem {
|
|
1231
|
-
static create(config, filter) {
|
|
1232
|
-
return new DateRangeItem(config, null, filter);
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
|
|
1236
|
-
class DateTimeItem extends BaseDateItem {
|
|
1237
|
-
static create(config, filter) {
|
|
1238
|
-
return new DateTimeItem(config, null, filter);
|
|
1239
|
-
}
|
|
1240
|
-
get chips() {
|
|
1241
|
-
return [];
|
|
1242
|
-
}
|
|
1243
|
-
}
|
|
1244
|
-
|
|
1245
|
-
class DateTimeRangeItem extends BaseDateRangeItem {
|
|
1246
|
-
static create(config, filter) {
|
|
1247
|
-
return new DateTimeRangeItem(config, null, filter);
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
|
|
1251
|
-
class RangeItem extends BaseItem {
|
|
1252
|
-
_additionalConfig;
|
|
1253
|
-
_filter;
|
|
1254
|
-
constructor(itemConfig, _additionalConfig, _filter) {
|
|
1255
|
-
super(itemConfig, _additionalConfig, _filter);
|
|
1256
|
-
this._additionalConfig = _additionalConfig;
|
|
1257
|
-
this._filter = _filter;
|
|
1258
|
-
this.options = itemConfig.options;
|
|
1259
|
-
this.prefix = itemConfig.prefix;
|
|
1260
|
-
this.suffix = itemConfig.suffix;
|
|
1261
|
-
}
|
|
1262
|
-
static create(config, additionalConfig, filter) {
|
|
1263
|
-
return new RangeItem(config, additionalConfig, filter);
|
|
1264
|
-
}
|
|
1265
|
-
get query() {
|
|
1266
|
-
const value = this.value;
|
|
1267
|
-
const name = this.name;
|
|
1268
|
-
const params = {};
|
|
1269
|
-
const paramMinName = getRangeName(name, 'min');
|
|
1270
|
-
const paramMaxName = getRangeName(name, 'max');
|
|
1271
|
-
if (isObject(value)) {
|
|
1272
|
-
params[paramMinName] = value.min || undefined;
|
|
1273
|
-
params[paramMaxName] = value.max || undefined;
|
|
1274
|
-
}
|
|
1275
|
-
else {
|
|
1276
|
-
params[paramMinName] = undefined;
|
|
1277
|
-
params[paramMaxName] = undefined;
|
|
1278
|
-
}
|
|
1279
|
-
return params;
|
|
1518
|
+
this.mode = itemConfig.mode || ItemDateMode.Calendar;
|
|
1280
1519
|
}
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
label: this.label[0],
|
|
1287
|
-
value: this.value.min,
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
if (this.value.max) {
|
|
1291
|
-
chips.push({
|
|
1292
|
-
name: 'max',
|
|
1293
|
-
label: this.label[1],
|
|
1294
|
-
value: this.value.max,
|
|
1295
|
-
});
|
|
1520
|
+
setValue(value, emitChange = true) {
|
|
1521
|
+
if (value) {
|
|
1522
|
+
if (!isDate(value) || !isValid(value)) {
|
|
1523
|
+
value = parseISO(value);
|
|
1524
|
+
}
|
|
1296
1525
|
}
|
|
1297
|
-
|
|
1526
|
+
super.setValue(value, emitChange);
|
|
1298
1527
|
}
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
class DateItem extends BaseDateItem {
|
|
1531
|
+
static create(config, filter) {
|
|
1532
|
+
return new DateItem(config, null, filter);
|
|
1533
|
+
}
|
|
1534
|
+
get queryParam() {
|
|
1535
|
+
if (!this.hasValue) {
|
|
1536
|
+
return {};
|
|
1303
1537
|
}
|
|
1304
|
-
|
|
1305
|
-
|
|
1538
|
+
return {
|
|
1539
|
+
[this.name]: iso8601(super.value),
|
|
1540
|
+
};
|
|
1541
|
+
}
|
|
1542
|
+
get chips() {
|
|
1543
|
+
if (!this.hasValue) {
|
|
1544
|
+
return [];
|
|
1306
1545
|
}
|
|
1307
|
-
|
|
1308
|
-
|
|
1546
|
+
let dateFormat = 'date';
|
|
1547
|
+
if (this.mode === ItemDateMode.ScrollMonthYear) {
|
|
1548
|
+
dateFormat = 'full-date-dayless';
|
|
1309
1549
|
}
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1550
|
+
return [
|
|
1551
|
+
{
|
|
1552
|
+
value: format(super.value, dateFormat),
|
|
1553
|
+
label: this.label,
|
|
1554
|
+
},
|
|
1555
|
+
];
|
|
1314
1556
|
}
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
class DateTimeItem extends BaseDateItem {
|
|
1560
|
+
static create(config, filter) {
|
|
1561
|
+
return new DateTimeItem(config, null, filter);
|
|
1320
1562
|
}
|
|
1321
|
-
|
|
1322
|
-
return
|
|
1323
|
-
.pipe(tap$1(() => {
|
|
1324
|
-
if (!this.label) {
|
|
1325
|
-
this.label = ['Min', 'Max'];
|
|
1326
|
-
}
|
|
1327
|
-
if (!this.value) {
|
|
1328
|
-
this.value = this.defaultValue || {};
|
|
1329
|
-
}
|
|
1330
|
-
}));
|
|
1563
|
+
get chips() {
|
|
1564
|
+
return [];
|
|
1331
1565
|
}
|
|
1332
1566
|
}
|
|
1333
1567
|
|
|
@@ -1458,58 +1692,6 @@ class TextItem extends BaseItem {
|
|
|
1458
1692
|
}
|
|
1459
1693
|
}
|
|
1460
1694
|
|
|
1461
|
-
function parseDate(value) {
|
|
1462
|
-
if (value && (!isDate(value) || !isValid(value))) {
|
|
1463
|
-
return parseISO(value);
|
|
1464
|
-
}
|
|
1465
|
-
return value;
|
|
1466
|
-
}
|
|
1467
|
-
|
|
1468
|
-
class WeekItem extends BaseItem {
|
|
1469
|
-
_additionalConfig;
|
|
1470
|
-
_filter;
|
|
1471
|
-
constructor(itemConfig, _additionalConfig, _filter) {
|
|
1472
|
-
super(itemConfig, _additionalConfig, _filter);
|
|
1473
|
-
this._additionalConfig = _additionalConfig;
|
|
1474
|
-
this._filter = _filter;
|
|
1475
|
-
this.seedDate = itemConfig.seedDate;
|
|
1476
|
-
}
|
|
1477
|
-
static create(config, filter) {
|
|
1478
|
-
return new WeekItem(config, null, filter);
|
|
1479
|
-
}
|
|
1480
|
-
setValue(value, emitChange = true) {
|
|
1481
|
-
if (value) {
|
|
1482
|
-
value.from = parseDate(value.from);
|
|
1483
|
-
value.to = parseDate(value.to);
|
|
1484
|
-
value.period = parseInt(value.period, 10) || undefined;
|
|
1485
|
-
}
|
|
1486
|
-
super.setValue(value, emitChange);
|
|
1487
|
-
}
|
|
1488
|
-
get query() {
|
|
1489
|
-
const value = this.value;
|
|
1490
|
-
const name = this.name;
|
|
1491
|
-
const paramFromName = getRangeName(name, 'from');
|
|
1492
|
-
const paramToName = getRangeName(name, 'to');
|
|
1493
|
-
const paramPeriodName = `${name}Period`;
|
|
1494
|
-
return {
|
|
1495
|
-
[paramFromName]: value?.from || undefined,
|
|
1496
|
-
[paramToName]: value?.to || undefined,
|
|
1497
|
-
[paramPeriodName]: value?.period || undefined,
|
|
1498
|
-
};
|
|
1499
|
-
}
|
|
1500
|
-
get chips() {
|
|
1501
|
-
if (!this.hasValue) {
|
|
1502
|
-
return [];
|
|
1503
|
-
}
|
|
1504
|
-
return [
|
|
1505
|
-
{
|
|
1506
|
-
value: formatPeriodObject(this.value),
|
|
1507
|
-
label: this.label,
|
|
1508
|
-
},
|
|
1509
|
-
];
|
|
1510
|
-
}
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1513
1695
|
function createFilterItem(item, config, filter) {
|
|
1514
1696
|
switch (item.type) {
|
|
1515
1697
|
case ItemType.Select: {
|
|
@@ -1670,131 +1852,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
|
|
|
1670
1852
|
type: Injectable
|
|
1671
1853
|
}] });
|
|
1672
1854
|
|
|
1673
|
-
const QUERY_PARAM_DELIMITER = ':';
|
|
1674
|
-
|
|
1675
|
-
function filterToQueryParam(value, name) {
|
|
1676
|
-
return `${encodeURIComponent(value)}${QUERY_PARAM_DELIMITER}${encodeURIComponent(name)}`;
|
|
1677
|
-
}
|
|
1678
|
-
function filterFromQueryParam(param) {
|
|
1679
|
-
const parts = param.split(QUERY_PARAM_DELIMITER);
|
|
1680
|
-
return [decodeURIComponent(parts[0]), decodeURIComponent(parts[1])];
|
|
1681
|
-
}
|
|
1682
|
-
|
|
1683
|
-
function parseItemValueFromStored(item, params) {
|
|
1684
|
-
const param = params[item.name];
|
|
1685
|
-
switch (item.type) {
|
|
1686
|
-
case ItemType.Range: {
|
|
1687
|
-
const min = params[getRangeName(item.name, 'min')];
|
|
1688
|
-
const max = params[getRangeName(item.name, 'max')];
|
|
1689
|
-
return { min: min, max: max };
|
|
1690
|
-
}
|
|
1691
|
-
case ItemType.DateRange:
|
|
1692
|
-
case ItemType.DateTimeRange: {
|
|
1693
|
-
const from = params[getRangeName(item.name, 'from')];
|
|
1694
|
-
const to = params[getRangeName(item.name, 'to')];
|
|
1695
|
-
return { from: from, to: to };
|
|
1696
|
-
}
|
|
1697
|
-
case ItemType.Week: {
|
|
1698
|
-
const from = params[getRangeName(item.name, 'from')];
|
|
1699
|
-
const to = params[getRangeName(item.name, 'to')];
|
|
1700
|
-
const period = params[`${item.name}Period`];
|
|
1701
|
-
return { from, to, period };
|
|
1702
|
-
}
|
|
1703
|
-
case ItemType.Select: {
|
|
1704
|
-
return itemTypeSelect(item, param);
|
|
1705
|
-
}
|
|
1706
|
-
case ItemType.Checkbox: {
|
|
1707
|
-
return param === 'true' || param === true;
|
|
1708
|
-
}
|
|
1709
|
-
case ItemType.AutoComplete: {
|
|
1710
|
-
const filterParts = filterFromQueryParam(param);
|
|
1711
|
-
return {
|
|
1712
|
-
name: filterParts[1],
|
|
1713
|
-
value: filterParts[0],
|
|
1714
|
-
};
|
|
1715
|
-
}
|
|
1716
|
-
case ItemType.AutoCompleteChips:
|
|
1717
|
-
case ItemType.Chips: {
|
|
1718
|
-
const filterParts = param.split(',');
|
|
1719
|
-
return filterParts.reduce((arry, value) => {
|
|
1720
|
-
const chipParts = filterFromQueryParam(value);
|
|
1721
|
-
arry.push({
|
|
1722
|
-
name: chipParts[1],
|
|
1723
|
-
value: chipParts[0],
|
|
1724
|
-
});
|
|
1725
|
-
return arry;
|
|
1726
|
-
}, []);
|
|
1727
|
-
}
|
|
1728
|
-
default: {
|
|
1729
|
-
return param;
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
}
|
|
1733
|
-
function itemTypeSelect(item, param) {
|
|
1734
|
-
if (!param) {
|
|
1735
|
-
return [];
|
|
1736
|
-
}
|
|
1737
|
-
const values = param.split(',');
|
|
1738
|
-
if (item.isolate) {
|
|
1739
|
-
const isolatedValue = item.isolateValues;
|
|
1740
|
-
item.isolate = arraysHaveSameElements(isolatedValue, values);
|
|
1741
|
-
return item.isolate
|
|
1742
|
-
? isolatedValue
|
|
1743
|
-
: values;
|
|
1744
|
-
}
|
|
1745
|
-
return values;
|
|
1746
|
-
}
|
|
1747
|
-
function arraysHaveSameElements(arr1, arr2) {
|
|
1748
|
-
arr1 = [...arr1].sort();
|
|
1749
|
-
arr2 = [...arr2].sort();
|
|
1750
|
-
return arr1.some((item) => {
|
|
1751
|
-
return arr2.includes(item);
|
|
1752
|
-
});
|
|
1753
|
-
}
|
|
1754
|
-
|
|
1755
|
-
/**
|
|
1756
|
-
* We need this function because when we store persisted/query/remote filter values
|
|
1757
|
-
* it stores with different format, ex.: Range will be stored as RangeFrom && RangeTo
|
|
1758
|
-
* and in this case we don't know how to restroe those values.
|
|
1759
|
-
*
|
|
1760
|
-
* This function do convertation for those kinds of stored values
|
|
1761
|
-
*
|
|
1762
|
-
* @param params
|
|
1763
|
-
* @param items
|
|
1764
|
-
* @param paramsCase
|
|
1765
|
-
*/
|
|
1766
|
-
function restoreItems(params, items) {
|
|
1767
|
-
const result = {};
|
|
1768
|
-
Object.keys(params)
|
|
1769
|
-
.forEach((name) => {
|
|
1770
|
-
const item = findItemWidthName(items, name);
|
|
1771
|
-
if (item) {
|
|
1772
|
-
result[item.name] = parseItemValueFromStored(item, params);
|
|
1773
|
-
}
|
|
1774
|
-
});
|
|
1775
|
-
return result;
|
|
1776
|
-
}
|
|
1777
|
-
function findItemWidthName(items, name) {
|
|
1778
|
-
return items
|
|
1779
|
-
.find((filterItem) => {
|
|
1780
|
-
if (filterItem instanceof RangeItem) {
|
|
1781
|
-
return name === getRangeName(filterItem.name, 'min') ||
|
|
1782
|
-
name === getRangeName(filterItem.name, 'max') ||
|
|
1783
|
-
name === filterItem.name;
|
|
1784
|
-
}
|
|
1785
|
-
else if (filterItem instanceof DateRangeItem || filterItem instanceof DateTimeRangeItem) {
|
|
1786
|
-
return name === getRangeName(filterItem.name, 'from') ||
|
|
1787
|
-
name === getRangeName(filterItem.name, 'to');
|
|
1788
|
-
}
|
|
1789
|
-
else if (filterItem instanceof WeekItem) {
|
|
1790
|
-
return name === getRangeName(filterItem.name, 'from')
|
|
1791
|
-
|| name === getRangeName(filterItem.name, 'to')
|
|
1792
|
-
|| name === `${filterItem.name}Period`;
|
|
1793
|
-
}
|
|
1794
|
-
return filterItem.name === name;
|
|
1795
|
-
});
|
|
1796
|
-
}
|
|
1797
|
-
|
|
1798
1855
|
class SortController {
|
|
1799
1856
|
_name = null;
|
|
1800
1857
|
_direction = null;
|
|
@@ -1905,11 +1962,12 @@ class QueryParamController {
|
|
|
1905
1962
|
const url = new URL(window.location.href);
|
|
1906
1963
|
Object.keys(data)
|
|
1907
1964
|
.forEach((name) => {
|
|
1908
|
-
|
|
1965
|
+
const value = data[name];
|
|
1966
|
+
if (value === undefined || value === null) {
|
|
1909
1967
|
url.searchParams.delete(name);
|
|
1910
1968
|
}
|
|
1911
1969
|
else {
|
|
1912
|
-
url.searchParams.set(name,
|
|
1970
|
+
url.searchParams.set(name, value);
|
|
1913
1971
|
}
|
|
1914
1972
|
});
|
|
1915
1973
|
history.replaceState({}, null, url.pathname + decodeURIComponent(url.search));
|
|
@@ -2063,7 +2121,10 @@ class FilterController {
|
|
|
2063
2121
|
return forkJoin(this.items
|
|
2064
2122
|
.map((item) => {
|
|
2065
2123
|
return item.init(values[item.name]);
|
|
2066
|
-
}))
|
|
2124
|
+
}))
|
|
2125
|
+
.pipe(tap(() => this.items.forEach((item) => {
|
|
2126
|
+
item.initCallback(item, this.filter);
|
|
2127
|
+
})));
|
|
2067
2128
|
}
|
|
2068
2129
|
_addItems(items) {
|
|
2069
2130
|
this._add$.next();
|
|
@@ -4109,5 +4170,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.13", ngImpo
|
|
|
4109
4170
|
* Generated bundle index. Do not edit.
|
|
4110
4171
|
*/
|
|
4111
4172
|
|
|
4112
|
-
export { ActionMode, AutocompleteChipsItem, AutocompleteItem, BaseItem, ButtonStyle, CheckboxItem, ChipsItem, DateItem, DateRangeItem, DateTimeItem, DateTimeRangeItem, FS_FILTER_CONFIG, FilterComponent, FilterItemComponent, FilterStatusBarDirective, FsFilterModule, ItemDateMode, ItemType, MenuActionMode,
|
|
4173
|
+
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 };
|
|
4113
4174
|
//# sourceMappingURL=firestitch-filter.mjs.map
|