@dile/crud 2.4.4 → 2.5.0

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.
@@ -39,17 +39,23 @@ export class DileCrudSingleActions extends DileCrudActions {
39
39
  return {
40
40
  actions: { type: Array },
41
41
  element: { type: Object },
42
+ directSingleActions: { type: Array },
42
43
  };
43
44
  }
44
45
 
45
46
  constructor() {
46
47
  super();
47
48
  this.actions = [];
49
+ this.directSingleActions = [];
48
50
  }
49
51
 
50
52
  get actionListTemplate() {
53
+ const visibleActions = this.actions.filter(action =>
54
+ (!action.shouldAppear || action.shouldAppear(this.element)) &&
55
+ !this.directSingleActions.includes(action.name)
56
+ );
51
57
  return html`
52
- ${this.actions.length > 0
58
+ ${visibleActions.length > 0
53
59
  ? html`
54
60
  <dile-card title="${this.translations.element_actions}">
55
61
  <dile-box-selector
@@ -57,9 +63,7 @@ export class DileCrudSingleActions extends DileCrudActions {
57
63
  attrForSelected="name"
58
64
  @dile-selected-changed="${this.onActionSelected}"
59
65
  >
60
- ${this.actions
61
- .filter(action => !action.shouldAppear || action.shouldAppear(this.element))
62
- .map(action => html`
66
+ ${visibleActions.map(action => html`
63
67
  <dile-box-selector-item
64
68
  label="${action.label}"
65
69
  name="${action.name}"
@@ -89,4 +93,15 @@ export class DileCrudSingleActions extends DileCrudActions {
89
93
  this.showAction();
90
94
  }
91
95
  }
96
+
97
+ triggerAction(actionName) {
98
+ this.selection = actionName;
99
+ this.computeDestructive();
100
+ const action = this.actions.find(a => a.name === actionName);
101
+ if (action && action.onClick) {
102
+ action.onClick(this.element);
103
+ } else {
104
+ this.showAction();
105
+ }
106
+ }
92
107
  }
@@ -76,20 +76,29 @@ export class DileCrudSingle extends DileI18nMixin(DileCrudMixin(LitElement)) {
76
76
  `
77
77
  }
78
78
 
79
+ get showActionsBar() {
80
+ const c = this.config;
81
+ const hasEdit = !c?.customization?.disableEdit;
82
+ const hasDirectActions = c?.actions?.directSingleActions?.length > 0;
83
+ const hasListActions = !c?.customization?.disableListActionsOnSingleComponent && c?.actions?.list?.length > 0;
84
+ return hasEdit || hasDirectActions || hasListActions;
85
+ }
86
+
79
87
  get contentTemplate() {
80
88
  return html`
81
89
  <main class="elcontainer">
82
90
  ${this.detailTemplate}
83
- ${this.config?.customization?.disableEdit && (!this.config?.actions?.list || this.config.actions.list.length === 0) ? '' : html`
91
+ ${this.showActionsBar ? html`
84
92
  <div class="actions" @action-success=${this.actionSuccess}>
85
93
  ${!this.config?.customization?.disableEdit ? html`
86
94
  <dile-button .icon="${editIcon}" @click=${this.edit}>
87
95
  ${this.startUpdateLabelComputed(this.config.labels.startUpdateAction, this.translations)}
88
96
  </dile-button>
89
97
  ` : ''}
90
- ${this.actionsTemplate}
98
+ ${this.directActionsTemplate}
99
+ ${this.config?.customization?.disableListActionsOnSingleComponent ? '' : this.actionsTemplate}
91
100
  </div>
92
- `}
101
+ ` : ''}
93
102
  </main>
94
103
 
95
104
  ${this.updateTemplate}
@@ -115,6 +124,7 @@ export class DileCrudSingle extends DileI18nMixin(DileCrudMixin(LitElement)) {
115
124
  return html`
116
125
  <dile-crud-single-actions
117
126
  .actions=${this.config.actions.single}
127
+ .directSingleActions=${this.config.actions.directSingleActions || []}
118
128
  .formActionsTemplate=${this.config.templates.formSingleActions}
119
129
  .actionIds=${this.actionIds}
120
130
  endpoint=${this.config.endpoint}
@@ -126,14 +136,36 @@ export class DileCrudSingle extends DileI18nMixin(DileCrudMixin(LitElement)) {
126
136
  `
127
137
  }
128
138
 
139
+ get directActionsTemplate() {
140
+ const directSingleActions = this.config.actions.directSingleActions || [];
141
+ return directSingleActions.map(actionName => {
142
+ const action = (this.config.actions.single || []).find(a => a.name === actionName);
143
+ if (!action) return '';
144
+ if (action.shouldAppear && !action.shouldAppear(this.element)) return '';
145
+ return html`
146
+ <dile-button class="action-controller" @click=${() => this.triggerDirectAction(actionName)}>
147
+ ${action.label}
148
+ </dile-button>
149
+ `;
150
+ });
151
+ }
152
+
129
153
  get detailElement() {
130
154
  return this.shadowRoot.getElementById('eldetail');
131
155
  }
132
156
 
157
+ get singleActionsElement() {
158
+ return this.shadowRoot.querySelector('dile-crud-single-actions');
159
+ }
160
+
133
161
  refresh() {
134
162
  this.detailElement.refresh();
135
163
  }
136
164
 
165
+ triggerDirectAction(actionName) {
166
+ this.singleActionsElement.triggerAction(actionName);
167
+ }
168
+
137
169
  elementLoaded(e) {
138
170
  this.element = e.detail.element;
139
171
  }
@@ -30,6 +30,7 @@ export const defaultConfig = {
30
30
  disableSort: true,
31
31
  disableFilter: true,
32
32
  disableHelp: true,
33
+ disableListActionsOnSingleComponent: false,
33
34
  },
34
35
  responseAdapter: new ResponseApiAdapter(),
35
36
  requestAdapter: new RequestApiAdapter(),
@@ -57,6 +58,7 @@ export const defaultConfig = {
57
58
  }
58
59
  ],
59
60
  single: [],
61
+ directSingleActions: [],
60
62
  },
61
63
  templates: {
62
64
  item: () => templatePlaceholder('item'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "2.4.4",
3
+ "version": "2.5.0",
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",
@@ -32,5 +32,5 @@
32
32
  "publishConfig": {
33
33
  "access": "public"
34
34
  },
35
- "gitHead": "d9fcd6a43318a4407751cdd25f9361502e9d2619"
35
+ "gitHead": "c94427356ce29d9ad6e492cc8ac7be41b0cdd665"
36
36
  }