@dile/crud 0.0.38 → 0.0.40

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.
@@ -5,6 +5,7 @@ import '@dile/ui/components/select/select';
5
5
  import '../../ajax/ajax.js'
6
6
  import '../../ui/crud-list-options.js';
7
7
  import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
8
+ import { ResponseApiAdapter } from '../../../lib/ResponseApiAdapter.js';
8
9
 
9
10
  export class DileCrudActions extends DileI18nMixin(LitElement) {
10
11
  static styles = css`
@@ -61,7 +62,8 @@ export class DileCrudActions extends DileI18nMixin(LitElement) {
61
62
  endpoint: { type: String },
62
63
  actions: { type: Array },
63
64
  formActionsTemplate: { type: Object },
64
- destructive: { type: Boolean, reflect: true, }
65
+ destructive: { type: Boolean, reflect: true, },
66
+ responseAdapter: { type: Object },
65
67
  };
66
68
  }
67
69
 
@@ -69,7 +71,8 @@ export class DileCrudActions extends DileI18nMixin(LitElement) {
69
71
  super();
70
72
  this.actionIds = [];
71
73
  this.actions = [];
72
- this.selection = 'DeleteAction'
74
+ this.selection = 'DeleteAction';
75
+ this.responseAdapter = new ResponseApiAdapter();
73
76
  }
74
77
 
75
78
  firstUpdated() {
@@ -176,23 +179,25 @@ export class DileCrudActions extends DileI18nMixin(LitElement) {
176
179
 
177
180
  doSuccessAction(e) {
178
181
  this.selectedActionForm.resetData();
182
+ this.responseAdapter.setResponse(e.detail);
179
183
  this.dispatchEvent(new CustomEvent('crud-action-success', {
180
184
  bubbles: true,
181
185
  composed: true,
182
186
  detail: {
183
- msg: e.detail.message,
184
- action: e.detail.data.action,
185
- data: e.detail.data.data,
187
+ msg: this.responseAdapter.getActionResponseMessage(),
188
+ action: this.responseAdapter.getActionResponseActionName(),
189
+ data: this.responseAdapter.getActionResponseActionData(),
186
190
  }
187
191
  }));
188
192
  }
189
193
 
190
194
  doErrorAction(e) {
195
+ this.responseAdapter.setResponse(e.detail);
191
196
  this.dispatchEvent(new CustomEvent('crud-action-error', {
192
197
  bubbles: true,
193
198
  composed: true,
194
199
  detail: {
195
- msg: e.detail,
200
+ msg:this.responseAdapter.getActionResponseValidationErrorMessage(),
196
201
  }
197
202
  }));
198
203
  }
@@ -80,7 +80,9 @@ export class DileCrudSingle extends DileI18nMixin(DileCrudMixin(LitElement)) {
80
80
  <main class="elcontainer">
81
81
  ${this.detailTemplate}
82
82
  <div class="actions" @action-success=${this.actionSuccess}>
83
- <dile-button gray .icon="${editIcon}" @click=${this.edit}>${this.updateLabelComputed(this.config.labels.updateAction, this.translations)}</dile-button>
83
+ <dile-button gray .icon="${editIcon}" @click=${this.edit}>
84
+ ${this.startUpdateLabelComputed(this.config.labels.startUpdateAction, this.translations)}
85
+ </dile-button>
84
86
  ${this.actionsTemplate}
85
87
  </div>
86
88
  </main>
@@ -20,6 +20,7 @@ export const DileCrudMixin = (superclass) => class extends superclass {
20
20
  .actions=${this.config.actions.list}
21
21
  .formActionsTemplate=${this.config.templates.formActions}
22
22
  language="${this.language}"
23
+ .responseAdapter=${this.config.responseAdapter}
23
24
  ></dile-crud-actions>
24
25
  `
25
26
  }
@@ -57,6 +58,9 @@ export const DileCrudMixin = (superclass) => class extends superclass {
57
58
  updateLabelComputed(label, translations) {
58
59
  return label ? label : translations?.update_label ? translations.update_label : 'Save';
59
60
  }
61
+ startUpdateLabelComputed(label, translations) {
62
+ return label ? label : translations?.start_update_label ? translations.start_update_label : 'Edit';
63
+ }
60
64
  helpLabelComputed(label, translations) {
61
65
  return label ? label : translations?.help_label ? translations.help_label : 'Help';
62
66
  }
@@ -33,5 +33,17 @@ export class ResponseApiAdapter {
33
33
  getIds() {
34
34
  return this.response.data;
35
35
  }
36
-
36
+
37
+ getActionResponseMessage() {
38
+ return this.response.message;
39
+ }
40
+ getActionResponseActionName() {
41
+ return this.response.data.action;
42
+ }
43
+ getActionResponseActionData() {
44
+ return this.response.data.data;
45
+ }
46
+ getActionResponseValidationErrorMessage() {
47
+ return this.response.message
48
+ }
37
49
  }
@@ -70,6 +70,7 @@ export const defaultConfig = {
70
70
  labels: {
71
71
  // insertAction: 'Create',
72
72
  // updateAction: 'Save',
73
+ // startUpdateAction: 'Edit',
73
74
  // insertWindowTitle: 'Create an item',
74
75
  // updateWindowTitle: 'Update an item',
75
76
  // helpTitle: 'Help',
package/lib/i18n/en.js CHANGED
@@ -13,6 +13,7 @@ export const translations = {
13
13
  error_operation: (operation) => `${operation == 'insert' ? 'Insertion' : 'Update'} error`,
14
14
  insert_label: "Create",
15
15
  update_label: "Update",
16
+ start_update_label: "Edit",
16
17
  delete_label: "Delete",
17
18
  cancel_label: "Cancel",
18
19
  accept_label: "Accept",
package/lib/i18n/es.js CHANGED
@@ -13,6 +13,7 @@ export const translations = {
13
13
  error_operation: (operation) => `Se ha producido un error en la ${operation == 'insert' ? 'inserción' : 'actualización'}`,
14
14
  insert_label: "Insertar",
15
15
  update_label: "Actualizar",
16
+ start_update_label: "Editar",
16
17
  delete_label: "Borrar",
17
18
  cancel_label: "Cancelar",
18
19
  accept_label: "Aceptar",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "0.0.38",
3
+ "version": "0.0.40",
4
4
  "description": "Components to create a generic crud system based on Web Components and Lit",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -31,5 +31,5 @@
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "4cb29e58e0f66c094ef5664b0e9aaf3d228f5c10"
34
+ "gitHead": "04e4cb1ee801ba221847efb9e8067102de43192e"
35
35
  }