Skip to content

Commit

Permalink
fix(ui): vcs strategy component (#4991)
Browse files Browse the repository at this point in the history
  • Loading branch information
fsamin authored Feb 19, 2020
1 parent 422477d commit 19ffb36
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 30 deletions.
13 changes: 6 additions & 7 deletions ui/src/app/model/keys.model.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
export class Keys {
static formatForSelect(...keys: any[]): AllKeys {
let k = new AllKeys();
k.ssh.push(...keys.filter(key => key.type === KeyType.SSH));
k.pgp.push(...keys.filter(key => key.type === KeyType.PGP));
return k;
}
export function formatKeysForSelect(...keys: Key[]): AllKeys {
let k = new AllKeys();
k.ssh.push(...keys.filter(key => key.type === KeyType.SSH));
k.pgp.push(...keys.filter(key => key.type === KeyType.PGP));
return k;
}


export class AllKeys {
ssh: Array<Key>;
pgp: Array<Key>;
Expand Down
31 changes: 9 additions & 22 deletions ui/src/app/service/keys/keys.service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { AllKeys, Key, Keys, KeyType } from 'app/model/keys.model';
import { AllKeys, formatKeysForSelect, Key} from 'app/model/keys.model';
import { forkJoin, Observable } from 'rxjs';
import { map } from 'rxjs/operators';

Expand All @@ -13,33 +13,20 @@ export class KeyService {
/**
* Get all keys (project/application) from the given project
* @param projectKey Project unique key
* @returns {Observable<Keys>}
* @returns {Observable<AllKeys>}
*/
getAllKeys(projectKey: string, appName?: string): Observable<AllKeys> {
if (!appName) {
return this._http.get<Keys>('/project/' + projectKey + '/keys').pipe(map(keys => {
return Keys.formatForSelect(keys);
return this._http.get<Key[]>('/project/' + projectKey + '/keys').pipe(map(keys => {
return formatKeysForSelect(...keys);
}));
}

return forkJoin<Keys, Keys> ([
this._http.get<Keys>('/project/' + projectKey + '/keys'),
this._http.get<Keys>('/project/' + projectKey + '/application/' + appName + '/keys')
]).pipe(map((k1, k2) => {
return Keys.formatForSelect(k1, k2);
}));
}

/**
* Get project keys from the given project
* @param projectKey Project unique key
* @returns {Observable<Keys>}
*/
getProjectKeys(projectKey: string): Observable<AllKeys> {
return this._http.get<Array<Key>>('/project/' + projectKey + '/keys').pipe(map(keys => {
let k = new AllKeys();
k.ssh.push(...keys.filter(key => key.type === KeyType.SSH));
k.pgp.push(...keys.filter(key => key.type === KeyType.PGP));
return forkJoin({
projectKeys: this._http.get<Key[]>('/project/' + projectKey + '/keys'),
appKeys: this._http.get<Key[]>('/project/' + projectKey + '/application/' + appName + '/keys')
}).pipe(map(({projectKeys, appKeys}) => {
let k = formatKeysForSelect(...projectKeys, ...appKeys);
return k;
}));
}
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/shared/vcs/vcs.strategy.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export class VCSStrategyComponent implements OnInit {

loadKeys() {
if (this.projectKeysOnly) {
this._keyService.getProjectKeys(this.project.key)
this._keyService.getAllKeys(this.project.key)
.pipe(finalize(() => this._cd.markForCheck()))
.subscribe(k => {
this.keys = k;
Expand Down

0 comments on commit 19ffb36

Please sign in to comment.