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
 
  68       dataFormat: this.dataFormats[0],
 
  70       correlateClearedMessage: false,
 
  74     this.TopicInput = new Topic();
 
  76       name: this.newTopic.name,
 
  77       login: this.newTopic.login,
 
  78       password: this.newTopic.password,
 
  79       sinkdbs: this.newTopic.sinkdbs,
 
  80       enabledSinkdbs: this.newTopic.sinkdbs,
 
  81       enabled: this.newTopic.enabled,
 
  82       saveRaw: this.newTopic.saveRaw,
 
  83       dataFormat: this.newTopic.dataFormat,
 
  84       ttl: this.newTopic.ttl,
 
  85       correlateClearedMessage: this.newTopic.correlateClearedMessage,
 
  86       messageIdPath: this.newTopic.messageIdPath,
 
  89     this.TopicInput = feeds;
 
  91     if (this.TopicInput.messageIdPath != null) {
 
  92       var feed = this.TopicInput.messageIdPath.split(",");
 
  93       for (var i = 0; i < feed.length; i++) {
 
  94         var data = { item: feed[i] };
 
  95         this.idExFields.push(data);
 
  98       this.idExFields.push([]);
 
 104     this.restApiService.getDbList().subscribe((data: {}) => {
 
 109   updateSelectedDB(event: any, name: string) {
 
 110     if (event.target.checked) {
 
 111       if (!this.tempSeletedDbs.find(db => db === name)) {
 
 112         this.tempSeletedDbs.push(name);
 
 115       const index = this.tempSeletedDbs.indexOf(name, 0);
 
 117         this.tempSeletedDbs.splice(index, 1);
 
 123     this.idExFields.push(this.idExNewField);
 
 124     this.idExNewField = {};
 
 127   deleteIdField(index: number) {
 
 128     if (this.idExFields.length > 1) {
 
 129       this.idExFields.splice(index, 1);
 
 134     this.newTopic = this.TopicInput;
 
 135     this.newTopic.name = this.t_topicname.nativeElement.value;
 
 136     this.newTopic.login = this.t_login.nativeElement.value;
 
 137     this.newTopic.password = this.t_password.nativeElement.value;
 
 138     this.newTopic.sinkdbs = this.tempSeletedDbs;
 
 139     this.newTopic.dataFormat = this.t_dataFormat.nativeElement.value;
 
 140     this.newTopic.ttl = this.t_ttl.nativeElement.value;
 
 141     this.newTopic.messageIdPath = "";
 
 142     for (var i = 0; i < this.idExFields.length; i++) {
 
 143       let item = "/" + this.idExFields[i].item;
 
 145         this.newTopic.messageIdPath = item;
 
 147         this.newTopic.messageIdPath =
 
 148           this.newTopic.messageIdPath + "," + item;
 
 152     if (this.newTopic.sinkdbs.length == 0) {
 
 155     console.log(this.newTopic);
 
 156     this.passEntry.emit(this.newTopic);