show actions conditinally on description-template-listing

This commit is contained in:
Sofia Papacharalampous 2024-06-21 13:06:43 +03:00
parent 6e12d13a3b
commit a2a3f5000d
2 changed files with 37 additions and 7 deletions

View File

@ -86,29 +86,29 @@
</ng-template> </ng-template>
<ng-template #actions let-row="row" let-item> <ng-template #actions let-row="row" let-item>
<div class="row" (click)="$event.stopPropagation()"> <div *ngIf="showActions(row)" class="row" (click)="$event.stopPropagation()">
<div class="col-auto"> <div class="col-auto">
<button mat-icon-button [matMenuTriggerFor]="actionsMenu"> <button mat-icon-button [matMenuTriggerFor]="actionsMenu">
<mat-icon>more_horiz</mat-icon> <mat-icon>more_horiz</mat-icon>
</button> </button>
<mat-menu #actionsMenu="matMenu"> <mat-menu #actionsMenu="matMenu">
<button *ngIf="row.status !== descriptionTemplateStatuses.Finalized && hasPermission(permissionEnum.EditDescriptionTemplate, row)" mat-menu-item [routerLink]="routerUtils.generateUrl(['/description-templates/', row.id])"> <button *ngIf="canEdit(row)" mat-menu-item [routerLink]="routerUtils.generateUrl(['/description-templates/', row.id])">
<mat-icon>edit</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.EDIT' | translate}} <mat-icon>edit</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.EDIT' | translate}}
</button> </button>
<button *ngIf="row.belongsToCurrentTenant != false && hasExplicitPermission(permissionEnum.EditDescriptionTemplate)" mat-menu-item [routerLink]="routerUtils.generateUrl(['/description-templates/new-version/', row.id])"> <button *ngIf="canAddNewVersion(row)" mat-menu-item [routerLink]="routerUtils.generateUrl(['/description-templates/new-version/', row.id])">
<mat-icon>queue</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.NEW-VERSION' | translate}} <mat-icon>queue</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.NEW-VERSION' | translate}}
</button> </button>
<button *ngIf="row.belongsToCurrentTenant != false && hasPermission(permissionEnum.CloneDescriptionTemplate, row)" mat-menu-item [routerLink]="routerUtils.generateUrl(['/description-templates/clone/', row.id])"> <button *ngIf="canClone(row)" mat-menu-item [routerLink]="routerUtils.generateUrl(['/description-templates/clone/', row.id])">
<mat-icon>content_copy</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.CLONE' | translate}} <mat-icon>content_copy</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.CLONE' | translate}}
</button> </button>
<button *ngIf="row.belongsToCurrentTenant != false && hasExplicitPermission(permissionEnum.EditDescriptionTemplate)" mat-menu-item [routerLink]="routerUtils.generateUrl(['/description-templates/versions/', row.groupId])"> <button *ngIf="canViewVersions(row)" mat-menu-item [routerLink]="routerUtils.generateUrl(['/description-templates/versions/', row.groupId])">
<mat-icon>library_books</mat-icon> <mat-icon>library_books</mat-icon>
{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.VIEW-VERSIONS' | translate}} {{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.VIEW-VERSIONS' | translate}}
</button> </button>
<button *ngIf="row.belongsToCurrentTenant != false && hasPermission(permissionEnum.ExportDescriptionTemplate, row)" mat-menu-item (click)="export($event, row.id)"> <button *ngIf="canDownloadXml(row)" mat-menu-item (click)="export($event, row.id)">
<mat-icon>download</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.DOWNLOAD-XML' | translate}} <mat-icon>download</mat-icon>{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.DOWNLOAD-XML' | translate}}
</button> </button>
<button *ngIf="row.belongsToCurrentTenant != false && hasPermission(permissionEnum.DeleteDescriptionTemplate, row)" mat-menu-item (click)="delete(row.id)"> <button *ngIf="canDelete(row)" mat-menu-item (click)="delete(row.id)">
<mat-icon>delete</mat-icon> <mat-icon>delete</mat-icon>
{{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.DELETE' | translate}} {{'DESCRIPTION-TEMPLATE-LISTING.ACTIONS.DELETE' | translate}}
</button> </button>

View File

@ -192,6 +192,36 @@ export class DescriptionTemplateListingComponent extends BaseListingComponent<De
this.onColumnsChangedInternal(event.properties.map(x => x.toString())); this.onColumnsChangedInternal(event.properties.map(x => x.toString()));
} }
public showActions(descriptionTemplate: DescriptionTemplate): boolean {
return this.canEdit(descriptionTemplate) || this.canAddNewVersion(descriptionTemplate) ||
this.canClone(descriptionTemplate) || this.canViewVersions(descriptionTemplate) ||
this.canDownloadXml(descriptionTemplate) || this.canDelete(descriptionTemplate);
}
public canEdit(descriptionTemplate: DescriptionTemplate): boolean {
return descriptionTemplate.status !== DescriptionTemplateStatus.Finalized && this.hasPermission(AppPermission.EditDescriptionTemplate, descriptionTemplate);
}
public canAddNewVersion(descriptionTemplate: DescriptionTemplate): boolean {
return descriptionTemplate.belongsToCurrentTenant != false && this.hasExplicitPermission(AppPermission.EditDescriptionTemplate);
}
public canClone(descriptionTemplate: DescriptionTemplate): boolean {
return descriptionTemplate.belongsToCurrentTenant != false && this.hasPermission(AppPermission.CloneDescriptionTemplate, descriptionTemplate);
}
public canViewVersions(descriptionTemplate: DescriptionTemplate): boolean {
return descriptionTemplate.belongsToCurrentTenant != false && this.hasExplicitPermission(AppPermission.EditDescriptionTemplate);
}
public canDownloadXml(descriptionTemplate: DescriptionTemplate): boolean {
return descriptionTemplate.belongsToCurrentTenant != false && this.hasPermission(AppPermission.ExportDescriptionTemplate, descriptionTemplate);
}
public canDelete(descriptionTemplate: DescriptionTemplate): boolean {
return descriptionTemplate.belongsToCurrentTenant != false && this.hasPermission(AppPermission.DeleteDescriptionTemplate, descriptionTemplate);
}
private onColumnsChangedInternal(columns: string[]) { private onColumnsChangedInternal(columns: string[]) {
// Here are defined the projection fields that always requested from the api. // Here are defined the projection fields that always requested from the api.
const fields = new Set(this.lookupFields); const fields = new Set(this.lookupFields);