@sankhyalabs/ezui 1.1.7 → 1.1.11

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.
@@ -172,10 +172,16 @@ const selectErrorMessage = (state, dataUnit, recordId, fieldName) => {
172
172
  const selectVisibleButtons = state => state.nonhist.visibleButtons;
173
173
 
174
174
  class DataUnit {
175
- constructor(name, unitLabel, cardinality = '1') {
175
+ constructor(name, unitLabel, cardinality = '1', parentDU = null) {
176
176
  this.name = name;
177
177
  this.unitLabel = unitLabel;
178
178
  this.cardinality = cardinality;
179
+ this._children = [];
180
+ if (parentDU != null) {
181
+ parentDU._children.push(this);
182
+ this.parentDU = parentDU;
183
+ this.parentDUName = parentDU.name;
184
+ }
179
185
  }
180
186
  set store(store) {
181
187
  this._store = store;
@@ -233,21 +239,57 @@ class DataUnit {
233
239
  insert() {
234
240
  const insertionIndex = this.records.length;
235
241
  const newRecordIndex = selectNewRecordIndex(this._store.getState(), this.name);
236
- this.records.push({ record__id: 'NEW_' + (newRecordIndex + 1) });
242
+ const newRecord = { record__id: 'NEW_' + (newRecordIndex + 1) };
243
+ this.bindToParent(newRecord);
244
+ this.records.push(newRecord);
237
245
  this._store.dispatch(insertRecord(this.name, insertionIndex));
238
246
  }
239
- getChangesToSave() {
247
+ buildChange(r) {
240
248
  const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
241
- const changesByRecord = Object.keys(duChanges).map(record__id => {
242
- const record = { record__id };
243
- const recordChanges = duChanges[record__id];
244
- Object.keys(recordChanges).forEach(fieldName => { record[fieldName] = recordChanges[fieldName]; });
245
- return record;
249
+ let recordChanges;
250
+ if (duChanges) {
251
+ recordChanges = duChanges[r.record__id];
252
+ }
253
+ let subChanges = [];
254
+ this._children.forEach(duChild => {
255
+ subChanges = subChanges.concat(duChild.getSubChanges(r.record__id));
246
256
  });
247
- return [{
248
- dataUnit: this.name,
249
- records: changesByRecord
250
- }];
257
+ if (recordChanges || subChanges.length > 0) {
258
+ const change = {
259
+ "__data__unit": this.name,
260
+ "__record__id": r.record__id,
261
+ "__sub__changes": subChanges
262
+ };
263
+ if (recordChanges) {
264
+ Object.keys(recordChanges).forEach(fieldName => { change[fieldName] = recordChanges[fieldName]; });
265
+ }
266
+ return change;
267
+ }
268
+ return undefined;
269
+ }
270
+ getSubChanges(id) {
271
+ const result = [];
272
+ if (this._records) {
273
+ this._records.filter(r => r.parent__record__id === id).forEach(r => {
274
+ const c = this.buildChange(r);
275
+ if (c) {
276
+ result.push(c);
277
+ }
278
+ });
279
+ }
280
+ return result;
281
+ }
282
+ getChangesToSave() {
283
+ let result = [];
284
+ if (this._records) {
285
+ this._records.forEach(r => {
286
+ const change = this.buildChange(r);
287
+ if (change) {
288
+ result.push(change);
289
+ }
290
+ });
291
+ }
292
+ return result;
251
293
  }
252
294
  save() {
253
295
  if (!this.validateRecords()) {
@@ -337,6 +379,17 @@ class DataUnit {
337
379
  }
338
380
  set records(records) {
339
381
  this._records = records;
382
+ if (this.parentDU) {
383
+ this._records.forEach(r => this.bindToParent(r));
384
+ }
385
+ }
386
+ bindToParent(r) {
387
+ if (this.parentDU) {
388
+ const parentRecord = this.parentDU.getCurrentRecord();
389
+ if (parentRecord) {
390
+ r.parent__record__id = parentRecord.record__id;
391
+ }
392
+ }
340
393
  }
341
394
  get records() {
342
395
  if (!this._records) {
@@ -361,7 +414,7 @@ class DataUnit {
361
414
  const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
362
415
  const recordsToValidate = [];
363
416
  this.records.forEach((record, i) => {
364
- const changes = duChanges[record.record__id];
417
+ const changes = duChanges ? duChanges[record.record__id] : undefined;
365
418
  if (changes) {
366
419
  recordsToValidate.push(Object.assign(Object.assign(Object.assign({}, record), changes), { record__index: i, record__changedfields: Object.keys(changes) }));
367
420
  }
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-9403fe8f.js');
6
6
  const RequestMetadata = require('./RequestMetadata-2cd01e8a.js');
7
- const DataUnit = require('./DataUnit-6a98d9de.js');
7
+ const DataUnit = require('./DataUnit-74f074a7.js');
8
8
 
9
9
  const ezButtonCss = ":host{--bt--min-width:100px;--bt--height:42px;--bt__icon--width:18px;--bt__inline__icon--padding:12px;--bt--padding-top:var(--space--medium, 12px);--bt--padding-bottom:var(--space--medium, 12px);--bt--padding-right:var(--space--large, 24px);--bt--padding-left:var(--space--large, 24px);--bt--color:var(--text--inverted, #FFF);--bt--font-size:var(--text--medium, 14px);--bt--font-family:var(--font-pattern, Arial);--bt--font-weight:var(--text-weight--large);--bt--background-color:var(--color--primary, #c0c0c0);--bt--border-radius:var(--border--radius-large, 12px);--bt--border:none;--bt--hover--background-color:var(--color--primary-700, var(--bt--background-color));--bt--disabled--color:var(--color--disable-primary, var(--bt--color));--bt--disabled--background-color:var(--color--disabled, var(--bt--background-color));--bt--focus--border:var(--bt--border);--bt--focus--box-shadow:none}button{display:flex;align-items:center;justify-content:center;margin:0;cursor:pointer;transition:background-color 0.2s linear;min-width:var(--bt--min-width);height:var(--bt--height);font-family:var(--bt--font-family);font-size:var(--bt--font-size);font-weight:var(--bt--font-weight);padding:var(--bt--padding-top) var(--bt--padding-right) var(--bt--padding-bottom) var(--bt--padding-left);border-radius:var(--bt--border-radius);background-color:var(--bt--background-color);color:var(--bt--color);fill:var(--bt--color);border:var(--bt--border)}button:hover{background-color:var(--bt--hover--background-color)}button:focus{outline:none;border:var(--bt--focus--border);box-shadow:var(--bt--focus--box-shadow)}button:disabled{background-color:var(--bt--disabled--background-color);color:var(--bt--disabled--color);fill:var(--bt--disabled--color);border:none;cursor:no-drop}button.icon{width:42px;min-width:42px;height:42px;padding:0px}a{font-family:var(--bt--font-family);font-size:var(--bt--font-size);font-weight:var(--bt--font-weight);cursor:pointer;display:flex;align-items:center;justify-content:center}";
10
10
 
@@ -2037,8 +2037,8 @@ const NavigationBar = ({ dataUnit: du, buttonProps }) => {
2037
2037
  return index.h("div", { class: "col col--sd-12 align--right" },
2038
2038
  buttonProps.previousVisible ? index.h("ez-button", { title: "Registro anterior", mode: "icon", enabled: du.hasPrevious(), onClick: () => du.previous(), image: "/themes/default/images/icons/actions-sprite.svg#previous-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2039
2039
  buttonProps.nextVisible ? index.h("ez-button", { title: "Pr\u00F3ximo registro", mode: "icon", enabled: du.hasNext(), onClick: () => du.next(), image: "/themes/default/images/icons/actions-sprite.svg#next-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2040
- buttonProps.removeVisible ? index.h("ez-button", { title: "Remover " + du.unitLabel, mode: "icon", enabled: du.hasCurrentRecord(), onClick: () => removeHandler(du), image: "/themes/default/images/icons/actions-sprite.svg#minus-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2041
- buttonProps.addVisible ? index.h("ez-button", { label: "Criar " + du.unitLabel, onClick: () => du.insert(), class: "button--secondary margin-right--medium" }) : null,
2040
+ buttonProps.removeVisible ? index.h("ez-button", { label: "Remover", enabled: du.hasCurrentRecord(), onClick: () => removeHandler(du), image: "/themes/default/images/icons/actions-sprite.svg#minus-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
2041
+ buttonProps.addVisible ? index.h("ez-button", { label: "Adicionar", onClick: () => du.insert(), class: "button--secondary margin-right--medium" }) : null,
2042
2042
  buttonProps.reloadVisible ? index.h("ez-button", { title: "Recarregar", mode: "icon", onClick: () => du.load(), image: "/themes/default/images/icons/actions-sprite.svg#rotate", class: "button--secondary margin-right--medium" }) : null,
2043
2043
  buttonProps.cancelVisible ? index.h("ez-button", { label: "Cancelar", enabled: du.hasChanges(), onClick: () => du.cancel(), class: "button--secondary margin-right--medium" }) : null,
2044
2044
  buttonProps.saveVisible ? index.h("ez-button", { label: "Salvar", enabled: du.hasChanges(), onClick: () => du.save(), class: "button--primary margin-right--medium" }) : null);
@@ -2160,7 +2160,7 @@ const FormSheet = ({ store, parentName, source, parentDataUnit, dataUnitBuilder
2160
2160
  const selectedTab = DataUnit.selectCurrentTab(store.getState(), parentName);
2161
2161
  const tabs = source.length > 1 ? source.map(form => index.h("ez-tab", { label: form.label, tabKey: form.name })) : null;
2162
2162
  const { subForms, items, name } = source[selectedTab];
2163
- const dataUnit = dataUnitBuilder(source[selectedTab].dataUnit);
2163
+ const dataUnit = dataUnitBuilder(source[selectedTab].dataUnit, parentDataUnit);
2164
2164
  source[selectedTab].dataUnit = dataUnit;
2165
2165
  const hasSubForms = subForms && subForms.length > 0;
2166
2166
  const changeTabHandler = (index) => {
@@ -2188,20 +2188,36 @@ const ezFormCss = "ez-form{display:flex;flex-direction:column;width:100%}.form-s
2188
2188
  const EzForm = class {
2189
2189
  constructor(hostRef) {
2190
2190
  index.registerInstance(this, hostRef);
2191
- this._dataUnits = [];
2191
+ this._dataUnits = new Map();
2192
+ this._duSources = new Map();
2192
2193
  this._requiredFieldsByDU = {};
2193
2194
  }
2194
2195
  async validate() {
2195
- for (let i = 0; i < this._dataUnits.length; i++) {
2196
- if (!this._dataUnits[i].validateRecords()) {
2196
+ for (let i = 0; i < this._duSources.size; i++) {
2197
+ const duName = Array.from(this._duSources.keys())[i];
2198
+ let du = this._dataUnits.get(duName);
2199
+ if (du === undefined) {
2200
+ const source = this._duSources.get(duName);
2201
+ du = this.buildDataUnit(source, source.parentDUName);
2202
+ }
2203
+ if (!du.validateRecords()) {
2197
2204
  return false;
2198
2205
  }
2199
2206
  }
2207
+ return true;
2200
2208
  }
2201
2209
  async getChanges() {
2210
+ debugger;
2202
2211
  let allChanges = [];
2203
- for (let i = 0; i < this._dataUnits.length; i++) {
2204
- allChanges = allChanges.concat(this._dataUnits[i].getChangesToSave());
2212
+ for (let i = 0; i < this._dataUnits.size; i++) {
2213
+ const du = Array.from(this._dataUnits.values())[i];
2214
+ //Só devemos buscar as alterações de DU raiz, pois os sub DUs serão enviados junto.
2215
+ if (!du.parentDU) {
2216
+ const duChanges = du.getChangesToSave();
2217
+ if (duChanges) {
2218
+ allChanges = allChanges.concat(duChanges);
2219
+ }
2220
+ }
2205
2221
  }
2206
2222
  return allChanges;
2207
2223
  }
@@ -2220,7 +2236,7 @@ const EzForm = class {
2220
2236
  }
2221
2237
  });
2222
2238
  };
2223
- if (records.length == 0) {
2239
+ if (dataUnit.records.length == 0) {
2224
2240
  recordValidator({});
2225
2241
  }
2226
2242
  else {
@@ -2244,8 +2260,9 @@ const EzForm = class {
2244
2260
  }
2245
2261
  }
2246
2262
  loadMDFromExecutor(callBack) {
2247
- if (this._loadMetadataFunction) {
2248
- const result = this._loadMetadataFunction();
2263
+ const loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
2264
+ if (loadMetadataFunction) {
2265
+ const result = loadMetadataFunction();
2249
2266
  if (result) {
2250
2267
  if (result instanceof Promise) {
2251
2268
  result.then(md => {
@@ -2298,13 +2315,20 @@ const EzForm = class {
2298
2315
  }
2299
2316
  });
2300
2317
  (_a = form.subForms) === null || _a === void 0 ? void 0 : _a.forEach((subForm, index) => {
2301
- const subDU = subForm.dataUnit ? subForm.dataUnit.name : duName;
2302
- processFields(subDU, subForm, form.name, index);
2318
+ const subDu = subForm.dataUnit;
2319
+ if (subDu) {
2320
+ this._duSources.set(subDu.name, subDu);
2321
+ subDu.parentDUName = duName;
2322
+ }
2323
+ processFields(subDu ? subDu.name : duName, subForm, form.name, index);
2303
2324
  });
2304
2325
  };
2305
2326
  this.metadata = metadata;
2306
2327
  metadata.map((form, index) => {
2307
- processFields(form.dataUnit.name, form, "__MAIN__FORM__", index);
2328
+ const du = form.dataUnit;
2329
+ const duName = du.name;
2330
+ this._duSources.set(duName, du);
2331
+ processFields(duName, form, "__MAIN__FORM__", index);
2308
2332
  });
2309
2333
  this._store.dispatch(DataUnit.formLoad());
2310
2334
  }
@@ -2316,11 +2340,6 @@ const EzForm = class {
2316
2340
  return null;
2317
2341
  }
2318
2342
  componentDidLoad() {
2319
- this._loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
2320
- this._loadDataFunction = this.parseExecutor(this.loadexecutor);
2321
- this._saveFunction = this.parseExecutor(this.saveexecutor);
2322
- this._removeFunction = this.parseExecutor(this.removeexecutor);
2323
- this._fieldSearchFunction = this.parseExecutor(this.fieldsearchexecutor);
2324
2343
  if (this.metadata) {
2325
2344
  this.updateMetadata(this.metadata);
2326
2345
  }
@@ -2331,27 +2350,34 @@ const EzForm = class {
2331
2350
  }
2332
2351
  }
2333
2352
  }
2334
- buildDataUnit(dataUnit) {
2353
+ buildDataUnit(dataUnit, parentDataUnit) {
2335
2354
  if (dataUnit) {
2336
2355
  const { name, unitLabel, records, cardinality } = dataUnit;
2337
2356
  if (!(dataUnit instanceof DataUnit.DataUnit)) {
2338
- dataUnit = new DataUnit.DataUnit(name, unitLabel, cardinality);
2339
- this._dataUnits.push(dataUnit);
2357
+ let parent;
2358
+ if (parentDataUnit instanceof DataUnit.DataUnit) {
2359
+ parent = parentDataUnit;
2360
+ }
2361
+ else {
2362
+ parent = this._dataUnits.get(parentDataUnit);
2363
+ }
2364
+ dataUnit = new DataUnit.DataUnit(name, unitLabel, cardinality, parent);
2365
+ this._dataUnits.set(dataUnit.name, dataUnit);
2340
2366
  if (records) {
2341
2367
  dataUnit.records = records;
2342
2368
  }
2343
2369
  dataUnit.store = this._store;
2344
- dataUnit.loadExecutor = this._loadDataFunction;
2345
- dataUnit.saveExecutor = this._saveFunction;
2346
- dataUnit.removeExecutor = this._removeFunction;
2370
+ dataUnit.loadExecutor = this.parseExecutor(this.loadexecutor);
2371
+ dataUnit.saveExecutor = this.parseExecutor(this.saveexecutor);
2372
+ dataUnit.removeExecutor = this.parseExecutor(this.removeexecutor);
2347
2373
  dataUnit.recordsValidator = this;
2348
- dataUnit.fieldSearchExecutor = this._fieldSearchFunction;
2374
+ dataUnit.fieldSearchExecutor = this.parseExecutor(this.fieldsearchexecutor);
2349
2375
  }
2350
2376
  }
2351
2377
  return dataUnit;
2352
2378
  }
2353
2379
  render() {
2354
- return this.metadata ? index.h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du) => this.buildDataUnit(du) }) : null;
2380
+ return this.metadata ? index.h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du, parentDataUnit) => this.buildDataUnit(du, parentDataUnit) }) : null;
2355
2381
  }
2356
2382
  get _host() { return index.getElement(this); }
2357
2383
  };
@@ -26,7 +26,6 @@ const EzModal = class {
26
26
  console.log(ev === null || ev === void 0 ? void 0 : ev.key);
27
27
  if ((ev === null || ev === void 0 ? void 0 : ev.key) === 'Escape' && this.closeesc) {
28
28
  this.oppened = false;
29
- debugger;
30
29
  this.ezChange.emit(this.oppened);
31
30
  }
32
31
  };
@@ -35,7 +34,6 @@ const EzModal = class {
35
34
  ev === null || ev === void 0 ? void 0 : ev.stopPropagation();
36
35
  if (ev instanceof PointerEvent && this.closeoutsideclick) {
37
36
  this.oppened = false;
38
- debugger;
39
37
  this.ezChange.emit(this.oppened);
40
38
  }
41
39
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  const index = require('./index-9403fe8f.js');
6
- const DataUnit = require('./DataUnit-6a98d9de.js');
6
+ const DataUnit = require('./DataUnit-74f074a7.js');
7
7
 
8
8
  const FormMetadata = class {
9
9
  constructor(hostRef) {
@@ -8,20 +8,36 @@ import { FormSheet } from './subcomponents/structure/FormSheet';
8
8
  import DataUnit from './subcomponents/DataUnit';
9
9
  export class EzForm {
10
10
  constructor() {
11
- this._dataUnits = [];
11
+ this._dataUnits = new Map();
12
+ this._duSources = new Map();
12
13
  this._requiredFieldsByDU = {};
13
14
  }
14
15
  async validate() {
15
- for (let i = 0; i < this._dataUnits.length; i++) {
16
- if (!this._dataUnits[i].validateRecords()) {
16
+ for (let i = 0; i < this._duSources.size; i++) {
17
+ const duName = Array.from(this._duSources.keys())[i];
18
+ let du = this._dataUnits.get(duName);
19
+ if (du === undefined) {
20
+ const source = this._duSources.get(duName);
21
+ du = this.buildDataUnit(source, source.parentDUName);
22
+ }
23
+ if (!du.validateRecords()) {
17
24
  return false;
18
25
  }
19
26
  }
27
+ return true;
20
28
  }
21
29
  async getChanges() {
30
+ debugger;
22
31
  let allChanges = [];
23
- for (let i = 0; i < this._dataUnits.length; i++) {
24
- allChanges = allChanges.concat(this._dataUnits[i].getChangesToSave());
32
+ for (let i = 0; i < this._dataUnits.size; i++) {
33
+ const du = Array.from(this._dataUnits.values())[i];
34
+ //Só devemos buscar as alterações de DU raiz, pois os sub DUs serão enviados junto.
35
+ if (!du.parentDU) {
36
+ const duChanges = du.getChangesToSave();
37
+ if (duChanges) {
38
+ allChanges = allChanges.concat(duChanges);
39
+ }
40
+ }
25
41
  }
26
42
  return allChanges;
27
43
  }
@@ -40,7 +56,7 @@ export class EzForm {
40
56
  }
41
57
  });
42
58
  };
43
- if (records.length == 0) {
59
+ if (dataUnit.records.length == 0) {
44
60
  recordValidator({});
45
61
  }
46
62
  else {
@@ -64,8 +80,9 @@ export class EzForm {
64
80
  }
65
81
  }
66
82
  loadMDFromExecutor(callBack) {
67
- if (this._loadMetadataFunction) {
68
- const result = this._loadMetadataFunction();
83
+ const loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
84
+ if (loadMetadataFunction) {
85
+ const result = loadMetadataFunction();
69
86
  if (result) {
70
87
  if (result instanceof Promise) {
71
88
  result.then(md => {
@@ -118,13 +135,20 @@ export class EzForm {
118
135
  }
119
136
  });
120
137
  (_a = form.subForms) === null || _a === void 0 ? void 0 : _a.forEach((subForm, index) => {
121
- const subDU = subForm.dataUnit ? subForm.dataUnit.name : duName;
122
- processFields(subDU, subForm, form.name, index);
138
+ const subDu = subForm.dataUnit;
139
+ if (subDu) {
140
+ this._duSources.set(subDu.name, subDu);
141
+ subDu.parentDUName = duName;
142
+ }
143
+ processFields(subDu ? subDu.name : duName, subForm, form.name, index);
123
144
  });
124
145
  };
125
146
  this.metadata = metadata;
126
147
  metadata.map((form, index) => {
127
- processFields(form.dataUnit.name, form, "__MAIN__FORM__", index);
148
+ const du = form.dataUnit;
149
+ const duName = du.name;
150
+ this._duSources.set(duName, du);
151
+ processFields(duName, form, "__MAIN__FORM__", index);
128
152
  });
129
153
  this._store.dispatch(formLoad());
130
154
  }
@@ -136,11 +160,6 @@ export class EzForm {
136
160
  return null;
137
161
  }
138
162
  componentDidLoad() {
139
- this._loadMetadataFunction = this.parseExecutor(this.metadataexecutor);
140
- this._loadDataFunction = this.parseExecutor(this.loadexecutor);
141
- this._saveFunction = this.parseExecutor(this.saveexecutor);
142
- this._removeFunction = this.parseExecutor(this.removeexecutor);
143
- this._fieldSearchFunction = this.parseExecutor(this.fieldsearchexecutor);
144
163
  if (this.metadata) {
145
164
  this.updateMetadata(this.metadata);
146
165
  }
@@ -151,27 +170,34 @@ export class EzForm {
151
170
  }
152
171
  }
153
172
  }
154
- buildDataUnit(dataUnit) {
173
+ buildDataUnit(dataUnit, parentDataUnit) {
155
174
  if (dataUnit) {
156
175
  const { name, unitLabel, records, cardinality } = dataUnit;
157
176
  if (!(dataUnit instanceof DataUnit)) {
158
- dataUnit = new DataUnit(name, unitLabel, cardinality);
159
- this._dataUnits.push(dataUnit);
177
+ let parent;
178
+ if (parentDataUnit instanceof DataUnit) {
179
+ parent = parentDataUnit;
180
+ }
181
+ else {
182
+ parent = this._dataUnits.get(parentDataUnit);
183
+ }
184
+ dataUnit = new DataUnit(name, unitLabel, cardinality, parent);
185
+ this._dataUnits.set(dataUnit.name, dataUnit);
160
186
  if (records) {
161
187
  dataUnit.records = records;
162
188
  }
163
189
  dataUnit.store = this._store;
164
- dataUnit.loadExecutor = this._loadDataFunction;
165
- dataUnit.saveExecutor = this._saveFunction;
166
- dataUnit.removeExecutor = this._removeFunction;
190
+ dataUnit.loadExecutor = this.parseExecutor(this.loadexecutor);
191
+ dataUnit.saveExecutor = this.parseExecutor(this.saveexecutor);
192
+ dataUnit.removeExecutor = this.parseExecutor(this.removeexecutor);
167
193
  dataUnit.recordsValidator = this;
168
- dataUnit.fieldSearchExecutor = this._fieldSearchFunction;
194
+ dataUnit.fieldSearchExecutor = this.parseExecutor(this.fieldsearchexecutor);
169
195
  }
170
196
  }
171
197
  return dataUnit;
172
198
  }
173
199
  render() {
174
- return this.metadata ? h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du) => this.buildDataUnit(du) }) : null;
200
+ return this.metadata ? h(FormSheet, { store: this._store, source: this.metadata, parentName: "__MAIN__FORM__", dataUnitBuilder: (du, parentDataUnit) => this.buildDataUnit(du, parentDataUnit) }) : null;
175
201
  }
176
202
  static get is() { return "ez-form"; }
177
203
  static get originalStyleUrls() { return {
@@ -1,10 +1,16 @@
1
1
  import { changeFieldValue, changesSaved, clearEdition, dataLoaded, dataLoading, insertRecord, nextRecord, previousRecord, recordRemoved, removingRecord, savingChanges } from '../store/Form.actions';
2
2
  import { selectRecordChanges, selectCurrentRecordIndex, selectLoadingData, selectNewRecordIndex, selectDataUnitChanges, selectErrorMessage } from '../store/Form.selectors';
3
3
  export default class DataUnit {
4
- constructor(name, unitLabel, cardinality = '1') {
4
+ constructor(name, unitLabel, cardinality = '1', parentDU = null) {
5
5
  this.name = name;
6
6
  this.unitLabel = unitLabel;
7
7
  this.cardinality = cardinality;
8
+ this._children = [];
9
+ if (parentDU != null) {
10
+ parentDU._children.push(this);
11
+ this.parentDU = parentDU;
12
+ this.parentDUName = parentDU.name;
13
+ }
8
14
  }
9
15
  set store(store) {
10
16
  this._store = store;
@@ -62,21 +68,57 @@ export default class DataUnit {
62
68
  insert() {
63
69
  const insertionIndex = this.records.length;
64
70
  const newRecordIndex = selectNewRecordIndex(this._store.getState(), this.name);
65
- this.records.push({ record__id: 'NEW_' + (newRecordIndex + 1) });
71
+ const newRecord = { record__id: 'NEW_' + (newRecordIndex + 1) };
72
+ this.bindToParent(newRecord);
73
+ this.records.push(newRecord);
66
74
  this._store.dispatch(insertRecord(this.name, insertionIndex));
67
75
  }
68
- getChangesToSave() {
76
+ buildChange(r) {
69
77
  const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
70
- const changesByRecord = Object.keys(duChanges).map(record__id => {
71
- const record = { record__id };
72
- const recordChanges = duChanges[record__id];
73
- Object.keys(recordChanges).forEach(fieldName => { record[fieldName] = recordChanges[fieldName]; });
74
- return record;
78
+ let recordChanges;
79
+ if (duChanges) {
80
+ recordChanges = duChanges[r.record__id];
81
+ }
82
+ let subChanges = [];
83
+ this._children.forEach(duChild => {
84
+ subChanges = subChanges.concat(duChild.getSubChanges(r.record__id));
75
85
  });
76
- return [{
77
- dataUnit: this.name,
78
- records: changesByRecord
79
- }];
86
+ if (recordChanges || subChanges.length > 0) {
87
+ const change = {
88
+ "__data__unit": this.name,
89
+ "__record__id": r.record__id,
90
+ "__sub__changes": subChanges
91
+ };
92
+ if (recordChanges) {
93
+ Object.keys(recordChanges).forEach(fieldName => { change[fieldName] = recordChanges[fieldName]; });
94
+ }
95
+ return change;
96
+ }
97
+ return undefined;
98
+ }
99
+ getSubChanges(id) {
100
+ const result = [];
101
+ if (this._records) {
102
+ this._records.filter(r => r.parent__record__id === id).forEach(r => {
103
+ const c = this.buildChange(r);
104
+ if (c) {
105
+ result.push(c);
106
+ }
107
+ });
108
+ }
109
+ return result;
110
+ }
111
+ getChangesToSave() {
112
+ let result = [];
113
+ if (this._records) {
114
+ this._records.forEach(r => {
115
+ const change = this.buildChange(r);
116
+ if (change) {
117
+ result.push(change);
118
+ }
119
+ });
120
+ }
121
+ return result;
80
122
  }
81
123
  save() {
82
124
  if (!this.validateRecords()) {
@@ -166,6 +208,17 @@ export default class DataUnit {
166
208
  }
167
209
  set records(records) {
168
210
  this._records = records;
211
+ if (this.parentDU) {
212
+ this._records.forEach(r => this.bindToParent(r));
213
+ }
214
+ }
215
+ bindToParent(r) {
216
+ if (this.parentDU) {
217
+ const parentRecord = this.parentDU.getCurrentRecord();
218
+ if (parentRecord) {
219
+ r.parent__record__id = parentRecord.record__id;
220
+ }
221
+ }
169
222
  }
170
223
  get records() {
171
224
  if (!this._records) {
@@ -190,7 +243,7 @@ export default class DataUnit {
190
243
  const duChanges = selectDataUnitChanges(this._store.getState(), this.name);
191
244
  const recordsToValidate = [];
192
245
  this.records.forEach((record, i) => {
193
- const changes = duChanges[record.record__id];
246
+ const changes = duChanges ? duChanges[record.record__id] : undefined;
194
247
  if (changes) {
195
248
  recordsToValidate.push(Object.assign(Object.assign(Object.assign({}, record), changes), { record__index: i, record__changedfields: Object.keys(changes) }));
196
249
  }
@@ -16,7 +16,7 @@ export const FormSheet = ({ store, parentName, source, parentDataUnit, dataUnitB
16
16
  const selectedTab = selectCurrentTab(store.getState(), parentName);
17
17
  const tabs = source.length > 1 ? source.map(form => h("ez-tab", { label: form.label, tabKey: form.name })) : null;
18
18
  const { subForms, items, name } = source[selectedTab];
19
- const dataUnit = dataUnitBuilder(source[selectedTab].dataUnit);
19
+ const dataUnit = dataUnitBuilder(source[selectedTab].dataUnit, parentDataUnit);
20
20
  source[selectedTab].dataUnit = dataUnit;
21
21
  const hasSubForms = subForms && subForms.length > 0;
22
22
  const changeTabHandler = (index) => {
@@ -15,8 +15,8 @@ export const NavigationBar = ({ dataUnit: du, buttonProps }) => {
15
15
  return h("div", { class: "col col--sd-12 align--right" },
16
16
  buttonProps.previousVisible ? h("ez-button", { title: "Registro anterior", mode: "icon", enabled: du.hasPrevious(), onClick: () => du.previous(), image: "/themes/default/images/icons/actions-sprite.svg#previous-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
17
17
  buttonProps.nextVisible ? h("ez-button", { title: "Pr\u00F3ximo registro", mode: "icon", enabled: du.hasNext(), onClick: () => du.next(), image: "/themes/default/images/icons/actions-sprite.svg#next-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
18
- buttonProps.removeVisible ? h("ez-button", { title: "Remover " + du.unitLabel, mode: "icon", enabled: du.hasCurrentRecord(), onClick: () => removeHandler(du), image: "/themes/default/images/icons/actions-sprite.svg#minus-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
19
- buttonProps.addVisible ? h("ez-button", { label: "Criar " + du.unitLabel, onClick: () => du.insert(), class: "button--secondary margin-right--medium" }) : null,
18
+ buttonProps.removeVisible ? h("ez-button", { label: "Remover", enabled: du.hasCurrentRecord(), onClick: () => removeHandler(du), image: "/themes/default/images/icons/actions-sprite.svg#minus-circle-inverted", class: "button--secondary margin-right--medium" }) : null,
19
+ buttonProps.addVisible ? h("ez-button", { label: "Adicionar", onClick: () => du.insert(), class: "button--secondary margin-right--medium" }) : null,
20
20
  buttonProps.reloadVisible ? h("ez-button", { title: "Recarregar", mode: "icon", onClick: () => du.load(), image: "/themes/default/images/icons/actions-sprite.svg#rotate", class: "button--secondary margin-right--medium" }) : null,
21
21
  buttonProps.cancelVisible ? h("ez-button", { label: "Cancelar", enabled: du.hasChanges(), onClick: () => du.cancel(), class: "button--secondary margin-right--medium" }) : null,
22
22
  buttonProps.saveVisible ? h("ez-button", { label: "Salvar", enabled: du.hasChanges(), onClick: () => du.save(), class: "button--primary margin-right--medium" }) : null);
@@ -17,7 +17,6 @@ export class EzModal {
17
17
  console.log(ev === null || ev === void 0 ? void 0 : ev.key);
18
18
  if ((ev === null || ev === void 0 ? void 0 : ev.key) === 'Escape' && this.closeesc) {
19
19
  this.oppened = false;
20
- debugger;
21
20
  this.ezChange.emit(this.oppened);
22
21
  }
23
22
  };
@@ -26,7 +25,6 @@ export class EzModal {
26
25
  ev === null || ev === void 0 ? void 0 : ev.stopPropagation();
27
26
  if (ev instanceof PointerEvent && this.closeoutsideclick) {
28
27
  this.oppened = false;
29
- debugger;
30
28
  this.ezChange.emit(this.oppened);
31
29
  }
32
30
  }