@neovici/cosmoz-omnitable 14.12.0 → 14.12.2
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/README.md +1 -2
- package/cosmoz-omnitable-column-boolean.js +81 -62
- package/cosmoz-omnitable-column-list-data.js +57 -49
- package/cosmoz-omnitable-column-list-horizontal.js +42 -26
- package/cosmoz-omnitable-group-row.js +10 -2
- package/cosmoz-omnitable-item-expand-line.js +1 -1
- package/grouped-list/cosmoz-grouped-list-row.js +1 -1
- package/grouped-list/use-cosmoz-grouped-list.js +12 -11
- package/grouped-list/use-selected-items.js +25 -25
- package/grouped-list/use-weak-state.js +2 -2
- package/grouped-list/utils.js +11 -9
- package/lib/compute-layout.js +3 -1
- package/lib/cosmoz-omnitable-amount-range-input.js +100 -97
- package/lib/cosmoz-omnitable-date-input-mixin.js +23 -13
- package/lib/cosmoz-omnitable-date-range-input.js +85 -78
- package/lib/cosmoz-omnitable-datetime-range-input.js +85 -78
- package/lib/cosmoz-omnitable-number-range-input.js +34 -27
- package/lib/cosmoz-omnitable-range-input-mixin.js +7 -10
- package/lib/cosmoz-omnitable-time-range-input.js +54 -30
- package/lib/layout.js +12 -14
- package/lib/polymer-haunted-render-mixin.js +14 -13
- package/lib/save-as-csv-action.js +31 -27
- package/lib/save-as-xlsx-action.js +13 -11
- package/lib/settings/cosmoz-omnitable-sort-group.js +1 -1
- package/lib/settings/drivers/context.js +1 -1
- package/lib/use-hash-state.js +1 -1
- package/lib/use-processed-items.js +20 -20
- package/lib/utils-amount.js +17 -26
- package/lib/utils-data.js +24 -24
- package/lib/utils-date.js +18 -34
- package/lib/utils-datetime.js +10 -15
- package/lib/utils-number.js +28 -29
- package/lib/utils-time.js +21 -24
- package/lib/utils.js +14 -0
- package/package.json +8 -2
|
@@ -22,7 +22,7 @@ const sortBy = (valueFn, descending) => (a, b) =>
|
|
|
22
22
|
new CustomEvent(`${kebab(key)}-changed`, {
|
|
23
23
|
bubbles: true,
|
|
24
24
|
detail: { value },
|
|
25
|
-
})
|
|
25
|
+
}),
|
|
26
26
|
);
|
|
27
27
|
});
|
|
28
28
|
},
|
|
@@ -51,7 +51,7 @@ export const useProcessedItems = ({
|
|
|
51
51
|
value.filter && column.serializeFilter(column, value.filter),
|
|
52
52
|
];
|
|
53
53
|
},
|
|
54
|
-
[columns]
|
|
54
|
+
[columns],
|
|
55
55
|
),
|
|
56
56
|
read = useCallback(
|
|
57
57
|
([filter, value]) => {
|
|
@@ -64,7 +64,7 @@ export const useProcessedItems = ({
|
|
|
64
64
|
notifyChanges(column, state);
|
|
65
65
|
return [filter, state];
|
|
66
66
|
},
|
|
67
|
-
[columns]
|
|
67
|
+
[columns],
|
|
68
68
|
),
|
|
69
69
|
[filters, setFilters] = useHashState({}, hashParam, {
|
|
70
70
|
multi: true,
|
|
@@ -80,7 +80,7 @@ export const useProcessedItems = ({
|
|
|
80
80
|
|
|
81
81
|
notifyChanges(
|
|
82
82
|
columns.find((c) => c.name === name),
|
|
83
|
-
newState
|
|
83
|
+
newState,
|
|
84
84
|
);
|
|
85
85
|
|
|
86
86
|
return {
|
|
@@ -91,11 +91,11 @@ export const useProcessedItems = ({
|
|
|
91
91
|
},
|
|
92
92
|
};
|
|
93
93
|
}),
|
|
94
|
-
[columns, setFilters]
|
|
94
|
+
[columns, setFilters],
|
|
95
95
|
),
|
|
96
96
|
filterValues = useMemo(
|
|
97
97
|
() => Object.values(filters).map((f) => f.filter),
|
|
98
|
-
[filters]
|
|
98
|
+
[filters],
|
|
99
99
|
),
|
|
100
100
|
filterFunctions = useMemo(() => {
|
|
101
101
|
return Object.fromEntries(
|
|
@@ -105,7 +105,7 @@ export const useProcessedItems = ({
|
|
|
105
105
|
!col.noLocalFilter &&
|
|
106
106
|
col.getFilterFn(col, filters[col.name]?.filter),
|
|
107
107
|
])
|
|
108
|
-
.filter(([, fn]) => !!fn)
|
|
108
|
+
.filter(([, fn]) => !!fn),
|
|
109
109
|
);
|
|
110
110
|
}, [columns, ...filterValues]),
|
|
111
111
|
filteredItems = useMemo(() => {
|
|
@@ -118,7 +118,7 @@ export const useProcessedItems = ({
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
return data.filter((item) =>
|
|
121
|
-
Object.values(filterFunctions).every((filterFn) => filterFn(item))
|
|
121
|
+
Object.values(filterFunctions).every((filterFn) => filterFn(item)),
|
|
122
122
|
);
|
|
123
123
|
}, [data, filterFunctions, noLocalFilter]),
|
|
124
124
|
// todo: extract function
|
|
@@ -137,10 +137,10 @@ export const useProcessedItems = ({
|
|
|
137
137
|
(a) =>
|
|
138
138
|
sortOnColumn.getComparableValue(
|
|
139
139
|
{ ...sortOnColumn, valuePath: sortOnColumn.sortOn },
|
|
140
|
-
a
|
|
140
|
+
a,
|
|
141
141
|
),
|
|
142
|
-
descending
|
|
143
|
-
)
|
|
142
|
+
descending,
|
|
143
|
+
),
|
|
144
144
|
);
|
|
145
145
|
}
|
|
146
146
|
|
|
@@ -148,7 +148,7 @@ export const useProcessedItems = ({
|
|
|
148
148
|
const groupedResults = filteredItems.reduce((acc, item) => {
|
|
149
149
|
const gval = groupOnColumn.getComparableValue(
|
|
150
150
|
{ ...groupOnColumn, valuePath: groupOnColumn.groupOn },
|
|
151
|
-
item
|
|
151
|
+
item,
|
|
152
152
|
);
|
|
153
153
|
|
|
154
154
|
if (gval === undefined) {
|
|
@@ -175,10 +175,10 @@ export const useProcessedItems = ({
|
|
|
175
175
|
(a) =>
|
|
176
176
|
groupOnColumn.getComparableValue(
|
|
177
177
|
{ ...groupOnColumn, valuePath: groupOnColumn.groupOn },
|
|
178
|
-
a.items[0]
|
|
178
|
+
a.items[0],
|
|
179
179
|
),
|
|
180
|
-
groupOnDescending
|
|
181
|
-
)
|
|
180
|
+
groupOnDescending,
|
|
181
|
+
),
|
|
182
182
|
);
|
|
183
183
|
|
|
184
184
|
if (!sortOnColumn || noLocalSort) {
|
|
@@ -193,10 +193,10 @@ export const useProcessedItems = ({
|
|
|
193
193
|
(a) =>
|
|
194
194
|
sortOnColumn.getComparableValue(
|
|
195
195
|
{ ...sortOnColumn, valuePath: sortOnColumn.sortOn },
|
|
196
|
-
a
|
|
196
|
+
a,
|
|
197
197
|
),
|
|
198
|
-
descending
|
|
199
|
-
)
|
|
198
|
+
descending,
|
|
199
|
+
),
|
|
200
200
|
);
|
|
201
201
|
return group;
|
|
202
202
|
});
|
|
@@ -236,7 +236,7 @@ export const useProcessedItems = ({
|
|
|
236
236
|
useEffect(() => {
|
|
237
237
|
setFilters((filters) => {
|
|
238
238
|
const hasUnparsedFilters = Object.values(filters).some(
|
|
239
|
-
(value) => value[unparsed] != null
|
|
239
|
+
(value) => value[unparsed] != null,
|
|
240
240
|
);
|
|
241
241
|
|
|
242
242
|
if (!hasUnparsedFilters) {
|
|
@@ -250,7 +250,7 @@ export const useProcessedItems = ({
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
return read([name, value[unparsed]]);
|
|
253
|
-
})
|
|
253
|
+
}),
|
|
254
254
|
);
|
|
255
255
|
});
|
|
256
256
|
}, [read]);
|
package/lib/utils-amount.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
2
2
|
import { toNumber } from './utils-number';
|
|
3
3
|
|
|
4
|
-
export const
|
|
5
|
-
/**
|
|
4
|
+
export const /**
|
|
6
5
|
* Converts a value to an amount object optionaly limiting it.
|
|
7
6
|
*
|
|
8
7
|
* @param {Object} rates The rates
|
|
@@ -11,12 +10,17 @@ export const
|
|
|
11
10
|
* @param {Function} limitFunc The function used to limit the number (Math.min|Math.max)
|
|
12
11
|
* @returns {Object|void} Value converted to Number or void
|
|
13
12
|
*/
|
|
14
|
-
toAmount = (rates = {}, value, limit, limitFunc) => {
|
|
13
|
+
toAmount = (rates = {}, value, limit, limitFunc) => {
|
|
14
|
+
// eslint-disable-line max-statements
|
|
15
15
|
if (value == null || value === '') {
|
|
16
16
|
return;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
if (
|
|
19
|
+
if (
|
|
20
|
+
typeof value !== 'object' ||
|
|
21
|
+
value.currency == null ||
|
|
22
|
+
value.currency === ''
|
|
23
|
+
) {
|
|
20
24
|
return null;
|
|
21
25
|
}
|
|
22
26
|
|
|
@@ -26,7 +30,7 @@ export const
|
|
|
26
30
|
}
|
|
27
31
|
const amount = {
|
|
28
32
|
currency: value.currency,
|
|
29
|
-
amount: number
|
|
33
|
+
amount: number,
|
|
30
34
|
};
|
|
31
35
|
|
|
32
36
|
if (limitFunc == null || limit == null) {
|
|
@@ -38,13 +42,11 @@ export const
|
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
// calculate value and limit amounts with rates
|
|
41
|
-
const
|
|
42
|
-
valAmount = amount.amount * (rates[amount.currency] || 1),
|
|
45
|
+
const valAmount = amount.amount * (rates[amount.currency] || 1),
|
|
43
46
|
limAmount = lAmount.amount * (rates[lAmount.currency] || 1),
|
|
44
47
|
lNumber = toNumber(valAmount, limAmount, limitFunc);
|
|
45
48
|
return lNumber === valAmount ? amount : lAmount;
|
|
46
49
|
},
|
|
47
|
-
|
|
48
50
|
getComparableValue = ({ valuePath, rates }, item) => {
|
|
49
51
|
if (item == null) {
|
|
50
52
|
return;
|
|
@@ -68,21 +70,18 @@ export const
|
|
|
68
70
|
|
|
69
71
|
return amount * (rates[value.currency] || 1);
|
|
70
72
|
},
|
|
71
|
-
|
|
72
|
-
applySingleFilter = (column, filter) => item => {
|
|
73
|
+
applySingleFilter = (column, filter) => (item) => {
|
|
73
74
|
const value = getComparableValue(column, item);
|
|
74
75
|
|
|
75
76
|
if (value == null) {
|
|
76
77
|
return false;
|
|
77
78
|
}
|
|
78
79
|
|
|
79
|
-
const
|
|
80
|
-
min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
80
|
+
const min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
81
81
|
max = getComparableValue({ ...column, valuePath: 'max' }, filter);
|
|
82
82
|
|
|
83
83
|
return !(value < min || value > max);
|
|
84
84
|
},
|
|
85
|
-
|
|
86
85
|
formatters = {},
|
|
87
86
|
getFormatter = (currency, locale) => {
|
|
88
87
|
const id = locale ? locale : '',
|
|
@@ -94,22 +93,18 @@ export const
|
|
|
94
93
|
|
|
95
94
|
formatters[key] = new Intl.NumberFormat(locale || undefined, {
|
|
96
95
|
style: 'currency',
|
|
97
|
-
currency
|
|
96
|
+
currency,
|
|
98
97
|
});
|
|
99
98
|
|
|
100
99
|
return formatters[key];
|
|
101
100
|
},
|
|
102
|
-
|
|
103
101
|
renderValue = (rates, value, locale) => {
|
|
104
102
|
const amount = toAmount(rates, value);
|
|
105
103
|
if (amount == null) {
|
|
106
104
|
return '';
|
|
107
105
|
}
|
|
108
|
-
return getFormatter(amount.currency, locale)
|
|
109
|
-
.format(amount.amount);
|
|
106
|
+
return getFormatter(amount.currency, locale).format(amount.amount);
|
|
110
107
|
},
|
|
111
|
-
|
|
112
|
-
|
|
113
108
|
getString = ({ valuePath, rates, locale }, item) => {
|
|
114
109
|
const value = toAmount(rates, get(item, valuePath));
|
|
115
110
|
if (value === undefined) {
|
|
@@ -120,15 +115,13 @@ export const
|
|
|
120
115
|
}
|
|
121
116
|
return renderValue(rates, value, locale);
|
|
122
117
|
},
|
|
123
|
-
|
|
124
|
-
toHashString = value => {
|
|
118
|
+
toHashString = (value) => {
|
|
125
119
|
if (!value) {
|
|
126
120
|
return '';
|
|
127
121
|
}
|
|
128
122
|
return value.amount + value.currency;
|
|
129
123
|
},
|
|
130
|
-
|
|
131
|
-
fromHashString = value => {
|
|
124
|
+
fromHashString = (value) => {
|
|
132
125
|
if (value == null || value === '') {
|
|
133
126
|
return;
|
|
134
127
|
}
|
|
@@ -138,10 +131,8 @@ export const
|
|
|
138
131
|
}
|
|
139
132
|
return {
|
|
140
133
|
amount: params[1],
|
|
141
|
-
currency: params[2]
|
|
134
|
+
currency: params[2],
|
|
142
135
|
};
|
|
143
136
|
},
|
|
144
|
-
|
|
145
137
|
getCurrency = ({ valuePath }, item) => get(item, valuePath)?.currency,
|
|
146
|
-
|
|
147
138
|
getInputString = ({ valuePath }, item) => get(item, valuePath)?.amount;
|
package/lib/utils-data.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { get, set } from '@polymer/polymer/lib/utils/path';
|
|
2
2
|
import { columnSymbol } from './use-dom-columns';
|
|
3
3
|
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
export const valuesFrom = (data, valuePath) =>
|
|
5
|
+
Array.isArray(data)
|
|
6
|
+
? data
|
|
7
|
+
.map((item) => get(item, valuePath))
|
|
8
|
+
.filter(
|
|
9
|
+
(value, index, self) =>
|
|
10
|
+
value != null && self.indexOf(value) === index,
|
|
11
|
+
)
|
|
12
|
+
: undefined,
|
|
12
13
|
defaultComputeSource = ({ externalValues, values, valuePath }, data) =>
|
|
13
14
|
externalValues || typeof values === 'function'
|
|
14
15
|
? values
|
|
15
16
|
: valuesFrom(data, valuePath),
|
|
16
|
-
|
|
17
17
|
onItemChange = (host, column, item, value) => {
|
|
18
|
-
const
|
|
19
|
-
{ valuePath } = column,
|
|
18
|
+
const { valuePath } = column,
|
|
20
19
|
oldValue = get(item, valuePath);
|
|
21
20
|
|
|
22
21
|
if (value === oldValue) {
|
|
@@ -25,18 +24,19 @@ export const
|
|
|
25
24
|
|
|
26
25
|
set(item, valuePath, value);
|
|
27
26
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
};
|
|
27
|
+
const change = {
|
|
28
|
+
item,
|
|
29
|
+
valuePath,
|
|
30
|
+
value,
|
|
31
|
+
oldValue,
|
|
32
|
+
column: column[columnSymbol],
|
|
33
|
+
};
|
|
36
34
|
|
|
37
|
-
host.dispatchEvent(
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
host.dispatchEvent(
|
|
36
|
+
new CustomEvent('column-item-changed', {
|
|
37
|
+
bubbles: true,
|
|
38
|
+
composed: true,
|
|
39
|
+
detail: change,
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
42
|
};
|
package/lib/utils-date.js
CHANGED
|
@@ -2,25 +2,23 @@ import { toLocalISOString, ensureDate } from '@neovici/cosmoz-utils/date';
|
|
|
2
2
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
3
3
|
import { toNumber } from './utils-number';
|
|
4
4
|
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
5
|
+
export const /**
|
|
9
6
|
* Calculates the local timezone offset and formats it to ISO Timezone string.
|
|
10
7
|
* @param {String} localISOString an ISO date string
|
|
11
8
|
* @return {String} the ISO timezone
|
|
12
9
|
*/
|
|
13
|
-
getTimezoneString = localISOString => {
|
|
10
|
+
getTimezoneString = (localISOString) => {
|
|
14
11
|
const off = -new Date(localISOString).getTimezoneOffset() / 60;
|
|
15
|
-
return (
|
|
12
|
+
return (
|
|
13
|
+
(off < 0 ? '-' : '+') + ['0', Math.abs(off)].join('').substr(-2) + ':00'
|
|
14
|
+
);
|
|
16
15
|
},
|
|
17
|
-
|
|
18
16
|
/**
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
getAbsoluteISOString = localISOString => {
|
|
17
|
+
* Computes the local timezone and adds it to a local ISO string
|
|
18
|
+
* @param {String} localISOString an ISO date string, without timezone info
|
|
19
|
+
* @return {String} an ISO date string, with timezone info
|
|
20
|
+
*/
|
|
21
|
+
getAbsoluteISOString = (localISOString) => {
|
|
24
22
|
// Most browsers use local timezone when no timezone is specified
|
|
25
23
|
// but Safari uses UTC, so we set it implicitly
|
|
26
24
|
// TODO: Consider removing this when/if Safari handles local timezone correctly
|
|
@@ -29,8 +27,7 @@ export const
|
|
|
29
27
|
}
|
|
30
28
|
return localISOString;
|
|
31
29
|
},
|
|
32
|
-
|
|
33
|
-
parseDate = value => {
|
|
30
|
+
parseDate = (value) => {
|
|
34
31
|
if (value == null || value === '') {
|
|
35
32
|
return;
|
|
36
33
|
}
|
|
@@ -56,7 +53,6 @@ export const
|
|
|
56
53
|
|
|
57
54
|
return date;
|
|
58
55
|
},
|
|
59
|
-
|
|
60
56
|
/**
|
|
61
57
|
* Get comparable number from date
|
|
62
58
|
*
|
|
@@ -79,7 +75,6 @@ export const
|
|
|
79
75
|
}
|
|
80
76
|
return toNumber(value.getTime());
|
|
81
77
|
},
|
|
82
|
-
|
|
83
78
|
/**
|
|
84
79
|
* Converts an value to date optionaly limiting it.
|
|
85
80
|
*
|
|
@@ -88,7 +83,8 @@ export const
|
|
|
88
83
|
* @param {Function} limitFunc Function used to limit the date (Math.min|Math.max)
|
|
89
84
|
* @returns {Date|void} Value converted to date optionaly limitated
|
|
90
85
|
*/
|
|
91
|
-
toDate = (value, limit, limitFunc) => {
|
|
86
|
+
toDate = (value, limit, limitFunc) => {
|
|
87
|
+
// eslint-disable-line max-statements
|
|
92
88
|
const date = parseDate(value);
|
|
93
89
|
|
|
94
90
|
if (date == null) {
|
|
@@ -109,7 +105,6 @@ export const
|
|
|
109
105
|
limitedValue = limitFunc(comparableDate, comparableLDate);
|
|
110
106
|
return limitedValue === comparableDate ? date : lDate;
|
|
111
107
|
},
|
|
112
|
-
|
|
113
108
|
renderValue = (value, formatter) => {
|
|
114
109
|
if (formatter == null) {
|
|
115
110
|
return;
|
|
@@ -120,9 +115,8 @@ export const
|
|
|
120
115
|
}
|
|
121
116
|
return formatter.format(date);
|
|
122
117
|
},
|
|
123
|
-
|
|
124
118
|
formatters = {},
|
|
125
|
-
getFormatter = locale => {
|
|
119
|
+
getFormatter = (locale) => {
|
|
126
120
|
const key = locale || '';
|
|
127
121
|
|
|
128
122
|
if (formatters[key]) {
|
|
@@ -133,7 +127,6 @@ export const
|
|
|
133
127
|
|
|
134
128
|
return formatters[key];
|
|
135
129
|
},
|
|
136
|
-
|
|
137
130
|
getString = ({ valuePath, locale }, item) => {
|
|
138
131
|
let value = get(item, valuePath);
|
|
139
132
|
if (value === undefined) {
|
|
@@ -145,17 +138,14 @@ export const
|
|
|
145
138
|
}
|
|
146
139
|
return renderValue(value, getFormatter(locale));
|
|
147
140
|
},
|
|
148
|
-
|
|
149
|
-
toInputString = value => {
|
|
141
|
+
toInputString = (value) => {
|
|
150
142
|
const date = toDate(value);
|
|
151
143
|
if (date == null) {
|
|
152
144
|
return null;
|
|
153
145
|
}
|
|
154
146
|
return toLocalISOString(date).slice(0, 10);
|
|
155
147
|
},
|
|
156
|
-
|
|
157
148
|
getInputString = ({ valuePath }, item) => toInputString(get(item, valuePath)),
|
|
158
|
-
|
|
159
149
|
fromInputString = (value, property) => {
|
|
160
150
|
const date = toDate(value);
|
|
161
151
|
if (date == null) {
|
|
@@ -169,15 +159,13 @@ export const
|
|
|
169
159
|
}
|
|
170
160
|
return date;
|
|
171
161
|
},
|
|
172
|
-
|
|
173
|
-
toHashString = value => {
|
|
162
|
+
toHashString = (value) => {
|
|
174
163
|
const string = toInputString(value);
|
|
175
164
|
if (string == null) {
|
|
176
165
|
return '';
|
|
177
166
|
}
|
|
178
167
|
return string;
|
|
179
168
|
},
|
|
180
|
-
|
|
181
169
|
toXlsxValue = ({ valuePath }, item) => {
|
|
182
170
|
if (!valuePath) {
|
|
183
171
|
return '';
|
|
@@ -193,19 +181,15 @@ export const
|
|
|
193
181
|
localDate.setHours(0, 0, 0, 0);
|
|
194
182
|
return localDate;
|
|
195
183
|
},
|
|
196
|
-
|
|
197
|
-
applySingleFilter = (column, filter) => item => {
|
|
184
|
+
applySingleFilter = (column, filter) => (item) => {
|
|
198
185
|
const value = getComparableValue(column, item);
|
|
199
186
|
|
|
200
187
|
if (value == null) {
|
|
201
188
|
return false;
|
|
202
189
|
}
|
|
203
190
|
|
|
204
|
-
const
|
|
205
|
-
min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
191
|
+
const min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
206
192
|
max = getComparableValue({ ...column, valuePath: 'max' }, filter);
|
|
207
193
|
|
|
208
194
|
return !(value < min || value > max);
|
|
209
195
|
};
|
|
210
|
-
|
|
211
|
-
|
package/lib/utils-datetime.js
CHANGED
|
@@ -2,10 +2,8 @@ import { toLocalISOString } from '@neovici/cosmoz-utils/date';
|
|
|
2
2
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
3
3
|
import { renderValue, toDate } from './utils-date';
|
|
4
4
|
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
-
formatters = {},
|
|
8
|
-
getFormatter = locale => {
|
|
5
|
+
export const formatters = {},
|
|
6
|
+
getFormatter = (locale) => {
|
|
9
7
|
const key = locale || '';
|
|
10
8
|
|
|
11
9
|
if (formatters[key]) {
|
|
@@ -17,14 +15,16 @@ export const
|
|
|
17
15
|
month: 'numeric',
|
|
18
16
|
day: 'numeric',
|
|
19
17
|
hour: 'numeric',
|
|
20
|
-
minute: 'numeric'
|
|
18
|
+
minute: 'numeric',
|
|
21
19
|
};
|
|
22
20
|
|
|
23
|
-
formatters[key] = new Intl.DateTimeFormat(
|
|
21
|
+
formatters[key] = new Intl.DateTimeFormat(
|
|
22
|
+
locale || undefined,
|
|
23
|
+
timeFormatOption,
|
|
24
|
+
);
|
|
24
25
|
|
|
25
26
|
return formatters[key];
|
|
26
27
|
},
|
|
27
|
-
|
|
28
28
|
getString = ({ valuePath, locale }, item) => {
|
|
29
29
|
const value = toDate(get(item, valuePath));
|
|
30
30
|
if (value === undefined) {
|
|
@@ -35,15 +35,13 @@ export const
|
|
|
35
35
|
}
|
|
36
36
|
return renderValue(value, getFormatter(locale));
|
|
37
37
|
},
|
|
38
|
-
|
|
39
38
|
toXlsxValue = ({ valuePath }, item) => {
|
|
40
39
|
if (!valuePath) {
|
|
41
40
|
return '';
|
|
42
41
|
}
|
|
43
42
|
return get(item, valuePath);
|
|
44
43
|
},
|
|
45
|
-
|
|
46
|
-
toHashString = value => {
|
|
44
|
+
toHashString = (value) => {
|
|
47
45
|
const date = toDate(value);
|
|
48
46
|
if (date == null) {
|
|
49
47
|
return '';
|
|
@@ -51,21 +49,18 @@ export const
|
|
|
51
49
|
//Use utc in hash
|
|
52
50
|
return date.toISOString().slice(0, 19).replace(/:/gu, '.');
|
|
53
51
|
},
|
|
54
|
-
|
|
55
|
-
fromHashString = value => {
|
|
52
|
+
fromHashString = (value) => {
|
|
56
53
|
if (value == null || value === '') {
|
|
57
54
|
return;
|
|
58
55
|
}
|
|
59
56
|
//Parse utc from hash string
|
|
60
57
|
return toDate(value.replace(/\./gu, ':') + 'Z');
|
|
61
58
|
},
|
|
62
|
-
|
|
63
|
-
toInputString = value => {
|
|
59
|
+
toInputString = (value) => {
|
|
64
60
|
const date = toDate(value);
|
|
65
61
|
if (date == null) {
|
|
66
62
|
return null;
|
|
67
63
|
}
|
|
68
64
|
return toLocalISOString(date).slice(0, 19);
|
|
69
65
|
},
|
|
70
|
-
|
|
71
66
|
getInputString = ({ valuePath }, item) => toInputString(get(item, valuePath));
|
package/lib/utils-number.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
1
|
import { get } from '@polymer/polymer/lib/utils/path';
|
|
3
2
|
import { memoooize } from '@neovici/cosmoz-utils/memoize';
|
|
4
3
|
|
|
5
|
-
export const
|
|
6
|
-
/**
|
|
4
|
+
export const /**
|
|
7
5
|
* Converts a value to number optionaly limiting it.
|
|
8
6
|
*
|
|
9
7
|
* @param {Number|*} value The value to convert to number
|
|
@@ -28,28 +26,24 @@ export const
|
|
|
28
26
|
}
|
|
29
27
|
return limitFunc(number, lNumber);
|
|
30
28
|
},
|
|
31
|
-
|
|
32
|
-
toInputString = value => {
|
|
29
|
+
toInputString = (value) => {
|
|
33
30
|
const val = toNumber(value);
|
|
34
31
|
if (val == null) {
|
|
35
32
|
return null;
|
|
36
33
|
}
|
|
37
34
|
return val.toString();
|
|
38
35
|
},
|
|
39
|
-
|
|
40
36
|
getInputString = ({ valuePath }, item) => {
|
|
41
37
|
const value = toNumber(get(item, valuePath));
|
|
42
38
|
return toInputString(value);
|
|
43
39
|
},
|
|
44
|
-
|
|
45
|
-
toHashString = value => {
|
|
40
|
+
toHashString = (value) => {
|
|
46
41
|
const string = toInputString(value);
|
|
47
42
|
if (string == null) {
|
|
48
43
|
return '';
|
|
49
44
|
}
|
|
50
45
|
return string;
|
|
51
46
|
},
|
|
52
|
-
|
|
53
47
|
getComparableValue = ({ valuePath, maximumFractionDigits }, item) => {
|
|
54
48
|
if (item == null) {
|
|
55
49
|
return;
|
|
@@ -68,21 +62,24 @@ export const
|
|
|
68
62
|
}
|
|
69
63
|
return value;
|
|
70
64
|
},
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
getString = (
|
|
65
|
+
makeFormatter = memoooize(
|
|
66
|
+
(locale, minimumFractionDigits, maximumFractionDigits) => {
|
|
67
|
+
const options = {
|
|
68
|
+
localeMatcher: 'best fit', // chrome expects this when using custom options
|
|
69
|
+
};
|
|
70
|
+
if (minimumFractionDigits !== null) {
|
|
71
|
+
options.minimumFractionDigits = minimumFractionDigits;
|
|
72
|
+
}
|
|
73
|
+
if (maximumFractionDigits !== null) {
|
|
74
|
+
options.maximumFractionDigits = maximumFractionDigits;
|
|
75
|
+
}
|
|
76
|
+
return new Intl.NumberFormat(locale || undefined, options);
|
|
77
|
+
},
|
|
78
|
+
),
|
|
79
|
+
getString = (
|
|
80
|
+
{ valuePath, locale, minimumFractionDigits, maximumFractionDigits },
|
|
81
|
+
item,
|
|
82
|
+
) => {
|
|
86
83
|
const value = get(item, valuePath);
|
|
87
84
|
|
|
88
85
|
if (value == null) {
|
|
@@ -93,19 +90,21 @@ export const
|
|
|
93
90
|
if (number == null) {
|
|
94
91
|
return;
|
|
95
92
|
}
|
|
96
|
-
const formatter = makeFormatter(
|
|
93
|
+
const formatter = makeFormatter(
|
|
94
|
+
locale,
|
|
95
|
+
minimumFractionDigits,
|
|
96
|
+
maximumFractionDigits,
|
|
97
|
+
);
|
|
97
98
|
return formatter.format(number);
|
|
98
99
|
},
|
|
99
|
-
|
|
100
|
-
applySingleFilter = (column, filter) => item => {
|
|
100
|
+
applySingleFilter = (column, filter) => (item) => {
|
|
101
101
|
const value = getComparableValue(column, item);
|
|
102
102
|
|
|
103
103
|
if (value == null) {
|
|
104
104
|
return false;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
|
-
const
|
|
108
|
-
min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
107
|
+
const min = getComparableValue({ ...column, valuePath: 'min' }, filter),
|
|
109
108
|
max = getComparableValue({ ...column, valuePath: 'max' }, filter);
|
|
110
109
|
|
|
111
110
|
return !(value < min || value > max);
|