@trudb/tru-common-lib 0.2.281 → 0.2.283
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.
|
@@ -7722,6 +7722,32 @@ class TruDataGrid {
|
|
|
7722
7722
|
setNoRowsTemplate = () => {
|
|
7723
7723
|
//this.noRowsTemplate = `<span style="font-size:14px;font-weight:bold;">No data found.</span>`;
|
|
7724
7724
|
};
|
|
7725
|
+
applyRelationships = (newEntity) => {
|
|
7726
|
+
if (this.entity) {
|
|
7727
|
+
newEntity[this.config.parentTableRelationshipRefName] = this.entity[this.config.parentTableRefName];
|
|
7728
|
+
}
|
|
7729
|
+
if (this.gridType === TruDataGridTypes.DetailManyToMany) {
|
|
7730
|
+
//let parentName = this.entity.constructor.name;
|
|
7731
|
+
let unassociatedType = this.config.resultConfig.entityManyToManyType;
|
|
7732
|
+
let ref = this.selectedUnassociatedChoice.value.$;
|
|
7733
|
+
let childToAssociate = this.dataContext.entityAccess().searchByRefCacheOnly(unassociatedType, ref, true);
|
|
7734
|
+
if (childToAssociate) {
|
|
7735
|
+
let enhancedEntity = this.enhanceRowDataForEntity(newEntity);
|
|
7736
|
+
enhancedEntity.$entity[unassociatedType.name + 'Ref'] = childToAssociate[unassociatedType.name + 'Ref'];
|
|
7737
|
+
enhancedEntity.$entity[this.config.parentTableRelationshipRefName] = this.entity[this.config.parentTableRefName];
|
|
7738
|
+
// remove item from the add dropdown control
|
|
7739
|
+
let itemIndex = this.unassociatedChoices.findIndex((choice) => {
|
|
7740
|
+
return choice[unassociatedType.name + 'Ref'] === childToAssociate[unassociatedType.name + 'Ref'];
|
|
7741
|
+
});
|
|
7742
|
+
this.unassociatedChoices.splice(itemIndex, 1);
|
|
7743
|
+
// clear add selection
|
|
7744
|
+
this.selectedUnassociatedChoice = undefined;
|
|
7745
|
+
// add row to grid
|
|
7746
|
+
this.unsavedEntities.push(enhancedEntity);
|
|
7747
|
+
this.api.applyTransaction({ add: [enhancedEntity], addIndex: 0 });
|
|
7748
|
+
}
|
|
7749
|
+
}
|
|
7750
|
+
};
|
|
7725
7751
|
subscribeTo = () => {
|
|
7726
7752
|
this.subs.push(this.appEnvironment.onSaveComplete$.pipe(skip(1)).subscribe(event => {
|
|
7727
7753
|
if (event?.successful)
|
|
@@ -7827,11 +7853,15 @@ class TruDataGrid {
|
|
|
7827
7853
|
});
|
|
7828
7854
|
if (!entityAlreadyInGrid) {
|
|
7829
7855
|
let enhancedEntity = this.enhanceRowDataForEntity(entity);
|
|
7830
|
-
if (changeArgs.entity.Ref < 0)
|
|
7856
|
+
if (changeArgs.entity.Ref < 0) {
|
|
7857
|
+
this.applyRelationships(entity);
|
|
7831
7858
|
this.rowData.push(enhancedEntity);
|
|
7832
|
-
|
|
7859
|
+
this.api.applyTransaction({ add: [enhancedEntity], addIndex: 0 });
|
|
7860
|
+
}
|
|
7861
|
+
else {
|
|
7833
7862
|
this.rowData.unshift(enhancedEntity);
|
|
7834
|
-
|
|
7863
|
+
this.api.applyTransaction({ add: [enhancedEntity] });
|
|
7864
|
+
}
|
|
7835
7865
|
}
|
|
7836
7866
|
}
|
|
7837
7867
|
}));
|
|
@@ -7954,6 +7984,7 @@ class TruDataGrid {
|
|
|
7954
7984
|
}
|
|
7955
7985
|
return false;
|
|
7956
7986
|
};
|
|
7987
|
+
//Can possibly merge with similar logic in onEntityAdded() observable above
|
|
7957
7988
|
addEntity = (newEntity, dataNotification = false) => {
|
|
7958
7989
|
let entityAlreadyInGrid = false;
|
|
7959
7990
|
this.api?.forEachNodeAfterFilter((rowNode) => {
|