@dile/crud 0.0.9

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.
Files changed (79) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +5 -0
  3. package/components/action/crud-actions.js +2 -0
  4. package/components/action/crud-delete-action.js +2 -0
  5. package/components/action/crud-single-actions.js +2 -0
  6. package/components/action/src/DileCrudActions.js +181 -0
  7. package/components/action/src/DileCrudDeleteAction.js +18 -0
  8. package/components/action/src/DileCrudSingleActions.js +77 -0
  9. package/components/ajax/ajax.js +2 -0
  10. package/components/ajax/index.js +1 -0
  11. package/components/ajax/src/DileAjax.js +108 -0
  12. package/components/ajax-form/ajax-form.js +2 -0
  13. package/components/ajax-form/index.js +1 -0
  14. package/components/ajax-form/src/DileAjaxForm.js +216 -0
  15. package/components/ajax-select-crud/ajax-select-crud.js +3 -0
  16. package/components/ajax-select-crud/index.js +1 -0
  17. package/components/ajax-select-crud/src/DileAjaxSelectCrud.js +75 -0
  18. package/components/crud/crud-single.js +2 -0
  19. package/components/crud/crud.js +2 -0
  20. package/components/crud/delete-action.js +2 -0
  21. package/components/crud/src/DileCrud.js +352 -0
  22. package/components/detail/crud-detail.js +2 -0
  23. package/components/detail/src/DileCrudDetail.js +166 -0
  24. package/components/insert/crud-insert.js +2 -0
  25. package/components/insert/index.js +1 -0
  26. package/components/insert/src/DileCrudInsert.js +78 -0
  27. package/components/item-delete/crud-item-delete.js +2 -0
  28. package/components/item-delete/index.js +1 -0
  29. package/components/item-delete/src/DileCrudItemDelete.js +106 -0
  30. package/components/list/crud-list-item.js +2 -0
  31. package/components/list/crud-list-pagination-links.js +2 -0
  32. package/components/list/crud-list-service.js +2 -0
  33. package/components/list/crud-list.js +2 -0
  34. package/components/list/crud-select-all.js +2 -0
  35. package/components/list/index.js +5 -0
  36. package/components/list/src/DileCrudList.js +332 -0
  37. package/components/list/src/DileCrudListItem.js +129 -0
  38. package/components/list/src/DileCrudListPaginationLinks.js +89 -0
  39. package/components/list/src/DileCrudListService.js +163 -0
  40. package/components/list/src/DileCrudSelectAll.js +158 -0
  41. package/components/single/crud-single.js +2 -0
  42. package/components/single/index.js +1 -0
  43. package/components/single/src/DileCrudSingle.js +142 -0
  44. package/components/ui/crud-filters-form.js +3 -0
  45. package/components/ui/crud-filters-list-item.js +2 -0
  46. package/components/ui/crud-filters-list.js +2 -0
  47. package/components/ui/crud-filters.js +2 -0
  48. package/components/ui/crud-list-options.js +2 -0
  49. package/components/ui/crud-page-size-select.js +2 -0
  50. package/components/ui/crud-page-size.js +2 -0
  51. package/components/ui/crud-pagination-nav-button.js +2 -0
  52. package/components/ui/crud-sort-form.js +2 -0
  53. package/components/ui/index.js +4 -0
  54. package/components/ui/src/DileCrudFilters.js +62 -0
  55. package/components/ui/src/DileCrudFiltersForm.js +58 -0
  56. package/components/ui/src/DileCrudFiltersList.js +70 -0
  57. package/components/ui/src/DileCrudFiltersListItem.js +28 -0
  58. package/components/ui/src/DileCrudListOptions.js +64 -0
  59. package/components/ui/src/DileCrudPageSize.js +27 -0
  60. package/components/ui/src/DileCrudPageSizeSelect.js +44 -0
  61. package/components/ui/src/DileCrudPaginationNavButton.js +44 -0
  62. package/components/ui/src/DileCrudSortForm.js +105 -0
  63. package/components/update/crud-update.js +2 -0
  64. package/components/update/index.js +1 -0
  65. package/components/update/src/DileCrudUpdate.js +81 -0
  66. package/lib/AxiosInstanceBuilder.js +21 -0
  67. package/lib/CrudConfigBuilder.js +13 -0
  68. package/lib/DileAxios.js +14 -0
  69. package/lib/DileConfig.js +0 -0
  70. package/lib/DileCrudMixin.js +72 -0
  71. package/lib/DileLoading.js +31 -0
  72. package/lib/RequestApiAdapter.js +15 -0
  73. package/lib/ResponseApiAdapter.js +37 -0
  74. package/lib/capitalizeString.js +3 -0
  75. package/lib/deepMerge.js +38 -0
  76. package/lib/defaultConfig.js +67 -0
  77. package/package.json +35 -0
  78. package/styles/crud-styles.js +6 -0
  79. package/styles/form-styles.js +24 -0
@@ -0,0 +1,106 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import '@dile/ui/components/confirm/confirm';
3
+ import { ResponseApiAdapter } from '../../../lib/ResponseApiAdapter.js';
4
+
5
+ export class DileCrudItemDelete extends LitElement {
6
+ static styles = [
7
+ css`
8
+ :host {
9
+ display: block;
10
+ --dile-modal-border-radius: 2px;
11
+ --dile-modal-width: 300px;
12
+ --dile-modal-height: auto;
13
+ --dile-modal-content-padding: 1.5rem;
14
+ --dile-modal-background-color: rgba(90, 20, 20, 0.7);
15
+ --dile-modal-content-shadow-color: rgba(90, 20, 20, 0.5);
16
+ --dile-confirm-buttons-text-align: center;
17
+ --dile-confirm-accept-button-color: var(--delete-icon-color, #e33);
18
+ --dile-confirm-accept-text-button-color: #fff;
19
+ --dile-confirm-cancel-button-color: var(--neutral-icon-color, #337aad);
20
+ --dile-confirm-cancel-text-button-color: #fff;
21
+ }
22
+ p {
23
+ text-align: center;
24
+ color: #303030;
25
+ }
26
+ `
27
+ ];
28
+
29
+ static get properties() {
30
+ return {
31
+ endpoint: { type: String },
32
+ relatedId: { type: String },
33
+ responseAdapter: { type: Object },
34
+ confirmMessage: { type: String },
35
+ cancelLabel: { type: String },
36
+ acceptLabel: { type: String },
37
+ };
38
+ }
39
+
40
+ constructor() {
41
+ super();
42
+ this.responseAdapter = new ResponseApiAdapter();
43
+ this.confirmMessage = 'Are you sure you want to delete this item?';
44
+ this.cancelLabel = 'Cancel';
45
+ this.acceptLabel = 'Delete'
46
+ }
47
+
48
+ firstUpdated() {
49
+ this.elconfirm = this.shadowRoot.getElementById('elconfirm');
50
+ this.ajaxdelete = this.shadowRoot.getElementById('ajaxdelete');
51
+ }
52
+
53
+ render() {
54
+ return html`
55
+ <dile-ajax
56
+ id="ajaxdelete"
57
+ method="delete"
58
+ url="${this.endpoint}/${this.relatedId}"
59
+ @ajax-success="${this.doSuccessDelete}"
60
+ @ajax-error="${this.doErrorDelete}"
61
+ ></dile-ajax>
62
+ <dile-confirm
63
+ cancelLabel="${this.cancelLabel}"
64
+ acceptLabel="${this.acceptLabel}"
65
+ id="elconfirm"
66
+ @dile-confirm-accepted=${this.deleteAccepted}
67
+ >
68
+ <p>${this.confirmMessage}</p>
69
+ </dile-confirm>
70
+ `;
71
+ }
72
+
73
+ delete(itemId) {
74
+ this.relatedId = itemId;
75
+ this.elconfirm.open();
76
+ }
77
+
78
+ deleteAccepted() {
79
+ this.ajaxdelete.generateRequest();
80
+ }
81
+
82
+ doSuccessDelete(e) {
83
+ this.dispatchEvent(new CustomEvent('delete-success', { bubbles: true, composed: true }));
84
+ }
85
+
86
+ doErrorDelete(e) {
87
+ let msg = this.computeResponseMessage(e.detail);
88
+ this.dispatchEvent(new CustomEvent('delete-error', {
89
+ bubbles: true,
90
+ composed: true,
91
+ detail: {
92
+ msg,
93
+ previousDetail: e.detail,
94
+ }
95
+ }));
96
+ }
97
+
98
+ computeResponseMessage(detail) {
99
+ this.responseAdapter.setResponse(detail);
100
+ let msg = this.responseAdapter.getMessage();
101
+ if(! msg) {
102
+ msg = 'Error';
103
+ }
104
+ return msg;
105
+ }
106
+ }
@@ -0,0 +1,2 @@
1
+ import { DileCrudListItem } from './src/DileCrudListItem';
2
+ customElements.define('dile-crud-list-item', DileCrudListItem);
@@ -0,0 +1,2 @@
1
+ import { DileCrudListPaginationLinks } from "./src/DileCrudListPaginationLinks";
2
+ customElements.define('dile-crud-list-pagination-links', DileCrudListPaginationLinks);
@@ -0,0 +1,2 @@
1
+ import { DileCrudListService } from "./src/DileCrudListService";
2
+ customElements.define('dile-crud-list-service', DileCrudListService);
@@ -0,0 +1,2 @@
1
+ import { DileCrudList } from "./src/DileCrudList";
2
+ customElements.define('dile-crud-list', DileCrudList);
@@ -0,0 +1,2 @@
1
+ import { DileCrudSelectAll } from "./src/DileCrudSelectAll";
2
+ customElements.define('dile-crud-select-all', DileCrudSelectAll);
@@ -0,0 +1,5 @@
1
+ export { DileCrudList } from "./src/DileCrudList.js";
2
+ export { DileCrudListItem } from ".src/DileCrudListItem.js";
3
+ export { DileCrudListPaginationLinks } from ".src/DileCrudListPaginationLinks.js";
4
+ export { DileCrudListService } from "./src/DileCrudListService.js";
5
+ export { DileCrudSelectAll } from "./src/DileCrudSelectAll.js";
@@ -0,0 +1,332 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import { deepMerge } from '../../../lib/deepMerge.js';
3
+ import { DileLoading, loadingStyles } from '../../../lib/DileLoading.js';
4
+ import '@dile/ui/components/button/button.js';
5
+ import '../../ajax/ajax.js'
6
+ import '../../ui/crud-filters-list.js';
7
+ import '../../list/crud-list-pagination-links.js';
8
+ import '../crud-list-item.js';
9
+ import '../crud-select-all';
10
+ import '../crud-list-service.js';
11
+
12
+ export class DileCrudList extends DileLoading(LitElement) {
13
+ static styles = [
14
+ loadingStyles,
15
+ css`
16
+ :host {
17
+ display: block;
18
+ padding: 0 0 1rem 0;
19
+ background-color: #fff;
20
+ }
21
+
22
+ .prev-summary {
23
+ display: flex;
24
+ flex-direction: column;
25
+ background-color: #999;
26
+ color: white;
27
+ font-size: 0.8em;
28
+ margin-bottom: 0.5rem;
29
+ border-bottom: 1px solid #ccc;
30
+ padding: 0.4rem 1rem;
31
+ line-height: 1.2rem;
32
+ }
33
+ dile-crud-select-all {
34
+ margin: 0.3rem 0.2rem 0.4rem 0;
35
+ }
36
+
37
+ .empty {
38
+ padding: var(--dile-crud-list-empty-padding, 3rem 1rem);
39
+ text-align: center;
40
+ }
41
+
42
+ @media(min-width: 500px) {
43
+ .prev-summary {
44
+ flex-direction: row;
45
+ align-items: center;
46
+ }
47
+ dile-crud-select-all {
48
+ margin: 0.2rem 0.6rem 0.2rem 0;
49
+ }
50
+ }
51
+ `
52
+ ];
53
+
54
+ static get properties() {
55
+ return {
56
+ config: { type: Object },
57
+ elements: { type: Array },
58
+ paginationData: { type: Object },
59
+ numItems: { type: Number },
60
+ pageSize: { type: Number },
61
+ keyword: { type: String },
62
+ isSelectAllActive: { type: Boolean },
63
+ sort: { type: Object },
64
+ actionIds: { type: Array },
65
+ filters: { type: Array },
66
+ belongsTo: { type: String },
67
+ relationId: { type: String },
68
+ };
69
+ }
70
+
71
+ constructor() {
72
+ super();
73
+ this.paginationData = {}
74
+ this.elements = [];
75
+ this.pageSize = 10;
76
+ this.keyword = '';
77
+ this.actionIds = [];
78
+ this.filters = [];
79
+ this.delayTime = 200;
80
+ this.delayTimer = null;
81
+ this.isSelectAllActive = false;
82
+ this.loading = true;
83
+ }
84
+
85
+ firstUpdated() {
86
+ this.pageSize = this.config.pageSize?.initial ?? this.pageSize;
87
+ this.elservice = this.shadowRoot.getElementById('elservice');
88
+ this.ajaxgetallids = this.shadowRoot.getElementById('ajaxgetallids');
89
+ this.updateComplete.then( () => this.refresh());
90
+
91
+ }
92
+
93
+ render() {
94
+ return html`
95
+ ${this.ajaxTemplate}
96
+
97
+ ${this.countSummaryTemplate}
98
+
99
+ ${this.filterListTemplate}
100
+
101
+ ${this.loading
102
+ ? this.loadingTemplate
103
+ : this.elements.length == 0
104
+ ? this.emptyTemplate
105
+ : html`
106
+ ${this.elementsTemplate}
107
+ ${this.config.customization?.hidePageReport ? '' : this.paginationTemplate}
108
+ `
109
+ }
110
+ `;
111
+ }
112
+
113
+ get filterListTemplate() {
114
+ return html`
115
+ <dile-crud-filters-list
116
+ keyword="${this.keyword}"
117
+ .filters="${this.filters}"
118
+ ></dile-crud-filters-list>
119
+ `
120
+ }
121
+
122
+ get countSummaryTemplate() {
123
+ return this.config.customization?.hideCountSummary ? '' : html`
124
+ <div class="prev-summary">
125
+ ${this.config.customization.hideCheckboxSelection
126
+ ? ''
127
+ : html`
128
+ <dile-crud-select-all
129
+ @crud-select-all=${this.crudSelectAll}
130
+ pageSize=${this.pageSize}
131
+ numItems=${this.numItems}
132
+ ?disablePagination=${this.config.customization?.disablePagination}
133
+ ></dile-crud-select-all>
134
+ `
135
+ }
136
+ <span>
137
+ ${this.numItems != undefined
138
+ ? html`
139
+ ${this.numItems} items in total. ${this.config.customization?.disablePagination ? '' : html`Showing ${this.pageSize} items per page.` }
140
+ `
141
+ : 'Loading...'
142
+ }
143
+ </span>
144
+ </div>
145
+ `
146
+ }
147
+
148
+ get ajaxTemplate() {
149
+ return html`
150
+ <dile-crud-list-service
151
+ id="elservice"
152
+ .config=${this.config}
153
+ .filters=${this.filters}
154
+ pageSize=${this.pageSize}
155
+ .keyword=${this.keyword}
156
+ .sort=${this.sort}
157
+ belongsTo=${this.belongsTo}
158
+ relationId=${this.relationId}
159
+ @crud-list-get-success=${this.getSuccess}
160
+ ></dile-crud-list-service>
161
+ <dile-ajax
162
+ id="ajaxgetallids"
163
+ method="get"
164
+ url="${this.allIdsUrl}"
165
+ @ajax-success="${this.doSuccessGetIds}"
166
+ @ajax-error="${this.doErrorGet}"
167
+ ></dile-ajax>
168
+ `;
169
+ }
170
+ get emptyTemplate() {
171
+ return html`
172
+ <div class="empty">
173
+ <p>There are no items yet</p>
174
+ ${this.config.customization.disableInsert || this.config.customization?.hideEmptyInsertButton
175
+ ? ''
176
+ : html`<p><dile-button @click=${this.dispatchInsertRequest}>${this.config.labels.insertAction}</dile-button></p>`
177
+ }
178
+
179
+ </div>
180
+ `;
181
+ }
182
+ get elementsTemplate() {
183
+ return html`
184
+ ${this.elements.map(element => html`
185
+ <dile-crud-list-item
186
+ itemId="${this.computeItemId(element)}"
187
+ .actionIds="${this.actionIds}"
188
+ ?disableEdit="${this.config?.customization?.disableEdit}"
189
+ ?disableDelete="${this.config?.customization?.disableDelete}"
190
+ ?hideCheckboxSelection="${this.config?.customization?.hideCheckboxSelection}"
191
+ @item-checkbox-changed=${this.onItemsCheckboxChanged}
192
+ >
193
+ ${this.config.templates.item(element)}
194
+ </dile-crud-list-item>
195
+ `)}
196
+ `;
197
+ }
198
+
199
+ getSuccess(e) {
200
+ this.loading = false;
201
+ this.elements = e.detail.elements;
202
+ this.numItems = e.detail.numItems;
203
+ this.paginationData = e.detail.paginationData;
204
+ }
205
+
206
+ computeItemId(element) {
207
+ return element.id;
208
+ }
209
+
210
+ get allIdsUrl() {
211
+ return `${this.config.endpoint}/allids`;
212
+ }
213
+
214
+ get paginationTemplate() {
215
+ if(! this.config.customization?.disablePagination) {
216
+ return html`
217
+ <dile-crud-list-pagination-links
218
+ .paginationData=${this.paginationData}
219
+ numItems="${this.numItems}"
220
+ pageSize="${this.pageSize}"
221
+ @crud-pagination-prev=${this.goPrev}
222
+ @crud-pagination-next=${this.goNext}
223
+ ></dile-crud-list-pagination-links>
224
+ `
225
+ }
226
+ }
227
+
228
+ dispatchInsertRequest() {
229
+ this.dispatchEvent(new CustomEvent('insert-requested', {
230
+ bubbles: true,
231
+ composed: true,
232
+ }));
233
+ }
234
+
235
+ goNext() {
236
+ this.elservice.goNext()
237
+ }
238
+
239
+ goPrev() {
240
+ this.elservice.goPrev()
241
+ }
242
+
243
+ refresh() {
244
+ this.loading = true;
245
+ this.numItems = undefined;
246
+ if (this.isSelectAllActive) {
247
+ this.shadowRoot.querySelector('dile-crud-select-all').reset();
248
+ }
249
+ this.elservice.refresh();
250
+ }
251
+
252
+ setKeyword(keyword) {
253
+ this.loading = true;
254
+ this.keyword = keyword;
255
+ this.elservice.setKeyword(keyword);
256
+ }
257
+
258
+ setSort(sortObject) {
259
+ this.loading = true;
260
+ this.sort = sortObject;
261
+ this.elservice.setSort(sortObject);
262
+ }
263
+
264
+ setPageSize(size) {
265
+ this.loading = true;
266
+ this.pageSize = size;
267
+ this.elservice.setPageSize(size);
268
+ }
269
+
270
+ setFilters(filters) {
271
+ this.loading = true;
272
+ this.filters = filters;
273
+ this.elservice.setFilters(filters);
274
+ }
275
+
276
+ crudSelectAll(e) {
277
+ this.isSelectAllActive = e.detail.pageChecked || e.detail.allChecked;
278
+ if (e.detail.pageChecked) {
279
+ this.dispactSelectAll(this.getPageIds());
280
+ } else if (e.detail.allChecked) {
281
+ this.getAllIds();
282
+ } else if (!e.detail.pageChecked && !e.detail.allChecked) {
283
+ this.dispactSelectAll([]);
284
+ }
285
+ }
286
+
287
+ dispactSelectAll(ids) {
288
+ this.actionIds = ids;
289
+ this.dispatchEvent(new CustomEvent('crud-list-all-ids-selected', {
290
+ bubbles: true,
291
+ composed: true,
292
+ detail: {
293
+ ids
294
+ }
295
+ }));
296
+ }
297
+
298
+ getPageIds() {
299
+ return this.elements.map(element => element.id);
300
+ }
301
+
302
+ getAllIds() {
303
+ if(this.config.customization?.disablePagination) {
304
+ let ids = this.elements.map(item => item.id);
305
+ this.dispactSelectAll(ids);
306
+ } else{
307
+ let data = {
308
+ keyword: this.keyword,
309
+ filters: this.filters,
310
+ }
311
+ if (this.belongsTo && this.relationId) {
312
+ data.belongsTo = this.belongsTo;
313
+ data.relationId = this.relationId;
314
+ }
315
+ data = this.config.requestAdapter.adaptIdsRequestData(data);
316
+ this.ajaxgetallids.data = data;
317
+ this.ajaxgetallids.generateRequest();
318
+ }
319
+ }
320
+
321
+ doSuccessGetIds(e) {
322
+ this.config.responseAdapter.setResponse(e.detail);
323
+ this.dispactSelectAll(this.config.responseAdapter.getIds());
324
+ }
325
+
326
+ onItemsCheckboxChanged(e) {
327
+ if (!e.detail.checked && this.isSelectAllActive) {
328
+ this.shadowRoot.querySelector('dile-crud-select-all').resetWithoutDispatch();
329
+ }
330
+
331
+ }
332
+ }
@@ -0,0 +1,129 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import '@dile/ui/components/checkbox/checkbox';
3
+ import '@dile/ui/components/icon/icon';
4
+ import { deleteIcon, editIcon } from '@dile/icons';
5
+
6
+ export class DileCrudListItem extends LitElement {
7
+ static styles = [
8
+ css`
9
+ :host {
10
+ display: block;
11
+ max-width: 100%;
12
+ width: 100%;
13
+ }
14
+ section {
15
+ max-width: 100%;
16
+ overflow: hidden;
17
+ display: flex;
18
+ align-items: center;
19
+ padding: 0.5rem 0.5rem;
20
+ border-bottom: 1px solid #ddd;
21
+ }
22
+ dile-checkbox {
23
+ margin-right: 0.5rem;
24
+ }
25
+ main {
26
+ flex-grow: 1;
27
+ overflow: hidden;
28
+ }
29
+ .actions {
30
+ margin-left: 0.5rem;
31
+ display: flex;
32
+ align-items: center;
33
+ text-align: right;
34
+ --dile-icon-size: 24px;
35
+ --dile-icon-color: var(--edit-icon-color, #33ad67);
36
+ }
37
+ dile-icon {
38
+ cursor: pointer;
39
+ margin: 0 0.2rem;
40
+ }
41
+ dile-icon.delete {
42
+ --dile-icon-color: var(--delete-icon-color, #e33);
43
+ }
44
+ @media(min-width: 550px) {
45
+ section {
46
+ padding: 0.5rem 1rem;
47
+ }
48
+ }
49
+ `
50
+ ];
51
+
52
+ static get properties() {
53
+ return {
54
+ itemId: { type: Number },
55
+ actionIds: { type: Array },
56
+ disableEdit: { type: Boolean },
57
+ disableDelete: { type: Boolean },
58
+ /** Hide checkboxes on the item list */
59
+ hideCheckboxSelection: { type: Boolean },
60
+ };
61
+ }
62
+
63
+ constructor() {
64
+ super();
65
+ this.actionIds = [];
66
+ this.disableEdit = false;
67
+ this.disableDelete = false;
68
+ this.hideCheckboxSelection = false;
69
+
70
+ }
71
+
72
+ render() {
73
+ return html`
74
+ <section>
75
+ ${this.hideCheckboxSelection ? '' : html`
76
+ <dile-checkbox ?checked="${this.includes(this.actionIds, this.itemId)}" @dile-checkbox-changed=${this.checkboxChanged}></dile-checkbox>
77
+ `}
78
+ <main>
79
+ <slot></slot>
80
+ </main>
81
+ <div class="actions">
82
+ ${this.disableEdit
83
+ ? ''
84
+ : html`<dile-icon .icon="${editIcon}" @click=${this.editClick}></dile-icon>`
85
+ }
86
+ ${this.disableDelete
87
+ ? ''
88
+ : html`<dile-icon class="delete" .icon="${deleteIcon}" @click=${this.deleteClick}></dile-icon>`
89
+ }
90
+ </div>
91
+ </section>
92
+ `;
93
+ }
94
+
95
+ includes(actionIds, itemId) {
96
+ return actionIds.includes(itemId);
97
+ }
98
+
99
+ checkboxChanged(e) {
100
+ this.dispatchEvent(new CustomEvent('item-checkbox-changed', {
101
+ bubbles: true,
102
+ composed: true,
103
+ detail: {
104
+ checked: e.detail.checked,
105
+ itemId: this.itemId
106
+ }
107
+ }));
108
+ }
109
+
110
+ editClick() {
111
+ this.dispatchEvent(new CustomEvent('crud-item-edit', {
112
+ bubbles: true,
113
+ composed: true,
114
+ detail: {
115
+ itemId: this.itemId
116
+ }
117
+ }));
118
+ }
119
+
120
+ deleteClick() {
121
+ this.dispatchEvent(new CustomEvent('crud-item-delete', {
122
+ bubbles: true,
123
+ composed: true,
124
+ detail: {
125
+ itemId: this.itemId
126
+ }
127
+ }));
128
+ }
129
+ }
@@ -0,0 +1,89 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import '../../ui/crud-pagination-nav-button';
3
+
4
+ export class DileCrudListPaginationLinks extends LitElement {
5
+ static styles = [
6
+ css`
7
+ :host {
8
+ display: block;
9
+ }
10
+ .pagination {
11
+ margin-top: 1rem;
12
+ display: grid;
13
+ align-items: center;
14
+ grid-template-columns: auto 1fr auto;
15
+ }
16
+ .pagination-summary, .pagination-summary-one-page {
17
+ text-align: center;
18
+ font-size: 0.8em;
19
+ }
20
+ .pagination-summary-one-page {
21
+ text-align: center;
22
+ padding-top: 0.5rem;
23
+ width: 100%;
24
+ margin-bottom: -0.4rem;
25
+ }
26
+ .pagination-prev {
27
+ margin-left: 0.5rem;
28
+ }
29
+ .pagination-next {
30
+ margin-right: 0.5rem;
31
+ }
32
+ `
33
+ ];
34
+
35
+ static get properties() {
36
+ return {
37
+ paginationData: { type: Object },
38
+ pageSize: { type: Number },
39
+ numItems: { type: Number },
40
+ };
41
+ }
42
+
43
+ render() {
44
+ if (this.numPages(this.numItems, this.pageSize) > 1) {
45
+ return html`
46
+ <div class="pagination">
47
+ <span class="pagination-prev">
48
+ <dile-crud-pagination-nav-button
49
+ @click=${this.goPrev}
50
+ ?disabled="${!this.paginationData.prevPage}"
51
+ direction="left"
52
+ ></dile-crud-pagination-nav-button>
53
+ </span>
54
+ <span class="pagination-summary">
55
+ Página ${this.paginationData.currentPage} de ${this.numPages(this.numItems, this.pageSize)}
56
+ </span>
57
+ <span class="pagination-next">
58
+ <dile-crud-pagination-nav-button
59
+ @click=${this.goNext}
60
+ ?disabled="${!this.paginationData.nextPage}"
61
+ direction="right"
62
+ ></dile-crud-pagination-nav-button>
63
+ </span>
64
+ </div>
65
+ `
66
+ } else {
67
+ return html`
68
+ <div class="pagination-summary-one-page">
69
+ Page 1 of 1
70
+ </div>
71
+ `;
72
+ }
73
+ }
74
+
75
+ numPages(count, size) {
76
+ const result = Math.ceil(count / size);
77
+ if(isNaN(result)) {
78
+ return "";
79
+ }
80
+ return result;
81
+ }
82
+
83
+ goPrev() {
84
+ this.dispatchEvent(new CustomEvent('crud-pagination-prev'));
85
+ }
86
+ goNext() {
87
+ this.dispatchEvent(new CustomEvent('crud-pagination-next'));
88
+ }
89
+ }