Skip to content

Commit

Permalink
Change KR state on checkin edit
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed May 31, 2024
1 parent b782e28 commit 22331d2
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
42 changes: 27 additions & 15 deletions frontend/src/app/diagram/diagram.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@ import { KeyResultMetric } from '../shared/types/model/KeyResultMetric';
import { calculateCurrentPercentage } from '../shared/common';
import { KeyResultOrdinal } from '../shared/types/model/KeyResultOrdinal';
import { Router } from '@angular/router';
import { AlignmentObject } from '../shared/types/model/AlignmentObject';
import { AlignmentConnection } from '../shared/types/model/AlignmentConnection';

@Component({
selector: 'app-diagram',
templateUrl: './diagram.component.html',
styleUrl: './diagram.component.scss',
})
export class DiagramComponent implements AfterViewInit, OnDestroy {
private alignmentData$ = new Subject<AlignmentLists>();
private alignmentData$: Subject<AlignmentLists> = new Subject<AlignmentLists>();
cy!: cytoscape.Core;
diagramData: any[] = [];
emptyDiagramData: boolean = false;
Expand All @@ -46,7 +48,18 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {

ngAfterViewInit() {
this.alignmentData.subscribe((alignmentData: AlignmentLists): void => {
if (JSON.stringify(this.alignmentDataCache) !== JSON.stringify(alignmentData)) {
let lastItem: AlignmentObject =
alignmentData.alignmentObjectDtoList[alignmentData.alignmentObjectDtoList.length - 1];

let shouldUpdate: boolean =
lastItem.objectTitle === 'reload'
? lastItem.objectType === 'true'
: JSON.stringify(this.alignmentDataCache) !== JSON.stringify(alignmentData);

if (shouldUpdate) {
if (lastItem.objectTitle === 'reload') {
alignmentData.alignmentObjectDtoList.pop();
}
this.alignmentDataCache = alignmentData;
this.diagramData = [];
this.cleanUpDiagram();
Expand Down Expand Up @@ -138,11 +151,11 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {
generateElements(alignmentData: AlignmentLists): void {
let observableArray: any[] = [];
let diagramElements: any[] = [];
alignmentData.alignmentObjectDtoList.forEach((alignmentObject) => {
alignmentData.alignmentObjectDtoList.forEach((alignmentObject: AlignmentObject) => {
if (alignmentObject.objectType == 'objective') {
let observable = new Observable((observer) => {
let objectiveTitle = this.replaceNonAsciiCharacters(alignmentObject.objectTitle);
let teamTitle = this.replaceNonAsciiCharacters(alignmentObject.objectTeamName);
let observable: Observable<any> = new Observable((observer) => {
let objectiveTitle: string = this.replaceNonAsciiCharacters(alignmentObject.objectTitle);
let teamTitle: string = this.replaceNonAsciiCharacters(alignmentObject.objectTeamName);
let element = {
data: {
id: 'Ob' + alignmentObject.objectId,
Expand All @@ -157,11 +170,14 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {
});
observableArray.push(observable);
} else {
let observable = this.keyResultService.getFullKeyResult(alignmentObject.objectId).pipe(
let observable: Observable<void> = this.keyResultService.getFullKeyResult(alignmentObject.objectId).pipe(
map((keyResult: KeyResult) => {
let keyResultTitle: string = this.replaceNonAsciiCharacters(alignmentObject.objectTitle);
let teamTitle: string = this.replaceNonAsciiCharacters(alignmentObject.objectTeamName);

if (keyResult.keyResultType == 'metric') {
let metricKeyResult = keyResult as KeyResultMetric;
let percentage = calculateCurrentPercentage(metricKeyResult);
let metricKeyResult: KeyResultMetric = keyResult as KeyResultMetric;
let percentage: number = calculateCurrentPercentage(metricKeyResult);

let keyResultState: string | undefined;
if (percentage < 30) {
Expand All @@ -175,8 +191,6 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {
} else {
keyResultState = undefined;
}
let keyResultTitle = this.replaceNonAsciiCharacters(alignmentObject.objectTitle);
let teamTitle = this.replaceNonAsciiCharacters(alignmentObject.objectTeamName);
let element = {
data: {
id: 'KR' + alignmentObject.objectId,
Expand All @@ -187,11 +201,9 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {
};
diagramElements.push(element);
} else {
let ordinalKeyResult = keyResult as KeyResultOrdinal;
let ordinalKeyResult: KeyResultOrdinal = keyResult as KeyResultOrdinal;
let keyResultState: string | undefined = ordinalKeyResult.lastCheckIn?.value.toString();

let keyResultTitle = this.replaceNonAsciiCharacters(alignmentObject.objectTitle);
let teamTitle = this.replaceNonAsciiCharacters(alignmentObject.objectTeamName);
let element = {
data: {
id: 'KR' + alignmentObject.objectId,
Expand All @@ -215,7 +227,7 @@ export class DiagramComponent implements AfterViewInit, OnDestroy {

generateConnections(alignmentData: AlignmentLists, diagramElements: any[]): void {
let edges: any[] = [];
alignmentData.alignmentConnectionDtoList.forEach((alignmentConnection) => {
alignmentData.alignmentConnectionDtoList.forEach((alignmentConnection: AlignmentConnection) => {
if (alignmentConnection.targetKeyResultId == null) {
let edge = {
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ export class KeyresultDetailComponent implements OnInit {
dialogRef.afterClosed().subscribe((result) => {
if (result != '' && result != undefined) {
this.loadKeyResult(this.keyResult$.getValue().id);
this.refreshDataService.markDataRefresh();
this.refreshDataService.markDataRefresh(true);
}
});
}
Expand Down
19 changes: 15 additions & 4 deletions frontend/src/app/overview/overview.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { RefreshDataService } from '../shared/services/refresh-data.service';
import { getQueryString, getValueFromQuery, isMobileDevice, trackByFn } from '../shared/common';
import { AlignmentService } from '../shared/services/alignment.service';
import { AlignmentLists } from '../shared/types/model/AlignmentLists';
import { AlignmentObject } from '../shared/types/model/AlignmentObject';

@Component({
selector: 'app-overview',
Expand Down Expand Up @@ -34,7 +35,7 @@ export class OverviewComponent implements OnInit, OnDestroy {
) {
this.refreshDataService.reloadOverviewSubject
.pipe(takeUntil(this.destroyed$))
.subscribe(() => this.loadOverviewWithParams());
.subscribe((reload: boolean | null | undefined) => this.loadOverviewWithParams(reload));

combineLatest([
refreshDataService.teamFilterReady.asObservable(),
Expand All @@ -58,18 +59,18 @@ export class OverviewComponent implements OnInit, OnDestroy {
}
}

loadOverviewWithParams() {
loadOverviewWithParams(reload?: boolean | null) {
const quarterQuery = this.activatedRoute.snapshot.queryParams['quarter'];
const teamQuery = this.activatedRoute.snapshot.queryParams['teams'];
const objectiveQuery = this.activatedRoute.snapshot.queryParams['objectiveQuery'];

const teamIds = getValueFromQuery(teamQuery);
const quarterId = getValueFromQuery(quarterQuery)[0];
const objectiveQueryString = getQueryString(objectiveQuery);
this.loadOverview(quarterId, teamIds, objectiveQueryString);
this.loadOverview(quarterId, teamIds, objectiveQueryString, reload);
}

loadOverview(quarterId?: number, teamIds?: number[], objectiveQuery?: string) {
loadOverview(quarterId?: number, teamIds?: number[], objectiveQuery?: string, reload?: boolean | null) {
if (this.isOverview) {
this.overviewService
.getOverview(quarterId, teamIds, objectiveQuery)
Expand All @@ -93,6 +94,16 @@ export class OverviewComponent implements OnInit, OnDestroy {
}),
)
.subscribe((alignmentLists) => {
if (reload != null) {
let kuchen: AlignmentObject = {
objectId: 0,
objectTitle: 'reload',
objectType: reload.toString(),
objectTeamName: '',
objectState: null,
};
alignmentLists.alignmentObjectDtoList.push(kuchen);
}
this.alignmentData$.next(alignmentLists);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ export class CheckInHistoryDialogComponent implements OnInit {
maxHeight: dialogConfig.maxHeight,
maxWidth: dialogConfig.maxWidth,
});
dialogRef.afterClosed().subscribe(() => {
dialogRef.afterClosed().subscribe((result) => {
this.loadCheckInHistory();
this.refreshDataService.markDataRefresh();
if (result != '' && result != undefined) {
this.refreshDataService.markDataRefresh(true);
}
});
}

Expand Down
6 changes: 3 additions & 3 deletions frontend/src/app/shared/services/refresh-data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import { DEFAULT_HEADER_HEIGHT_PX } from '../constantLibary';
providedIn: 'root',
})
export class RefreshDataService {
public reloadOverviewSubject: Subject<void> = new Subject();
public reloadOverviewSubject: Subject<boolean | null | undefined> = new Subject();

public quarterFilterReady: Subject<void> = new Subject<void>();
public teamFilterReady: Subject<void> = new Subject<void>();

public okrBannerHeightSubject: BehaviorSubject<number> = new BehaviorSubject<number>(DEFAULT_HEADER_HEIGHT_PX);

markDataRefresh() {
this.reloadOverviewSubject.next();
markDataRefresh(reload?: boolean | null) {
this.reloadOverviewSubject.next(reload);
}
}

0 comments on commit 22331d2

Please sign in to comment.