From 0f56a5565a0de28d49321188c471c66c364c574a Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Fri, 15 Nov 2024 12:19:40 +0100 Subject: [PATCH 1/2] use full objective just if needed in after action --- .../objective/ObjectiveMenuActions.ts | 9 ++- .../objective/ObjectiveMenuAfterActions.ts | 57 +++++++++++-------- .../objective/objective.component.ts | 8 +-- .../objective-menu-actions.service.ts | 2 +- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/frontend/src/app/components/objective/ObjectiveMenuActions.ts b/frontend/src/app/components/objective/ObjectiveMenuActions.ts index a33b090e23..2e36aa7ed6 100644 --- a/frontend/src/app/components/objective/ObjectiveMenuActions.ts +++ b/frontend/src/app/components/objective/ObjectiveMenuActions.ts @@ -1,5 +1,4 @@ import { DialogService } from '../../services/dialog.service'; -import { Objective } from '../../shared/types/model/Objective'; import { RefreshDataService } from '../../services/refresh-data.service'; import { ObjectiveMin } from '../../shared/types/model/ObjectiveMin'; import { ObjectiveFormComponent } from '../../shared/dialog/objective-dialog/objective-form.component'; @@ -20,7 +19,7 @@ export class ObjectiveMenuActions { releaseFromQuarterAction(objective: ObjectiveMin): ObjectiveMenuEntry { const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.RELEASE'); - const afterAction: ObjectiveMenuAfterAction = (objective, dialogResult) => + const afterAction: ObjectiveMenuAfterAction = (objective: ObjectiveMin, dialogResult) => this.afterActions.releaseFromQuarter(objective); return { displayName: 'Objective veröffentlichen', action: action, afterAction: afterAction }; } @@ -53,7 +52,7 @@ export class ObjectiveMenuActions { data: { objectiveTitle: objective.title }, }; const action: ObjectiveMenuAction = () => this.dialogService.open(CompleteDialogComponent, config); - const afterAction: ObjectiveMenuAfterAction = (obj: Objective, result: any) => + const afterAction: ObjectiveMenuAfterAction = (obj: ObjectiveMin, result: any) => this.afterActions.completeObjective(obj, result); return { displayName: 'Objective abschliessen', action: action, afterAction: afterAction }; @@ -61,7 +60,7 @@ export class ObjectiveMenuActions { objectiveBackToDraft(): ObjectiveMenuEntry { const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.TO_DRAFT'); - const afterAction: ObjectiveMenuAfterAction = (obj: Objective, result: any) => + const afterAction: ObjectiveMenuAfterAction = (obj: ObjectiveMin, result: any) => this.afterActions.objectiveBackToDraft(obj); return { displayName: 'Objective als Draft speichern', action: action, afterAction: afterAction }; @@ -69,7 +68,7 @@ export class ObjectiveMenuActions { objectiveReopen(): ObjectiveMenuEntry { const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.REOPEN'); - const afterAction: ObjectiveMenuAfterAction = (obj: Objective, result: any) => + const afterAction: ObjectiveMenuAfterAction = (obj: ObjectiveMin, result: any) => this.afterActions.objectiveReopen(obj); return { displayName: 'Objective wiedereröffnen', action: action, afterAction: afterAction }; diff --git a/frontend/src/app/components/objective/ObjectiveMenuAfterActions.ts b/frontend/src/app/components/objective/ObjectiveMenuAfterActions.ts index 5691305fa9..4d0e237e21 100644 --- a/frontend/src/app/components/objective/ObjectiveMenuAfterActions.ts +++ b/frontend/src/app/components/objective/ObjectiveMenuAfterActions.ts @@ -3,6 +3,7 @@ import { State } from '../../shared/types/enums/State'; import { Completed } from '../../shared/types/model/Completed'; import { ObjectiveService } from '../../services/objective.service'; import { RefreshDataService } from '../../services/refresh-data.service'; +import { ObjectiveMin } from '../../shared/types/model/ObjectiveMin'; export class ObjectiveMenuAfterActions { constructor( @@ -10,40 +11,48 @@ export class ObjectiveMenuAfterActions { private readonly refreshDataService: RefreshDataService, ) {} - completeObjective(objective: Objective, result: { endState: string; comment: string | null; objective: any }) { - objective.state = result.endState as State; - const completed: Completed = { - id: null, - version: objective.version, - objective: objective, - comment: result.comment, - }; - this.objectiveService.updateObjective(objective).subscribe(() => { - this.objectiveService.createCompleted(completed).subscribe(() => { - this.refreshDataService.markDataRefresh(); + completeObjective(objectiveMin: ObjectiveMin, result: { endState: string; comment: string | null; objective: any }) { + this.objectiveService.getFullObjective(objectiveMin.id).subscribe((objective: Objective) => { + objective.state = result.endState as State; + const completed: Completed = { + id: null, + version: objectiveMin.version, + objective: objective, + comment: result.comment, + }; + this.objectiveService.updateObjective(objective).subscribe(() => { + this.objectiveService.createCompleted(completed).subscribe(() => { + this.refreshDataService.markDataRefresh(); + }); }); }); } - releaseFromQuarter(objective: Objective) { - objective.state = 'ONGOING' as State; - this.objectiveService.updateObjective(objective).subscribe(() => { - this.refreshDataService.markDataRefresh(); + releaseFromQuarter(objectiveMin: ObjectiveMin) { + this.objectiveService.getFullObjective(objectiveMin.id).subscribe((objective: Objective) => { + objective.state = 'ONGOING' as State; + this.objectiveService.updateObjective(objective).subscribe(() => { + this.refreshDataService.markDataRefresh(); + }); }); } - objectiveBackToDraft(objective: Objective) { - objective.state = 'DRAFT' as State; - this.objectiveService.updateObjective(objective).subscribe(() => { - this.refreshDataService.markDataRefresh(); + objectiveBackToDraft(objectiveMin: ObjectiveMin) { + this.objectiveService.getFullObjective(objectiveMin.id).subscribe((objective: Objective) => { + objective.state = 'DRAFT' as State; + this.objectiveService.updateObjective(objective).subscribe(() => { + this.refreshDataService.markDataRefresh(); + }); }); } - objectiveReopen(objective: Objective) { - objective.state = 'ONGOING' as State; - this.objectiveService.updateObjective(objective).subscribe(() => { - this.objectiveService.deleteCompleted(objective.id).subscribe(() => { - this.refreshDataService.markDataRefresh(); + objectiveReopen(objectiveMin: ObjectiveMin) { + this.objectiveService.getFullObjective(objectiveMin.id).subscribe((objective: Objective) => { + objective.state = 'ONGOING' as State; + this.objectiveService.updateObjective(objective).subscribe(() => { + this.objectiveService.deleteCompleted(objective.id).subscribe(() => { + this.refreshDataService.markDataRefresh(); + }); }); }); } diff --git a/frontend/src/app/components/objective/objective.component.ts b/frontend/src/app/components/objective/objective.component.ts index d67984a57b..321960e631 100644 --- a/frontend/src/app/components/objective/objective.component.ts +++ b/frontend/src/app/components/objective/objective.component.ts @@ -48,10 +48,10 @@ export class ObjectiveComponent { .afterClosed() .pipe(take(1)) .subscribe((result) => { - this.objectiveService.getFullObjective(objectiveMin.id).subscribe((objective) => { - menuEntry.afterAction(objective, result); - this.trigger?.focus(); - }); + if (result) { + menuEntry.afterAction(objectiveMin, result); + } + this.trigger?.focus(); }); } diff --git a/frontend/src/app/services/objective-menu-actions.service.ts b/frontend/src/app/services/objective-menu-actions.service.ts index 5dd1c2b285..32d27aac32 100644 --- a/frontend/src/app/services/objective-menu-actions.service.ts +++ b/frontend/src/app/services/objective-menu-actions.service.ts @@ -11,7 +11,7 @@ import { ObjectiveMenuActions } from '../components/objective/ObjectiveMenuActio import { GJ_REGEX_PATTERN } from '../shared/constantLibary'; export type ObjectiveMenuAction = () => MatDialogRef; -export type ObjectiveMenuAfterAction = (objective: Objective, dialogResult: any) => any; +export type ObjectiveMenuAfterAction = (objective: ObjectiveMin, dialogResult: any) => any; export interface ObjectiveMenuEntry { displayName: string; From c0741cda40978d5f36d2deb33d24d141cfef99a6 Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Fri, 15 Nov 2024 12:20:17 +0100 Subject: [PATCH 2/2] rereoute properly to overview after objective delte in sidepanel --- .../components/objective-detail/objective-detail.component.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/components/objective-detail/objective-detail.component.ts b/frontend/src/app/components/objective-detail/objective-detail.component.ts index 5bd2ba1b87..c5dfa7e138 100644 --- a/frontend/src/app/components/objective-detail/objective-detail.component.ts +++ b/frontend/src/app/components/objective-detail/objective-detail.component.ts @@ -75,12 +75,12 @@ export class ObjectiveDetailComponent { }) .afterClosed() .subscribe((result) => { + this.refreshDataService.markDataRefresh(); if (result.delete) { - this.router.navigate(['']); + this.backToOverview(); } else { this.loadObjective(this.objective$.value.id); } - this.refreshDataService.markDataRefresh(); }); }