diff --git a/src/app/modules/devices/device-instances/device-instances.component.ts b/src/app/modules/devices/device-instances/device-instances.component.ts index f6ea37b9..c6e3d415 100644 --- a/src/app/modules/devices/device-instances/device-instances.component.ts +++ b/src/app/modules/devices/device-instances/device-instances.component.ts @@ -250,19 +250,7 @@ export class DeviceInstancesComponent implements OnInit, AfterViewInit { }), //handle results map((deviceInstancesWithTotal: DeviceInstancesTotalModel) => { - let missingCreators: string[] = []; - deviceInstancesWithTotal?.result?.forEach(device => { - if(device.shared && device.creator && !this.userIdToName[device.creator] && !missingCreators.includes(device.creator)) { - missingCreators.push(device.creator); - } - }) - missingCreators.forEach(creator => { - this.permissionsService.getUserById(creator).subscribe(value => { - if(value) { - this.userIdToName[value.id] = value.username; - } - }) - }) + this.loadUserNames(deviceInstancesWithTotal.result); this.setDevicesAndTotal(deviceInstancesWithTotal); return deviceInstancesWithTotal; }), @@ -275,6 +263,22 @@ export class DeviceInstancesComponent implements OnInit, AfterViewInit { } } + private loadUserNames(elements: {creator: string, shared: boolean}[]) { + let missingCreators: string[] = []; + elements?.forEach(element => { + if(element.shared && element.creator && !this.userIdToName[element.creator] && !missingCreators.includes(element.creator)) { + missingCreators.push(element.creator); + } + }) + missingCreators.forEach(creator => { + this.permissionsService.getUserById(creator).subscribe(value => { + if(value) { + this.userIdToName[value.id] = value.username; + } + }) + }) + } + private setDevicesAndTotal(result: DeviceInstancesTotalModel) { this.dataSource.data = result.result; this.totalCount = result.total; diff --git a/src/app/modules/devices/networks/networks.component.ts b/src/app/modules/devices/networks/networks.component.ts index dd9b8ed3..b6c79281 100644 --- a/src/app/modules/devices/networks/networks.component.ts +++ b/src/app/modules/devices/networks/networks.component.ts @@ -182,26 +182,29 @@ export class NetworksComponent implements OnInit, OnDestroy { .searchNetworks(this.searchText, this.pageSize, this.offset, this.sortBy, this.sortDirection) .pipe( map((networks: NetworksPermModel[]) => { - let missingCreators: string[] = []; - networks?.forEach(network => { - if(network.shared && network.creator && !this.userIdToName[network.creator] && !missingCreators.includes(network.creator)) { - missingCreators.push(network.creator); - } - }) - missingCreators.forEach(creator => { - this.permissionsService.getUserById(creator).subscribe(value => { - if(value) { - this.userIdToName[value.id] = value.username; - } - }) - }) - + this.loadUserNames(networks); this.dataSource.data = networks; return networks; }) ); } + private loadUserNames(elements: {creator: string, shared: boolean}[]) { + let missingCreators: string[] = []; + elements?.forEach(element => { + if(element.shared && element.creator && !this.userIdToName[element.creator] && !missingCreators.includes(element.creator)) { + missingCreators.push(element.creator); + } + }) + missingCreators.forEach(creator => { + this.permissionsService.getUserById(creator).subscribe(value => { + if(value) { + this.userIdToName[value.id] = value.username; + } + }) + }) + } + reload() { this.offset = 0; this.pageSize = 20; diff --git a/src/app/modules/processes/process-repo/process-repo.component.html b/src/app/modules/processes/process-repo/process-repo.component.html index 68edb45b..bb00f254 100644 --- a/src/app/modules/processes/process-repo/process-repo.component.html +++ b/src/app/modules/processes/process-repo/process-repo.component.html @@ -52,7 +52,7 @@