@lenne.tech/ng-base 14.13.1 → 14.13.2

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.
@@ -1477,28 +1477,9 @@ class ModelFormComponent {
1477
1477
  if (this.logging) {
1478
1478
  console.log('ModelFormComponent::submit->formValue', this.form.value);
1479
1479
  }
1480
- const data = Object.assign({}, this.form.value);
1481
- for (const [key, value] of Object.entries(data)) {
1482
- if ((this.config[key]?.roles ? !this.user.hasAllRoles(this.config[key]?.roles) : false) ||
1483
- this.config[key]?.exclude) {
1484
- delete data[key];
1485
- }
1486
- if (value && typeof value === 'object' && !Array.isArray(value)) {
1487
- data[key] = Object.keys(data[key])
1488
- .filter((k) => data[key][k] != null)
1489
- .reduce((a, k) => ({ ...a, [k]: data[key][k] }), {});
1490
- if (Object.keys(data[key])?.length === 0) {
1491
- if (this.logging) {
1492
- console.log('Object is empty from result');
1493
- }
1494
- data[key] = null;
1495
- }
1496
- }
1497
- // Set type for graphql method
1498
- if (this.fields[key]?.type === 'Float') {
1499
- data[key] = Number(value);
1500
- }
1501
- }
1480
+ // Prepare data for server request
1481
+ let data = Object.assign({}, this.form.value);
1482
+ data = this.prepareDataForRequest(this.config, this.fields, data);
1502
1483
  if (this.logging) {
1503
1484
  console.log('ModelFormComponent::submit->valueToGraphql', data);
1504
1485
  }
@@ -1567,6 +1548,35 @@ class ModelFormComponent {
1567
1548
  });
1568
1549
  });
1569
1550
  }
1551
+ /**
1552
+ * Prepare data for server
1553
+ */
1554
+ prepareDataForRequest(config, fieldsConfig, data) {
1555
+ for (const [key, value] of Object.entries(data)) {
1556
+ if ((config[key]?.roles ? !this.user.hasAllRoles(config[key]?.roles) : false) || config[key]?.exclude) {
1557
+ delete data[key];
1558
+ }
1559
+ if (value && typeof value === 'object' && !Array.isArray(value)) {
1560
+ data[key] = Object.keys(data[key])
1561
+ .filter((k) => data[key][k] != null)
1562
+ .reduce((a, k) => ({ ...a, [k]: data[key][k] }), {});
1563
+ if (Object.keys(data[key])?.length === 0) {
1564
+ if (this.logging) {
1565
+ console.log('Object is empty from result');
1566
+ }
1567
+ data[key] = null;
1568
+ }
1569
+ }
1570
+ // Set type for graphql method
1571
+ if (fieldsConfig[key]?.type === 'Float') {
1572
+ data[key] = Number(value);
1573
+ }
1574
+ if (fieldsConfig[key]?.fields && Object.keys(fieldsConfig[key]?.fields).length > 0) {
1575
+ data[key] = this.prepareDataForRequest(config[key]?.fields, fieldsConfig[key]?.fields, data[key]);
1576
+ }
1577
+ }
1578
+ return data;
1579
+ }
1570
1580
  /**
1571
1581
  * Init fab buttons for mobile devices
1572
1582
  */
@@ -1585,6 +1595,9 @@ class ModelFormComponent {
1585
1595
  event.subscribe(() => this.deleteObject());
1586
1596
  }
1587
1597
  }
1598
+ /**
1599
+ * Set file changes for process
1600
+ */
1588
1601
  processFileChanges(event) {
1589
1602
  const index = this.fileChanges?.findIndex((e) => e.field === event.field);
1590
1603
  if (index !== undefined && index !== -1) {