Commit 79097f6f authored by Lukas Burgey's avatar Lukas Burgey

Add filtering empty VOs

parent e4355aa1
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { throwError as observableThrowError, Observable, BehaviorSubject, of, EMPTY } from 'rxjs';
import { map, catchError } from 'rxjs/operators';
import { map, catchError, combineLatest } from 'rxjs/operators';
import { CookieService } from 'ngx-cookie-service';
import { StompConfig, StompRService } from '@stomp/ng2-stompjs';
......@@ -9,6 +9,7 @@ import { Message } from '@stomp/stompjs';
import { SnackBarService } from './snackbar.service';
import { IdpService } from './idp.service';
import { PreferencesService, Prefs } from './preferences/preferences.service';
import {
VO, User, Update, State, Deployment, DeploymentState, SSHKey, NewSSHKey, IdP, Service, Site, JSONObject
......@@ -45,6 +46,7 @@ export class UserService {
private snackBar: SnackBarService,
private idpService: IdpService,
private stompService: StompRService,
private prefs: PreferencesService,
) {
this.user$ = new BehaviorSubject(null);
this.connect();
......@@ -368,11 +370,6 @@ export class UserService {
);
}
public subscribeVOs(): Observable<VO[]> {
let voSelector = (user: User) => user ? user.vos : [];
return this.subscribeSpecific<VO[]>(voSelector);
}
public subscribeDeployment(selector: (dep: Deployment) => boolean): Observable<Deployment> {
return this.subscribeDeployments().pipe(
map((deployments: Deployment[]) => {
......@@ -387,4 +384,28 @@ export class UserService {
public subscribeServices(): Observable<Service[]> {
return this.subscribeSpecific(this.serviceSelector);
}
public subscribeVOs(): Observable<VO[]> {
const voSelector = (user: User) => user ? user.vos : [];
const vos$ = this.subscribeSpecific<VO[]>(voSelector);
return this.prefs.connect().pipe(
combineLatest(
vos$,
this.subscribeServices(),
(prefs: Prefs, vos: VO[], svc: Service[]) => {
if (prefs.showEmptyVOs) {
// filter VOs that have no services
return vos.filter(
(vo: VO) => svc.some(
(s: Service) => s.vos.some(
svo => svo.id === vo.id,
),
),
);
}
return vos;
}
)
);
}
}
Markdown is supported
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