@dile/crud 0.7.2 → 0.7.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/components/crud/src/DileCrud.js +20 -0
- package/components/item-delete/crud-item-delete.js +1 -1
- package/components/item-delete/index.js +1 -1
- package/components/item-delete/src/DileCrudItemDelete.js +16 -5
- package/components/item-restore/crud-item-restore.js +2 -0
- package/components/item-restore/index.js +1 -0
- package/components/item-restore/src/DileCrudItemRestore.js +49 -0
- package/components/list/src/DileCrudList.js +4 -2
- package/components/list/src/DileCrudListItem.js +36 -7
- package/lib/defaultConfig.js +1 -0
- package/lib/i18n/en.js +1 -0
- package/lib/i18n/es.js +1 -0
- package/package.json +3 -3
|
@@ -5,6 +5,7 @@ import '@dile/ui/components/select/select.js';
|
|
|
5
5
|
import '@dile/ui/components/modal/modal.js';
|
|
6
6
|
import '@dile/ui/components/modal/modal-help.js';
|
|
7
7
|
import '../../item-delete/crud-item-delete.js';
|
|
8
|
+
import '../../item-restore/crud-item-restore.js';
|
|
8
9
|
import '../../list/crud-list.js';
|
|
9
10
|
import '../../ui/crud-sort-form.js';
|
|
10
11
|
import '../../ui/crud-page-size.js';
|
|
@@ -106,6 +107,9 @@ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
|
|
|
106
107
|
get deleteElement() {
|
|
107
108
|
return this.shadowRoot.getElementById('eldelete');
|
|
108
109
|
}
|
|
110
|
+
get restoreElement() {
|
|
111
|
+
return this.shadowRoot.getElementById('elrestore');
|
|
112
|
+
}
|
|
109
113
|
get filtersElement() {
|
|
110
114
|
return this.shadowRoot.getElementById('elfilters');
|
|
111
115
|
}
|
|
@@ -143,6 +147,13 @@ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
|
|
|
143
147
|
language="${this.language}"
|
|
144
148
|
></dile-crud-item-delete>
|
|
145
149
|
|
|
150
|
+
<dile-crud-item-restore
|
|
151
|
+
id="elrestore"
|
|
152
|
+
endpoint="${this.config.endpoint}"
|
|
153
|
+
@restore-success=${this.restoreSuccess}
|
|
154
|
+
language="${this.language}"
|
|
155
|
+
></dile-crud-item-restore>
|
|
156
|
+
|
|
146
157
|
${this.insertTemplate}
|
|
147
158
|
${this.updateTemplate}
|
|
148
159
|
`;
|
|
@@ -186,6 +197,7 @@ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
|
|
|
186
197
|
.config=${this.config}
|
|
187
198
|
@crud-item-edit=${this.updateRequest}
|
|
188
199
|
@crud-item-delete=${this.itemDeleteRequest}
|
|
200
|
+
@crud-item-restore=${this.itemRestoreRequest}
|
|
189
201
|
@insert-requested=${this.openInsert}
|
|
190
202
|
.actionIds=${this.actionIds}
|
|
191
203
|
belongsTo=${this.belongsTo}
|
|
@@ -371,6 +383,10 @@ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
|
|
|
371
383
|
this.deleteElement.delete(e.detail.itemId)
|
|
372
384
|
}
|
|
373
385
|
|
|
386
|
+
itemRestoreRequest(e) {
|
|
387
|
+
this.restoreElement.restore(e.detail.itemId)
|
|
388
|
+
}
|
|
389
|
+
|
|
374
390
|
// SUCCESS HANDLERS
|
|
375
391
|
modalInsertSuccess() {
|
|
376
392
|
this.modalInsert.close();
|
|
@@ -381,6 +397,10 @@ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
|
|
|
381
397
|
this.refresh();
|
|
382
398
|
}
|
|
383
399
|
|
|
400
|
+
restoreSuccess() {
|
|
401
|
+
this.refresh();
|
|
402
|
+
}
|
|
403
|
+
|
|
384
404
|
refresh() {
|
|
385
405
|
this.listElement.refresh();
|
|
386
406
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { DileCrudItemDelete } from "./src/DileCrudItemDelete";
|
|
1
|
+
import { DileCrudItemDelete } from "./src/DileCrudItemDelete.js";
|
|
2
2
|
customElements.define('dile-crud-item-delete', DileCrudItemDelete);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { DileCrudItemDelete } from "./src/DileCrudItemDelete";
|
|
1
|
+
export { DileCrudItemDelete } from "./src/DileCrudItemDelete.js";
|
|
@@ -4,6 +4,8 @@ import { ResponseApiAdapter } from '../../../lib/ResponseApiAdapter.js';
|
|
|
4
4
|
import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
|
|
5
5
|
import '../../ajax/ajax.js';
|
|
6
6
|
|
|
7
|
+
const OPERATION_ITEM_MISSING_ERROR = 'Please provide the element id to delete';
|
|
8
|
+
|
|
7
9
|
export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
8
10
|
static styles = [
|
|
9
11
|
css`
|
|
@@ -36,12 +38,17 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
36
38
|
confirmMessage: { type: String },
|
|
37
39
|
cancelLabel: { type: String },
|
|
38
40
|
acceptLabel: { type: String },
|
|
41
|
+
method: { type: String },
|
|
39
42
|
};
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
constructor() {
|
|
43
46
|
super();
|
|
47
|
+
this.successEventName = 'delete-success';
|
|
48
|
+
this.errorEventName = 'delete-error';
|
|
44
49
|
this.responseAdapter = new ResponseApiAdapter();
|
|
50
|
+
this.method = 'delete';
|
|
51
|
+
this.ITEM_TO_DELETE_
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
firstUpdated() {
|
|
@@ -53,8 +60,8 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
53
60
|
return html`
|
|
54
61
|
<dile-ajax
|
|
55
62
|
id="ajaxdelete"
|
|
56
|
-
method="
|
|
57
|
-
url="${this.endpoint
|
|
63
|
+
method="${this.method}"
|
|
64
|
+
url="${this.computeUrl(this.endpoint, this.relatedId)}"
|
|
58
65
|
@ajax-success="${this.doSuccessDelete}"
|
|
59
66
|
@ajax-error="${this.doErrorDelete}"
|
|
60
67
|
></dile-ajax>
|
|
@@ -69,12 +76,16 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
69
76
|
`;
|
|
70
77
|
}
|
|
71
78
|
|
|
79
|
+
computeUrl(endpoint, relatedId) {
|
|
80
|
+
return `${endpoint}/${relatedId}`
|
|
81
|
+
}
|
|
82
|
+
|
|
72
83
|
delete(itemId) {
|
|
73
84
|
if(itemId != "" && itemId != undefined) {
|
|
74
85
|
this.relatedId = itemId;
|
|
75
86
|
this.elconfirm.open();
|
|
76
87
|
} else {
|
|
77
|
-
throw new Error(
|
|
88
|
+
throw new Error(OPERATION_ITEM_MISSING_ERROR);
|
|
78
89
|
}
|
|
79
90
|
}
|
|
80
91
|
|
|
@@ -84,7 +95,7 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
84
95
|
|
|
85
96
|
doSuccessDelete(e) {
|
|
86
97
|
let msg = this.computeResponseMessage(e.detail);
|
|
87
|
-
this.dispatchEvent(new CustomEvent(
|
|
98
|
+
this.dispatchEvent(new CustomEvent(this.successEventName, {
|
|
88
99
|
bubbles: true,
|
|
89
100
|
composed: true,
|
|
90
101
|
detail: {
|
|
@@ -96,7 +107,7 @@ export class DileCrudItemDelete extends DileI18nMixin(LitElement) {
|
|
|
96
107
|
|
|
97
108
|
doErrorDelete(e) {
|
|
98
109
|
let msg = this.computeResponseMessage(e.detail);
|
|
99
|
-
this.dispatchEvent(new CustomEvent(
|
|
110
|
+
this.dispatchEvent(new CustomEvent(this.errorEventName, {
|
|
100
111
|
bubbles: true,
|
|
101
112
|
composed: true,
|
|
102
113
|
detail: {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { DileCrudItemDelete } from "./src/DileCrudItemDelete.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { css } from "lit";
|
|
2
|
+
import { DileCrudItemDelete } from "../../item-delete/src/DileCrudItemDelete.js";
|
|
3
|
+
|
|
4
|
+
const OPERATION_ITEM_MISSING_ERROR = 'Please provide the element id to restore';
|
|
5
|
+
|
|
6
|
+
export class DileCrudItemRestore extends DileCrudItemDelete {
|
|
7
|
+
static styles = [
|
|
8
|
+
super.styles,
|
|
9
|
+
css`
|
|
10
|
+
:host {
|
|
11
|
+
--dile-confirm-accept-button-color: var(--neutral-icon-color, #337aad);
|
|
12
|
+
}
|
|
13
|
+
`
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
static get properties() {
|
|
17
|
+
return {
|
|
18
|
+
urlSufix: { type: String }
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this.successEventName = 'restore-success';
|
|
25
|
+
this.errorEventName = 'restore-error';
|
|
26
|
+
this.method = 'post';
|
|
27
|
+
this.urlSufix = 'restore';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
computeUrl(endpoint, relatedId) {
|
|
31
|
+
return `${endpoint}/${relatedId}/${this.urlSufix}`
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
restore(itemId) {
|
|
35
|
+
this.delete(itemId);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
cancelLabelComputed(label, translations) {
|
|
39
|
+
return label ? label : translations?.cancel_label ? translations.cancel_label : 'Cancel';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
acceptLabelComputed(label, translations) {
|
|
43
|
+
return label ? label : translations?.accept_label ? translations.accept_label : 'Accept';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
confirmMessageComputed(message, translations) {
|
|
47
|
+
return message ? message : translations?.restore_confirm_message ? translations.restore_confirm_message : 'Are you sure?';
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -201,10 +201,12 @@ export class DileCrudList extends DileI18nMixin(DileLoading(LitElement)) {
|
|
|
201
201
|
<dile-crud-list-item
|
|
202
202
|
itemId="${this.computeItemId(element)}"
|
|
203
203
|
.actionIds="${this.actionIds}"
|
|
204
|
-
?disableEdit
|
|
205
|
-
?disableDelete
|
|
204
|
+
?disableEdit=${this.config?.customization?.disableEdit}
|
|
205
|
+
?disableDelete=${this.config?.customization?.disableDelete}
|
|
206
|
+
?disableRestore=${this.config?.customization?.disableRestore}
|
|
206
207
|
?hideCheckboxSelection="${this.config?.customization?.hideCheckboxSelection}"
|
|
207
208
|
@item-checkbox-changed=${this.onItemsCheckboxChanged}
|
|
209
|
+
?isDeleted=${element.deleted_at}
|
|
208
210
|
>
|
|
209
211
|
${this.config.templates.item(element)}
|
|
210
212
|
</dile-crud-list-item>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LitElement, html, css } from 'lit';
|
|
2
2
|
import '@dile/ui/components/checkbox/checkbox';
|
|
3
3
|
import '@dile/ui/components/icon/icon';
|
|
4
|
-
import { deleteIcon, editIcon } from '@dile/icons';
|
|
4
|
+
import { deleteIcon, editIcon, restoreFromTrashIcon } from '@dile/icons';
|
|
5
5
|
|
|
6
6
|
export class DileCrudListItem extends LitElement {
|
|
7
7
|
static styles = [
|
|
@@ -57,6 +57,7 @@ export class DileCrudListItem extends LitElement {
|
|
|
57
57
|
disableDelete: { type: Boolean },
|
|
58
58
|
/** Hide checkboxes on the item list */
|
|
59
59
|
hideCheckboxSelection: { type: Boolean },
|
|
60
|
+
isDeleted: { type: Boolean },
|
|
60
61
|
};
|
|
61
62
|
}
|
|
62
63
|
|
|
@@ -65,6 +66,7 @@ export class DileCrudListItem extends LitElement {
|
|
|
65
66
|
this.actionIds = [];
|
|
66
67
|
this.disableEdit = false;
|
|
67
68
|
this.disableDelete = false;
|
|
69
|
+
this.disableRestore = false;
|
|
68
70
|
this.hideCheckboxSelection = false;
|
|
69
71
|
|
|
70
72
|
}
|
|
@@ -79,22 +81,39 @@ export class DileCrudListItem extends LitElement {
|
|
|
79
81
|
<slot></slot>
|
|
80
82
|
</main>
|
|
81
83
|
<div class="actions">
|
|
82
|
-
${this.
|
|
84
|
+
${this.isDeleted
|
|
85
|
+
? this.restoreActionsTemplate
|
|
86
|
+
: this.regularActionsTemplate
|
|
87
|
+
}
|
|
88
|
+
</div>
|
|
89
|
+
</section>
|
|
90
|
+
`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
get regularActionsTemplate() {
|
|
94
|
+
return html`
|
|
95
|
+
${this.disableEdit
|
|
83
96
|
? ''
|
|
84
97
|
: html`<dile-icon .icon="${editIcon}" @click=${this.editClick}></dile-icon>`
|
|
85
98
|
}
|
|
86
|
-
|
|
99
|
+
${this.disableDelete
|
|
87
100
|
? ''
|
|
88
101
|
: html`<dile-icon class="delete" .icon="${deleteIcon}" @click=${this.deleteClick}></dile-icon>`
|
|
89
102
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
103
|
+
`
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
get restoreActionsTemplate() {
|
|
107
|
+
return html`
|
|
108
|
+
${this.disableRestore
|
|
109
|
+
? ''
|
|
110
|
+
: html`<dile-icon .icon="${restoreFromTrashIcon}" @click=${this.restoreClick}></dile-icon>`
|
|
111
|
+
}
|
|
112
|
+
`
|
|
93
113
|
}
|
|
94
114
|
|
|
95
115
|
includes(actionIds, itemId) {
|
|
96
116
|
const stringIds = actionIds.map(String);
|
|
97
|
-
// console.log(stringIds, String(itemId));
|
|
98
117
|
return stringIds.includes(String(itemId));
|
|
99
118
|
}
|
|
100
119
|
|
|
@@ -128,4 +147,14 @@ export class DileCrudListItem extends LitElement {
|
|
|
128
147
|
}
|
|
129
148
|
}));
|
|
130
149
|
}
|
|
150
|
+
|
|
151
|
+
restoreClick() {
|
|
152
|
+
this.dispatchEvent(new CustomEvent('crud-item-restore', {
|
|
153
|
+
bubbles: true,
|
|
154
|
+
composed: true,
|
|
155
|
+
detail: {
|
|
156
|
+
itemId: this.itemId
|
|
157
|
+
}
|
|
158
|
+
}));
|
|
159
|
+
}
|
|
131
160
|
}
|
package/lib/defaultConfig.js
CHANGED
package/lib/i18n/en.js
CHANGED
|
@@ -32,6 +32,7 @@ export const translations = {
|
|
|
32
32
|
run_action_label: "Run action",
|
|
33
33
|
loading: "Loading...",
|
|
34
34
|
delete_confirm_message: "Are you sure you want to delete this item?",
|
|
35
|
+
restore_confirm_message: "Are you sure you want to restore this item?",
|
|
35
36
|
delete_confirm_message_plural: "Are you sure you want to delete those items?",
|
|
36
37
|
items_total: "items in total",
|
|
37
38
|
showing_page_size: (pageSize) => `Showing ${pageSize} items per page.`,
|
package/lib/i18n/es.js
CHANGED
|
@@ -32,6 +32,7 @@ export const translations = {
|
|
|
32
32
|
run_action_label: "Realizar acción",
|
|
33
33
|
loading: "Cargando...",
|
|
34
34
|
delete_confirm_message: "¿Estás seguro que quieres borrar este ítem?",
|
|
35
|
+
restore_confirm_message: "¿Estás seguro que quieres restaurar este ítem?",
|
|
35
36
|
delete_confirm_message_plural: "¿Seguro que quieres borrar estos elementos?",
|
|
36
37
|
items_total: "Elementos en total",
|
|
37
38
|
showing_page_size: (pageSize) => `Mostrando ${pageSize} elementos por página.`,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dile/crud",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.4",
|
|
4
4
|
"description": "Components to create a generic crud system based on Web Components and Lit",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -24,12 +24,12 @@
|
|
|
24
24
|
},
|
|
25
25
|
"homepage": "https://dile-components.com/",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@dile/ui": "^2.8.
|
|
27
|
+
"@dile/ui": "^2.8.1",
|
|
28
28
|
"axios": "^1.8.4",
|
|
29
29
|
"lit": "^2.7.0 || ^3.0.0"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "eae8a7897e7baf3b5b3a9f4ab8a9f94e85e94ec5"
|
|
35
35
|
}
|