Skip to content

Commit

Permalink
Added delete button to case detail screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ivo-ritense committed Nov 22, 2024
1 parent ca4e80c commit 73ddcd4
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 2 deletions.
6 changes: 6 additions & 0 deletions projects/valtimo/config/assets/core/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
"cancel": "Absagen",
"delete": "Löschen"
},
"delete": {
"delete": "Case löschen",
"title": "Case löschen",
"description": "Möchten Sie diesen Case und alle zugehörigen Informationen wirklich löschen? Diese Aktion kann nicht rückgängig gemacht werden.",
"confirm": "Löschen"
},
"formio": {
"noFormSpecified": "Für diese Registerkarte wurde keine Formulardefinition angegeben.",
"formNotFound": "Die Formulardefinition '{{formDefinitionName}}' konnte nicht gefunden werden."
Expand Down
6 changes: 6 additions & 0 deletions projects/valtimo/config/assets/core/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
"cancel": "Cancel",
"delete": "Delete"
},
"delete": {
"delete": "Delete case",
"title": "Delete case",
"description": "Are you sure you want to delete this case and all related information? This action cannot be undone.",
"confirm": "Delete"
},
"formio": {
"noFormSpecified": "No form definition has been specified for this tab.",
"formNotFound": "The form definition '{{formDefinitionName}}' could not be found."
Expand Down
6 changes: 6 additions & 0 deletions projects/valtimo/config/assets/core/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@
"cancel": "Annuleren",
"delete": "Verwijderen"
},
"delete": {
"delete": "Dossier verwijderen",
"title": "Dossier verwijderen",
"description": "Weet u zeker dat u dit dossier en alle gerelateerde informatie wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.",
"confirm": "Verwijderen"
},
"formio": {
"noFormSpecified": "Voor dit tabblad is geen formulierdefinitie opgegeven.",
"formNotFound": "De formulierdefinitie '{{formDefinitionName}}' kan niet worden gevonden."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ export class DocumentService {
return this.http.put<DocumentResult>(`${this.valtimoEndpointUri}v1/document`, document);
}

public deleteDocument(documentId: string): Observable<any> {
return this.http.delete(`${this.valtimoEndpointUri}v1/document/${documentId}`);
}

// ProcessDocument-calls
public getProcessDocumentDefinitions(): Observable<ProcessDocumentDefinition> {
return this.http.get<ProcessDocumentDefinition>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,17 @@
</cds-overflow-menu-option>
</ng-template>

<ng-template #deleteButton let-canDelete="canDelete">
<cds-overflow-menu-option
*ngIf="canDelete"
[disabled]="(isDeleting$ | async)"
(click)="deleteDocument()"
type="danger"
>
<span>{{ 'dossier.delete.delete' | translate }}</span>
</cds-overflow-menu-option>
</ng-template>

<ng-template #customStartTrigger>
<button
[size]="(compactMode$ | async) ? 'sm' : 'lg'"
Expand All @@ -195,6 +206,15 @@
</button>
</ng-template>

<valtimo-confirmation-modal
confirmButtonTextTranslationKey="dossier.delete.confirm"
confirmButtonType="danger"
contentTranslationKey="dossier.delete.description"
[showModalSubject$]="showDeleteModal$"
titleTranslationKey="dossier.delete.title"
(confirmEvent)="onConfirmDelete()"
></valtimo-confirmation-modal>

<ng-container renderInPageHeader [fullWidth]="true">
<ng-template>
<div
Expand All @@ -205,6 +225,7 @@
canAssign: canAssign$ | async,
canClaim: canClaim$ | async,
canHaveAssignee: canHaveAssignee$ | async,
canDelete: canDelete$ | async,
document: document$ | async,
caseStatus: caseStatus$ | async,
} as obs"
Expand Down Expand Up @@ -236,7 +257,7 @@
<div class="buttons-container">
<cds-overflow-menu
[ngClass]="{'--compact': compactMode$ | async}"
*ngIf="obs.canHaveAssignee"
*ngIf="obs.canHaveAssignee || obs.canDelete"
flip="true"
[offset]="(compactMode$ | async) ? {y: 48, x: -4} : {y: 48, x: 4}"
class="overflow-button assign-overflow"
Expand All @@ -251,6 +272,13 @@
<cds-overflow-menu-option (selected)="unassignAssignee()" [disabled]="!obs.assigneeId">
{{ 'assignDocument.remove' | translate }}
</cds-overflow-menu-option>
<ng-container
*ngTemplateOutlet="
deleteButton;
context: {canDelete: obs.canDelete}
"
>
</ng-container>
</cds-overflow-menu>

<cds-overflow-menu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ import {TabImpl, TabLoaderImpl} from '../../models';
import {
CAN_ASSIGN_CASE_PERMISSION,
CAN_CLAIM_CASE_PERMISSION,
CAN_DELETE_CASE_PERMISSION,
DOSSIER_DETAIL_PERMISSION_RESOURCE,
} from '../../permissions';
import {DossierDetailLayoutService, DossierService, DossierTabService} from '../../services';
Expand Down Expand Up @@ -127,6 +128,8 @@ export class DossierDetailComponent
filter(key => !!key)
);

public readonly showDeleteModal$: BehaviorSubject<boolean> = new BehaviorSubject(false);

public readonly document$: Observable<ValtimoDocument | null> =
this.dossierService.refreshDocument$.pipe(
switchMap(() => this.route.params),
Expand Down Expand Up @@ -202,6 +205,8 @@ export class DossierDetailComponent
map(caseSettings => caseSettings?.canHaveAssignee)
);

public readonly isDeleting$ = new BehaviorSubject<boolean>(false);

public readonly canAssignLoaded$ = new BehaviorSubject<boolean>(false);
public readonly canAssign$: Observable<boolean> = this.route.paramMap.pipe(
switchMap((params: ParamMap) =>
Expand All @@ -224,6 +229,19 @@ export class DossierDetailComponent
)
);

public readonly canDeleteLoaded$ = new BehaviorSubject<boolean>(false);
public readonly canDelete$: Observable<boolean> = this.route.paramMap.pipe(
switchMap((params: ParamMap) =>
this.permissionService.requestPermission(CAN_DELETE_CASE_PERMISSION, {
resource: DOSSIER_DETAIL_PERMISSION_RESOURCE.jsonSchemaDocument,
identifier: params.get('documentId') ?? '',
})
),
tap(() => {
this.canDeleteLoaded$.next(true);
})
);

public readonly loadingTabs$ = new BehaviorSubject<boolean>(true);
public readonly noTabsConfigured$ = new BehaviorSubject<boolean>(false);
public activeTab$: Observable<TabImpl>;
Expand Down Expand Up @@ -373,6 +391,24 @@ export class DossierDetailComponent
});
}

public deleteDocument(): void {
this.showDeleteModal$.next(true);
}

public onConfirmDelete(): void {
this.documentService.deleteDocument(this.documentId).subscribe({
next: (): void => {
this.isAssigning$.next(false);
this.showDeleteModal$.next(false);
this.router.navigate([`/dossiers/${this.documentDefinitionName}`]);
},
error: (): void => {
this.isAssigning$.next(false);
this.logger.debug('Something went wrong while deleting the case');
},
});
}

public onTaskClickEvent(taskProcessLinkResult: TaskWithProcessLink): void {
if (!taskProcessLinkResult.processLinkActivityResult) {
this.isAdmin$.pipe(take(1)).subscribe(isAdmin => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ const CAN_CREATE_CASE_PERMISSION: PermissionRequest = {
resource: DOSSIER_DETAIL_PERMISSION_RESOURCE.jsonSchemaDocument,
};

const CAN_DELETE_CASE_PERMISSION: PermissionRequest = {
action: PERMISSION_ACTION.delete,
resource: DOSSIER_DETAIL_PERMISSION_RESOURCE.jsonSchemaDocument,
};

export {
CAN_ADD_NOTE_PERMISSION,
CAN_ASSIGN_CASE_PERMISSION,
Expand All @@ -75,4 +80,5 @@ export {
DOSSIER_DETAIL_PERMISSION_RESOURCE,
CAN_VIEW_CASE_PERMISSION,
CAN_CREATE_CASE_PERMISSION,
CAN_DELETE_CASE_PERMISSION,
};
2 changes: 1 addition & 1 deletion src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ export const environment: ValtimoConfig = {
experimentalDmnEditing: true,
largeLogoMargin: true,
sortFilesByDate: true,
disableCaseCount: false,
disableCaseCount: true,
returnToLastUrlAfterTokenExpiration: true,
useStartEventNameAsStartFormTitle: true,
allowUserThemeSwitching: true,
Expand Down

0 comments on commit 73ddcd4

Please sign in to comment.