2     Copyright (C) 2019 CMCC, Inc. and others. All rights reserved.
 
   4     Licensed under the Apache License, Version 2.0 (the "License");
 
   5     you may not use this file except in compliance with the License.
 
   6     You may obtain a copy of the License at
 
   8             http://www.apache.org/licenses/LICENSE-2.0
 
  10     Unless required by applicable law or agreed to in writing, software
 
  11     distributed under the License is distributed on an "AS IS" BASIS,
 
  12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13     See the License for the specific language governing permissions and
 
  14     limitations under the License.
 
  24 } from "@angular/core";
 
  25 import {NgbActiveModal} from "@ng-bootstrap/ng-bootstrap";
 
  26 import {RestApiService} from "src/app/core/services/rest-api.service";
 
  27 import {AdminService} from "src/app/core/services/admin.service";
 
  28 import {Topic} from "src/app/core/models/topic.model";
 
  31   selector: 'app-new-topic-model',
 
  32   templateUrl: './new-topic-model.component.html',
 
  33   styleUrls: ['./new-topic-model.component.css']
 
  35 export class NewTopicModelComponent implements OnInit {
 
  36   @Input() newTopic: Topic;
 
  37   @Output() passEntry: EventEmitter<any> = new EventEmitter();
 
  41   dataFormats: Array<string> = ["JSON", "XML"];
 
  42   tempSeletedDbs: any = [];
 
  43   idExFields: Array<any> = [];
 
  44   idExNewField: any = {};
 
  45   @ViewChild("t_topicname") t_topicname: ElementRef;
 
  46   @ViewChild("t_login") t_login: ElementRef;
 
  47   @ViewChild("t_password") t_password: ElementRef;
 
  48   @ViewChild("t_dataFormat") t_dataFormat: ElementRef;
 
  49   @ViewChild("t_ttl") t_ttl: ElementRef;
 
  52     public activeModal: NgbActiveModal,
 
  53     public adminService: AdminService,
 
  54     private restApiService: RestApiService
 
  67       dataFormat: this.dataFormats[0],
 
  69       correlateClearedMessage: false,
 
  73     this.TopicInput = new Topic();
 
  75         name: this.newTopic.name,
 
  76         login: this.newTopic.login,
 
  77         password:this.newTopic.password,
 
  78         sinkdbs: this.newTopic.sinkdbs,
 
  79         enabled: this.newTopic.enabled,
 
  80         saveRaw: this.newTopic.saveRaw,
 
  81         dataFormat: this.newTopic.dataFormat,
 
  82         ttl: this.newTopic.ttl,
 
  83         correlateClearedMessage: this.newTopic.correlateClearedMessage,
 
  84         messageIdPath: this.newTopic.messageIdPath,
 
  87     this.TopicInput = feeds;
 
  88     this. idExFields = [];
 
  89     if (this.TopicInput.messageIdPath != null) {
 
  90       var feed = this.TopicInput.messageIdPath.split(",");
 
  91       for (var i = 0; i < feed.length; i++) {
 
  92         var data = { item: feed[i] };
 
  93         this.idExFields.push(data);
 
  96       this.idExFields.push([]);
 
 102     this.restApiService.getDbList().subscribe((data: {}) => {
 
 107   updateSelectedDB(event: any, name: string) {
 
 108     if (event.target.checked) {
 
 109       if (!this.tempSeletedDbs.find(db => db === name)) {
 
 110         this.tempSeletedDbs.push(name);
 
 113       const index = this.tempSeletedDbs.indexOf(name, 0);
 
 115         this.tempSeletedDbs.splice(index, 1);
 
 121     this.idExFields.push(this.idExNewField);
 
 122     this.idExNewField = {};
 
 125   deleteIdField(index: number) {
 
 126     if (this.idExFields.length > 1) {
 
 127       this.idExFields.splice(index, 1);
 
 132     this.newTopic = this.TopicInput;
 
 133     this.newTopic.name = this.t_topicname.nativeElement.value;
 
 134     this.newTopic.login = this.t_login.nativeElement.value;
 
 135     this.newTopic.password = this.t_password.nativeElement.value;
 
 136     this.newTopic.sinkdbs = this.tempSeletedDbs;
 
 137     this.newTopic.dataFormat = this.t_dataFormat.nativeElement.value;
 
 138     this.newTopic.ttl = this.t_ttl.nativeElement.value;
 
 139     this.newTopic.messageIdPath = "";
 
 140     for (var i = 0; i < this.idExFields.length; i++) {
 
 141       let item = "/"+this.idExFields[i].item;
 
 143         this.newTopic.messageIdPath = item;
 
 145         this.newTopic.messageIdPath =
 
 146           this.newTopic.messageIdPath + "," + item;
 
 150     if (this.newTopic.sinkdbs.length == 0) {
 
 153     console.log(this.newTopic);
 
 154     this.passEntry.emit(this.newTopic);