support swagger for microservice definition
[sdc/sdc-workflow-designer.git] / sdc-workflow-designer-ui / src / app / components / menu / microservice / microservice-list / microservice-list.component.ts
1 /**
2  * Copyright (c) 2017 ZTE Corporation.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * and the Apache License 2.0 which both accompany this distribution,
6  * and are available at http://www.eclipse.org/legal/epl-v10.html
7  * and http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Contributors:
10  *     ZTE - initial API and implementation and/or initial documentation
11  */
12
13 import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
14 import { ModalDirective } from 'ngx-bootstrap/modal';
15
16 import { Microservice } from '../../../../model/workflow/microservice';
17
18 /**
19  * toolbar component contains some basic operations(save) and all of the supported workflow nodes.
20  * The supported nodes can be dragged to container component. which will add a new node to the workflow.
21  */
22 @Component({
23     selector: 'b4t-microservice-list',
24     templateUrl: 'microservice-list.component.html',
25 })
26 export class MicroserviceListComponent {
27     @Input() microservices: Microservice[];
28     @Output() microserviceSelected = new EventEmitter<Microservice>();
29
30     public onMicroserviceSelected(microservice: Microservice) {
31         this.microserviceSelected.emit(microservice);
32     }
33
34     public addMicroservice() {
35         const microservice = new Microservice('new microservice', '', null, '');
36         this.microservices.push(microservice);
37
38         this.onMicroserviceSelected(microservice);
39     }
40
41     public deleteMicroservice(index: number, microservice: Microservice) {
42         this.deleteMicroService(microservice.name, microservice.version);
43
44         // set the next microservice selected
45         let selectedMicroservice;
46         if (this.microservices.length > 0) {
47             if (this.microservices[index]) {
48                 selectedMicroservice = this.microservices[index];
49             } else {
50                 selectedMicroservice = this.microservices[index - 1];
51             }
52         }
53         this.onMicroserviceSelected(selectedMicroservice);
54     }
55
56     private deleteMicroService(name: string, version: string) {
57         const index = this.microservices.findIndex(service => (service.name === name && service.version === version));
58         if(index !== -1) {
59             return this.microservices.splice(index, 1)[0];
60         }
61
62         return undefined;
63     }
64 }