@dile/crud 2.12.1 → 2.12.3
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/components/crud/src/DileCrud.js +6 -0
- package/components/list/src/DileCrudList.js +8 -0
- package/components/select-ajax-simple/src/DileSelectAjaxSimple.js +47 -0
- package/components/ui/src/DileCrudFilters.js +31 -2
- package/components/ui/src/DileCrudFiltersForm.js +10 -0
- package/components/ui/src/DileCrudFiltersList.js +22 -11
- package/package.json +3 -3
|
@@ -295,6 +295,7 @@ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
|
|
|
295
295
|
class="action-controller"
|
|
296
296
|
id="elfilters"
|
|
297
297
|
@filters-changed=${this.filtersChanged}
|
|
298
|
+
@filters-display-changed=${this.filtersDisplayChanged}
|
|
298
299
|
.filters=${this.config.availableFilters || []}
|
|
299
300
|
language="${this.language}"
|
|
300
301
|
></dile-crud-filters>
|
|
@@ -369,6 +370,7 @@ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
|
|
|
369
370
|
<dile-crud-filters-inline
|
|
370
371
|
id="elfilters"
|
|
371
372
|
@filters-changed=${this.filtersChanged}
|
|
373
|
+
@filters-display-changed=${this.filtersDisplayChanged}
|
|
372
374
|
.filters=${this.config.availableFilters || []}
|
|
373
375
|
language="${this.language}"
|
|
374
376
|
></dile-crud-filters-inline>
|
|
@@ -525,6 +527,10 @@ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
|
|
|
525
527
|
this.listElement.setFilters(e.detail.filters);
|
|
526
528
|
}
|
|
527
529
|
|
|
530
|
+
filtersDisplayChanged() {
|
|
531
|
+
this.listElement?.refreshFiltersList?.();
|
|
532
|
+
}
|
|
533
|
+
|
|
528
534
|
removeFilter(e) {
|
|
529
535
|
if(e.detail.name == 'keyword') {
|
|
530
536
|
const searchInput = this.searchInputElement;
|
|
@@ -440,6 +440,14 @@ export class DileCrudList extends DileI18nMixin(DileLoading(LitElement)) {
|
|
|
440
440
|
this.elservice.setPageSize(size);
|
|
441
441
|
}
|
|
442
442
|
|
|
443
|
+
/**
|
|
444
|
+
* Re-renders the active filters chips without reloading the list
|
|
445
|
+
* (e.g. when the label of a select_ajax filter value becomes known).
|
|
446
|
+
*/
|
|
447
|
+
refreshFiltersList() {
|
|
448
|
+
this.shadowRoot.querySelector('dile-crud-filters-list')?.requestUpdate();
|
|
449
|
+
}
|
|
450
|
+
|
|
443
451
|
setFilters(filters) {
|
|
444
452
|
this.loading = true;
|
|
445
453
|
this.filters = filters;
|
|
@@ -106,6 +106,7 @@ export class DileSelectAjaxSimple extends DileAxios(DileEmmitChange(LitElement))
|
|
|
106
106
|
if (this.value) {
|
|
107
107
|
this.selectCurrentValue();
|
|
108
108
|
}
|
|
109
|
+
this.dispatchDataLoaded();
|
|
109
110
|
});
|
|
110
111
|
} else {
|
|
111
112
|
this.registerError();
|
|
@@ -124,6 +125,51 @@ export class DileSelectAjaxSimple extends DileAxios(DileEmmitChange(LitElement))
|
|
|
124
125
|
return Array.isArray(json) ? json : [];
|
|
125
126
|
}
|
|
126
127
|
|
|
128
|
+
/**
|
|
129
|
+
* The item in `data` whose `idProperty` matches the current `value`, or null.
|
|
130
|
+
*/
|
|
131
|
+
get selectedItem() {
|
|
132
|
+
if (this.value === undefined || this.value === null || this.value === '') {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
return (this.data || []).find(item => String(item[this.idProperty]) === String(this.value)) ?? null;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* The `displayProperty` of the selected item, or an empty string when unknown.
|
|
140
|
+
*/
|
|
141
|
+
get selectedLabel() {
|
|
142
|
+
return this.selectedItem?.[this.displayProperty] ?? '';
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
emmitChange() {
|
|
146
|
+
this.dispatchEvent(new CustomEvent('element-changed', {
|
|
147
|
+
bubbles: true,
|
|
148
|
+
composed: true,
|
|
149
|
+
detail: {
|
|
150
|
+
name: this.name,
|
|
151
|
+
value: this.value,
|
|
152
|
+
selectedItem: this.selectedItem,
|
|
153
|
+
selectedLabel: this.selectedLabel,
|
|
154
|
+
}
|
|
155
|
+
}));
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Notifies that options are available, without emitting a value change
|
|
159
|
+
dispatchDataLoaded() {
|
|
160
|
+
this.dispatchEvent(new CustomEvent('dile-select-ajax-data-loaded', {
|
|
161
|
+
bubbles: true,
|
|
162
|
+
composed: true,
|
|
163
|
+
detail: {
|
|
164
|
+
name: this.name,
|
|
165
|
+
value: this.value,
|
|
166
|
+
data: this.data,
|
|
167
|
+
selectedItem: this.selectedItem,
|
|
168
|
+
selectedLabel: this.selectedLabel,
|
|
169
|
+
}
|
|
170
|
+
}));
|
|
171
|
+
}
|
|
172
|
+
|
|
127
173
|
registerError() {
|
|
128
174
|
this.ajaxError = true;
|
|
129
175
|
this.loading = false;
|
|
@@ -171,6 +217,7 @@ export class DileSelectAjaxSimple extends DileAxios(DileEmmitChange(LitElement))
|
|
|
171
217
|
: html`
|
|
172
218
|
<dile-select
|
|
173
219
|
name="${this.name}"
|
|
220
|
+
value="${this.value ?? ''}"
|
|
174
221
|
?disabled=${this.disabled}
|
|
175
222
|
?errored=${this.errored}
|
|
176
223
|
message="${this.message || ''}"
|
|
@@ -30,6 +30,7 @@ export class DileCrudFilters extends DileI18nMixin(LitElement) {
|
|
|
30
30
|
id="elform"
|
|
31
31
|
.filters=${this.filters}
|
|
32
32
|
@dile-form-changed=${this.filtersChanged}
|
|
33
|
+
@dile-select-ajax-data-loaded=${this.selectAjaxDataLoaded}
|
|
33
34
|
></dile-crud-filters-form>
|
|
34
35
|
`;
|
|
35
36
|
}
|
|
@@ -52,21 +53,29 @@ export class DileCrudFilters extends DileI18nMixin(LitElement) {
|
|
|
52
53
|
|
|
53
54
|
filtersChanged(e) {
|
|
54
55
|
const data = e.detail.data;
|
|
56
|
+
const form = this.shadowRoot.getElementById('elform');
|
|
55
57
|
this.filters = this.filters.map(filter => {
|
|
56
58
|
if (filter.name in data) {
|
|
57
|
-
|
|
59
|
+
const valueLabel = filter.type === 'select_ajax' && form
|
|
60
|
+
? form.getSelectedLabel(filter.name)
|
|
61
|
+
: '';
|
|
62
|
+
this.setFilterValue(filter, data[filter.name], valueLabel);
|
|
58
63
|
}
|
|
59
64
|
return filter;
|
|
60
65
|
});
|
|
61
66
|
this.dispatchFiltersChanged();
|
|
62
67
|
}
|
|
63
68
|
|
|
64
|
-
setFilterValue(filter, value) {
|
|
69
|
+
setFilterValue(filter, value, valueLabel = '') {
|
|
65
70
|
switch (filter.type) {
|
|
66
71
|
case 'select':
|
|
72
|
+
filter.active = value !== '';
|
|
73
|
+
filter.value = value;
|
|
74
|
+
break;
|
|
67
75
|
case 'select_ajax':
|
|
68
76
|
filter.active = value !== '';
|
|
69
77
|
filter.value = value;
|
|
78
|
+
filter.valueLabel = value !== '' ? valueLabel : '';
|
|
70
79
|
break;
|
|
71
80
|
default:
|
|
72
81
|
filter.active = value;
|
|
@@ -74,6 +83,26 @@ export class DileCrudFilters extends DileI18nMixin(LitElement) {
|
|
|
74
83
|
}
|
|
75
84
|
}
|
|
76
85
|
|
|
86
|
+
// Options of a select_ajax filter were loaded: resolve the chip label without
|
|
87
|
+
// dispatching filters-changed (that would reload the list).
|
|
88
|
+
selectAjaxDataLoaded(e) {
|
|
89
|
+
const { name, value, selectedLabel } = e.detail;
|
|
90
|
+
const filter = this.filters.find(f => f.name === name && f.type === 'select_ajax');
|
|
91
|
+
if (!filter || !filter.active || String(filter.value) !== String(value ?? '')) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if ((filter.valueLabel || '') !== (selectedLabel || '')) {
|
|
95
|
+
filter.valueLabel = selectedLabel || '';
|
|
96
|
+
this.dispatchEvent(new CustomEvent('filters-display-changed', {
|
|
97
|
+
bubbles: true,
|
|
98
|
+
composed: true,
|
|
99
|
+
detail: {
|
|
100
|
+
filters: this.filters,
|
|
101
|
+
}
|
|
102
|
+
}));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
77
106
|
dispatchFiltersChanged() {
|
|
78
107
|
this.dispatchEvent(new CustomEvent('filters-changed', {
|
|
79
108
|
bubbles: true,
|
|
@@ -36,6 +36,16 @@ export class DileCrudFiltersForm extends DileFormChangeDetect(DileForm(LitElemen
|
|
|
36
36
|
`;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Returns the label of the option selected in a select_ajax filter field,
|
|
41
|
+
* or an empty string when it is not known (yet).
|
|
42
|
+
*/
|
|
43
|
+
getSelectedLabel(name) {
|
|
44
|
+
const field = Array.from(this.shadowRoot?.querySelectorAll('dile-select-ajax-simple') || [])
|
|
45
|
+
.find(el => el.name === name);
|
|
46
|
+
return field?.selectedLabel ?? '';
|
|
47
|
+
}
|
|
48
|
+
|
|
39
49
|
getFilterField(filter) {
|
|
40
50
|
if (filter.hidden) {
|
|
41
51
|
return '';
|
|
@@ -44,21 +44,32 @@ export class DileCrudFiltersList extends LitElement {
|
|
|
44
44
|
|
|
45
45
|
filterItemTemplate(filter) {
|
|
46
46
|
if(! filter.hidden && filter.active) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
47
|
+
return html`
|
|
48
|
+
<dile-crud-filters-list-item name="${filter.name}" label="${this.chipLabel(filter)}" ?active="${filter.active}"></dile-crud-filters-list-item>
|
|
49
|
+
`;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
chipLabel(filter) {
|
|
54
|
+
let valueLabel;
|
|
55
|
+
switch(filter.type) {
|
|
56
|
+
case 'select':
|
|
57
|
+
valueLabel = this.findLabelInOption(filter);
|
|
58
|
+
break;
|
|
59
|
+
case 'select_ajax':
|
|
60
|
+
valueLabel = filter.valueLabel || '';
|
|
61
|
+
if (!valueLabel) {
|
|
62
|
+
return filter.label;
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
default:
|
|
66
|
+
return filter.label;
|
|
57
67
|
}
|
|
68
|
+
return filter.showLabelInChip && valueLabel ? `${filter.label}: ${valueLabel}` : valueLabel;
|
|
58
69
|
}
|
|
59
70
|
|
|
60
71
|
findLabelInOption(filter) {
|
|
61
|
-
let option = filter.options.find((option) => option.value == filter.value);
|
|
72
|
+
let option = (filter.options || []).find((option) => option.value == filter.value);
|
|
62
73
|
if(option) {
|
|
63
74
|
return option.label;
|
|
64
75
|
} else {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/crud",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.3",
|
|
4
4
|
"description": "Components to create a generic crud system based on Web Components and Lit",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"homepage": "https://dile-components.com/",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@dile/image-cropper": "^0.1.1",
|
|
29
|
-
"@dile/ui": "^3.20.
|
|
29
|
+
"@dile/ui": "^3.20.2",
|
|
30
30
|
"axios": "^1.19.0",
|
|
31
31
|
"lit": "^2.7.0 || ^3.0.0"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "c6bb68030489b454927cbe7f36dd49388d87ff71"
|
|
37
37
|
}
|