@neovici/cosmoz-omnitable 7.3.0 → 8.0.0-beta.4
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 +25 -0
- package/cosmoz-omnitable-column-amount.js +89 -320
- package/cosmoz-omnitable-column-autocomplete.js +36 -47
- package/cosmoz-omnitable-column-boolean.js +107 -209
- package/cosmoz-omnitable-column-date.js +89 -102
- package/cosmoz-omnitable-column-datetime.js +86 -119
- package/cosmoz-omnitable-column-list-data.js +4 -1
- package/cosmoz-omnitable-column-list-horizontal.js +20 -38
- package/cosmoz-omnitable-column-list-mixin.js +133 -140
- package/cosmoz-omnitable-column-list.js +19 -28
- package/cosmoz-omnitable-column-mixin.js +69 -447
- package/cosmoz-omnitable-column-number.js +91 -183
- package/cosmoz-omnitable-column-time.js +77 -162
- package/cosmoz-omnitable-column.js +49 -93
- package/cosmoz-omnitable-group-row.js +1 -5
- package/cosmoz-omnitable-header-row.js +9 -6
- package/cosmoz-omnitable-item-expand.js +0 -3
- package/cosmoz-omnitable-item-row.js +5 -8
- package/cosmoz-omnitable-styles.js +1 -5
- package/cosmoz-omnitable.js +74 -770
- package/lib/cosmoz-omnitable-amount-range-input.js +295 -0
- package/{cosmoz-omnitable-column-date-mixin.js → lib/cosmoz-omnitable-date-input-mixin.js} +4 -26
- package/lib/cosmoz-omnitable-date-range-input.js +81 -0
- package/lib/cosmoz-omnitable-datetime-range-input.js +75 -0
- package/lib/cosmoz-omnitable-number-range-input.js +159 -0
- package/{cosmoz-omnitable-column-range-mixin.js → lib/cosmoz-omnitable-range-input-mixin.js} +45 -123
- package/lib/cosmoz-omnitable-settings.js +7 -4
- package/lib/cosmoz-omnitable-time-range-input.js +130 -0
- package/lib/generic-sorter.js +2 -2
- package/lib/invoke.js +1 -0
- package/lib/memoize.js +54 -0
- package/lib/polymer-haunted-render-mixin.js +19 -0
- package/lib/save-as-csv-action.js +32 -0
- package/lib/save-as-xlsx-action.js +25 -0
- package/lib/use-canvas-width.js +1 -1
- package/lib/use-dom-columns.js +138 -0
- package/lib/use-fast-layout.js +21 -2
- package/lib/use-hash-state.js +59 -0
- package/lib/use-layout.js +1 -1
- package/lib/use-omnitable.js +26 -14
- package/lib/use-processed-items.js +132 -0
- package/lib/use-sort-and-group-options.js +30 -0
- package/lib/utils-amount.js +147 -0
- package/lib/utils-data.js +36 -0
- package/lib/utils-date.js +204 -0
- package/lib/utils-datetime.js +71 -0
- package/lib/utils-number.js +112 -0
- package/lib/utils-time.js +115 -0
- package/package.json +1 -1
- package/lib/use-force-render.js +0 -8
- package/lib/use-render-on-column-updates.js +0 -18
package/README.md
CHANGED
|
@@ -5,3 +5,28 @@ cosmoz-omnitable
|
|
|
5
5
|
[](https://codeclimate.com/github/Neovici/cosmoz-omnitable/maintainability)
|
|
6
6
|
[](https://codecov.io/gh/Neovici/cosmoz-omnitable)
|
|
7
7
|
[](https://github.com/semantic-release/semantic-release)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
migration TODO:
|
|
11
|
+
|
|
12
|
+
* check if dropping the visibility code has any adverse effect (might be related to hash-params)
|
|
13
|
+
x add legacy ots compatibility layer: dispatch filter-changed and other similar events from the columns
|
|
14
|
+
* verify each custom render function in FE
|
|
15
|
+
x convert DOM columns to config
|
|
16
|
+
x empty columns of all state
|
|
17
|
+
x hash params
|
|
18
|
+
x xlsx + csv export
|
|
19
|
+
* test for source
|
|
20
|
+
|
|
21
|
+
FE editable columns in:
|
|
22
|
+
views/administration/accounting-model/dimension-values.html.js
|
|
23
|
+
views/administration/periods/list.js
|
|
24
|
+
|
|
25
|
+
FE column-item-changed in:
|
|
26
|
+
views/administration/periods/list.js
|
|
27
|
+
|
|
28
|
+
BUGS:
|
|
29
|
+
* when navigating the queue, filters are not reset when view-core is reused
|
|
30
|
+
* autocomplete columns without valueProperty might not work
|
|
31
|
+
* treenode cells have show-max-nodes="undefined"
|
|
32
|
+
* treenode source has empty texts
|
|
@@ -5,369 +5,138 @@ import './ui-helpers/cosmoz-clear-button';
|
|
|
5
5
|
|
|
6
6
|
import { PolymerElement } from '@polymer/polymer/polymer-element';
|
|
7
7
|
import { html } from 'lit-html';
|
|
8
|
-
import { ifDefined } from 'lit-html/directives/if-defined';
|
|
9
8
|
|
|
10
9
|
import { columnMixin } from './cosmoz-omnitable-column-mixin';
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
} from '@
|
|
15
|
-
|
|
10
|
+
import { valuesFrom } from './lib/utils-data';
|
|
11
|
+
import './lib/cosmoz-omnitable-amount-range-input';
|
|
12
|
+
import { getComparableValue, getCurrency, applySingleFilter, getString, getInputString, toAmount, toHashString, fromHashString } from './lib/utils-amount';
|
|
13
|
+
import { get } from '@polymer/polymer/lib/utils/path';
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
* @polymer
|
|
19
17
|
* @customElement
|
|
20
|
-
* @appliesMixin rangeColumnMixin
|
|
21
18
|
* @appliesMixin columnMixin
|
|
22
|
-
* @appliesMixin translatable
|
|
23
19
|
*/
|
|
24
|
-
class OmnitableColumnAmount extends
|
|
25
|
-
PolymerElement
|
|
26
|
-
))) {
|
|
27
|
-
static get is() {
|
|
28
|
-
return 'cosmoz-omnitable-column-amount';
|
|
29
|
-
}
|
|
30
|
-
static get observers() {
|
|
31
|
-
return [
|
|
32
|
-
'_valuesChanged(autodetect, currency, values)'
|
|
33
|
-
];
|
|
34
|
-
}
|
|
20
|
+
class OmnitableColumnAmount extends columnMixin(PolymerElement) {
|
|
35
21
|
static get properties() {
|
|
36
22
|
return {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
autodetect: {
|
|
48
|
-
type: Boolean,
|
|
49
|
-
value: false
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Exchange rates of currencies. Example: {"EUR": 1, "USD":0.8169982616, "AUD":0.6529827192, "SEK": 0.1019271438}'
|
|
54
|
-
* Default exchange rate is 1 and it is used for every currency that is present on column values but missing from exchange rates object.
|
|
55
|
-
*/
|
|
56
|
-
rates: {
|
|
57
|
-
type: Object
|
|
58
|
-
},
|
|
59
|
-
width: {
|
|
60
|
-
type: String,
|
|
61
|
-
value: '70px'
|
|
62
|
-
},
|
|
63
|
-
editWidth: {
|
|
64
|
-
type: String,
|
|
65
|
-
value: '70px'
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
cellClass: {
|
|
69
|
-
type: String,
|
|
70
|
-
value: 'amount-cell align-right'
|
|
71
|
-
},
|
|
72
|
-
headerCellClass: {
|
|
73
|
-
type: String,
|
|
74
|
-
value: 'amount-header-cell'
|
|
75
|
-
},
|
|
76
|
-
// trigger filter updates manually
|
|
77
|
-
autoupdate: {
|
|
78
|
-
type: String,
|
|
79
|
-
value: false
|
|
80
|
-
},
|
|
81
|
-
_filterText: {
|
|
82
|
-
type: String,
|
|
83
|
-
computed: '_computeFilterText(filter.*, _formatters)'
|
|
84
|
-
}
|
|
23
|
+
min: { type: Number, value: null, notify: true },
|
|
24
|
+
max: { type: Number, value: null, notify: true },
|
|
25
|
+
locale: { type: String, value: null, notify: true },
|
|
26
|
+
autoupdate: { type: Boolean, value: false, notify: true },
|
|
27
|
+
currency: { type: String, notify: true },
|
|
28
|
+
autodetect: { type: Boolean, value: false, notify: true },
|
|
29
|
+
rates: { type: Object, notify: true },
|
|
30
|
+
width: { type: String, value: '70px' },
|
|
31
|
+
cellClass: { type: String, value: 'amount-cell align-right' },
|
|
32
|
+
headerCellClass: { type: String, value: 'amount-header-cell' }
|
|
85
33
|
};
|
|
86
34
|
}
|
|
87
35
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
36
|
+
getFilterFn(column, filter) {
|
|
37
|
+
const
|
|
38
|
+
min = getComparableValue(filter, 'min', column),
|
|
39
|
+
max = getComparableValue(filter, 'max', column);
|
|
91
40
|
|
|
92
|
-
|
|
93
|
-
const onChange = event => {
|
|
94
|
-
event.model = { item };
|
|
95
|
-
return column._amountValueChanged(event);
|
|
96
|
-
};
|
|
97
|
-
return html`<paper-input no-label-float type="number" @change=${ onChange } .value=${ column.getInputString(item, column.valuePath) }>
|
|
98
|
-
<div suffix>${ column.getCurrency(item, column.valuePath) }</div>
|
|
99
|
-
</paper-input>`;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// eslint-disable-next-line max-lines-per-function
|
|
103
|
-
renderHeader(column) {
|
|
104
|
-
const onOpenedChanged = event => {
|
|
105
|
-
column.headerFocused = event.detail.value;
|
|
106
|
-
column._onDropdownOpenedChanged(event);
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
return html`
|
|
110
|
-
<cosmoz-clear-button @click=${ () => column.resetFilter() } ?visible=${ column.hasFilter() }></cosmoz-clear-button>
|
|
111
|
-
<paper-dropdown-menu
|
|
112
|
-
label=${ column.title }
|
|
113
|
-
placeholder=${ ifDefined(column._filterText) }
|
|
114
|
-
class="external-values-${ column.externalValues }"
|
|
115
|
-
title=${ column._tooltip }
|
|
116
|
-
horizontal-align=${ column.preferredDropdownHorizontalAlign }
|
|
117
|
-
?opened=${ column.headerFocused }
|
|
118
|
-
@opened-changed=${ onOpenedChanged }
|
|
119
|
-
>
|
|
120
|
-
<div class="dropdown-content" slot="dropdown-content" style="padding: 15px; min-width: 150px;">
|
|
121
|
-
<h3 style="margin: 0;">${ column.title }</h3>
|
|
122
|
-
<paper-input
|
|
123
|
-
class=${ column._fromClasses }
|
|
124
|
-
type="number"
|
|
125
|
-
label=${ _('Min amount') }
|
|
126
|
-
title=${ _('Minimum amount') }
|
|
127
|
-
.value=${ column._filterInput.min }
|
|
128
|
-
@value-changed=${ event => column.set('_filterInput.min', event.detail.value) }
|
|
129
|
-
@blur=${ event => column._onBlur(event) }
|
|
130
|
-
@keydown=${ event => column._onKeyDown(event) }
|
|
131
|
-
min=${ column._toInputStringAmount(column._limit.fromMin) }
|
|
132
|
-
max=${ column._toInputStringAmount(column._limit.fromMax) }
|
|
133
|
-
><div slot="suffix" suffix>${ column.filter.min?.currency }</div></paper-input>
|
|
134
|
-
<paper-input
|
|
135
|
-
class=${ column._toClasses }
|
|
136
|
-
type="number"
|
|
137
|
-
label=${ _('Max amount') }
|
|
138
|
-
title=${ _('Maximum amount') }
|
|
139
|
-
.value=${ column._filterInput.max }
|
|
140
|
-
@value-changed=${ event => column.set('_filterInput.max', event.detail.value) }
|
|
141
|
-
@blur=${ event => column._onBlur(event) }
|
|
142
|
-
@keydown=${ event => column._onKeyDown(event) }
|
|
143
|
-
min=${ column._toInputStringAmount(column._limit.toMin) }
|
|
144
|
-
max=${ column._toInputStringAmount(column._limit.toMax) }
|
|
145
|
-
><div slot="suffix" suffix>${ column.filter.max?.currency }</div></paper-input>
|
|
146
|
-
</div>
|
|
147
|
-
</paper-dropdown-menu>
|
|
148
|
-
`;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* Auto-detect currency property: Most frequently occurring currency
|
|
153
|
-
* @param {boolean} autodetect Whether the currency property will be the currency with highest occurrence in values or not.
|
|
154
|
-
* @param {string} currency Base currency used in filters.
|
|
155
|
-
* @param {Array} values Array of amounts
|
|
156
|
-
* @returns {void}
|
|
157
|
-
*/
|
|
158
|
-
_valuesChanged(autodetect, currency, values) {
|
|
159
|
-
if (!Array.isArray(values) || values.length < 1) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
if (!autodetect && currency) {
|
|
41
|
+
if (min == null && max == null) {
|
|
163
42
|
return;
|
|
164
43
|
}
|
|
165
|
-
|
|
166
|
-
const currencies = values.reduce((p, n) => {
|
|
167
|
-
if (n.currency) {
|
|
168
|
-
const c = n.currency;
|
|
169
|
-
p[c] = (p[c] || 0) + 1;
|
|
170
|
-
}
|
|
171
|
-
return p;
|
|
172
|
-
}, {});
|
|
173
|
-
|
|
174
|
-
let key = Object.keys(currencies)[0];
|
|
175
|
-
Object.keys(currencies).reduce((p, n) => {
|
|
176
|
-
const max = Math.max(p, currencies[n]);
|
|
177
|
-
if (max === currencies[n]) {
|
|
178
|
-
key = n;
|
|
179
|
-
}
|
|
180
|
-
return max;
|
|
181
|
-
}, 0);
|
|
182
|
-
this.set('currency', key);
|
|
44
|
+
return applySingleFilter(column, filter);
|
|
183
45
|
}
|
|
184
46
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
*
|
|
188
|
-
* @param {Object} value The value to convert to number
|
|
189
|
-
* @param {Object} limit The value used to limit the number
|
|
190
|
-
* @param {Function} limitFunc The function used to limit the number (Math.min|Math.max)
|
|
191
|
-
* @returns {Object|void} Value converted to Number or void
|
|
192
|
-
*/
|
|
193
|
-
toAmount(value, limit, limitFunc) { // eslint-disable-line max-statements
|
|
194
|
-
if (value == null || value === '') {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
if (typeof value !== 'object' || value.currency == null || value.currency === '') {
|
|
199
|
-
return null;
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
const number = this.toNumber(value.amount);
|
|
203
|
-
if (number == null || Number.isNaN(number)) {
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
206
|
-
const amount = {
|
|
207
|
-
currency: value.currency,
|
|
208
|
-
amount: number
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
if (limitFunc == null || limit == null) {
|
|
212
|
-
return amount;
|
|
213
|
-
}
|
|
214
|
-
const lAmount = this.toAmount(limit);
|
|
215
|
-
if (lAmount == null) {
|
|
216
|
-
return amount;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// calculate value and limit amounts with rates
|
|
220
|
-
const rates = this.rates || {},
|
|
221
|
-
valAmount = amount.amount * (rates[amount.currency] || 1),
|
|
222
|
-
limAmount = lAmount.amount * (rates[lAmount.currency] || 1),
|
|
223
|
-
lNumber = this.toNumber(valAmount, limAmount, limitFunc);
|
|
224
|
-
return lNumber === valAmount ? amount : lAmount;
|
|
47
|
+
getString(column, item) {
|
|
48
|
+
return getString(column, item);
|
|
225
49
|
}
|
|
226
50
|
|
|
227
|
-
|
|
228
|
-
return
|
|
51
|
+
toXlsxValue(column, item) {
|
|
52
|
+
return getString(column, item);
|
|
229
53
|
}
|
|
230
54
|
|
|
231
|
-
|
|
232
|
-
return
|
|
55
|
+
cellTitleFn(column, item) {
|
|
56
|
+
return getString(column, item);
|
|
233
57
|
}
|
|
234
58
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
* @param {Object} item Item to be processed
|
|
239
|
-
* @param {String} valuePath Property path
|
|
240
|
-
* @returns {Number|void} Valid value or void
|
|
241
|
-
*/
|
|
242
|
-
getComparableValue(item, valuePath) {
|
|
243
|
-
const value = super.getComparableValue(item, valuePath);
|
|
59
|
+
getComparableValue(item, valuePath, column) {
|
|
60
|
+
return getComparableValue(item, valuePath, column);
|
|
61
|
+
}
|
|
244
62
|
|
|
245
|
-
|
|
63
|
+
serializeFilter({ rates }, filter) {
|
|
64
|
+
if (filter == null) {
|
|
246
65
|
return;
|
|
247
66
|
}
|
|
248
|
-
const
|
|
249
|
-
|
|
67
|
+
const
|
|
68
|
+
min = toAmount(rates, filter.min),
|
|
69
|
+
max = toAmount(rates, filter.max);
|
|
250
70
|
|
|
251
|
-
if (
|
|
252
|
-
return
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return amount * (rates[value.currency] || 1);
|
|
256
|
-
}
|
|
257
|
-
getString(item, valuePath = this.valuePath) {
|
|
258
|
-
const value = this.toValue(this.get(valuePath, item));
|
|
259
|
-
if (value === undefined) {
|
|
260
|
-
return '';
|
|
261
|
-
}
|
|
262
|
-
if (value === null) {
|
|
263
|
-
return 'Invalid value';
|
|
71
|
+
if (min == null && max == null) {
|
|
72
|
+
return;
|
|
264
73
|
}
|
|
265
|
-
return
|
|
74
|
+
return toHashString(min) + '~' + toHashString(max);
|
|
266
75
|
}
|
|
267
76
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
getFormatter(currency, locale) {
|
|
274
|
-
const id = locale ? locale : '',
|
|
275
|
-
key = currency + id || '',
|
|
276
|
-
formatters = this._formatters = this._formatters || {};
|
|
277
|
-
if (formatters[key]) {
|
|
278
|
-
return formatters[key];
|
|
77
|
+
deserializeFilter(column, filter) {
|
|
78
|
+
if (filter == null || filter === '') {
|
|
79
|
+
return null;
|
|
279
80
|
}
|
|
81
|
+
const matches = filter.match(/^([^~]+)?~([^~]+)?/iu);
|
|
280
82
|
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
currency
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
return formatters[key];
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Converts an amount to symbol and value to be rendered.
|
|
290
|
-
*
|
|
291
|
-
* @param {Object} value Amount to be formated
|
|
292
|
-
* @param {Object} _formatters = this._formatters All possible formatters.
|
|
293
|
-
* @returns {String} Formated value or empty string.
|
|
294
|
-
*/
|
|
295
|
-
renderValue(value) {
|
|
296
|
-
const amount = this.toAmount(value);
|
|
297
|
-
if (amount == null) {
|
|
298
|
-
return '';
|
|
83
|
+
if (!Array.isArray(matches)) {
|
|
84
|
+
return null;
|
|
299
85
|
}
|
|
300
|
-
return this.getFormatter(amount.currency, this.locale)
|
|
301
|
-
.format(value.amount);
|
|
302
|
-
}
|
|
303
|
-
|
|
304
|
-
_amountValueChanged(event) {
|
|
305
|
-
const input = event.target,
|
|
306
|
-
value = input.value,
|
|
307
|
-
item = event.model.item,
|
|
308
|
-
originalValue = this.get(this.valuePath, item),
|
|
309
|
-
amountValue = Number(value),
|
|
310
|
-
newValue = {
|
|
311
|
-
amount: amountValue,
|
|
312
|
-
currency: originalValue.currency
|
|
313
|
-
};
|
|
314
86
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
_toInputString(value) {
|
|
320
|
-
const amount = this.toValue(value);
|
|
321
|
-
if (amount == null) {
|
|
322
|
-
return null; //Need null to clear input
|
|
323
|
-
}
|
|
324
|
-
return this.toNumber(amount.amount);
|
|
87
|
+
return {
|
|
88
|
+
min: fromHashString(matches[1]),
|
|
89
|
+
max: fromHashString(matches[2])
|
|
90
|
+
};
|
|
325
91
|
}
|
|
326
92
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (rates == null) {
|
|
330
|
-
return this._toInputString(value);
|
|
331
|
-
}
|
|
332
|
-
const amount = this.toValue(value);
|
|
333
|
-
if (amount == null) {
|
|
334
|
-
return null;
|
|
335
|
-
}
|
|
336
|
-
const toCurrency = this.toNumber(amount.amount) * (rates[amount.currency] || 1) / (rates[this.currency] || 1);
|
|
337
|
-
return toCurrency.toFixed(2);
|
|
93
|
+
renderCell(column, { item }) {
|
|
94
|
+
return html`<span>${ column.getString(column, item) }</span>`;
|
|
338
95
|
}
|
|
339
96
|
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
}
|
|
345
|
-
return this.toValue({
|
|
346
|
-
amount: number,
|
|
347
|
-
currency: property && this.get(['filter', property, 'currency']) || this.currency
|
|
97
|
+
renderEditCell(column, { item }, onItemChange) {
|
|
98
|
+
const onChange = event => onItemChange({
|
|
99
|
+
amount: event.target.value,
|
|
100
|
+
currency: get(item, column.valuePath)?.currency
|
|
348
101
|
});
|
|
349
|
-
}
|
|
350
102
|
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
return value.amount + value.currency;
|
|
103
|
+
return html`<paper-input no-label-float type="number" @change=${ onChange } .value=${ getInputString(column, item) }>
|
|
104
|
+
<div slot="suffix">${ getCurrency(column, item) }</div>
|
|
105
|
+
</paper-input>`;
|
|
356
106
|
}
|
|
357
107
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
108
|
+
renderHeader(
|
|
109
|
+
{ title,
|
|
110
|
+
min,
|
|
111
|
+
max,
|
|
112
|
+
locale,
|
|
113
|
+
rates,
|
|
114
|
+
currency,
|
|
115
|
+
autoupdate,
|
|
116
|
+
autodetect },
|
|
117
|
+
{ filter },
|
|
118
|
+
setState,
|
|
119
|
+
source
|
|
120
|
+
) {
|
|
121
|
+
return html`<cosmoz-omnitable-amount-range-input
|
|
122
|
+
.title=${ title }
|
|
123
|
+
.filter=${ filter }
|
|
124
|
+
.values=${ source }
|
|
125
|
+
.rates=${ rates }
|
|
126
|
+
.min=${ min }
|
|
127
|
+
.max=${ max }
|
|
128
|
+
.locale=${ locale }
|
|
129
|
+
.currency=${ currency }
|
|
130
|
+
.autoupdate=${ autoupdate }
|
|
131
|
+
.autodetect=${ autodetect }
|
|
132
|
+
@filter-changed=${ ({ detail: { value }}) => setState(state => ({ ...state, filter: value })) }
|
|
133
|
+
@header-focused-changed=${ ({ detail: { value }}) => setState(state => ({ ...state, headerFocused: value })) }
|
|
134
|
+
></cosmoz-omnitable-amount-range-input>`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
computeSource({ valuePath }, data) {
|
|
138
|
+
return valuesFrom(data, valuePath);
|
|
370
139
|
}
|
|
371
140
|
}
|
|
372
141
|
|
|
373
|
-
customElements.define(
|
|
142
|
+
customElements.define('cosmoz-omnitable-column-amount', OmnitableColumnAmount);
|
|
@@ -6,11 +6,19 @@ import {
|
|
|
6
6
|
html, nothing
|
|
7
7
|
} from 'lit-html';
|
|
8
8
|
|
|
9
|
-
import { columnMixin } from './cosmoz-omnitable-column-mixin.js';
|
|
10
|
-
import { listColumnMixin } from './cosmoz-omnitable-column-list-mixin';
|
|
9
|
+
import { columnMixin, getString } from './cosmoz-omnitable-column-mixin.js';
|
|
10
|
+
import { computeSource, listColumnMixin, onChange, onFocus, onText, toAutocompleteSource } from './cosmoz-omnitable-column-list-mixin';
|
|
11
11
|
import {
|
|
12
12
|
prop, strProp, array
|
|
13
13
|
} from '@neovici/cosmoz-autocomplete/lib/utils';
|
|
14
|
+
import { get } from '@polymer/polymer/lib/utils/path';
|
|
15
|
+
|
|
16
|
+
export const
|
|
17
|
+
getComparableValue = (item, valuePath, { textProperty, valueProperty } = {}) => {
|
|
18
|
+
const property = textProperty ? strProp(textProperty) : prop(valueProperty),
|
|
19
|
+
values = array(valuePath && get(item, valuePath)).map(property);
|
|
20
|
+
return values.length > 1 ? values.filter(Boolean).join(',') : values[0];
|
|
21
|
+
};
|
|
14
22
|
|
|
15
23
|
/**
|
|
16
24
|
* @polymer
|
|
@@ -18,69 +26,50 @@ import {
|
|
|
18
26
|
* @appliesMixin columnMixin
|
|
19
27
|
*/
|
|
20
28
|
class OmnitableColumnAutocomplete extends listColumnMixin(columnMixin(PolymerElement)) {
|
|
21
|
-
static get is() {
|
|
22
|
-
return 'cosmoz-omnitable-column-autocomplete';
|
|
23
|
-
}
|
|
24
|
-
|
|
25
29
|
static get properties() {
|
|
26
30
|
return {
|
|
27
|
-
headerCellClass: {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
minWidth: {
|
|
33
|
-
type: String,
|
|
34
|
-
value: '55px'
|
|
35
|
-
},
|
|
36
|
-
|
|
37
|
-
editMinWidth: {
|
|
38
|
-
type: String,
|
|
39
|
-
value: '55px'
|
|
40
|
-
}
|
|
31
|
+
headerCellClass: { type: String, value: 'autocomplete-header-cell' },
|
|
32
|
+
minWidth: { type: String, value: '55px' },
|
|
33
|
+
editMinWidth: { type: String, value: '55px' }
|
|
41
34
|
};
|
|
42
35
|
}
|
|
43
36
|
|
|
44
37
|
renderCell(column, { item }) {
|
|
45
|
-
return html`<span class="default-column">${ column.getString(
|
|
38
|
+
return html`<span class="default-column">${ column.getString(column, item) }</span>`;
|
|
46
39
|
}
|
|
47
40
|
|
|
48
|
-
renderEditCell(column, { item }) {
|
|
49
|
-
const onChange = event =>
|
|
50
|
-
|
|
51
|
-
return column._valueChanged(event);
|
|
52
|
-
};
|
|
53
|
-
return html`<paper-input
|
|
54
|
-
no-label-float
|
|
55
|
-
type="text"
|
|
56
|
-
@change=${ onChange }
|
|
57
|
-
.value=${ column.getString(item, column.valuePath) }
|
|
58
|
-
></paper-input>`;
|
|
41
|
+
renderEditCell(column, { item }, onItemChange) {
|
|
42
|
+
const onChange = event => onItemChange(event.target.value);
|
|
43
|
+
return html`<paper-input no-label-float type="text" @change=${ onChange } .value=${ getString(column, item) }></paper-input>`;
|
|
59
44
|
}
|
|
60
45
|
|
|
61
|
-
renderHeader(column) {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
46
|
+
renderHeader(column, { filter, query }, setState, source) {
|
|
47
|
+
const
|
|
48
|
+
spinner = column.loading
|
|
49
|
+
? html`<paper-spinner-lite style="width: 20px; height: 20px;" suffix slot="suffix" active></paper-spinner-lite>`
|
|
50
|
+
: nothing;
|
|
65
51
|
|
|
66
52
|
return html`<cosmoz-autocomplete-ui
|
|
67
53
|
class="external-values-${ column.externalValues }"
|
|
68
54
|
.label=${ column.title }
|
|
69
|
-
.source=${ column.
|
|
55
|
+
.source=${ toAutocompleteSource(source, column.valueProperty, column.textProperty) }
|
|
70
56
|
.textProperty=${ column.textProperty }
|
|
71
57
|
.valueProperty=${ column.valueProperty }
|
|
72
|
-
.value=${
|
|
73
|
-
.text=${
|
|
74
|
-
.onChange=${
|
|
75
|
-
.onFocus=${
|
|
76
|
-
.onText=${
|
|
58
|
+
.value=${ filter }
|
|
59
|
+
.text=${ query }
|
|
60
|
+
.onChange=${ onChange(setState) }
|
|
61
|
+
.onFocus=${ onFocus(setState) }
|
|
62
|
+
.onText=${ onText(setState) }
|
|
77
63
|
>${ spinner }</cosmoz-autocomplete-ui>`;
|
|
78
64
|
}
|
|
79
65
|
|
|
80
|
-
getComparableValue(item, valuePath
|
|
81
|
-
|
|
82
|
-
values = array(valuePath && this.get(valuePath, item)).map(property);
|
|
83
|
-
return values.length > 1 ? values.filter(Boolean).join(',') : values[0];
|
|
66
|
+
getComparableValue(item, valuePath, column) {
|
|
67
|
+
return getComparableValue(item, valuePath, column);
|
|
84
68
|
}
|
|
69
|
+
|
|
70
|
+
computeSource(column, data) {
|
|
71
|
+
return computeSource(column, data);
|
|
72
|
+
}
|
|
73
|
+
|
|
85
74
|
}
|
|
86
|
-
customElements.define(
|
|
75
|
+
customElements.define('cosmoz-omnitable-column-autocomplete', OmnitableColumnAutocomplete);
|