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 { RestConfig } from '../../../../model/rest-config';
 
  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.
 
  23     selector: 'b4t-microservice-list',
 
  24     templateUrl: 'microservice-list.component.html',
 
  26 export class MicroserviceListComponent {
 
  27     @Input() microservices: RestConfig[];
 
  28     @Output() microserviceSelected = new EventEmitter<RestConfig>();
 
  30     public onMicroserviceSelected(microservice: RestConfig) {
 
  31         this.microserviceSelected.emit(microservice);
 
  34     public addMicroservice() {
 
  35         const microservice = new RestConfig(this.getConfigId(), 'new microservice', '', null);
 
  36         this.microservices.push(microservice);
 
  38         this.onMicroserviceSelected(microservice);
 
  41     public deleteMicroservice(index: number, microservice: RestConfig) {
 
  42         this.deleteMicroService(microservice.name, microservice.version);
 
  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];
 
  50                 selectedMicroservice = this.microservices[index - 1];
 
  53         this.onMicroserviceSelected(selectedMicroservice);
 
  56     private deleteMicroService(name: string, version: string) {
 
  57         const index = this.microservices.findIndex(service => (service.name === name && service.version === version));
 
  59             return this.microservices.splice(index, 1)[0];
 
  65     private getConfigId(): string {
 
  66         const idSet = new Set<string>();
 
  67         this.microservices.forEach(config => {
 
  71         for(let index = 0; index < idSet.size; index++) {
 
  72             const id = `config${index}`;