Commit 8e571c0e authored by Lukas Burgey's avatar Lukas Burgey

Put ssh keys into a map

parent 6eac125b
...@@ -28,7 +28,7 @@ export class UserService { ...@@ -28,7 +28,7 @@ export class UserService {
private user: User; private user: User;
private user$: BehaviorSubject<User>; private user$: BehaviorSubject<User>;
private sshKeys: SSHKey[] = new Array<SSHKey>(); private sshKeys: Map<number, SSHKey> = new Map([]);
private sshKeys$ = new BehaviorSubject<SSHKey[]>([]); private sshKeys$ = new BehaviorSubject<SSHKey[]>([]);
private deploymentStates: Map<number, DeploymentState> = new Map([]); private deploymentStates: Map<number, DeploymentState> = new Map([]);
...@@ -71,11 +71,10 @@ export class UserService { ...@@ -71,11 +71,10 @@ export class UserService {
this.user = undefined; this.user = undefined;
this.deployments = new Map([]); this.deployments = new Map([]);
this.deployments$.next([]); this.deployments$.next([]);
this.sshKeys = []; this.sshKeys = new Map([]);
this.sshKeys$.next([]); this.sshKeys$.next([]);
} }
this.loggedIn = false; this.loggedIn = false;
} else { } else {
// LOGGED IN // LOGGED IN
...@@ -88,8 +87,11 @@ export class UserService { ...@@ -88,8 +87,11 @@ export class UserService {
this.connectLiveUpdates(newUser.id); this.connectLiveUpdates(newUser.id);
} }
if (newUser.ssh_keys) { if (newUser.ssh_keys) {
this.sshKeys = newUser.ssh_keys; this.sshKeys = new Map([]);
this.sshKeys$.next(this.sshKeys); newUser.ssh_keys.forEach(
(key: SSHKey) => this.sshKeys.set(key.id, key),
);
this.sshKeys$.next(Array.from(this.sshKeys.values()));
} }
if (newUser.deployments) { if (newUser.deployments) {
newUser.deployments.forEach( newUser.deployments.forEach(
...@@ -294,8 +296,8 @@ export class UserService { ...@@ -294,8 +296,8 @@ export class UserService {
catchError(this.handleError(true, "Error changing deployment")), catchError(this.handleError(true, "Error changing deployment")),
).subscribe( ).subscribe(
(newKey: SSHKey) => { (newKey: SSHKey) => {
this.sshKeys.push(newKey); this.sshKeys.set(newKey.id, newKey);
this.sshKeys$.next(this.sshKeys); this.sshKeys$.next(Array.from(this.sshKeys.values()));
}, },
this.logErrorAndFetch, this.logErrorAndFetch,
); );
...@@ -307,10 +309,8 @@ export class UserService { ...@@ -307,10 +309,8 @@ export class UserService {
catchError(this.handleError(true, "Error changing deployment")), catchError(this.handleError(true, "Error changing deployment")),
).subscribe( ).subscribe(
_ => { _ => {
this.sshKeys = this.sshKeys.filter( this.sshKeys.delete(key.id);
k => key.id != k.id this.sshKeys$.next(Array.from(this.sshKeys.values()));
);
this.sshKeys$.next(this.sshKeys);
}, },
this.logErrorAndFetch, this.logErrorAndFetch,
); );
......
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