This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit b0c3caed authored by Michael Breu's avatar Michael Breu
Browse files

Fixed

parent c3e9f1f7
3 merge requests!188Merging Peer Reviewing et. al to Master,!181Resolve "Prüfen des Caches der Review Badge Statistiken",!164211 peer reviewing functionality
......@@ -10,5 +10,6 @@
"java.test.config": {
"name": "standard",
"envFile": "${workspaceRoot}/src/test/resources/config/.env"
}
},
"typescript.tsdk": "node_modules\\typescript\\lib"
}
import { EventEmitter, Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, tap } from 'rxjs';
import { BehaviorSubject, Observable, tap } from 'rxjs';
import { ApplicationConfigService } from 'app/core/config/application-config.service';
import { ReviewRequest } from './reviewRequest.model';
import { Review, ReviewStatisticsDTO } from './review.model';
......@@ -52,31 +52,43 @@ export class ReviewManagementService {
return this.http.post<Review>(this.resourceUrl + '/rewardBadge', review).pipe(tap(() => this.resetStatistics()));
}
private reviewStatisticsCache: ReviewStatisticsDTO | undefined;
reviewStatisticsCacheChanged = new EventEmitter<ReviewStatisticsDTO>();
private reviewStatisticsCache: BehaviorSubject<ReviewStatisticsDTO> | undefined;
public getReviewStatistics(): Observable<ReviewStatisticsDTO> {
if (this.reviewStatisticsCache) {
return new Observable<ReviewStatisticsDTO>(subscriber => subscriber.next(this.reviewStatisticsCache)); // return cached value
return this.reviewStatisticsCache;
} else {
// no cached value -> fetch from server and cache it -> return it to subscriber (component) via observable -> component updates its view accordingly
return this.countAllByUser().pipe(
// fetch from server
tap(statistics => {
this.reviewStatisticsCache = statistics;
this.reviewStatisticsCacheChanged.emit(statistics);
}) // cache it
);
this.reviewStatisticsCache = new BehaviorSubject<ReviewStatisticsDTO>(undefined!);
this.countAllByUser().subscribe(statistics => {
if (this.reviewStatisticsCache) {
this.reviewStatisticsCache.next(statistics); // update cached value
} else {
// this should never happen, but just in case
// we loose all previous listeners to the observable
this.reviewStatisticsCache = new BehaviorSubject<ReviewStatisticsDTO>(undefined!);
this.reviewStatisticsCache.next(statistics);
}
});
return this.reviewStatisticsCache;
}
}
/**
* resets and reloads the review statistics cache
*/
resetStatistics() {
this.reviewStatisticsCache = undefined;
this.getReviewStatistics();
this.countAllByUser().subscribe(statistics => {
if (this.reviewStatisticsCache) {
this.reviewStatisticsCache.next(statistics); // update cached value
} else {
this.reviewStatisticsCache = new BehaviorSubject<ReviewStatisticsDTO>(undefined!);
this.reviewStatisticsCache.next(statistics);
}
});
}
countAllByUser(): Observable<ReviewStatisticsDTO> {
private countAllByUser(): Observable<ReviewStatisticsDTO> {
return this.http.post<ReviewStatisticsDTO>(this.resourceUrl + '/countAllByUser', null);
}
......
......@@ -228,9 +228,6 @@ export class ReviewMenuBadgeComponent implements OnInit {
this.reviewManagementService.getReviewStatistics().subscribe((res: ReviewStatisticsDTO) => {
this.statistics = res;
});
this.reviewManagementService.reviewStatisticsCacheChanged.subscribe(res => {
this.statistics = res;
});
}
getReviewActionCount(): number {
......@@ -274,9 +271,6 @@ export class ReviewRequestedMenuBadgeComponent implements OnInit {
this.reviewManagementService.getReviewStatistics().subscribe((res: ReviewStatisticsDTO) => {
this.statistics = res;
});
this.reviewManagementService.reviewStatisticsCacheChanged.subscribe(res => {
this.statistics = res;
});
}
getReviewRequestedCount(): number {
......@@ -314,9 +308,6 @@ export class ImprovementsRequestedMenuBadgeComponent implements OnInit {
this.reviewManagementService.getReviewStatistics().subscribe((res: ReviewStatisticsDTO) => {
this.statistics = res;
});
this.reviewManagementService.reviewStatisticsCacheChanged.subscribe(res => {
this.statistics = res;
});
}
getReviewRequestedCount(): number {
......@@ -349,9 +340,6 @@ export class BadgeAwardedMenuBadgeComponent implements OnInit {
this.reviewManagementService.getReviewStatistics().subscribe((res: ReviewStatisticsDTO) => {
this.statistics = res;
});
this.reviewManagementService.reviewStatisticsCacheChanged.subscribe(res => {
this.statistics = res;
});
}
getBadgeCount(): number {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment