Skip to content

Commit

Permalink
refactor objective menu action to generic menu action
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Jan 27, 2025
1 parent 06af08f commit 5ad0581
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
36 changes: 18 additions & 18 deletions frontend/src/app/components/objective/objective-menu-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { ObjectiveMin } from '../../shared/types/model/objective-min';
import { ObjectiveFormComponent } from '../../shared/dialog/objective-dialog/objective-form.component';
import { CompleteDialogComponent } from '../../shared/dialog/complete-dialog/complete-dialog.component';
import {
ObjectiveMenuAction,
ObjectiveMenuAfterAction,
MenuAction,
MenuAfterAction,
ObjectiveMenuEntry
} from '../../services/objective-menu-actions.service';
import { ObjectiveMenuAfterActions } from './objective-menu-after-actions';
Expand All @@ -16,8 +16,8 @@ export class ObjectiveMenuActions {
private readonly afterActions: ObjectiveMenuAfterActions) {}

releaseFromQuarterAction(): ObjectiveMenuEntry {
const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.RELEASE');
const afterAction: ObjectiveMenuAfterAction = (objective: ObjectiveMin) => this.afterActions.releaseFromQuarter(objective);
const action: MenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.RELEASE');
const afterAction: MenuAfterAction<ObjectiveMin> = (objective: ObjectiveMin) => this.afterActions.releaseFromQuarter(objective);
return { displayName: 'Objective veröffentlichen',
action: action,
afterAction: afterAction };
Expand All @@ -26,17 +26,17 @@ export class ObjectiveMenuActions {
releaseFromBacklogAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = { data: { objective: { objectiveId: objective.id },
action: 'releaseBacklog' } };
const action: ObjectiveMenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: ObjectiveMenuAfterAction = () => this.refreshDataService.markDataRefresh();
const action: MenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: MenuAfterAction<ObjectiveMin> = () => this.refreshDataService.markDataRefresh();
return { displayName: 'Objective veröffentlichen',
action: action,
afterAction };
}

editObjectiveAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = { data: { objective: { objectiveId: objective.id } } };
const action: ObjectiveMenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: ObjectiveMenuAfterAction = () => {
const action: MenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: MenuAfterAction<ObjectiveMin> = () => {
this.refreshDataService.markDataRefresh();
};
return { displayName: 'Objective bearbeiten',
Expand All @@ -47,16 +47,16 @@ export class ObjectiveMenuActions {
duplicateObjectiveAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = { data: { objective: { objectiveId: objective.id },
action: 'duplicate' } };
const action: ObjectiveMenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: ObjectiveMenuAfterAction = () => this.refreshDataService.markDataRefresh();
const action: MenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: MenuAfterAction<ObjectiveMin> = () => this.refreshDataService.markDataRefresh();
return { displayName: 'Objective duplizieren',
action: action,
afterAction: afterAction };
}

deleteObjectiveAction(): ObjectiveMenuEntry {
const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.DELETE.OBJECTIVE');
const afterAction: ObjectiveMenuAfterAction = (objective, dialogResult) => this.afterActions.deleteObjective(objective);
const action: MenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.DELETE.OBJECTIVE');
const afterAction: MenuAfterAction<ObjectiveMin> = (objective, dialogResult) => this.afterActions.deleteObjective(objective);
return { displayName: 'Objective löschen',
action: action,
afterAction: afterAction };
Expand All @@ -66,26 +66,26 @@ export class ObjectiveMenuActions {
const config = {
data: { objectiveTitle: objective.title }
};
const action: ObjectiveMenuAction = () => this.dialogService.open(CompleteDialogComponent, config);
const afterAction: ObjectiveMenuAfterAction = (obj: ObjectiveMin, result: any) => this.afterActions.completeObjective(obj, result);
const action: MenuAction = () => this.dialogService.open(CompleteDialogComponent, config);
const afterAction: MenuAfterAction<ObjectiveMin> = (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: ObjectiveMin) => this.afterActions.objectiveBackToDraft(obj);
const action: MenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.TO_DRAFT');
const afterAction: MenuAfterAction<ObjectiveMin> = (obj: ObjectiveMin) => 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: ObjectiveMin) => this.afterActions.objectiveReopen(obj);
const action: MenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.REOPEN');
const afterAction: MenuAfterAction<ObjectiveMin> = (obj: ObjectiveMin) => this.afterActions.objectiveReopen(obj);

return { displayName: 'Objective wiedereröffnen',
action: action,
Expand Down
8 changes: 4 additions & 4 deletions frontend/src/app/services/objective-menu-actions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { ObjectiveMenuActions } from '../components/objective/objective-menu-act
import { GJ_REGEX_PATTERN } from '../shared/constant-library';
import { CompletedService } from './completed.service';

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

export interface ObjectiveMenuEntry {
displayName: string;
action: ObjectiveMenuAction;
afterAction: ObjectiveMenuAfterAction;
action: MenuAction;
afterAction: MenuAfterAction<ObjectiveMin>;
}

@Injectable({
Expand Down

0 comments on commit 5ad0581

Please sign in to comment.