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

Bug/1150 delete objective #1158

Merged
merged 2 commits into from
Nov 15, 2024
Merged
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
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
Loading