Skip to content

Commit a1319ab

Browse files
Johaney-sHejdaJakub
authored andcommitted
fix(admin): fixed two-entity attributes selection, setting and removal
* on resource and facility details, it was not possible to correctly work with two-entity attributes * now they are correctly shown, filtered, updatable and removable
1 parent 51f2fb4 commit a1319ab

File tree

3 files changed

+193
-76
lines changed

3 files changed

+193
-76
lines changed

apps/admin-gui/src/app/shared/components/dialogs/create-attribute-dialog/create-attribute-dialog.component.ts

Lines changed: 60 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,29 @@ export class CreateAttributeDialogComponent implements OnInit {
163163

164164
switch (this.data.entity) {
165165
case 'facility':
166-
this.attributesManager
167-
.setFacilityAttributes({
168-
facility: this.data.entityId,
169-
attributes: this.selected.selected,
170-
})
171-
.subscribe(() => {
172-
this.handleSuccess();
173-
});
166+
switch (this.data.secondEntity) {
167+
case 'user':
168+
this.attributesManager
169+
.setUserFacilityAttributes({
170+
facility: this.data.entityId,
171+
user: this.data.secondEntityId,
172+
attributes: this.selected.selected,
173+
})
174+
.subscribe(() => {
175+
this.handleSuccess();
176+
});
177+
break;
178+
default:
179+
this.attributesManager
180+
.setFacilityAttributes({
181+
facility: this.data.entityId,
182+
attributes: this.selected.selected,
183+
})
184+
.subscribe(() => {
185+
this.handleSuccess();
186+
});
187+
break;
188+
}
174189
break;
175190
case 'group':
176191
switch (this.data.secondEntity) {
@@ -232,14 +247,39 @@ export class CreateAttributeDialogComponent implements OnInit {
232247
}
233248
break;
234249
case 'resource':
235-
this.attributesManager
236-
.setResourceAttributes({
237-
resource: this.data.entityId,
238-
attributes: this.selected.selected,
239-
})
240-
.subscribe(() => {
241-
this.handleSuccess();
242-
});
250+
switch (this.data.secondEntity) {
251+
case 'member':
252+
this.attributesManager
253+
.setMemberResourceAttributes({
254+
resource: this.data.entityId,
255+
member: this.data.secondEntityId,
256+
attributes: this.selected.selected,
257+
})
258+
.subscribe(() => {
259+
this.handleSuccess();
260+
});
261+
break;
262+
case 'group':
263+
this.attributesManager
264+
.setGroupResourceAttributes({
265+
resource: this.data.entityId,
266+
group: this.data.secondEntityId,
267+
attributes: this.selected.selected,
268+
})
269+
.subscribe(() => {
270+
this.handleSuccess();
271+
});
272+
break;
273+
default:
274+
this.attributesManager
275+
.setResourceAttributes({
276+
resource: this.data.entityId,
277+
attributes: this.selected.selected,
278+
})
279+
.subscribe(() => {
280+
this.handleSuccess();
281+
});
282+
}
243283
break;
244284
case 'user':
245285
switch (this.data.secondEntity) {
@@ -312,6 +352,9 @@ export class CreateAttributeDialogComponent implements OnInit {
312352
if (!this.data.secondEntity) {
313353
return true;
314354
}
315-
return attribute.entity === `${this.data.entity}_${this.data.secondEntity}`;
355+
return (
356+
attribute.entity === `${this.data.entity}_${this.data.secondEntity}` ||
357+
attribute.entity === `${this.data.secondEntity}_${this.data.entity}`
358+
);
316359
}
317360
}

apps/admin-gui/src/app/shared/components/dialogs/delete-attribute-dialog/delete-attribute-dialog.component.ts

Lines changed: 84 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -61,101 +61,114 @@ export class DeleteAttributeDialogComponent implements OnInit {
6161
this.loading = true;
6262
switch (this.data.entity) {
6363
case 'vo':
64-
this.attributesManager.removeVoAttributes(this.data.entityId, ids).subscribe(
65-
() => {
64+
this.attributesManager.removeVoAttributes(this.data.entityId, ids).subscribe({
65+
next: () => {
6666
this.onSuccess();
6767
},
68-
() => (this.loading = false)
69-
);
68+
error: () => (this.loading = false),
69+
});
7070
break;
7171
case 'group':
7272
switch (this.data.secondEntity) {
7373
case 'resource':
7474
this.attributesManager
7575
.removeGroupResourceAttributes(this.data.entityId, this.data.secondEntityId, ids)
76-
.subscribe(
77-
() => {
76+
.subscribe({
77+
next: () => {
7878
this.onSuccess();
7979
},
80-
() => (this.loading = false)
81-
);
80+
error: () => (this.loading = false),
81+
});
8282
break;
8383
default:
84-
this.attributesManager.removeGroupAttributes(this.data.entityId, ids).subscribe(
85-
() => {
84+
this.attributesManager.removeGroupAttributes(this.data.entityId, ids).subscribe({
85+
next: () => {
8686
this.onSuccess();
8787
},
88-
() => (this.loading = false)
89-
);
88+
error: () => (this.loading = false),
89+
});
9090
}
9191
break;
9292
case 'user':
9393
switch (this.data.secondEntity) {
9494
case 'facility':
9595
this.attributesManager
9696
.removeUserFacilityAttributes(this.data.entityId, this.data.secondEntityId, ids)
97-
.subscribe(
98-
() => {
97+
.subscribe({
98+
next: () => {
9999
this.onSuccess();
100100
},
101-
() => (this.loading = false)
102-
);
101+
error: () => (this.loading = false),
102+
});
103103
break;
104104
default:
105-
this.attributesManager.removeUserAttributes(this.data.entityId, ids).subscribe(
106-
() => {
105+
this.attributesManager.removeUserAttributes(this.data.entityId, ids).subscribe({
106+
next: () => {
107107
this.onSuccess();
108108
},
109-
() => (this.loading = false)
110-
);
109+
error: () => (this.loading = false),
110+
});
111111
}
112112
break;
113113
case 'member':
114114
switch (this.data.secondEntity) {
115115
case 'resource':
116116
this.attributesManager
117117
.removeMemberResourceAttributes(this.data.entityId, this.data.secondEntityId, ids)
118-
.subscribe(
119-
() => {
118+
.subscribe({
119+
next: () => {
120120
this.onSuccess();
121121
},
122-
() => (this.loading = false)
123-
);
122+
error: () => (this.loading = false),
123+
});
124124
break;
125125
case 'group':
126126
this.attributesManager
127127
.removeMemberGroupAttributes(this.data.entityId, this.data.secondEntityId, ids)
128-
.subscribe(
129-
() => {
128+
.subscribe({
129+
next: () => {
130130
this.onSuccess();
131131
},
132-
() => (this.loading = false)
133-
);
132+
error: () => (this.loading = false),
133+
});
134134
break;
135135
default:
136-
this.attributesManager.removeMemberAttributes(this.data.entityId, ids).subscribe(
137-
() => {
136+
this.attributesManager.removeMemberAttributes(this.data.entityId, ids).subscribe({
137+
next: () => {
138138
this.onSuccess();
139139
},
140-
() => (this.loading = false)
141-
);
140+
error: () => (this.loading = false),
141+
});
142142
}
143143
break;
144144
case 'facility':
145-
this.attributesManager.removeFacilityAttributes(this.data.entityId, ids).subscribe(
146-
() => {
147-
this.onSuccess();
148-
},
149-
() => (this.loading = false)
150-
);
145+
switch (this.data.secondEntity) {
146+
case 'user':
147+
this.attributesManager
148+
.removeUserFacilityAttributes(this.data.secondEntityId, this.data.entityId, ids)
149+
.subscribe({
150+
next: () => {
151+
this.onSuccess();
152+
},
153+
error: () => (this.loading = false),
154+
});
155+
break;
156+
default:
157+
this.attributesManager.removeFacilityAttributes(this.data.entityId, ids).subscribe({
158+
next: () => {
159+
this.onSuccess();
160+
},
161+
error: () => (this.loading = false),
162+
});
163+
}
151164
break;
152165
case 'host':
153-
this.attributesManager.removeHostAttributes(this.data.entityId, ids).subscribe(
154-
() => {
166+
this.attributesManager.removeHostAttributes(this.data.entityId, ids).subscribe({
167+
next: () => {
155168
this.onSuccess();
156169
},
157-
() => (this.loading = false)
158-
);
170+
error: () => (this.loading = false),
171+
});
159172
break;
160173
case 'ues':
161174
this.attributesManager.removeUesAttributes(this.data.entityId, ids).subscribe({
@@ -166,9 +179,35 @@ export class DeleteAttributeDialogComponent implements OnInit {
166179
});
167180
break;
168181
case 'resource':
169-
this.attributesManager
170-
.removeResourceAttributes(this.data.entityId, ids)
171-
.subscribe({ next: () => this.onSuccess(), error: () => (this.loading = false) });
182+
switch (this.data.secondEntity) {
183+
case 'member':
184+
this.attributesManager
185+
.removeMemberResourceAttributes(this.data.secondEntityId, this.data.entityId, ids)
186+
.subscribe({
187+
next: () => {
188+
this.onSuccess();
189+
},
190+
error: () => (this.loading = false),
191+
});
192+
break;
193+
case 'group':
194+
this.attributesManager
195+
.removeGroupResourceAttributes(this.data.secondEntityId, this.data.entityId, ids)
196+
.subscribe({
197+
next: () => {
198+
this.onSuccess();
199+
},
200+
error: () => (this.loading = false),
201+
});
202+
break;
203+
default:
204+
this.attributesManager.removeResourceAttributes(this.data.entityId, ids).subscribe({
205+
next: () => {
206+
this.onSuccess();
207+
},
208+
error: () => (this.loading = false),
209+
});
210+
}
172211
break;
173212
}
174213
}

libs/perun/dialogs/src/lib/edit-attribute-dialog/edit-attribute-dialog.component.ts

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,27 @@ export class EditAttributeDialogComponent implements OnInit {
127127
}
128128
break;
129129
case 'facility':
130-
this.attributesManager
131-
.setFacilityAttributes({
132-
facility: this.data.entityId,
133-
attributes: this.data.attributes,
134-
})
135-
.subscribe(() => {
136-
this.onSuccess();
137-
});
130+
switch (this.data.secondEntity) {
131+
case 'user':
132+
this.attributesManager
133+
.setFacilityUserAttributes({
134+
facility: this.data.entityId,
135+
user: this.data.secondEntityId,
136+
attributes: this.data.attributes,
137+
})
138+
.subscribe(() => this.onSuccess());
139+
break;
140+
default:
141+
this.attributesManager
142+
.setFacilityAttributes({
143+
facility: this.data.entityId,
144+
attributes: this.data.attributes,
145+
})
146+
.subscribe(() => {
147+
this.onSuccess();
148+
});
149+
break;
150+
}
138151
break;
139152
case 'host':
140153
this.attributesManager
@@ -157,12 +170,34 @@ export class EditAttributeDialogComponent implements OnInit {
157170
});
158171
break;
159172
case 'resource':
160-
this.attributesManager
161-
.setResourceAttributes({
162-
resource: this.data.entityId,
163-
attributes: this.data.attributes,
164-
})
165-
.subscribe(() => this.onSuccess());
173+
switch (this.data.secondEntity) {
174+
case 'member':
175+
this.attributesManager
176+
.setMemberResourceAttributes({
177+
resource: this.data.entityId,
178+
member: this.data.secondEntityId,
179+
attributes: this.data.attributes,
180+
})
181+
.subscribe(() => this.onSuccess());
182+
break;
183+
case 'group':
184+
this.attributesManager
185+
.setResourceGroupAttributes({
186+
resource: this.data.entityId,
187+
group: this.data.secondEntityId,
188+
attributes: this.data.attributes,
189+
})
190+
.subscribe(() => this.onSuccess());
191+
break;
192+
default:
193+
this.attributesManager
194+
.setResourceAttributes({
195+
resource: this.data.entityId,
196+
attributes: this.data.attributes,
197+
})
198+
.subscribe(() => this.onSuccess());
199+
break;
200+
}
166201
break;
167202
}
168203
}

0 commit comments

Comments
 (0)