Skip to content

Commit

Permalink
place functions in related files instead of common.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Nov 5, 2024
1 parent 6ca5240 commit 5d851ff
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
14 changes: 11 additions & 3 deletions frontend/src/app/components/objective/objective.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -20,7 +21,6 @@ export class ObjectiveComponent implements OnInit {
public objective$ = new Subject<ObjectiveMin>();
menuEntries = this.objective$.pipe(map((objective) => this.objectiveMenuActionsService.getMenu(objective)));
protected readonly trackByFn = trackByFn;
protected readonly isObjectiveComplete = isObjectiveComplete;

constructor(
private dialogService: DialogService,
Expand All @@ -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 });
}

Expand Down Expand Up @@ -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) ?? '';
}
}
14 changes: 11 additions & 3 deletions frontend/src/app/services/objective-menu-actions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any>;
export type ObjectiveMenuAfterAction = (objective: Objective, dialogResult: any) => any;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
12 changes: 0 additions & 12 deletions frontend/src/app/shared/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,22 +94,10 @@ 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;
} else {
return false;
}
}

export function getStateByValue(value: string): string {
return Object.keys(State).find((key) => State[key as keyof typeof State] === value) ?? '';
}

0 comments on commit 5d851ff

Please sign in to comment.