Skip to content

Commit

Permalink
introduce objectiveMenuAction file
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Oct 23, 2024
1 parent c961ba8 commit e1ee55a
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 93 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
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';
import { CompleteDialogComponent } from '../../shared/dialog/complete-dialog/complete-dialog.component';
import {
ObjectiveMenuAction,
ObjectiveMenuAfterAction,
ObjectiveMenuEntry,
} from '../../services/objective-menu-actions.service';
import { ObjectiveMenuAfterActions } from './ObjectiveMenuAfterActions';

export class ObjectiveMenuActions {
constructor(
private readonly dialogService: DialogService,
private readonly refreshDataService: RefreshDataService,
private readonly afterActions: ObjectiveMenuAfterActions,
) {}

releaseFromQuarterAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.RELEASE');
const afterAction: ObjectiveMenuAfterAction = (objective, dialogResult) =>
this.afterActions.releaseFromQuarter(objective);
return { displayName: 'Objective veröffentlichen', action: action, afterAction: afterAction };
}

releaseFromBacklogAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = { data: { objective: { objectiveId: objective }, action: 'releaseBacklog' } };
const action: ObjectiveMenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: ObjectiveMenuAfterAction = () => 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 = () => {};
return { displayName: 'Objective bearbeiten', action: action, afterAction: afterAction };
}

duplicateObjectiveAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = { data: { objective: { objectiveId: objective.id } } };
const action: ObjectiveMenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: ObjectiveMenuAfterAction = () => this.refreshDataService.markDataRefresh();
return { displayName: 'Objective duplizieren', action: action, afterAction: afterAction };
}

completeObjectiveAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = {
data: { objectiveTitle: objective.title },
};
const action: ObjectiveMenuAction = () => this.dialogService.open(CompleteDialogComponent, config);
const afterAction: ObjectiveMenuAfterAction = (obj: Objective, result: any) =>
this.afterActions.completeObjective(obj, result);

return { displayName: 'Objective abschliessen', action: action, afterAction: afterAction };
}

objectiveBackToDraft(): ObjectiveMenuEntry {
const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.DRAFT_CREATE');
const afterAction: ObjectiveMenuAfterAction = (obj: Objective, result: any) =>
this.afterActions.objectiveBackToDraft(obj);

return { displayName: 'Objective als Draft speicherns', action: action, afterAction: afterAction };
}

objectiveReopen(): ObjectiveMenuEntry {
const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.REOPEN');
const afterAction: ObjectiveMenuAfterAction = (obj: Objective, result: any) =>
this.afterActions.objectiveReopen(obj);

return { displayName: 'Objective wiedereröffnen', action: action, afterAction: afterAction };
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { DialogService } from '../../services/dialog.service';
import { Objective } from '../../shared/types/model/Objective';
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';

export class ObjectiveMenuAfterActionFactory {
export class ObjectiveMenuAfterActions {
constructor(
private readonly dialogService: DialogService,
private readonly objectiveService: ObjectiveService,
private readonly refreshDataService: RefreshDataService,
) {}
Expand Down
23 changes: 0 additions & 23 deletions frontend/src/app/components/objective/objective.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { Component, Input, OnInit } from '@angular/core';
import { MenuEntry } from '../../shared/types/menu-entry';
import { ObjectiveMin } from '../../shared/types/model/ObjectiveMin';
import { Router } from '@angular/router';
import { BehaviorSubject, map } from 'rxjs';
import { RefreshDataService } from '../../services/refresh-data.service';
import { State } from '../../shared/types/enums/State';
import { ObjectiveService } from '../../services/objective.service';
import { Completed } from '../../shared/types/model/Completed';
import { Objective } from '../../shared/types/model/Objective';
import { isObjectiveComplete, trackByFn } from '../../shared/common';
import { KeyresultDialogComponent } from '../keyresult-dialog/keyresult-dialog.component';
import { TranslateService } from '@ngx-translate/core';
Expand Down Expand Up @@ -65,25 +61,6 @@ export class ObjectiveComponent implements OnInit {
});
}

handleDialogResult(menuEntry: MenuEntry, result: { endState: string; comment: string | null; objective: any }) {
if (menuEntry.action) {
this.objectiveService.getFullObjective(this.objective$.value.id).subscribe((objective) => {
if (menuEntry.action == 'complete') {
} else if (menuEntry.action == 'release') {
} else if (menuEntry.action == 'duplicate') {
this.refreshDataService.markDataRefresh();
} else if (menuEntry.action == 'releaseBacklog') {
this.refreshDataService.markDataRefresh();
} else if (menuEntry.action == 'todraft') {
}
});
} else {
if (result?.objective) {
this.refreshDataService.markDataRefresh();
}
}
}

openObjectiveDetail(objectiveId: number) {
this.router.navigate(['details/objective', objectiveId]);
}
Expand Down
84 changes: 17 additions & 67 deletions frontend/src/app/services/objective-menu-actions.service.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { Injectable } from '@angular/core';
import { DialogService } from './dialog.service';
import { MatDialogRef } from '@angular/material/dialog';
import { ObjectiveFormComponent } from '../shared/dialog/objective-dialog/objective-form.component';
import { CompleteDialogComponent } from '../shared/dialog/complete-dialog/complete-dialog.component';
import { ObjectiveMin } from '../shared/types/model/ObjectiveMin';
import { State } from '../shared/types/enums/State';
import { isInBacklogQuarter, isObjectiveComplete } from '../shared/common';
import { ObjectiveMenuAfterActionFactory } from '../components/objective/ObjectiveMenuAfterActionFactory';
import { ObjectiveMenuAfterActions } from '../components/objective/ObjectiveMenuAfterActions';
import { ObjectiveService } from './objective.service';
import { RefreshDataService } from './refresh-data.service';
import { Objective } from '../shared/types/model/Objective';
import { ObjectiveMenuActions } from '../components/objective/ObjectiveMenuActionFactory';

export type ObjectiveMenuAction = () => MatDialogRef<any>;
export type ObjectiveMenuAfterAction = (objective: Objective, dialogResult: any) => any;
Expand All @@ -24,13 +23,15 @@ export interface ObjectiveMenuEntry {
providedIn: 'root',
})
export class ObjectiveMenuActionsService {
afterActions: ObjectiveMenuAfterActionFactory;
afterActions: ObjectiveMenuAfterActions;
actions: ObjectiveMenuActions;
constructor(
private readonly dialogService: DialogService,
dialogService: DialogService,
objectiveService: ObjectiveService,
private readonly refreshDataService: RefreshDataService,
refreshDataService: RefreshDataService,
) {
this.afterActions = new ObjectiveMenuAfterActionFactory(dialogService, objectiveService, refreshDataService);
this.afterActions = new ObjectiveMenuAfterActions(objectiveService, refreshDataService);
this.actions = new ObjectiveMenuActions(dialogService, refreshDataService, this.afterActions);
}

getMenu(objective: ObjectiveMin): ObjectiveMenuEntry[] {
Expand All @@ -50,76 +51,25 @@ export class ObjectiveMenuActionsService {
}

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

private getDraftMenuActions(objective: ObjectiveMin): ObjectiveMenuEntry[] {
const releaseAction = isInBacklogQuarter(objective)
? this.releaseFromBacklogAction(objective)
: this.releaseFromQuarterAction(objective);
? this.actions.releaseFromBacklogAction(objective)
: this.actions.releaseFromQuarterAction(objective);
return [releaseAction];
}

private getOngoingMenuActions(objective: ObjectiveMin): ObjectiveMenuEntry[] {
return [this.editObjectiveAction(objective), this.completeObjectiveAction(objective), this.objectiveBackToDraft()];
return [
this.actions.editObjectiveAction(objective),
this.actions.completeObjectiveAction(objective),
this.actions.objectiveBackToDraft(),
];
}

private getCompletedMenuActions(objective: ObjectiveMin): ObjectiveMenuEntry[] {
return [this.objectiveReopen()];
}

private releaseFromQuarterAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.RELEASE');
const afterAction: ObjectiveMenuAfterAction = (objective, dialogResult) =>
this.afterActions.releaseFromQuarter(objective);
return { displayName: 'Objective veröffentlichen', action: action, afterAction: afterAction };
}

private releaseFromBacklogAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = { data: { objective: { objectiveId: objective }, action: 'releaseBacklog' } };
const action: ObjectiveMenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: ObjectiveMenuAfterAction = () => this.refreshDataService.markDataRefresh();
return { displayName: 'Objective veröffentlichen', action: action, afterAction };
}

private editObjectiveAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = { data: { objective: { objectiveId: objective.id } } };
const action: ObjectiveMenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: ObjectiveMenuAfterAction = () => {};
return { displayName: 'Objective bearbeiten', action: action, afterAction: afterAction };
}

private duplicateObjectiveAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = { data: { objective: { objectiveId: objective.id } } };
const action: ObjectiveMenuAction = () => this.dialogService.open(ObjectiveFormComponent, config);
const afterAction: ObjectiveMenuAfterAction = () => this.refreshDataService.markDataRefresh();
return { displayName: 'Objective duplizieren', action: action, afterAction: afterAction };
}

private completeObjectiveAction(objective: ObjectiveMin): ObjectiveMenuEntry {
const config = {
data: { objectiveTitle: objective.title },
};
const action: ObjectiveMenuAction = () => this.dialogService.open(CompleteDialogComponent, config);
const afterAction: ObjectiveMenuAfterAction = (obj: Objective, result: any) =>
this.afterActions.completeObjective(obj, result);

return { displayName: 'Objective abschliessen', action: action, afterAction: afterAction };
}

private objectiveBackToDraft(): ObjectiveMenuEntry {
const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.DRAFT_CREATE');
const afterAction: ObjectiveMenuAfterAction = (obj: Objective, result: any) =>
this.afterActions.objectiveBackToDraft(obj);

return { displayName: 'Objective als Draft speicherns', action: action, afterAction: afterAction };
}

private objectiveReopen(): ObjectiveMenuEntry {
const action: ObjectiveMenuAction = () => this.dialogService.openConfirmDialog('CONFIRMATION.REOPEN');
const afterAction: ObjectiveMenuAfterAction = (obj: Objective, result: any) =>
this.afterActions.objectiveReopen(obj);

return { displayName: 'Objective wiedereröffnen', action: action, afterAction: afterAction };
return [this.actions.objectiveReopen()];
}
}

0 comments on commit e1ee55a

Please sign in to comment.