Skip to content

Commit

Permalink
Bug/1150 delete objective (#1158)
Browse files Browse the repository at this point in the history
* use full objective just if needed in after action

* rereoute properly to overview after objective delte in sidepanel
  • Loading branch information
kcinay055679 authored Nov 15, 2024
1 parent 210adc5 commit c573cbe
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

Expand Down
9 changes: 4 additions & 5 deletions frontend/src/app/components/objective/ObjectiveMenuActions.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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 };
}
Expand Down Expand Up @@ -53,23 +52,23 @@ 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 };
}

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 };
}

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 };
Expand Down
57 changes: 33 additions & 24 deletions frontend/src/app/components/objective/ObjectiveMenuAfterActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,56 @@ 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(
private readonly objectiveService: ObjectiveService,
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();
});
});
});
}
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/app/components/objective/objective.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ObjectiveMenuActions } from '../components/objective/ObjectiveMenuActio
import { GJ_REGEX_PATTERN } from '../shared/constantLibary';

export type ObjectiveMenuAction = () => MatDialogRef<any>;
export type ObjectiveMenuAfterAction = (objective: Objective, dialogResult: any) => any;
export type ObjectiveMenuAfterAction = (objective: ObjectiveMin, dialogResult: any) => any;

export interface ObjectiveMenuEntry {
displayName: string;
Expand Down

0 comments on commit c573cbe

Please sign in to comment.