summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-05 00:17:45 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2018-01-05 00:17:45 +0100
commitbbef877fbb1c32981e86e407afd095e24d10232a (patch)
tree19e1ac24b32f4f3d080cd73c92936d4a6a2db1cb
parentf1083a8259b3d2f560b5f3ccb8b47c94e297d7fa (diff)
Webapp: Fixed SDKs installation
Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
-rw-r--r--webapp/src/app/@core-xds/services/sdk.service.ts30
-rw-r--r--webapp/src/app/pages/sdks/sdk-card/sdk-card.component.html2
-rw-r--r--webapp/src/app/pages/sdks/sdk-card/sdk-card.component.ts6
-rw-r--r--webapp/src/app/pages/sdks/sdk-management/sdk-management.component.ts4
-rw-r--r--webapp/src/app/pages/sdks/sdks.component.ts4
5 files changed, 37 insertions, 9 deletions
diff --git a/webapp/src/app/@core-xds/services/sdk.service.ts b/webapp/src/app/@core-xds/services/sdk.service.ts
index 8fa6ad2..181ad6f 100644
--- a/webapp/src/app/@core-xds/services/sdk.service.ts
+++ b/webapp/src/app/@core-xds/services/sdk.service.ts
@@ -24,6 +24,24 @@ import { XDSAgentService } from '../services/xdsagent.service';
import 'rxjs/add/observable/throw';
+/* FIXME: syntax only compatible with TS>2.4.0
+export enum StatusType {
+ DISABLE = 'Disable',
+ NOT_INSTALLED = 'Not Installed',
+ INSTALLING = 'Installing',
+ UNINSTALLING = 'Un-installing',
+ INSTALLED = 'Installed'
+}
+*/
+export type StatusTypeEnum = 'Disable' | 'Not Installed' | 'Installing' | 'Un-installing' | 'Installed';
+export const StatusType = {
+ DISABLE: 'Disable',
+ NOT_INSTALLED: 'Not Installed',
+ INSTALLING: 'Installing',
+ UNINSTALLING: 'Un-installing',
+ INSTALLED: 'Installed',
+};
+
export interface ISdk {
id: string;
name: string;
@@ -97,7 +115,7 @@ export class SdkService {
this._addSdk(evMgt.sdk);
});
this.xdsSvr.onSdkRemove().subscribe(evMgt => {
- if (evMgt.sdk.status !== 'Not Installed') {
+ if (evMgt.sdk.status !== StatusType.NOT_INSTALLED) {
/* tslint:disable:no-console */
console.log('Error: received event:sdk-remove with invalid status: evMgt=', evMgt);
return;
@@ -142,8 +160,14 @@ export class SdkService {
private _addSdk(sdk: ISdk, noNext?: boolean): ISdk {
- // add new sdk
- this._sdksList.push(sdk);
+ // check if sdk already exists
+ const idx = this._sdksList.findIndex(s => s.id === sdk.id);
+ if (idx >= 0) {
+ this._sdksList[idx] = sdk;
+ } else {
+ // add new sdk
+ this._sdksList.push(sdk);
+ }
// sort sdk array
this._sdksList.sort((a, b) => {
diff --git a/webapp/src/app/pages/sdks/sdk-card/sdk-card.component.html b/webapp/src/app/pages/sdks/sdk-card/sdk-card.component.html
index 2edc0d3..ba878ba 100644
--- a/webapp/src/app/pages/sdks/sdk-card/sdk-card.component.html
+++ b/webapp/src/app/pages/sdks/sdk-card/sdk-card.component.html
@@ -6,7 +6,7 @@
{{ sdk.name }}
</div>
<div class="col-6 col-md-4 text-right" role="group">
- <button class="btn btn-outline-danger btn-tn btn-xds" (click)="remove(sdk)">
+ <button class="btn btn-outline-danger btn-tn btn-xds" [disabled]="!canRemove(sdk)" (click)="remove(sdk)">
<span class="fa fa-trash fa-size-x2"></span>
</button>
</div>
diff --git a/webapp/src/app/pages/sdks/sdk-card/sdk-card.component.ts b/webapp/src/app/pages/sdks/sdk-card/sdk-card.component.ts
index 997f01d..ffb0852 100644
--- a/webapp/src/app/pages/sdks/sdk-card/sdk-card.component.ts
+++ b/webapp/src/app/pages/sdks/sdk-card/sdk-card.component.ts
@@ -17,7 +17,7 @@
*/
import { Component, Input, Pipe, PipeTransform } from '@angular/core';
-import { SdkService, ISdk } from '../../../@core-xds/services/sdk.service';
+import { SdkService, ISdk, StatusType } from '../../../@core-xds/services/sdk.service';
import { AlertService } from '../../../@core-xds/services/alert.service';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
@@ -42,6 +42,10 @@ export class SdkCardComponent {
) {
}
+ canRemove(sdk: ISdk) {
+ return sdk.status === StatusType.INSTALLED;
+ }
+
remove(sdk: ISdk) {
const modal = this.modalService.open(ConfirmModalComponent, {
size: 'lg',
diff --git a/webapp/src/app/pages/sdks/sdk-management/sdk-management.component.ts b/webapp/src/app/pages/sdks/sdk-management/sdk-management.component.ts
index c885238..68620a1 100644
--- a/webapp/src/app/pages/sdks/sdk-management/sdk-management.component.ts
+++ b/webapp/src/app/pages/sdks/sdk-management/sdk-management.component.ts
@@ -24,7 +24,7 @@ import { ConfirmModalComponent, EType } from '../../confirm/confirm-modal/confir
import { SdkInstallComponent } from './sdk-install.component';
import { AlertService } from '../../../@core-xds/services/alert.service';
-import { SdkService, ISdk } from '../../../@core-xds/services/sdk.service';
+import { SdkService, ISdk, StatusType } from '../../../@core-xds/services/sdk.service';
import { ISdkMessage } from '../../../@core-xds/services/xdsagent.service';
interface ISdkMgt extends ISdk {
@@ -90,7 +90,7 @@ export class SdkManagementComponent implements OnInit {
this.sdks = [];
sdks.forEach(s => {
// only display not installed SDK
- if (s.status !== 'Not Installed') {
+ if (s.status !== StatusType.NOT_INSTALLED) {
return;
}
profMap[s.profile] = s.profile;
diff --git a/webapp/src/app/pages/sdks/sdks.component.ts b/webapp/src/app/pages/sdks/sdks.component.ts
index 12d2f71..d0679e9 100644
--- a/webapp/src/app/pages/sdks/sdks.component.ts
+++ b/webapp/src/app/pages/sdks/sdks.component.ts
@@ -21,7 +21,7 @@ import { Observable } from 'rxjs/Observable';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';
-import { SdkService, ISdk } from '../../@core-xds/services/sdk.service';
+import { SdkService, ISdk, StatusType } from '../../@core-xds/services/sdk.service';
@Component({
selector: 'xds-sdks',
@@ -44,6 +44,6 @@ export class SdksComponent implements OnInit {
}
isVisible(sdk: ISdk) {
- return sdk.status === 'Installed' || sdk.status === 'Installing';
+ return sdk.status === StatusType.INSTALLED || sdk.status === StatusType.INSTALLING;
}
}