Skip to content
Permalink
Browse files

Move loading of AspectTypes to separate, global service. Remove unuse…

…d metric finder method
  • Loading branch information...
nilskuhn committed Jun 11, 2019
1 parent f1474db commit 22ef27fa9c2c7ae30903f2215d2ac79c4ab0967f
@@ -6,6 +6,7 @@ import {Observable} from "rxjs";
import {ExtendedPerformanceAspect, PerformanceAspectType} from "../../models/perfomance-aspect.model";
import {Application} from "../../models/application.model";
import {AspectConfigurationService} from "./services/aspect-configuration.service";
import {PerformanceAspectService} from "../../services/performance-aspect.service";

@Component({
selector: 'osm-aspect-configuration',
@@ -20,11 +21,15 @@ export class AspectConfigurationComponent implements OnInit {
performanceAspects$: Observable<ExtendedPerformanceAspect[]>;
aspectTypes$: Observable<PerformanceAspectType[]>;

constructor(private route: ActivatedRoute, private applicationService: ApplicationService, private aspectConfService: AspectConfigurationService) {
constructor(
private route: ActivatedRoute,
private applicationService: ApplicationService,
private aspectConfService: AspectConfigurationService,
private perfAspectService: PerformanceAspectService) {
this.application$ = applicationService.selectedApplication$;
this.page$ = aspectConfService.selectedPage$;
this.performanceAspects$ = aspectConfService.extendedAspects$;
this.aspectTypes$ = aspectConfService.aspectTypes$;
this.aspectTypes$ = perfAspectService.aspectTypes$;
}

ngOnInit() {
@@ -12,6 +12,7 @@ import {
} from "../../../models/perfomance-aspect.model";
import {Application} from "../../../models/application.model";
import {LocationDto} from "../../application-dashboard/models/location.model";
import {PerformanceAspectService} from "../../../services/performance-aspect.service";

@Injectable({
providedIn: 'root'
@@ -23,12 +24,9 @@ export class AspectConfigurationService {
extendedAspects$ = new BehaviorSubject<ExtendedPerformanceAspect[]>([]);

selectedPage$ = new ReplaySubject<Page>(1);

aspectTypes$ = new ReplaySubject<PerformanceAspectType[]>(1);
selectedAspectType$ = new ReplaySubject<PerformanceAspectType>(1);

constructor(private http: HttpClient, private applicationService: ApplicationService) {
this.loadAspectTypes();
constructor(private http: HttpClient, private applicationService: ApplicationService, private perfAspectService: PerformanceAspectService) {
this.prepareExtensionOfAspects();
this.loadBrowserInfos();
this.getPerfAspectParams()
@@ -100,16 +98,8 @@ export class AspectConfigurationService {
return extendedAspects;
}

private loadAspectTypes() {
this.http.get<PerformanceAspectType[]>("/aspectConfiguration/rest/getAspectTypes").pipe(
catchError((error) => {
console.error(error);
return EMPTY;
})).subscribe((types: PerformanceAspectType[]) => this.aspectTypes$.next(types));
}

public initSelectedAspectType(typeName: string) {
this.aspectTypes$.pipe(
this.perfAspectService.aspectTypes$.pipe(
map((types: PerformanceAspectType[]) => {
return types.find((type: PerformanceAspectType) => type.name == typeName)
})
@@ -41,7 +41,6 @@ describe('MetricFinderComponent', () => {

beforeEach(() => {
metricService = TestBed.get(MetricFinderService);
metricService.loadTestData = jasmine.createSpy('loadTestData');
fixture = TestBed.createComponent(MetricFinderComponent);
component = fixture.componentInstance;
fixture.detectChanges();
@@ -15,12 +15,6 @@ export class MetricFinderService {
) {
}

public loadTestData(): void {
const now = Date.now();
const dayInMillisecs = 1000 * 60 * 60 * 24 * 14;
this.loadData(new Date(now - 38 * dayInMillisecs), new Date(now), 48, 1, 18);
}

public loadData(from: Date, to: Date, application: number, page: number, browser: number): void {
const params = {
from: from.toISOString(),
@@ -0,0 +1,17 @@
import {TestBed} from '@angular/core/testing';

import {PerformanceAspectService} from './performance-aspect.service';
import {HttpClientTestingModule} from "@angular/common/http/testing";

describe('PerformanceAspectService', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [
HttpClientTestingModule
]
}));

it('should be created', () => {
const service: PerformanceAspectService = TestBed.get(PerformanceAspectService);
expect(service).toBeTruthy();
});
});
@@ -0,0 +1,25 @@
import {Injectable} from '@angular/core';
import {EMPTY, ReplaySubject} from "rxjs";
import {PerformanceAspectType} from "../models/perfomance-aspect.model";
import {HttpClient} from "@angular/common/http";
import {catchError} from "rxjs/operators";

@Injectable({
providedIn: 'root'
})
export class PerformanceAspectService {

aspectTypes$ = new ReplaySubject<PerformanceAspectType[]>(1);

constructor(private http: HttpClient) {
this.loadAspectTypes();
}

loadAspectTypes() {
this.http.get<PerformanceAspectType[]>("/aspectConfiguration/rest/getAspectTypes").pipe(
catchError((error) => {
console.error(error);
return EMPTY;
})).subscribe((types: PerformanceAspectType[]) => this.aspectTypes$.next(types));
}
}

0 comments on commit 22ef27f

Please sign in to comment.
You can’t perform that action at this time.