@dile/crud 2.5.24 → 2.6.1
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.
|
@@ -322,12 +322,17 @@ export class DileCrudList extends DileI18nMixin(DileLoading(LitElement)) {
|
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
refresh() {
|
|
325
|
+
this.dispatchEvent(new CustomEvent('crud-list-refresh', {
|
|
326
|
+
bubbles: true,
|
|
327
|
+
composed: true,
|
|
328
|
+
}));
|
|
325
329
|
this.loading = true;
|
|
326
330
|
this.numItems = undefined;
|
|
327
331
|
if (this.isSelectAllActive) {
|
|
328
332
|
this.shadowRoot.querySelector('dile-crud-select-all').reset();
|
|
329
333
|
}
|
|
330
334
|
this.elservice.refresh();
|
|
335
|
+
|
|
331
336
|
}
|
|
332
337
|
|
|
333
338
|
setKeyword(keyword) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DileCrudListLite } from './src/DileCrudListLite.js';
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { LitElement, html, css } from 'lit';
|
|
2
|
+
import { DileAxios } from '../../../lib/DileAxios.js';
|
|
3
|
+
import '../../list/crud-list-item.js';
|
|
4
|
+
import '@dile/iconlib/dile-iconlib.js';
|
|
5
|
+
import '@dile/ui/components/spinner/spinner-horizontal.js';
|
|
6
|
+
|
|
7
|
+
export class DileCrudListLite extends DileAxios(LitElement) {
|
|
8
|
+
static styles = [
|
|
9
|
+
css`
|
|
10
|
+
:host {
|
|
11
|
+
display: block;
|
|
12
|
+
}
|
|
13
|
+
.spinner-container {
|
|
14
|
+
min-height: 2.5rem;
|
|
15
|
+
display: flex;
|
|
16
|
+
align-items: center;
|
|
17
|
+
}
|
|
18
|
+
p.empty {
|
|
19
|
+
margin: 0;
|
|
20
|
+
color: var(--dile-on-background-color, #303030);
|
|
21
|
+
}
|
|
22
|
+
p.error {
|
|
23
|
+
margin: 0;
|
|
24
|
+
color: var(--dile-crud-list-lite-error-color, #c00);
|
|
25
|
+
}
|
|
26
|
+
dile-iconlib.item-icon {
|
|
27
|
+
--dile-icon-color: var(--dile-crud-list-lite-icon-color, #888);
|
|
28
|
+
--dile-icon-size: var(--dile-crud-list-lite-icon-size, 20px);
|
|
29
|
+
margin-right: var(--dile-crud-list-lite-icon-margin-right, 0.5rem);
|
|
30
|
+
}
|
|
31
|
+
a.footer-link {
|
|
32
|
+
display: block;
|
|
33
|
+
margin-top: var(--dile-crud-list-lite-footer-link-margin-top, 0.75rem);
|
|
34
|
+
color: var(--dile-crud-list-lite-footer-link-color, var(--dile-primary-color, #7BB93D));
|
|
35
|
+
font-size: var(--dile-crud-list-lite-footer-link-font-size, 0.9rem);
|
|
36
|
+
text-align: var(--dile-crud-list-lite-footer-link-text-align, right);
|
|
37
|
+
}
|
|
38
|
+
button.show-more-link {
|
|
39
|
+
display: block;
|
|
40
|
+
width: 100%;
|
|
41
|
+
margin-top: var(--dile-crud-list-lite-show-more-link-margin-top, 0.75rem);
|
|
42
|
+
padding: 0;
|
|
43
|
+
border: 0;
|
|
44
|
+
background: none;
|
|
45
|
+
font: inherit;
|
|
46
|
+
cursor: pointer;
|
|
47
|
+
color: var(--dile-crud-list-lite-show-more-link-color, var(--dile-primary-color, #7BB93D));
|
|
48
|
+
font-size: var(--dile-crud-list-lite-show-more-link-font-size, 0.9rem);
|
|
49
|
+
text-align: var(--dile-crud-list-lite-show-more-link-text-align, right);
|
|
50
|
+
text-decoration: underline;
|
|
51
|
+
}
|
|
52
|
+
`
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
static get properties() {
|
|
56
|
+
return {
|
|
57
|
+
endpoint: { type: String },
|
|
58
|
+
resultDataProperty: { type: String },
|
|
59
|
+
getResultList: { type: Object },
|
|
60
|
+
additionalQueryString: { type: Object },
|
|
61
|
+
|
|
62
|
+
idProperty: { type: String },
|
|
63
|
+
labelProperty: { type: String },
|
|
64
|
+
linkProperty: { type: String },
|
|
65
|
+
icon: { type: String },
|
|
66
|
+
iconProperty: { type: String },
|
|
67
|
+
itemTemplate: { type: Object },
|
|
68
|
+
|
|
69
|
+
maxItems: { type: Number },
|
|
70
|
+
moreLinkLabel: { type: String },
|
|
71
|
+
footerLinkLabel: { type: String },
|
|
72
|
+
footerLinkUrl: { type: String },
|
|
73
|
+
|
|
74
|
+
showEditAction: { type: Boolean },
|
|
75
|
+
showDeleteAction: { type: Boolean },
|
|
76
|
+
showRestoreAction: { type: Boolean },
|
|
77
|
+
deletedProperty: { type: String },
|
|
78
|
+
|
|
79
|
+
emptyMessage: { type: String },
|
|
80
|
+
ajaxErrorMessage: { type: String },
|
|
81
|
+
disableLoadOnStart: { type: Boolean },
|
|
82
|
+
|
|
83
|
+
loading: { type: Boolean, state: true },
|
|
84
|
+
ajaxError: { type: Boolean, state: true },
|
|
85
|
+
data: { type: Array, state: true },
|
|
86
|
+
_visibleCount: { state: true },
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
constructor() {
|
|
91
|
+
super();
|
|
92
|
+
this.resultDataProperty = 'data';
|
|
93
|
+
this.idProperty = 'id';
|
|
94
|
+
this.labelProperty = 'name';
|
|
95
|
+
this.showEditAction = false;
|
|
96
|
+
this.showDeleteAction = false;
|
|
97
|
+
this.showRestoreAction = false;
|
|
98
|
+
this.emptyMessage = 'No data available';
|
|
99
|
+
this.ajaxErrorMessage = 'Error loading data';
|
|
100
|
+
this.disableLoadOnStart = false;
|
|
101
|
+
this.loading = false;
|
|
102
|
+
this.ajaxError = false;
|
|
103
|
+
this.data = [];
|
|
104
|
+
this._started = false;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
connectedCallback() {
|
|
108
|
+
super.connectedCallback();
|
|
109
|
+
if (!this.disableLoadOnStart) {
|
|
110
|
+
this.start();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Triggers the first load. Only needed when `disableLoadOnStart` is set;
|
|
116
|
+
* calling it again after the first load is a no-op (use refresh() instead).
|
|
117
|
+
*/
|
|
118
|
+
start() {
|
|
119
|
+
if (this._started) return;
|
|
120
|
+
this._started = true;
|
|
121
|
+
this.loadData();
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
refresh() {
|
|
125
|
+
if (!this._started) {
|
|
126
|
+
this.start();
|
|
127
|
+
} else {
|
|
128
|
+
this.loadData();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
loadData() {
|
|
133
|
+
this.loading = true;
|
|
134
|
+
this.ajaxError = false;
|
|
135
|
+
let params = { ...(this.additionalQueryString || {}) };
|
|
136
|
+
this.axiosInstance.get(this.endpoint, { params })
|
|
137
|
+
.then((response) => {
|
|
138
|
+
if (response.status === 200) {
|
|
139
|
+
this.data = this.getResultData(response.data);
|
|
140
|
+
this._visibleCount = this.maxItems;
|
|
141
|
+
this.updateComplete.then(() => this.loading = false);
|
|
142
|
+
} else {
|
|
143
|
+
this.registerError();
|
|
144
|
+
}
|
|
145
|
+
})
|
|
146
|
+
.catch(() => this.registerError());
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
getResultData(json) {
|
|
150
|
+
if (this.getResultList) {
|
|
151
|
+
return this.getResultList(json) ?? [];
|
|
152
|
+
}
|
|
153
|
+
if (this.resultDataProperty) {
|
|
154
|
+
return json[this.resultDataProperty] ?? [];
|
|
155
|
+
}
|
|
156
|
+
return Array.isArray(json) ? json : [];
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
registerError() {
|
|
160
|
+
this.ajaxError = true;
|
|
161
|
+
this.loading = false;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Returns the ids (per `idProperty`) of every fetched item, regardless of `maxItems`.
|
|
166
|
+
*/
|
|
167
|
+
getAllIds() {
|
|
168
|
+
return this.data.map(item => item[this.idProperty]);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Reveals one extra batch (of `maxItems` size) of already-fetched items.
|
|
173
|
+
*/
|
|
174
|
+
showMore() {
|
|
175
|
+
this._visibleCount = Math.min(this.data.length, (this._visibleCount ?? this.maxItems) + this.maxItems);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
render() {
|
|
179
|
+
if (!this._started) {
|
|
180
|
+
return html``;
|
|
181
|
+
}
|
|
182
|
+
return this.loading
|
|
183
|
+
? html`<div class="spinner-container"><dile-spinner-horizontal active></dile-spinner-horizontal></div>`
|
|
184
|
+
: this.ajaxError
|
|
185
|
+
? html`<p class="error">${this.ajaxErrorMessage}</p>`
|
|
186
|
+
: this.data.length === 0
|
|
187
|
+
? html`<p class="empty">${this.emptyMessage}</p>`
|
|
188
|
+
: this.listTemplate;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
get listTemplate() {
|
|
192
|
+
const items = this.maxItems ? this.data.slice(0, this._visibleCount ?? this.maxItems) : this.data;
|
|
193
|
+
const showMoreLinkVisible = this.moreLinkLabel && this.maxItems && items.length < this.data.length;
|
|
194
|
+
return html`
|
|
195
|
+
<div class="elements-container">
|
|
196
|
+
${items.map(item => html`
|
|
197
|
+
<dile-crud-list-item
|
|
198
|
+
.item=${item}
|
|
199
|
+
itemId="${item[this.idProperty]}"
|
|
200
|
+
hideCheckboxSelection
|
|
201
|
+
?disableEdit=${!this.showEditAction}
|
|
202
|
+
?disableDelete=${!this.showDeleteAction}
|
|
203
|
+
?disableRestore=${!this.showRestoreAction}
|
|
204
|
+
?isDeleted=${this.deletedProperty && item[this.deletedProperty]}
|
|
205
|
+
>
|
|
206
|
+
${this.itemTemplate ? this.itemTemplate(item) : this.defaultItemTemplate(item)}
|
|
207
|
+
</dile-crud-list-item>
|
|
208
|
+
`)}
|
|
209
|
+
</div>
|
|
210
|
+
${showMoreLinkVisible ? html`<button type="button" class="show-more-link" @click=${this.showMore}>${this.moreLinkLabel}</button>` : ''}
|
|
211
|
+
${this.footerLinkUrl ? html`<a class="footer-link" href="${this.footerLinkUrl}">${this.footerLinkLabel}</a>` : ''}
|
|
212
|
+
`;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
defaultItemTemplate(item) {
|
|
216
|
+
const icon = (this.iconProperty && item[this.iconProperty]) || this.icon;
|
|
217
|
+
const label = item[this.labelProperty];
|
|
218
|
+
return html`
|
|
219
|
+
${icon ? html`<dile-iconlib class="item-icon" icon="${icon}" aria-hidden="true"></dile-iconlib>` : ''}
|
|
220
|
+
${this.linkProperty
|
|
221
|
+
? html`<a href="${item[this.linkProperty]}">${label}</a>`
|
|
222
|
+
: html`<span>${label}</span>`
|
|
223
|
+
}
|
|
224
|
+
`;
|
|
225
|
+
}
|
|
226
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/crud",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
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",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://dile-components.com/",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@dile/ui": "^3.9.
|
|
28
|
+
"@dile/ui": "^3.9.3",
|
|
29
29
|
"axios": "^1.19.0",
|
|
30
30
|
"lit": "^2.7.0 || ^3.0.0"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "6c8664d4efb3dea1f363ed00eee50c8964fa2321"
|
|
36
36
|
}
|