@@ -11,12 +11,18 @@ import {
11
11
ResourcesManagerService ,
12
12
RichMember ,
13
13
User ,
14
+ UsersManagerService ,
14
15
} from '@perun-web-apps/perun/openapi' ;
15
16
import { MatDialog } from '@angular/material/dialog' ;
16
17
import { AttributesListComponent } from '@perun-web-apps/perun/components' ;
17
18
import { SelectionModel } from '@angular/cdk/collections' ;
18
19
import { DeleteAttributeDialogComponent } from '../dialogs/delete-attribute-dialog/delete-attribute-dialog.component' ;
19
- import { getDefaultDialogConfig , getRecentlyVisitedIds } from '@perun-web-apps/perun/utils' ;
20
+ import {
21
+ compareFnName ,
22
+ compareFnUser ,
23
+ getDefaultDialogConfig ,
24
+ getRecentlyVisitedIds ,
25
+ } from '@perun-web-apps/perun/utils' ;
20
26
import { EditAttributeDialogComponent } from '@perun-web-apps/perun/dialogs' ;
21
27
import { CreateAttributeDialogComponent } from '../dialogs/create-attribute-dialog/create-attribute-dialog.component' ;
22
28
import { Urns } from '@perun-web-apps/perun/urns' ;
@@ -32,27 +38,31 @@ export class TwoEntityAttributePageComponent implements OnInit {
32
38
@Input ( ) firstEntityId : number ;
33
39
@Input ( ) firstEntity : string ;
34
40
@Input ( ) secondEntity : string ;
41
+ @Input ( ) specificSecondEntity : Resource | Facility | Group | RichMember | User = null ;
42
+ @Input ( ) facilityId : number ;
35
43
entityValues : Resource [ ] | Facility [ ] | Group [ ] | RichMember [ ] | User [ ] = [ ] ;
36
44
attributes : Attribute [ ] = [ ] ;
37
45
selection = new SelectionModel < Attribute > ( true , [ ] ) ;
38
- specificSecondEntity : Resource | Facility | Group | RichMember | User ;
39
46
allowedStatuses : string [ ] = [ 'INVALID' , 'VALID' ] ;
40
47
loading = false ;
41
48
innerLoading = false ;
42
49
filterValue = '' ;
43
50
filterEmpty = true ;
44
51
noEntityMessage : string ;
52
+ showSelect = true ;
45
53
46
54
constructor (
47
55
private attributesManagerService : AttributesManagerService ,
48
56
private resourcesManagerService : ResourcesManagerService ,
49
57
private facilitiesManagerService : FacilitiesManagerService ,
50
58
private groupsManagerService : GroupsManagerService ,
51
59
private membersManager : MembersManagerService ,
60
+ private usersManager : UsersManagerService ,
52
61
private dialog : MatDialog
53
62
) { }
54
63
55
64
ngOnInit ( ) : void {
65
+ this . showSelect = this . specificSecondEntity === null ;
56
66
this . loadEntityValues ( ) ;
57
67
this . setMessages ( this . secondEntity . toLowerCase ( ) ) ;
58
68
}
@@ -113,13 +123,26 @@ export class TwoEntityAttributePageComponent implements OnInit {
113
123
}
114
124
break ;
115
125
case 'user' :
116
- this . facilitiesManagerService
117
- . getAssignedFacilitiesByUser ( this . firstEntityId )
118
- . subscribe ( ( facilities ) => {
119
- this . entityValues = facilities ;
120
- this . preselectEntity ( ) ;
121
- this . loading = false ;
122
- } ) ;
126
+ switch ( this . secondEntity ) {
127
+ case 'resource' :
128
+ this . usersManager
129
+ . getAssociatedResourcesForUser ( this . facilityId , this . firstEntityId )
130
+ . subscribe ( ( resources ) => {
131
+ this . entityValues = resources ;
132
+ this . preselectEntity ( ) ;
133
+ this . loading = false ;
134
+ } ) ;
135
+ break ;
136
+ default :
137
+ this . facilitiesManagerService
138
+ . getAssignedFacilitiesByUser ( this . firstEntityId )
139
+ . subscribe ( ( facilities ) => {
140
+ this . entityValues = facilities ;
141
+ this . preselectEntity ( ) ;
142
+ this . loading = false ;
143
+ } ) ;
144
+ break ;
145
+ }
123
146
break ;
124
147
case 'resource' :
125
148
switch ( this . secondEntity ) {
@@ -158,13 +181,18 @@ export class TwoEntityAttributePageComponent implements OnInit {
158
181
}
159
182
160
183
preselectEntity ( ) : void {
161
- if ( this . entityValues . length !== 0 ) {
184
+ if ( this . specificSecondEntity !== null ) {
185
+ this . specifySecondEntity ( this . specificSecondEntity ) ;
186
+ } else if ( this . entityValues . length !== 0 ) {
162
187
this . findInitiallySelectedEntity ( ) ;
163
188
}
164
189
}
165
190
166
191
findInitiallySelectedEntity ( ) : void {
167
- let initialEntity = this . entityValues [ 0 ] ;
192
+ let initialEntity =
193
+ this . secondEntity === 'member' || this . secondEntity === 'user'
194
+ ? this . entityValues . sort ( compareFnUser ) [ 0 ]
195
+ : this . entityValues . sort ( compareFnName ) [ 0 ] ;
168
196
const recentIds = getRecentlyVisitedIds ( this . entityKey ( ) ) ;
169
197
if ( recentIds ) {
170
198
for ( const entity of this . entityValues ) {
@@ -231,12 +259,28 @@ export class TwoEntityAttributePageComponent implements OnInit {
231
259
}
232
260
break ;
233
261
case 'user' :
234
- this . attributesManagerService
235
- . getUserFacilityAttributes ( this . firstEntityId , entityId )
236
- . subscribe ( ( attributes ) => {
237
- this . attributes = attributes ;
238
- this . innerLoading = false ;
239
- } ) ;
262
+ switch ( this . secondEntity ) {
263
+ case 'resource' :
264
+ this . membersManager
265
+ . getMemberByUser ( ( this . specificSecondEntity as Resource ) . voId , this . firstEntityId )
266
+ . subscribe ( ( member ) => {
267
+ this . attributesManagerService
268
+ . getMemberResourceAttributes ( member . id , entityId )
269
+ . subscribe ( ( attributes ) => {
270
+ this . attributes = attributes ;
271
+ this . innerLoading = false ;
272
+ } ) ;
273
+ } ) ;
274
+ break ;
275
+ default :
276
+ this . attributesManagerService
277
+ . getUserFacilityAttributes ( this . firstEntityId , entityId )
278
+ . subscribe ( ( attributes ) => {
279
+ this . attributes = attributes ;
280
+ this . innerLoading = false ;
281
+ } ) ;
282
+ break ;
283
+ }
240
284
break ;
241
285
case 'resource' :
242
286
switch ( this . secondEntity ) {
0 commit comments