Skip to content

Commit

Permalink
SNRGY-2314: add 'shared' to process-designs
Browse files Browse the repository at this point in the history
  • Loading branch information
IngoRoessner committed Feb 16, 2024
1 parent 192c8dc commit 127741e
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}),
Expand All @@ -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;
Expand Down
31 changes: 17 additions & 14 deletions src/app/modules/devices/networks/networks.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<div fxLayout="row" fxLayoutAlign="center center" class="footer-buttons">
<mat-checkbox formControlName="selected" (change)="countCheckboxes()">
</mat-checkbox>
<mat-icon matTooltip="Process is shared" *ngIf="item.value.shared"
<mat-icon matTooltip="Process is shared by {{userIdToName[item.value.creator]}}" *ngIf="item.value.shared"
class="color-sidenav info-icon">share
</mat-icon>
<div fxFlex></div>
Expand Down
30 changes: 26 additions & 4 deletions src/app/modules/processes/process-repo/process-repo.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { SortModel } from '../../../core/components/sort/shared/sort.model';
import { forkJoin, Observable, Subscription } from 'rxjs';
import { SearchbarService } from '../../../core/components/searchbar/shared/searchbar.service';
import { ResponsiveService } from '../../../core/services/responsive.service';
import { ProcessModel } from './shared/process.model';
import {ProcessModel, ProcessPermModel} from './shared/process.model';
import { ProcessRepoService } from './shared/process-repo.service';
import { UtilService } from '../../../core/services/util.service';
import { DomSanitizer, SafeUrl } from '@angular/platform-browser';
Expand All @@ -32,6 +32,7 @@ import { MatSnackBar } from '@angular/material/snack-bar';
import { ProcessRepoConditionModel, ProcessRepoConditionsModel } from './shared/process-repo-conditions.model';
import { Router } from '@angular/router';
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
import {PermissionsService} from "../../permissions/shared/permissions.service";

const grids = new Map([
['xs', 1],
Expand Down Expand Up @@ -74,6 +75,8 @@ export class ProcessRepoComponent implements OnInit, AfterViewInit, OnDestroy {
private gridColChangeTimeout: number | undefined;
private knownMainPanelOffsetHeight = 0;

userIdToName: {[key: string]: string} = {};

@ViewChild('mainPanel', { static: false }) mainPanel!: ElementRef;

constructor(
Expand All @@ -89,6 +92,7 @@ export class ProcessRepoComponent implements OnInit, AfterViewInit, OnDestroy {
private snackBar: MatSnackBar,
private router: Router,
private _formBuilder: FormBuilder,
private permissionsService: PermissionsService,
) {
const sub = this.authorizationService.getUserId();
if (typeof sub === 'string') {
Expand Down Expand Up @@ -290,7 +294,8 @@ export class ProcessRepoComponent implements OnInit, AfterViewInit, OnDestroy {
this.sortAttribute.order,
this.getConditions(),
)
.subscribe((repoItems: ProcessModel[]) => {
.subscribe((repoItems: ProcessPermModel[]) => {
this.loadUserNames(repoItems);
this.animationDone = true;
this.addToFormArray(repoItems);
if (repoItems.length !== this.limit) {
Expand All @@ -300,8 +305,24 @@ export class ProcessRepoComponent implements OnInit, AfterViewInit, OnDestroy {
});
}

private addToFormArray(repoItems: ProcessModel[]): void {
repoItems.forEach((repoItem: ProcessModel) => {
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 addToFormArray(repoItems: ProcessPermModel[]): void {
repoItems.forEach((repoItem: ProcessPermModel) => {
this.repoItems.push(
this._formBuilder.group({
id: repoItem.id,
Expand All @@ -311,6 +332,7 @@ export class ProcessRepoComponent implements OnInit, AfterViewInit, OnDestroy {
bpmn_xml: repoItem.bpmn_xml,
publish: repoItem.publish,
shared: repoItem.shared,
creator: repoItem.creator,
parent_id: repoItem.parent_id,
image: this.provideImg(repoItem.svgXML),
permissions: repoItem.permissions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { ErrorHandlerService } from '../../../../core/services/error-handler.ser
import { environment } from '../../../../../environments/environment';
import { catchError, map, mergeMap, retryWhen } from 'rxjs/operators';
import { Observable, timer } from 'rxjs';
import { ProcessModel } from './process.model';
import {ProcessModel, ProcessPermModel} from './process.model';
import { DesignerProcessModel } from '../../designer/shared/designer.model';
import { ProcessRepoConditionsModel } from './process-repo-conditions.model';
import { DeviceTypeBaseModel } from '../../../metadata/device-types-overview/shared/device-type.model';
Expand Down Expand Up @@ -56,9 +56,9 @@ export class ProcessRepoService {
feature: string,
order: string,
conditions: ProcessRepoConditionsModel | null,
): Observable<ProcessModel[]> {
): Observable<ProcessPermModel[]> {
return this.http
.post<ProcessModel[]>(environment.permissionSearchUrl + '/v3/query/processmodel', {
.post<ProcessPermModel[]>(environment.permissionSearchUrl + '/v3/query/processmodel', {
resource: 'processmodel',
find: {
search: query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ export interface ProcessModel {
};
selected: boolean;
}

export interface ProcessPermModel extends ProcessModel {
creator: string;
}

0 comments on commit 127741e

Please sign in to comment.