Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/1128 add delete to objective menu #1132

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions frontend/cypress/e2e/objective-crud.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as users from '../fixtures/users.json';
import CyOverviewPage from '../support/helper/dom-helper/pages/overviewPage';
import ObjectiveDialog from '../support/helper/dom-helper/dialogs/objectiveDialog';
import ConfirmDialog from '../support/helper/dom-helper/dialogs/confirmDialog';

describe('CRUD operations', () => {
let op = new CyOverviewPage();
Expand Down Expand Up @@ -41,10 +42,9 @@ describe('CRUD operations', () => {
});

it(`Delete existing objective`, () => {
cy.get('.objective').first().findByTestId('three-dot-menu').click();
op.selectFromThreeDotMenu('Objective bearbeiten');
ObjectiveDialog.do()
.deleteObjective()
op.getObjectiveByState('ongoing').findByTestId('three-dot-menu').click();
op.selectFromThreeDotMenu('Objective löschen');
ConfirmDialog.do()
.checkTitle('Objective löschen')
.checkDescription(
'Möchtest du dieses Objective wirklich löschen? Zugehörige Key Results werden dadurch ebenfalls gelöscht!',
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/app/components/objective/ObjectiveMenuActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export class ObjectiveMenuActions {
return { displayName: 'Objective duplizieren', action: action, afterAction: afterAction };
}

deleteObjectiveAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.DELETE.OBJECTIVE');
const afterAction: ObjectiveMenuAfterAction = (objective, dialogResult) =>
this.afterActions.deleteObjective(objective);
return { displayName: 'Objective löschen', action: action, afterAction: afterAction };
}

completeObjectiveAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = {
data: { objectiveTitle: objective.title },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export class ObjectiveMenuAfterActions {
});
}

deleteObjective(objective: ObjectiveMin) {
this.objectiveService.deleteObjective(objective.id).subscribe(() => {
this.refreshDataService.markDataRefresh();
});
}

objectiveBackToDraft(objectiveMin: ObjectiveMin) {
this.objectiveService.getFullObjective(objectiveMin.id).subscribe((objective: Objective) => {
objective.state = 'DRAFT' as State;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class ObjectiveMenuActionsService {
}

private getDefaultActions(objective: ObjectiveMin): ObjectiveMenuEntry[] {
return [this.actions.duplicateObjectiveAction(objective)];
return [this.actions.duplicateObjectiveAction(objective), this.actions.deleteObjectiveAction(objective)];
}

private getDraftMenuActions(objective: ObjectiveMin): ObjectiveMenuEntry[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,6 @@
</button>
<button color="primary" mat-button mat-dialog-close [attr.data-testId]="'cancel'">Abbrechen</button>
</div>

<div class="col-auto" *ngIf="data.objective.objectiveId && data.action != 'duplicate'">
<button color="primary" type="button" mat-button (click)="deleteObjective()" [attr.data-testId]="'delete'">
Objective Löschen
</button>
</div>
>
</ng-container>
</app-dialog-template-core>
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,6 @@ export class ObjectiveFormComponent implements OnInit, OnDestroy {
}
}

deleteObjective() {
const dialog = this.dialogService.openConfirmDialog('CONFIRMATION.DELETE.OBJECTIVE');
dialog.afterClosed().subscribe((result) => {
if (result) {
this.objectiveService.deleteObjective(this.data.objective.objectiveId!).subscribe({
next: () => {
let objectiveDTO: Objective = { id: this.data.objective.objectiveId! } as unknown as Objective;
this.closeDialog(objectiveDTO, true);
},
error: () => {
this.dialogRef.close();
},
});
}
});
}

objectiveToObjectiveMin(objectiveDto: Objective): ObjectiveMin {
return {
...objectiveDto,
Expand Down
Loading