From 5d851ffdb134556ee31bd72d7f228844f0f4373a Mon Sep 17 00:00:00 2001 From: Yanick Minder Date: Tue, 5 Nov 2024 09:29:27 +0100 Subject: [PATCH] place functions in related files instead of common.ts --- .../components/objective/objective.component.ts | 14 +++++++++++--- .../app/services/objective-menu-actions.service.ts | 14 +++++++++++--- frontend/src/app/shared/common.ts | 12 ------------ 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/frontend/src/app/components/objective/objective.component.ts b/frontend/src/app/components/objective/objective.component.ts index e79de7c11b..eb9a9ce14f 100644 --- a/frontend/src/app/components/objective/objective.component.ts +++ b/frontend/src/app/components/objective/objective.component.ts @@ -4,11 +4,12 @@ import { Router } from '@angular/router'; import { map, Subject } from 'rxjs'; import { RefreshDataService } from '../../services/refresh-data.service'; import { ObjectiveService } from '../../services/objective.service'; -import { getStateByValue, isObjectiveComplete, trackByFn } from '../../shared/common'; +import { trackByFn } from '../../shared/common'; import { KeyresultDialogComponent } from '../keyresult-dialog/keyresult-dialog.component'; import { TranslateService } from '@ngx-translate/core'; import { DialogService } from '../../services/dialog.service'; import { ObjectiveMenuActionsService, ObjectiveMenuEntry } from '../../services/objective-menu-actions.service'; +import { State } from '../../shared/types/enums/State'; @Component({ selector: 'app-objective-column', @@ -20,7 +21,6 @@ export class ObjectiveComponent implements OnInit { public objective$ = new Subject(); menuEntries = this.objective$.pipe(map((objective) => this.objectiveMenuActionsService.getMenu(objective))); protected readonly trackByFn = trackByFn; - protected readonly isObjectiveComplete = isObjectiveComplete; constructor( private dialogService: DialogService, @@ -38,7 +38,7 @@ export class ObjectiveComponent implements OnInit { ngOnInit() {} getStateTooltip(stateString: string): string { - const state = getStateByValue(stateString); + const state = this.getStateByValue(stateString); return this.translate.instant('INFORMATION.OBJECTIVE_STATE_TOOLTIP', { state: state }); } @@ -71,4 +71,12 @@ export class ObjectiveComponent implements OnInit { this.refreshDataService.markDataRefresh(); }); } + + isObjectiveComplete(objective: ObjectiveMin): boolean { + return objective.state == State.SUCCESSFUL || objective.state == State.NOTSUCCESSFUL; + } + + getStateByValue(value: string): string { + return Object.keys(State).find((key) => State[key as keyof typeof State] === value) ?? ''; + } } diff --git a/frontend/src/app/services/objective-menu-actions.service.ts b/frontend/src/app/services/objective-menu-actions.service.ts index f8feec6efb..2057c8d3a3 100644 --- a/frontend/src/app/services/objective-menu-actions.service.ts +++ b/frontend/src/app/services/objective-menu-actions.service.ts @@ -3,12 +3,12 @@ import { DialogService } from './dialog.service'; import { MatDialogRef } from '@angular/material/dialog'; import { ObjectiveMin } from '../shared/types/model/ObjectiveMin'; import { State } from '../shared/types/enums/State'; -import { isInBacklogQuarter, isObjectiveComplete } from '../shared/common'; 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/ObjectiveMenuActions'; +import { GJ_REGEX_PATTERN } from '../shared/constantLibary'; export type ObjectiveMenuAction = () => MatDialogRef; export type ObjectiveMenuAfterAction = (objective: Objective, dialogResult: any) => any; @@ -39,7 +39,7 @@ export class ObjectiveMenuActionsService { } private getSpecificMenuEntries(objective: ObjectiveMin): ObjectiveMenuEntry[] { - if (isObjectiveComplete(objective)) { + if (this.isObjectiveComplete(objective)) { return this.getCompletedMenuActions(objective); } else if (objective.state === State.ONGOING) { return this.getOngoingMenuActions(objective); @@ -71,8 +71,16 @@ export class ObjectiveMenuActionsService { } private getReleaseAction(objective: ObjectiveMin): ObjectiveMenuEntry { - return isInBacklogQuarter(objective) + return this.isInBacklogQuarter(objective) ? this.actions.releaseFromBacklogAction(objective) : this.actions.releaseFromQuarterAction(objective); } + + private isObjectiveComplete(objective: ObjectiveMin): boolean { + return objective.state == State.SUCCESSFUL || objective.state == State.NOTSUCCESSFUL; + } + + private isInBacklogQuarter(objective: ObjectiveMin) { + return !GJ_REGEX_PATTERN.test(objective.quarter.label); + } } diff --git a/frontend/src/app/shared/common.ts b/frontend/src/app/shared/common.ts index 8dd48aceca..08d308d47d 100644 --- a/frontend/src/app/shared/common.ts +++ b/frontend/src/app/shared/common.ts @@ -94,14 +94,6 @@ export function isMobileDevice() { return window.navigator.userAgent.toLowerCase().includes('mobile'); } -export function isInBacklogQuarter(objective: ObjectiveMin) { - return !GJ_REGEX_PATTERN.test(objective.quarter.label); -} - -export function isObjectiveComplete(objective: ObjectiveMin): boolean { - return objective.state == State.SUCCESSFUL || objective.state == State.NOTSUCCESSFUL; -} - export function hasFormFieldErrors(formGroup: FormGroup, field: string) { if (formGroup.get(field)?.dirty || formGroup.get(field)?.touched) { return formGroup.get(field)?.errors; @@ -109,7 +101,3 @@ export function hasFormFieldErrors(formGroup: FormGroup, field: string) { return false; } } - -export function getStateByValue(value: string): string { - return Object.keys(State).find((key) => State[key as keyof typeof State] === value) ?? ''; -}