unpdate microservice config info 05/27905/1
authorLvbo163 <lv.bo163@zte.com.cn>
Thu, 11 Jan 2018 01:52:16 +0000 (09:52 +0800)
committerLvbo163 <lv.bo163@zte.com.cn>
Thu, 11 Jan 2018 01:52:16 +0000 (09:52 +0800)
add id for microservice config info

Issue-ID: SDC-899

Change-Id: I2cc2543458aea11603fd70ca95b25581ecd87a50
Signed-off-by: Lvbo163 <lv.bo163@zte.com.cn>
sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-detail/microservice-detail.component.html
sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-detail/microservice-detail.component.ts
sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.ts
sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice.component.ts

index 3a0942e..d13895d 100644 (file)
@@ -33,7 +33,7 @@
 <div *ngIf="dynamic" class="form-group row">
     <label class="col-md-2 form-control-label text-md-right">Definition</label>
     <div class="col-md-8" style="padding-right:0px">
-        <input class="form-control" [(ngModel)]="microservice.definition">
+        <input class="form-control" [(ngModel)]="microservice.url">
     </div>
     <div class="col-md-2" style="padding-left:0px">
         <button class="btn" (click)="loadDynamicInfo()">load</button>
index ec72729..bffaef4 100644 (file)
@@ -16,6 +16,7 @@ import { ModalDirective } from 'ngx-bootstrap/modal';
 import { Microservice } from '../../../../model/workflow/microservice';
 import { WorkflowConfigService } from '../../../../services/workflow-config.service';
 import { Swagger } from "../../../../model/swagger";
+import { RestConfig } from '../../../../model/rest-config';
 
 /**
  * toolbar component contains some basic operations(save) and all of the supported workflow nodes.
@@ -26,7 +27,7 @@ import { Swagger } from "../../../../model/swagger";
     templateUrl: 'microservice-detail.component.html',
 })
 export class MicroserviceDetailComponent implements OnChanges {
-    @Input() microservice: Microservice;
+    @Input() microservice: RestConfig;
 
     public detail: string;
     public dynamic = false;
@@ -36,15 +37,23 @@ export class MicroserviceDetailComponent implements OnChanges {
 
     public ngOnChanges() {
         if(this.microservice == null) {
-            this.microservice = new Microservice('', '', null, '');
+            this.microservice = new RestConfig('', '', null, '');
         }
-        this.dynamic = this.microservice.definition !== '';
+        this.checkDynamic();
         this.parseSwagger2String();
     }
 
+    private checkDynamic() {
+        if(this.microservice.url) {
+            this.dynamic = true;
+        } else {
+            this.dynamic = false;
+        }
+    }
+
     private parseSwagger2String() {
-        if (this.microservice.swaggerJson) {
-            this.detail = JSON.stringify(this.microservice.swaggerJson);
+        if (this.microservice.swagger) {
+            this.detail = JSON.stringify(this.microservice.swagger);
         } else {
             this.detail = '';
         }
@@ -56,10 +65,10 @@ export class MicroserviceDetailComponent implements OnChanges {
                 const swagger = new Swagger(JSON.parse(detail));
                 this.detail = detail;
                 console.log(swagger);
-                this.microservice.swaggerJson = detail;
+                this.microservice.swagger = swagger;
             } else {
                 this.detail = '';
-                this.microservice.swaggerJson = null;
+                this.microservice.swagger = null;
             }
         } catch (e) {
             // if detail is not a json object, then not change the swagger
@@ -71,16 +80,16 @@ export class MicroserviceDetailComponent implements OnChanges {
         this.onDetailChanged(null);
 
         if(!dynamic) {
-            this.microservice.definition = null;
+            this.microservice.url = null;
         }
     }
 
     private loadDynamicInfo() {
-        this.configService.loadDynamicInfo(this.microservice.definition)
+        this.configService.loadDynamicInfo(this.microservice.url)
         .subscribe(response => {
             try {
 
-                this.microservice.swaggerJson = response;
+                this.microservice.swagger = response;
                 this.parseSwagger2String();
             } catch (e) {
                 console.log('detail transfer error');
index 6e31b2e..b44d423 100644 (file)
@@ -14,6 +14,7 @@ import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core
 import { ModalDirective } from 'ngx-bootstrap/modal';
 
 import { Microservice } from '../../../../model/workflow/microservice';
+import { RestConfig } from '../../../../model/rest-config';
 
 /**
  * toolbar component contains some basic operations(save) and all of the supported workflow nodes.
@@ -24,15 +25,15 @@ import { Microservice } from '../../../../model/workflow/microservice';
     templateUrl: 'microservice-list.component.html',
 })
 export class MicroserviceListComponent {
-    @Input() microservices: Microservice[];
-    @Output() microserviceSelected = new EventEmitter<Microservice>();
+    @Input() microservices: RestConfig[];
+    @Output() microserviceSelected = new EventEmitter<RestConfig>();
 
-    public onMicroserviceSelected(microservice: Microservice) {
+    public onMicroserviceSelected(microservice: RestConfig) {
         this.microserviceSelected.emit(microservice);
     }
 
     public addMicroservice() {
-        const microservice = new Microservice('new microservice', '', null, '');
+        const microservice = new RestConfig(this.getConfigId(), 'new microservice', '', null);
         this.microservices.push(microservice);
 
         this.onMicroserviceSelected(microservice);
@@ -61,4 +62,20 @@ export class MicroserviceListComponent {
 
         return undefined;
     }
+
+    private getConfigId(): string {
+        const idSet = new Set<string>();
+        this.microservices.forEach(config => {
+            idSet.add(config.id);
+        });
+
+        for(let index = 0; index < idSet.size; index++) {
+            const id = `config${index}`;
+            if(!idSet.has(id)) {
+                return id;
+            }
+        }
+
+        return `config0`;
+    }
 }
index 4591eef..eeedac4 100644 (file)
@@ -16,6 +16,8 @@ import { ModalDirective } from 'ngx-bootstrap/modal';
 import { MicroserviceListComponent } from './microservice-list/microservice-list.component';
 import { Microservice } from "../../../model/workflow/microservice";
 import { WorkflowConfigService } from "../../../services/workflow-config.service";
+import { RestService } from '../../../services/rest.service';
+import { RestConfig } from '../../../model/rest-config';
 
 /**
  * microservice component
@@ -28,10 +30,10 @@ import { WorkflowConfigService } from "../../../services/workflow-config.service
 export class MicroserviceComponent {
     @ViewChild('microserviceModal') public microserviceModal: ModalDirective;
 
-    public microservices: Microservice[];
+    public microservices: RestConfig[];
     public currentMicroservice: Microservice;
 
-    constructor(private workflowConfigService: WorkflowConfigService) {
+    constructor(private restService: RestService) {
     }
 
     public microserviceSelected(microservice: any) {
@@ -39,7 +41,7 @@ export class MicroserviceComponent {
     }
 
     public show() {
-        this.microservices = this.workflowConfigService.getMicroservices();
+        this.microservices = this.restService.getRestConfigs();
         this.microserviceModal.show();
     }