Commit 223b68c7 authored by Lukas Burgey's avatar Lukas Burgey

Lint parts of the user service

parent a38b54f8
......@@ -17,6 +17,7 @@ import * as t from './types/types.module';
@Injectable()
export class UserService {
private _loggedIn: boolean = false;
private loggedIn$ = new BehaviorSubject<boolean>(false);
private user: t.User;
private user$ = <BehaviorSubject<t.User>> new BehaviorSubject(new Object);
......@@ -27,42 +28,22 @@ export class UserService {
private sshKeys: t.SSHKey[] = new Array<t.SSHKey>();
private sshKeys$ = <BehaviorSubject<t.SSHKey[]>> new BehaviorSubject([]);
public messages: string[] = [];
private messages: string[] = [];
// local copy of services
public services: t.Service[] = [];
private services: t.Service[] = [];
public groupMap: Map<string, t.Service[]> = new Map();
public groupsParsed: boolean = false;
// TODO put in preferences cookie
autoLogin = false;
constructor(
public cookieService: CookieService,
public http: HttpClient,
public snackBar: SnackBarService,
public idpService: IdpService,
private cookieService: CookieService,
private http: HttpClient,
private snackBar: SnackBarService,
private idpService: IdpService,
private _stompService: StompRService,
) {
this.update();
// AUTO LOGIN
this.subscribeUserState().subscribe(
(state: t.UserState) => {
console.log(JSON.stringify(state));
if (!state) {
this.idpService.subscribeIdps().subscribe(
(idps: t.IdP[]) => {
if (idps.length === 1 && this.autoLogin) {
this.login(idps[0]);
}
}
);
}
}
);
}
// DATA SERVICE API
......@@ -78,6 +59,10 @@ export class UserService {
return this.sshKeys$.asObservable();
}
public subscribeLoggedIn(): Observable<boolean> {
return this.loggedIn$.asObservable();
}
// PRIVATE API
private initStomp() {
// handle with care
......@@ -227,22 +212,31 @@ export class UserService {
return dep
}
// PUBLIC API
public loggedIn(): boolean {
if (this.userState) {
return true;
}
return false;
}
public update(): void {
this.http.get('/backend/api/state').subscribe(
(data: t.StateAPIResult) => this.stateAPIUpdate(data),
(err: any) => this.errorLogger(err, 'receiving data from the server')
);
}
public serviceDescription(service: t.Service): string {
if (service.description != "") {
return service.description;
}
return "No description";
}
public getDeployment(service: t.Service): t.Deployment {
return this.userState.deployments.find(
dep => {
if (dep.service) {
return dep.service.id === service.id;
}
return false
}
dep => dep.service && dep.service.id === service.id
);
}
......@@ -285,26 +279,13 @@ export class UserService {
return new MatTableDataSource(this.user.ssh_keys);
}
public loggedIn(): boolean {
if (this.userState) {
return true;
}
return false;
}
public update(): void {
this.http.get('/backend/api/state').subscribe(
(data: t.StateAPIResult) => this.stateAPIUpdate(data),
(err: HttpErrorResponse) => {
console.log('Error', err);
this.snackBar.open('Error receiving data from the server');
}
);
}
public errorHandler(error: any): void {
public errorLogger(error: any, msg?: string): void {
console.log(error);
this.snackBar.open('Error');
if (msg) {
this.snackBar.open('Error: '+msg);
} else {
this.snackBar.open('Error');
}
}
public login(idp: t.IdP) {
......@@ -318,8 +299,8 @@ export class UserService {
public logout() {
this.http.post('/backend/auth/v1/logout', {}).subscribe(
(data: t.StateAPIResult) => this.stateAPIUpdate(data),
(err) => {
this.errorHandler(err);
(err: any) => {
this.errorLogger(err);
this._logout();
}
);
......
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