diff options
Diffstat (limited to 'webapp')
-rw-r--r-- | webapp/src/app/@core-xds/services/sdk.service.ts | 49 | ||||
-rw-r--r-- | webapp/src/app/@core-xds/services/xdsagent.service.ts | 71 |
2 files changed, 82 insertions, 38 deletions
diff --git a/webapp/src/app/@core-xds/services/sdk.service.ts b/webapp/src/app/@core-xds/services/sdk.service.ts index 6191c85..f854744 100644 --- a/webapp/src/app/@core-xds/services/sdk.service.ts +++ b/webapp/src/app/@core-xds/services/sdk.service.ts @@ -62,6 +62,7 @@ export interface ISdk { export interface ISdkManagementMsg { cmdID: string; timestamp: string; + action: string; sdk: ISdk; stdout: string; stderr: string; @@ -97,7 +98,7 @@ export class SdkService { this.xdsSvr.getSdks(this.curServerID).subscribe((sdks) => { this._sdksList = []; sdks.forEach(s => { - this._addSdk(s, true); + this._addUpdateSdk(s, true); }); // TODO: get previous val from xds-config service / cookie @@ -111,18 +112,17 @@ export class SdkService { }); // Add listener on sdk creation, deletion and change events - this.xdsSvr.onSdkInstall().subscribe(evMgt => { - this._addSdk(evMgt.sdk); - }); - this.xdsSvr.onSdkRemove().subscribe(evMgt => { - if (evMgt.sdk.status !== StatusType.NOT_INSTALLED) { + this.xdsSvr.onSdkAdd().subscribe(sdk => this._addUpdateSdk(sdk)); + this.xdsSvr.onSdkChange().subscribe(sdk => this._addUpdateSdk(sdk)); + + this.xdsSvr.onSdkRemove().subscribe(sdk => { + if (sdk.status !== StatusType.NOT_INSTALLED) { /* tslint:disable:no-console */ - console.log('Error: received event:sdk-remove with invalid status: evMgt=', evMgt); + console.log('Error: received event:sdk-remove with invalid status: sdk=', sdk); return; } - this._delSdk(evMgt.sdk); + this._delSdk(sdk); }); - } public setCurrent(s: ISdk) { @@ -145,7 +145,11 @@ export class SdkService { } public onInstall(): Observable<ISdkManagementMsg> { - return this.xdsSvr.onSdkInstall(); + return this.xdsSvr.onSdkManagement().filter(ev => ev.action === 'installing'); + } + + public onRemove(): Observable<ISdkManagementMsg> { + return this.xdsSvr.onSdkManagement().filter(ev => ev.action === 'removing'); } public abortInstall(sdk: ISdk): Observable<ISdk> { @@ -158,27 +162,28 @@ export class SdkService { /** Private **/ - private _addSdk(sdk: ISdk, noNext?: boolean): ISdk { + private _addUpdateSdk(sdk: ISdk, noNext?: boolean): ISdk { // check if sdk already exists const idx = this._sdksList.findIndex(s => s.id === sdk.id); if (idx >= 0) { + // Just update existing one this._sdksList[idx] = sdk; } else { // add new sdk this._sdksList.push(sdk); - } - // sort sdk array - this._sdksList.sort((a, b) => { - if (a.name < b.name) { - return -1; - } - if (a.name > b.name) { - return 1; - } - return 0; - }); + // sort sdk array + this._sdksList.sort((a, b) => { + if (a.name < b.name) { + return -1; + } + if (a.name > b.name) { + return 1; + } + return 0; + }); + } if (!noNext) { this.sdksSubject.next(this._sdksList); diff --git a/webapp/src/app/@core-xds/services/xdsagent.service.ts b/webapp/src/app/@core-xds/services/xdsagent.service.ts index 27e14cf..033185b 100644 --- a/webapp/src/app/@core-xds/services/xdsagent.service.ts +++ b/webapp/src/app/@core-xds/services/xdsagent.service.ts @@ -133,8 +133,10 @@ export class XDSAgentService { protected projectDel$ = new Subject<IXDSProjectConfig>(); protected projectChange$ = new Subject<IXDSProjectConfig>(); - protected sdkInstall$ = new Subject<ISdkManagementMsg>(); - protected sdkRemove$ = new Subject<ISdkManagementMsg>(); + protected sdkAdd$ = new Subject<ISdk>(); + protected sdkRemove$ = new Subject<ISdk>(); + protected sdkChange$ = new Subject<ISdk>(); + protected sdkManagement$ = new Subject<ISdkManagementMsg>(); private baseUrl: string; private wsUrl: string; @@ -249,6 +251,8 @@ export class XDSAgentService { } }); + /*** Project events ****/ + this.socket.on('event:project-add', (ev) => { if (ev && ev.data && ev.data.id) { this.projectAdd$.next(Object.assign({}, ev.data)); @@ -280,32 +284,59 @@ export class XDSAgentService { } }); - this.socket.on('event:sdk-install', (ev) => { - if (ev && ev.data && ev.data.sdk) { - const evt = <ISdkManagementMsg>ev.data; - this.sdkInstall$.next(Object.assign({}, evt)); + /*** SDK Events ***/ - if (ev.sessionID !== '' && ev.sessionID !== this.httpSessionID && evt.sdk.name) { - this.alert.info('SDK "' + evt.sdk.name + '" has been installed by another tool.'); + this.socket.on('event:sdk-add', (ev) => { + if (ev && ev.data && ev.data.id) { + const evt = <ISdk>ev.data; + this.sdkAdd$.next(Object.assign({}, evt)); + + if (ev.sessionID !== '' && ev.sessionID !== this.httpSessionID && evt.name) { + this.alert.info('SDK "' + evt.name + '" has been added by another tool.'); } } else if (isDevMode) { - /* tslint:disable:no-console */ - console.log('Warning: received event:sdk-install with unknown data: ev=', ev); + console.log('Warning: received event:sdk-add with unknown data: ev=', ev); } }); this.socket.on('event:sdk-remove', (ev) => { + if (ev && ev.data && ev.data.id) { + const evt = <ISdk>ev.data; + this.sdkRemove$.next(Object.assign({}, evt)); + + if (ev.sessionID !== '' && ev.sessionID !== this.httpSessionID && evt.name) { + this.alert.info('SDK "' + evt.name + '" has been removed by another tool.'); + } + } else if (isDevMode) { + console.log('Warning: received event:sdk-remove with unknown data: ev=', ev); + } + }); + + this.socket.on('event:sdk-state-change', (ev) => { + if (ev && ev.data && ev.data.id) { + const evt = <ISdk>ev.data; + this.sdkChange$.next(Object.assign({}, evt)); + + } else if (isDevMode) { + console.log('Warning: received event:sdk-state-change with unknown data: ev=', ev); + } + }); + + + this.socket.on('event:sdk-management', (ev) => { if (ev && ev.data && ev.data.sdk) { const evt = <ISdkManagementMsg>ev.data; - this.sdkRemove$.next(Object.assign({}, evt)); + this.sdkManagement$.next(Object.assign({}, evt)); if (ev.sessionID !== '' && ev.sessionID !== this.httpSessionID && evt.sdk.name) { - this.alert.info('SDK "' + evt.sdk.name + '" has been removed by another tool.'); + this.alert.info('SDK "' + evt.sdk.name + '" has been installed by another tool.'); } } else if (isDevMode) { - console.log('Warning: received event:sdk-remove with unknown data: ev=', ev); + /* tslint:disable:no-console */ + console.log('Warning: received event:sdk-install with unknown data: ev=', ev); } }); + } /** @@ -323,14 +354,22 @@ export class XDSAgentService { return this.projectChange$.asObservable(); } - onSdkInstall(): Observable<ISdkManagementMsg> { - return this.sdkInstall$.asObservable(); + onSdkAdd(): Observable<ISdk> { + return this.sdkAdd$.asObservable(); } - onSdkRemove(): Observable<ISdkManagementMsg> { + onSdkRemove(): Observable<ISdk> { return this.sdkRemove$.asObservable(); } + onSdkChange(): Observable<ISdk> { + return this.sdkChange$.asObservable(); + } + + onSdkManagement(): Observable<ISdkManagementMsg> { + return this.sdkManagement$.asObservable(); + } + /** ** Misc / Version ***/ |