Skip to content

Commit 5f235e2

Browse files
JHoellitenthedominikriemer
authored
Edit Assets links for adapter while editing (apache#3817)
Co-authored-by: Philipp Zehnder <tenthe@users.noreply.github.com> Co-authored-by: Dominik Riemer <dominik.riemer@gmail.com>
1 parent 94b660f commit 5f235e2

File tree

9 files changed

+394
-50
lines changed

9 files changed

+394
-50
lines changed

ui/projects/streampipes/platform-services/src/lib/model/assets/asset.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export interface SpAssetModel extends SpAsset {
105105
export interface SpAssetTreeNode {
106106
assetId: string;
107107
assetName: string;
108+
assetLinks: AssetLink[];
108109
assets?: SpAssetTreeNode[];
109110
spAssetModelId: string;
110111
flattenPath: any[];

ui/src/app/connect/components/adapter-configuration/adapter-asset-configuration/adapter-asset-configuration.component.ts

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import {
2626
AssetLinkType,
2727
SpAsset,
2828
SpAssetTreeNode,
29+
AdapterDescription,
2930
} from '@streampipes/platform-services';
3031
import { MatStepper } from '@angular/material/stepper';
3132
import { Observable } from 'rxjs';
@@ -39,11 +40,15 @@ import { Observable } from 'rxjs';
3940
export class AdapterAssetConfigurationComponent implements OnInit {
4041
@Input() linkageData: LinkageData[] = [];
4142
@Input() stepper: MatStepper;
43+
@Input() isEdit: boolean;
44+
@Input() adapter: AdapterDescription;
4245

4346
@Output() adapterStartedEmitter: EventEmitter<void> =
4447
new EventEmitter<void>();
4548

4649
@Output() selectedAssetsChange = new EventEmitter<SpAssetTreeNode[]>();
50+
@Output() deselectedAssetsChange = new EventEmitter<SpAssetTreeNode[]>();
51+
@Output() originalAssetsEmitter = new EventEmitter<SpAssetTreeNode[]>();
4752

4853
treeControl: NestedTreeControl<SpAssetTreeNode>;
4954
dataSource: MatTreeNestedDataSource<SpAssetTreeNode>;
@@ -56,6 +61,8 @@ export class AdapterAssetConfigurationComponent implements OnInit {
5661
assetLinksLoaded = false;
5762
updateObservable: Observable<SpAssetModel>;
5863
selectedAssets: SpAssetTreeNode[] = [];
64+
deselectedAssets: SpAssetTreeNode[] = [];
65+
originalAssets: SpAssetTreeNode[] = [];
5966

6067
constructor(private assetService: AssetManagementService) {
6168
this.treeControl = new NestedTreeControl<SpAssetTreeNode>(
@@ -76,13 +83,40 @@ export class AdapterAssetConfigurationComponent implements OnInit {
7683
asset => asset.assetId === node.assetId,
7784
);
7885

86+
const index_deselected = this.deselectedAssets.findIndex(
87+
asset => asset.assetId === node.assetId,
88+
);
89+
7990
if (index > -1) {
8091
this.selectedAssets.splice(index, 1);
92+
if (this.isNodeInOriginalData(node)) {
93+
this.deselectedAssets.push(node);
94+
}
8195
} else {
8296
this.selectedAssets.push(node);
97+
if (index_deselected > -1) {
98+
this.deselectedAssets.splice(index_deselected, 1);
99+
}
83100
}
84101

85-
this.selectedAssetsChange.emit(this.selectedAssets);
102+
const selectEmit = this.selectedAssets.filter(
103+
node => !this.isNodeInOriginalData(node),
104+
);
105+
106+
this.selectedAssetsChange.emit(selectEmit);
107+
this.deselectedAssetsChange.emit(this.deselectedAssets);
108+
}
109+
110+
private isNodeInOriginalData(node: SpAssetTreeNode): boolean {
111+
for (const asset of this.originalAssets) {
112+
if (
113+
asset.assetId === node.assetId &&
114+
asset.spAssetModelId === node.spAssetModelId
115+
) {
116+
return true;
117+
}
118+
}
119+
return false;
86120
}
87121

88122
isSelected(node: SpAssetTreeNode): boolean {
@@ -100,9 +134,50 @@ export class AdapterAssetConfigurationComponent implements OnInit {
100134
next: assets => {
101135
this.assetsData = this.mapAssets(assets);
102136
this.dataSource.data = this.assetsData;
137+
if (this.isEdit) {
138+
this.setSelect();
139+
}
103140
},
104141
});
105142
}
143+
144+
private setSelect() {
145+
if (!this.adapter || !this.adapter.elementId) {
146+
return;
147+
}
148+
149+
this.assetsData.forEach(node => {
150+
this.selectNodeIfMatch(node);
151+
});
152+
}
153+
154+
private selectNodeIfMatch(
155+
node: SpAssetTreeNode,
156+
path: SpAssetTreeNode[] = [],
157+
) {
158+
const currentPath = [...path, node];
159+
160+
if (
161+
node.assetLinks &&
162+
node.assetLinks.some(
163+
link => link.resourceId === this.adapter.elementId,
164+
)
165+
) {
166+
if (!this.isSelected(node)) {
167+
this.selectedAssets.push(node);
168+
this.originalAssets.push(node);
169+
this.originalAssetsEmitter.emit(this.originalAssets);
170+
currentPath.forEach(n => this.treeControl.expand(n));
171+
}
172+
}
173+
174+
if (node.assets) {
175+
node.assets.forEach(child =>
176+
this.selectNodeIfMatch(child, currentPath),
177+
);
178+
}
179+
}
180+
106181
private mapAssets(
107182
apiAssets: SpAsset[],
108183
parentId: string = '',
@@ -124,6 +199,7 @@ export class AdapterAssetConfigurationComponent implements OnInit {
124199
assetId: asset.assetId,
125200
assetName: asset.assetName,
126201
flattenPath: flattenedPath,
202+
assetLinks: asset.assetLinks,
127203
assets: asset.assets
128204
? this.mapAssets(asset.assets, parentId, flattenedPathCopy)
129205
: [],

ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,18 @@
108108
[optionDescription]="'Add Adapter to an existing Asset' | translate"
109109
optionIcon="precision_manufacturing"
110110
dataCy="show-asset-checkbox"
111+
[isChecked]="
112+
showAsset && (!isEditMode || originalAssets.length > 0)
113+
"
111114
(optionSelectedEmitter)="showAsset = $event"
112115
>
113116
<sp-adapter-asset-configuration
114117
*ngIf="showAsset"
118+
[isEdit]="isEditMode"
119+
[adapter]="adapterDescription"
115120
(selectedAssetsChange)="onSelectedAssetsChange($event)"
121+
(deselectedAssetsChange)="onDeselectedAssetsChange($event)"
122+
(originalAssetsEmitter)="onOriginalAssetsEmitted($event)"
116123
>
117124
</sp-adapter-asset-configuration>
118125
</sp-adapter-options-panel>

ui/src/app/connect/components/adapter-configuration/start-adapter-configuration/start-adapter-configuration.component.ts

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,12 @@
1616
*
1717
*/
1818

19-
import {
20-
Component,
21-
EventEmitter,
22-
Input,
23-
OnInit,
24-
Output,
25-
SimpleChanges,
26-
OnChanges,
27-
} from '@angular/core';
19+
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
2820
import {
2921
AdapterDescription,
30-
SpAssetTreeNode,
3122
EventRateTransformationRuleDescription,
3223
EventSchema,
24+
SpAssetTreeNode,
3325
RemoveDuplicatesTransformationRuleDescription,
3426
} from '@streampipes/platform-services';
3527
import {
@@ -67,8 +59,6 @@ export class StartAdapterConfigurationComponent implements OnInit {
6759

6860
@Input() isEditMode: boolean;
6961

70-
@Input() stepper: MatStepper;
71-
7262
/**
7363
* Cancels the adapter configuration process
7464
*/
@@ -110,6 +100,8 @@ export class StartAdapterConfigurationComponent implements OnInit {
110100
showCode = false;
111101
showAsset = false;
112102
selectedAssets = [];
103+
deselectedAssets = [];
104+
originalAssets = [];
113105

114106
constructor(
115107
private dialogService: DialogService,
@@ -120,6 +112,7 @@ export class StartAdapterConfigurationComponent implements OnInit {
120112
) {}
121113

122114
ngOnInit(): void {
115+
this.showAsset = this.isEditMode;
123116
this.startAdapterForm = this._formBuilder.group({});
124117
this.startAdapterForm.addControl(
125118
'adapterName',
@@ -189,6 +182,9 @@ export class StartAdapterConfigurationComponent implements OnInit {
189182
data: {
190183
adapter: this.adapterDescription,
191184
editMode: true,
185+
selectedAssets: this.selectedAssets,
186+
deselectedAssets: this.deselectedAssets,
187+
originalAssets: this.originalAssets,
192188
},
193189
});
194190

@@ -213,8 +209,7 @@ export class StartAdapterConfigurationComponent implements OnInit {
213209
selectedAssets: this.selectedAssets,
214210
},
215211
});
216-
const dialogInstance =
217-
dialogRef.componentInstance as unknown as AdapterStartedDialog;
212+
218213
dialogRef.afterClosed().subscribe(() => {
219214
this.adapterStartedEmitter.emit();
220215
});
@@ -224,6 +219,14 @@ export class StartAdapterConfigurationComponent implements OnInit {
224219
this.selectedAssets = updatedAssets;
225220
}
226221

222+
onDeselectedAssetsChange(updatedAssets: SpAssetTreeNode[]): void {
223+
this.deselectedAssets = updatedAssets;
224+
}
225+
226+
onOriginalAssetsEmitted(updatedAssets: SpAssetTreeNode[]): void {
227+
this.originalAssets = updatedAssets;
228+
}
229+
227230
private checkAndApplyStreamRules(): void {
228231
if (this.removeDuplicates) {
229232
const removeDuplicates: RemoveDuplicatesTransformationRuleDescription =

ui/src/app/connect/dialog/adapter-started/adapter-started-dialog.component.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
[pipelineOperationStatus]="pipelineOperationStatus"
4646
[saveInDataLake]="saveInDataLake"
4747
[saveInAsset]="addToAssetText"
48+
[deletedFromAsset]="deletedFromAssetText"
4849
[templateErrorMessage]="templateErrorMessage"
4950
[adapterErrorMessage]="adapterErrorMessage"
5051
></sp-adapter-started-success>

0 commit comments

Comments
 (0)