From e1ee55aad69aecdffb3f303d2357695cc242b1f9 Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Wed, 23 Oct 2024 16:06:21 +0200 Subject: [PATCH] introduce objectiveMenuAction file --- .../objective/ObjectiveMenuActionFactory.ts | 75 +++++++++++++++++ ...actory.ts => ObjectiveMenuAfterActions.ts} | 4 +- .../objective/objective.component.ts | 23 ----- .../objective-menu-actions.service.ts | 84 ++++--------------- 4 files changed, 93 insertions(+), 93 deletions(-) create mode 100644 frontend/src/app/components/objective/ObjectiveMenuActionFactory.ts rename frontend/src/app/components/objective/{ObjectiveMenuAfterActionFactory.ts => ObjectiveMenuAfterActions.ts} (91%) diff --git a/frontend/src/app/components/objective/ObjectiveMenuActionFactory.ts b/frontend/src/app/components/objective/ObjectiveMenuActionFactory.ts new file mode 100644 index 0000000000..917ef05ae8 --- /dev/null +++ b/frontend/src/app/components/objective/ObjectiveMenuActionFactory.ts @@ -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 }; + } +} diff --git a/frontend/src/app/components/objective/ObjectiveMenuAfterActionFactory.ts b/frontend/src/app/components/objective/ObjectiveMenuAfterActions.ts similarity index 91% rename from frontend/src/app/components/objective/ObjectiveMenuAfterActionFactory.ts rename to frontend/src/app/components/objective/ObjectiveMenuAfterActions.ts index ffdf30909f..5691305fa9 100644 --- a/frontend/src/app/components/objective/ObjectiveMenuAfterActionFactory.ts +++ b/frontend/src/app/components/objective/ObjectiveMenuAfterActions.ts @@ -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, ) {} diff --git a/frontend/src/app/components/objective/objective.component.ts b/frontend/src/app/components/objective/objective.component.ts index f198fdb3a8..f0623ac54a 100644 --- a/frontend/src/app/components/objective/objective.component.ts +++ b/frontend/src/app/components/objective/objective.component.ts @@ -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'; @@ -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]); } diff --git a/frontend/src/app/services/objective-menu-actions.service.ts b/frontend/src/app/services/objective-menu-actions.service.ts index 86e8acd173..765678ed24 100644 --- a/frontend/src/app/services/objective-menu-actions.service.ts +++ b/frontend/src/app/services/objective-menu-actions.service.ts @@ -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; export type ObjectiveMenuAfterAction = (objective: Objective, dialogResult: any) => any; @@ -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[] { @@ -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()]; } }