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
10 * ZTE - initial API and implementation and/or initial documentation
13 import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core';
14 import { ModalDirective } from 'ngx-bootstrap/modal';
16 import { Microservice } from '../../../../model/workflow/microservice';
17 import { RestConfig } from '../../../../model/rest-config';
20 * toolbar component contains some basic operations(save) and all of the supported workflow nodes.
21 * The supported nodes can be dragged to container component. which will add a new node to the workflow.
24 selector: 'b4t-microservice-list',
25 templateUrl: 'microservice-list.component.html',
27 export class MicroserviceListComponent {
28 @Input() microservices: RestConfig[];
29 @Output() microserviceSelected = new EventEmitter<RestConfig>();
31 public onMicroserviceSelected(microservice: RestConfig) {
32 this.microserviceSelected.emit(microservice);
35 public addMicroservice() {
36 const microservice = new RestConfig(this.getConfigId(), 'new microservice', '', null);
37 this.microservices.push(microservice);
39 this.onMicroserviceSelected(microservice);
42 public deleteMicroservice(index: number, microservice: Microservice) {
43 this.deleteMicroService(microservice.name, microservice.version);
45 // set the next microservice selected
46 let selectedMicroservice;
47 if (this.microservices.length > 0) {
48 if (this.microservices[index]) {
49 selectedMicroservice = this.microservices[index];
51 selectedMicroservice = this.microservices[index - 1];
54 this.onMicroserviceSelected(selectedMicroservice);
57 private deleteMicroService(name: string, version: string) {
58 const index = this.microservices.findIndex(service => (service.name === name && service.version === version));
60 return this.microservices.splice(index, 1)[0];
66 private getConfigId(): string {
67 const idSet = new Set<string>();
68 this.microservices.forEach(config => {
72 for(let index = 0; index < idSet.size; index++) {
73 const id = `config${index}`;