@dile/crud 0.0.33 → 0.0.35

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.
@@ -4,8 +4,9 @@ import '@dile/ui/components/confirm/confirm';
4
4
  import '@dile/ui/components/select/select';
5
5
  import '../../ajax/ajax.js'
6
6
  import '../../ui/crud-list-options.js';
7
+ import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
7
8
 
8
- export class DileCrudActions extends LitElement {
9
+ export class DileCrudActions extends DileI18nMixin(LitElement) {
9
10
  static styles = css`
10
11
  :host {
11
12
  display: block;
@@ -20,6 +21,13 @@ export class DileCrudActions extends LitElement {
20
21
  --dile-confirm-cancel-button-color: var(--dile-danger-color, #E31E1B);
21
22
  --dile-confirm-cancel-text-button-color: var(--dile-on-danger-color, #fff);
22
23
  }
24
+ :host([destructive]) {
25
+ --dile-confirm-cancel-button-color: var(--dile-primary-color, #378dca);
26
+ --dile-confirm-cancel-text-button-color: var(--dile-on-primary-color, #fff);
27
+ --dile-confirm-accept-button-color: var(--dile-danger-color, #E31E1B);
28
+ --dile-confirm-accept-text-button-color: var(--dile-on-danger-color, #fff);
29
+
30
+ }
23
31
  p {
24
32
  margin: 0 0 0.75rem 0;
25
33
  }
@@ -53,6 +61,7 @@ export class DileCrudActions extends LitElement {
53
61
  endpoint: { type: String },
54
62
  actions: { type: Array },
55
63
  formActionsTemplate: { type: Object },
64
+ destructive: { type: Boolean, reflect: true, }
56
65
  };
57
66
  }
58
67
 
@@ -90,12 +99,12 @@ export class DileCrudActions extends LitElement {
90
99
 
91
100
  get actionListTemplate() {
92
101
  return html`
93
- <dile-crud-list-options .icon="${moreVertIcon}" label="Acciones" class="${this.actionIds.length > 0 ? 'visible' : 'hide'}">
94
- <p>${this.actionIds.length} ${this.actionIds.length == 1 ? 'elemento' : 'elementos'}</p>
102
+ <dile-crud-list-options .icon="${moreVertIcon}" label="${this.translations.actions_label}" class="${this.actionIds.length > 0 ? 'visible' : 'hide'}">
103
+ <p>${this.actionIds.length} ${this.actionIds.length == 1 ? this.translations.element_label : this.translations.element_plural_label}</p>
95
104
  <div @element-changed=${this.selectorChanged}>
96
105
  ${this.selectActionsTemplate}
97
106
  </div>
98
- <dile-button @click=${this.showAction}>Realizar acción</dile-button>
107
+ <dile-button @click=${this.showAction}>${this.translations.run_action_label}</dile-button>
99
108
  </dile-crud-list-options>
100
109
  `;
101
110
  }
@@ -114,8 +123,8 @@ export class DileCrudActions extends LitElement {
114
123
  return html`
115
124
  <dile-confirm
116
125
  id="elconfirm"
117
- cancelLabel="Cancelar"
118
- acceptLabel="Aceptar"
126
+ cancelLabel="${this.translations.cancel_label}"
127
+ acceptLabel="${this.translations.accept_label}"
119
128
  @dile-confirm-accepted=${this.doAction}
120
129
  >
121
130
  <div class="modalcontainer">
@@ -131,6 +140,16 @@ export class DileCrudActions extends LitElement {
131
140
 
132
141
  selectorChanged(e) {
133
142
  this.selection = e.target.value;
143
+ if(this.isDestructive()) {
144
+ this.destructive = true;
145
+ } else {
146
+ this.destructive = false;
147
+ }
148
+ }
149
+
150
+ isDestructive() {
151
+ const currentAction = this.actions.find(action => action.name == this.selection);
152
+ return currentAction && currentAction.destructive;
134
153
  }
135
154
 
136
155
  showAction() {
@@ -1,7 +1,8 @@
1
1
  import { LitElement, html, css } from 'lit';
2
2
  import { DileForm } from '@dile/ui/mixins/form';
3
+ import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
3
4
 
4
- export class DileCrudDeleteAction extends DileForm(LitElement) {
5
+ export class DileCrudDeleteAction extends DileI18nMixin(DileForm(LitElement)) {
5
6
  static styles = [
6
7
  css`
7
8
  :host {
@@ -12,7 +13,7 @@ export class DileCrudDeleteAction extends DileForm(LitElement) {
12
13
 
13
14
  render() {
14
15
  return html`
15
- <p>Are you sure you want to delete those items?</p>
16
+ <p>${this.translations.delete_confirm_message_plural}</p>
16
17
  `;
17
18
  }
18
19
  }
@@ -3,6 +3,7 @@ import { DileCrudActions } from './DileCrudActions.js';
3
3
  import '@dile/ui/components/box-selector/box-selector.js';
4
4
  import '@dile/ui/components/box-selector/box-selector-item.js';
5
5
  import '@dile/ui/components/card/card.js';
6
+ import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
6
7
 
7
8
  export class DileCrudSingleActions extends DileCrudActions {
8
9
  static styles = [
@@ -48,7 +49,7 @@ export class DileCrudSingleActions extends DileCrudActions {
48
49
  return html`
49
50
  ${this.actions.length > 0
50
51
  ? html`
51
- <dile-card title="Element action">
52
+ <dile-card title="${this.translations.element_actions}">
52
53
  <dile-box-selector
53
54
  class="action-list"
54
55
  attrForSelected="name"
@@ -17,8 +17,9 @@ import { formStyles } from '../../../styles/form-styles.js';
17
17
  import { DileCrudMixin } from '../../../lib/DileCrudMixin.js';
18
18
  import { crudStyles } from '../../../styles/crud-styles.js';
19
19
  import { addIcon } from '@dile/icons';
20
+ import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
20
21
 
21
- export class DileCrud extends DileCrudMixin(LitElement) {
22
+ export class DileCrud extends DileI18nMixin(DileCrudMixin(LitElement)) {
22
23
  static styles = [
23
24
  formStyles,
24
25
  crudStyles,
@@ -149,7 +150,9 @@ export class DileCrud extends DileCrudMixin(LitElement) {
149
150
  get insertButtomTemplate() {
150
151
  return html`
151
152
  <div class="insertButtonContainer">
152
- <dile-button-icon @click="${this.openInsert}" .icon="${addIcon}">${this.config.labels.insertAction}</dile-button-icon>
153
+ <dile-button-icon @click="${this.openInsert}" .icon="${addIcon}">
154
+ ${this.insertLabelComputed(this.config.labels.insertAction, this.translations)}
155
+ </dile-button-icon>
153
156
  </div>
154
157
  `
155
158
  }
@@ -162,11 +165,11 @@ export class DileCrud extends DileCrudMixin(LitElement) {
162
165
  blocking
163
166
  >
164
167
  <dile-crud-insert
165
- title=${this.config.labels.insertWindowTitle}
168
+ title=${this.insertLabelComputed(this.config.labels.insertWindowTitle, this.translations)}
166
169
  endpoint="${this.config.endpoint}"
167
170
  .responseAdapter=${this.config.responseAdapter}
168
171
  .formTemplate=${this.config.templates.insertForm}
169
- actionLabel=${this.config.labels.insertAction}
172
+ actionLabel=${this.insertLabelComputed(this.config.labels.insertAction, this.translations)}
170
173
  formIdentifier="${this.config.formIds.insertForm}"
171
174
  @crud-insert-success="${this.modalInsertSuccess}"
172
175
  belongsTo=${this.belongsTo}
@@ -186,14 +189,15 @@ export class DileCrud extends DileCrudMixin(LitElement) {
186
189
  .actionIds=${this.actionIds}
187
190
  belongsTo=${this.belongsTo}
188
191
  relationId=${this.relationId}
192
+ language="${this.language}"
189
193
  ></dile-crud-list>
190
194
  `
191
195
  }
192
196
  get helpTemplate() {
193
197
  return html`
194
198
  <dile-modal-help
195
- title="${this.config.labels.helpTitle}"
196
- label="${this.config.labels.helpButtonLabel}"
199
+ title="${this.helpLabelComputed(this.config.labels.helpTitle, this.translations)}"
200
+ label="${this.helpLabelComputed(this.config.labels.helpButtonLabel, this.translations)}"
197
201
  >${this.config.templates.help()}</dile-modal-help>`
198
202
  }
199
203
 
@@ -217,6 +221,7 @@ export class DileCrud extends DileCrudMixin(LitElement) {
217
221
  id="elfilters"
218
222
  @filters-changed=${this.filtersChanged}
219
223
  .filters=${this.config.availableFilters || []}
224
+ language="${this.language}"
220
225
  ></dile-crud-filters>
221
226
  `
222
227
  }
@@ -228,6 +233,7 @@ export class DileCrud extends DileCrudMixin(LitElement) {
228
233
  @page-size-changed=${this.pageSizeChanged}
229
234
  .pageSizes=${this.config.pageSize.available || [10, 25, 50]}
230
235
  pageSize="${this.config.pageSize.initial}"
236
+ language="${this.language}"
231
237
  ></dile-crud-page-size>
232
238
  `
233
239
  }
@@ -240,6 +246,7 @@ export class DileCrud extends DileCrudMixin(LitElement) {
240
246
  sortField="${this.config.sort.initialSortField}"
241
247
  sortDirection="${this.config.sort.initialSortDirection || 'desc'}"
242
248
  @sort-changed=${this.sortFormChanged}
249
+ language="${this.language}"
243
250
  ></dile-crud-sort-form>
244
251
  `
245
252
  }
@@ -139,7 +139,7 @@ export class DileCrudList extends DileI18nMixin(DileLoading(LitElement)) {
139
139
  ? html`
140
140
  ${this.numItems} ${this.translations.items_total}. ${this.config.customization?.disablePagination ? '' : this.translations.showing_page_size(this.pageSize) }
141
141
  `
142
- : 'Loading...'
142
+ : this.translations.loading
143
143
  }
144
144
  </span>
145
145
  </div>
@@ -12,8 +12,9 @@ import '../../update/crud-update.js';
12
12
  import '../../action/crud-actions.js';
13
13
  import '../../action/crud-single-actions';
14
14
  import '../../action/crud-delete-action.js';
15
+ import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
15
16
 
16
- export class DileCrudSingle extends DileCrudMixin(LitElement) {
17
+ export class DileCrudSingle extends DileI18nMixin(DileCrudMixin(LitElement)) {
17
18
  static styles = [
18
19
  formStyles,
19
20
  css`
@@ -79,7 +80,7 @@ export class DileCrudSingle extends DileCrudMixin(LitElement) {
79
80
  <main class="elcontainer">
80
81
  ${this.detailTemplate}
81
82
  <div class="actions" @action-success=${this.actionSuccess}>
82
- <dile-button gray .icon="${editIcon}" @click=${this.edit}>Editar</dile-button>
83
+ <dile-button gray .icon="${editIcon}" @click=${this.edit}>${this.updateLabelComputed(this.config.labels.updateAction, this.translations)}</dile-button>
83
84
  ${this.actionsTemplate}
84
85
  </div>
85
86
  </main>
@@ -111,6 +112,7 @@ export class DileCrudSingle extends DileCrudMixin(LitElement) {
111
112
  .actionIds=${this.actionIds}
112
113
  endpoint=${this.config.endpoint}
113
114
  @crud-action-success=${this.actionSuccess}
115
+ language="${this.language}"
114
116
  ></dile-crud-single-actions>
115
117
  `
116
118
  }
@@ -2,8 +2,9 @@ import { LitElement, html, css } from 'lit';
2
2
  import { filterIcon } from '@dile/icons';
3
3
  import '../crud-filters-form.js';
4
4
  import '../crud-list-options.js'
5
+ import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
5
6
 
6
- export class DileCrudFilters extends LitElement {
7
+ export class DileCrudFilters extends DileI18nMixin(LitElement) {
7
8
  static get properties() {
8
9
  return {
9
10
  filters: { type: Array }
@@ -17,7 +18,7 @@ export class DileCrudFilters extends LitElement {
17
18
 
18
19
  render() {
19
20
  return html`
20
- <dile-crud-list-options .icon="${filterIcon}" label="Filtros" >
21
+ <dile-crud-list-options .icon="${filterIcon}" label="${this.translations.filters_label}" >
21
22
  <dile-crud-filters-form
22
23
  id="elform"
23
24
  .filters=${this.filters}
@@ -2,8 +2,9 @@ import { LitElement, html, css } from 'lit';
2
2
  import '../crud-list-options';
3
3
  import '../crud-page-size-select';
4
4
  import { descriptionIcon } from '@dile/icons';
5
+ import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
5
6
 
6
- export class DileCrudPageSize extends LitElement {
7
+ export class DileCrudPageSize extends DileI18nMixin(LitElement) {
7
8
 
8
9
  static get properties() {
9
10
  return {
@@ -19,7 +20,7 @@ export class DileCrudPageSize extends LitElement {
19
20
 
20
21
  render() {
21
22
  return html`
22
- <dile-crud-list-options .icon="${descriptionIcon}" label="Page">
23
+ <dile-crud-list-options .icon="${descriptionIcon}" label="${this.translations.page_label}">
23
24
  <dile-crud-page-size-select pageSize="${this.pageSize}" .pageSizes=${this.pageSizes}></dile-crud-page-size-select>
24
25
  </dile-crud-list-options>
25
26
  `;
@@ -4,8 +4,9 @@ import '@dile/ui/components/radio-group/radio-group';
4
4
  import '@dile/ui/components/radio-group/radio';
5
5
  import { sortIcon } from '@dile/icons';
6
6
  import '../crud-list-options';
7
+ import { DileI18nMixin } from '../../../lib/DileI18nMixin.js';
7
8
 
8
- export class DileCrudSortForm extends LitElement {
9
+ export class DileCrudSortForm extends DileI18nMixin(LitElement) {
9
10
  static styles = [
10
11
  css`
11
12
  :host {
@@ -49,7 +50,7 @@ export class DileCrudSortForm extends LitElement {
49
50
 
50
51
  render() {
51
52
  return html`
52
- <dile-crud-list-options class="action-controller" .icon="${sortIcon}" label="Order">
53
+ <dile-crud-list-options class="action-controller" .icon="${sortIcon}" label="${this.translations.sort_label}">
53
54
  <dile-radio-group
54
55
  name="selector"
55
56
  @dile-radio-group-changed=${this.radioGroupChanged}
@@ -9,26 +9,6 @@ export const DileCrudMixin = (superclass) => class extends superclass {
9
9
  return this.shadowRoot.getElementById('modalUpdate');
10
10
  }
11
11
 
12
- // get listElement() {
13
- // return this.shadowRoot.querySelector('dile-crud-list');
14
- // }
15
- // get insertElement() {
16
- // return this.shadowRoot.getElementById('elinsert');
17
- // }
18
- // get deleteElement() {
19
- // return this.shadowRoot.getElementById('eldelete');
20
- // }
21
- // get actionsElement() {
22
- // return this.shadowRoot.getElementById('elactions');
23
- // }
24
- // get filtersElement() {
25
- // return this.shadowRoot.getElementById('elfilters');
26
- // }
27
-
28
- // itemDeleteRequest(e) {
29
- // this.deleteElement.delete(e.detail.itemId);
30
- // }
31
-
32
12
  get actionsTemplate() {
33
13
  return html`
34
14
  <dile-crud-actions
@@ -39,6 +19,7 @@ export const DileCrudMixin = (superclass) => class extends superclass {
39
19
  endpoint=${this.config.endpoint}
40
20
  .actions=${this.config.actions.list}
41
21
  .formActionsTemplate=${this.config.templates.formActions}
22
+ language="${this.language}"
42
23
  ></dile-crud-actions>
43
24
  `
44
25
  }
@@ -52,11 +33,11 @@ export const DileCrudMixin = (superclass) => class extends superclass {
52
33
  >
53
34
  <dile-crud-update
54
35
  id="updateElement"
55
- title=${this.config.labels.updateWindowTitle}
36
+ title="${this.updateLabelComputed(this.config.labels.updateWindowTitle, this.translations)}"
56
37
  endpoint="${this.config.endpoint}"
57
38
  .responseAdapter=${this.config.responseAdapter}
58
39
  .formTemplate=${this.config.templates.updateForm}
59
- actionLabel=${this.config.labels.updateAction}
40
+ actionLabel="${this.updateLabelComputed(this.config.labels.updateAction, this.translations)}"
60
41
  formIdentifier="${this.config.formIds.updateForm}"
61
42
  @crud-update-success="${this.modalUpdateSuccess}"
62
43
  ></dile-crud-update>
@@ -69,4 +50,15 @@ export const DileCrudMixin = (superclass) => class extends superclass {
69
50
  this.modalUpdate.close();
70
51
  this.refresh();
71
52
  }
53
+
54
+ insertLabelComputed(label, translations) {
55
+ return label ? label : translations?.insert_label ? translations.insert_label : 'Insert';
56
+ }
57
+ updateLabelComputed(label, translations) {
58
+ return label ? label : translations?.update_label ? translations.update_label : 'Save';
59
+ }
60
+ helpLabelComputed(label, translations) {
61
+ return label ? label : translations?.help_label ? translations.help_label : 'Help';
62
+ }
63
+
72
64
  }
@@ -47,7 +47,8 @@ export const defaultConfig = {
47
47
  list: [
48
48
  {
49
49
  label: 'Delete',
50
- name: 'DeleteAction'
50
+ name: 'DeleteAction',
51
+ destructive: true,
51
52
  }
52
53
  ],
53
54
  single: [],
@@ -60,19 +61,19 @@ export const defaultConfig = {
60
61
  detail: () => templatePlaceholder('detail'),
61
62
  formActions: (actionName) => html`
62
63
  <dile-pages attrForSelected="action" selected="${actionName}">
63
- <dile-crud-delete-action action="DeleteAction"></dile-crud-delete-action>
64
+ <dile-crud-delete-action action="DeleteAction"></dile-crud-delete-action>
64
65
  </dile-pages>
65
66
  `,
66
67
  relations: () => '',
67
68
  formSingleActions: () => '',
68
69
  },
69
70
  labels: {
70
- insertAction: 'Create',
71
- updateAction: 'Save',
72
- insertWindowTitle: 'Insert an item',
73
- updateWindowTitle: 'Update an item',
74
- helpTitle: 'Help',
75
- helpButtonLabel: 'Help',
71
+ // insertAction: 'Create',
72
+ // updateAction: 'Save',
73
+ // insertWindowTitle: 'Create an item',
74
+ // updateWindowTitle: 'Update an item',
75
+ // helpTitle: 'Help',
76
+ // helpButtonLabel: 'Help',
76
77
  },
77
78
  formIds: {
78
79
  insertForm: 'insertform',
package/lib/i18n/en.js CHANGED
@@ -11,11 +11,22 @@ export const translations = {
11
11
  ajax_form_not_supported: "Operation not supported in dile-ajax-form use 'insert' or 'update'",
12
12
  success_operation: (operation) => operation == 'insert' ? 'The new item has been created' : 'Item updated successfully',
13
13
  error_operation: (operation) => `${operation == 'insert' ? 'Insertion' : 'Update'} error`,
14
- insert_label: "Insert",
14
+ insert_label: "Create",
15
15
  update_label: "Update",
16
16
  delete_label: "Delete",
17
17
  cancel_label: "Cancel",
18
+ accept_label: "Accept",
19
+ help_label: "Help",
20
+ filters_label: "Filters",
21
+ sort_label: "Sort",
22
+ page_label: "Page",
23
+ actions_label: "Actions",
24
+ element_label: "Element",
25
+ element_plural_label: "Elements",
26
+ run_action_label: "Run action",
27
+ loading: "Loading...",
18
28
  delete_confirm_message: "Are you sure you want to delete this item?",
29
+ delete_confirm_message_plural: "Are you sure you want to delete those items?",
19
30
  items_total: "items in total",
20
31
  showing_page_size: (pageSize) => `Showing ${pageSize} items per page.`,
21
32
  empty_list: "There are no items yet",
@@ -25,4 +36,6 @@ export const translations = {
25
36
  all: "all",
26
37
  all_in_page: "All in this page",
27
38
  select_matching: "Select all matching",
39
+ element_actions: "Element actions",
40
+
28
41
  };
package/lib/i18n/es.js CHANGED
@@ -15,7 +15,18 @@ export const translations = {
15
15
  update_label: "Actualizar",
16
16
  delete_label: "Borrar",
17
17
  cancel_label: "Cancelar",
18
+ accept_label: "Aceptar",
19
+ help_label: "Ayuda",
20
+ filters_label: "Filtros",
21
+ sort_label: "Orden",
22
+ page_label: "Página",
23
+ actions_label: "Acciones",
24
+ element_label: "Elemento",
25
+ element_plural_label: "Elementos",
26
+ run_action_label: "Realizar acción",
27
+ loading: "Cargando...",
18
28
  delete_confirm_message: "¿Estás seguro que quieres borrar este ítem?",
29
+ delete_confirm_message_plural: "¿Seguro que quieres borrar estos elementos?",
19
30
  items_total: "Elementos en total",
20
31
  showing_page_size: (pageSize) => `Mostrando ${pageSize} elementos por página.`,
21
32
  empty_list: "No tenemos elementos todavía",
@@ -25,5 +36,5 @@ export const translations = {
25
36
  all: "todos",
26
37
  all_in_page: "Todos de esta página",
27
38
  select_matching: "Seleccionar coincidentes",
28
-
39
+ element_actions: "Acciones en este ítem",
29
40
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "0.0.33",
3
+ "version": "0.0.35",
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": "15a59318f4be16facc3e442c13709fc0c543b57b"
34
+ "gitHead": "51111b38c0b87c4e0e0db9e180c7ddb7d3f90c7a"
35
35
  }