@dile/crud 0.0.68 → 0.0.70

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.
@@ -79,8 +79,10 @@ export class DileAjax extends DileAxios(DileI18nMixin(LitElement)) {
79
79
  const status = res.status;
80
80
  switch (status) {
81
81
  case 422:
82
+ this.dispatchError(res.data.message || this.translations.http_422, res.data, this.getValidationErrors(res.data));
83
+ break;
82
84
  case 400:
83
- this.dispatchError(res.data.message, res.data, this.getValidationErrors(res.data));
85
+ this.dispatchError(res.data.message || this.translations.http_400, res.data, this.getValidationErrors(res.data));
84
86
  break;
85
87
  case 404:
86
88
  if(res.data.message) {
@@ -127,6 +129,8 @@ export class DileAjax extends DileAxios(DileI18nMixin(LitElement)) {
127
129
 
128
130
  dispatchResponse(response) {
129
131
  this.dispatchEvent(new CustomEvent('ajax-response', {
132
+ bubbles: true,
133
+ composed: true,
130
134
  detail: {
131
135
  response
132
136
  }
@@ -0,0 +1,2 @@
1
+ export { DileRelationChecker } from './src/DileRelationChecker.js';
2
+ export { DileRelationCheckerItem } from './src/DileRelationCheckerItem.js';
@@ -0,0 +1,3 @@
1
+ import { DileRelationCheckerItem } from './src/DileRelationCheckerItem.js';
2
+
3
+ customElements.define('dile-relation-checker-item', DileRelationCheckerItem);
@@ -0,0 +1,3 @@
1
+ import { DileRelationChecker } from './src/DileRelationChecker.js';
2
+
3
+ customElements.define('dile-relation-checker', DileRelationChecker);
@@ -0,0 +1,185 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import {ifDefined} from 'lit/directives/if-defined.js';
3
+ import '@dile/ui/components/input/input-search.js';
4
+ import '../relation-checker-item.js';
5
+ import '../../ajax/ajax.js';
6
+
7
+ export class DileRelationChecker extends LitElement {
8
+ static styles = [
9
+ css`
10
+ :host {
11
+ display: block;
12
+ }
13
+ dile-input-search {
14
+ margin-bottom: 1rem;
15
+ }
16
+ `
17
+ ];
18
+
19
+ static get properties() {
20
+ return {
21
+ /**
22
+ * Endpoint to receive the list of items that can be checked, with their status
23
+ * Receives all items, indicating which ones are checked
24
+ * { label, id, checked }
25
+ */
26
+ endpointGet: { type: String },
27
+
28
+ /**
29
+ * Route to toggle the checked/unchecked status of an item
30
+ * It will send an objetc { id, checked }
31
+ */
32
+ endpointCheck: { type: String},
33
+
34
+ /**
35
+ * Array of items received for potential relationships
36
+ */
37
+ items: { type: Array },
38
+
39
+ /**
40
+ * Title label for the box
41
+ */
42
+ label: { type: String },
43
+
44
+ /**
45
+ * Keyword for the filter
46
+ */
47
+ keyword: { type: String },
48
+
49
+ /**
50
+ * Function to get the items for the relations
51
+ */
52
+ getRelationItems: { type: Object },
53
+
54
+ /**
55
+ * Tooltip compute function
56
+ */
57
+ computeTooltip: { type: Object },
58
+ };
59
+ }
60
+
61
+ constructor() {
62
+ super();
63
+ this.items = [];
64
+ this.getRelationItems = (response) => response.data;
65
+ this.computeTooltip = (item) => null;
66
+ }
67
+
68
+ render() {
69
+ return html`
70
+ ${this.ajaxTemplate}
71
+ <h2>${this.label}</h2>
72
+ <dile-input-search
73
+ @dile-input-search=${this.searchHandler}
74
+ @dile-input-search-cleared=${this.clearKeywordHandler}
75
+ ></dile-input-search>
76
+ ${this.computedItems(this.items, this.keyword).map( item => html`
77
+ <dile-relation-checker-item
78
+ .item=${item}
79
+ @relation-item-changed="${this.relationItemChanged}"
80
+ tooltip=${ifDefined(this.computeTooltip(item))}
81
+ ></dile-relation-checker-item>
82
+ `)}
83
+ `;
84
+ }
85
+
86
+ firstUpdated() {
87
+ this.ajaxsave = this.shadowRoot.getElementById('ajaxsave');
88
+ this.ajaxget = this.shadowRoot.getElementById('ajaxget');
89
+ this.refresh();
90
+ }
91
+
92
+ get ajaxTemplate() {
93
+ return html`
94
+ <dile-ajax
95
+ id="ajaxget"
96
+ method="get"
97
+ url="${this.endpointGet}"
98
+ @ajax-success="${this.doSuccessGet}"
99
+ @ajax-error="${this.doErrorGet}"
100
+ ></dile-ajax>
101
+ <dile-ajax
102
+ id="ajaxsave"
103
+ method="post"
104
+ url="${this.endpointCheck}"
105
+ @ajax-success="${this.doSuccessSave}"
106
+ @ajax-error="${this.doErrorSave}"
107
+ ></dile-ajax>
108
+ `
109
+ }
110
+
111
+ relationItemChanged(e) {
112
+ this.save(e.detail.item.id, e.detail.checked);
113
+ }
114
+
115
+ save(name, checked) {
116
+ this.ajaxsave.data = {
117
+ id: name,
118
+ checked: checked,
119
+ };
120
+ this.ajaxsave.generateRequest();
121
+ }
122
+
123
+ doSuccessGet(e) {
124
+ this.items = this.getRelationItems(e.detail);
125
+ this.dispatchEvent(new CustomEvent('relation-data-recived', {
126
+ bubbles: true,
127
+ composed: true,
128
+ detail: {
129
+ items: this.items
130
+ }
131
+ }));
132
+ }
133
+
134
+ doErrorGet() {
135
+ this.customDispatch('relation-error-get');
136
+ }
137
+
138
+ doSuccessSave() {
139
+ this.customDispatch('relation-success-save');
140
+ this.refresh();
141
+ }
142
+
143
+ refresh() {
144
+ this.updateComplete.then(() => this.ajaxget.generateRequest());
145
+ }
146
+
147
+ doErrorSave() {
148
+ this.customDispatch('relation-error-save');
149
+ }
150
+
151
+ customDispatch(eventName) {
152
+ this.dispatchEvent(new CustomEvent(eventName, {
153
+ bubbles: true,
154
+ composed: true,
155
+ }));
156
+ }
157
+
158
+ doCheckItem(ele) {
159
+ this.items = this.items.map(item => {
160
+ if(item.id == ele.id) {
161
+ return {
162
+ ...item,
163
+ checked: true
164
+ }
165
+ }
166
+ return item;
167
+ })
168
+ this.save(ele.id, true);
169
+ }
170
+
171
+ searchHandler(e) {
172
+ this.keyword = e.detail.keyword;
173
+ }
174
+
175
+ clearKeywordHandler() {
176
+ this.keyword = undefined;
177
+ }
178
+
179
+ computedItems(items, keyword) {
180
+ if(!keyword) {
181
+ return items;
182
+ }
183
+ return items.filter( item => item.label.toLowerCase().indexOf(keyword.toLowerCase()) != -1);
184
+ }
185
+ }
@@ -0,0 +1,69 @@
1
+ import { LitElement, html, css } from 'lit';
2
+ import '@dile/ui/components/checkbox/checkbox.js';
3
+ import '@dile/ui/components/tooltip/chip-tooltip';
4
+
5
+ export class DileRelationCheckerItem extends LitElement {
6
+ static styles = [
7
+ css`
8
+ :host {
9
+ display: block;
10
+ --dile-checkbox-size: 24px;
11
+ }
12
+ div.item {
13
+ display: flex;
14
+ align-items: center;
15
+ margin: 0 0 0.6rem;
16
+ padding-bottom: 0.1rem;
17
+ border-bottom: 1px solid #ddd;
18
+ }
19
+ div.grow {
20
+ flex-grow: 1;
21
+ }
22
+ dile-chip-tooltip {
23
+ margin-right: 0.5rem;
24
+ }
25
+ .onlyicon {
26
+ --dile-chip-tooltip-padding: 0.15rem;
27
+ --dile-chip-tooltip-icon-size: 18px;
28
+ }
29
+ `
30
+ ];
31
+
32
+ static get properties() {
33
+ return {
34
+ item: { type: Object },
35
+ tooltip: { type: String },
36
+ };
37
+ }
38
+
39
+ render() {
40
+ return html`
41
+ <div class="item">
42
+ <div class="grow">
43
+ <dile-checkbox
44
+ name="${this.item.id}"
45
+ @dile-checkbox-changed=${this.checkboxChanged}
46
+ ?checked=${this.item.checked}
47
+ >${this.item.label}</dile-checkbox>
48
+ </div>
49
+ ${this.tooltip
50
+ ? html`<dile-chip-tooltip class="onlyicon" message="${this.tooltip}" position="left"></dile-chip-tooltip>`
51
+ : ''
52
+ }
53
+ </div>
54
+ `;
55
+ }
56
+
57
+ checkboxChanged(e) {
58
+ e.stopPropagation();
59
+ this.dispatchEvent(new CustomEvent('relation-item-changed', {
60
+ bubbles: true,
61
+ composed: true,
62
+ detail: {
63
+ item: this.item,
64
+ checked: e.detail.checked
65
+ }
66
+ }));
67
+ }
68
+
69
+ }
package/lib/i18n/en.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export const translations = {
2
2
  http_unhandled_success: "Unhandled success server response",
3
3
  http_404: "Not found error",
4
+ http_400: "Bad Request",
5
+ http_422: "Unprocessable Entity",
4
6
  http_401: "Unauthorized",
5
7
  http_405: "Method Not Allowed",
6
8
  http_413: "Content Too Large",
package/lib/i18n/es.js CHANGED
@@ -1,6 +1,8 @@
1
1
  export const translations = {
2
2
  http_unhandled_success: "Respuesta de éxito no procesada",
3
3
  http_404: "Recurso inexistente",
4
+ http_400: "Solicitud incorrecta",
5
+ http_422: "Validación de la solicitud incorrecta",
4
6
  http_401: "No autorizado",
5
7
  http_405: "Método HTTP no permitido",
6
8
  http_413: "Contenido enviado al servidor demasiado largo",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dile/crud",
3
- "version": "0.0.68",
3
+ "version": "0.0.70",
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.polydile.com/",
26
26
  "dependencies": {
27
- "@dile/ui": "^2.1.37",
27
+ "@dile/ui": "^2.1.38",
28
28
  "axios": "^1.7.2",
29
29
  "lit": "^2.7.0 || ^3.0.0"
30
30
  },
31
31
  "publishConfig": {
32
32
  "access": "public"
33
33
  },
34
- "gitHead": "98d572545dae6e89cda4f2240bc0e5caface20e0"
34
+ "gitHead": "89e5a0ffc7b9c39d53acd2e4552b05d54de23604"
35
35
  }