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

Add filtering empty VOs

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