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.
18 * @author Chunmeng Guo
21 import {Component, EventEmitter, Input, OnInit, Output, ElementRef, ViewChild} from '@angular/core';
23 import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
24 import { RestApiService } from "src/app/core/services/rest-api.service";
25 import { NgxSpinnerService } from "ngx-spinner";
27 import { Kafka } from "../../../../core/models/kafka.model";
30 selector: 'app-new-kafka-modal',
31 templateUrl: './new-kafka-modal.component.html',
32 styleUrls: ['./new-kafka-modal.component.css']
34 export class NewKafkaModalComponent implements OnInit {
35 @Input() kafka: Kafka;
36 @Input() kafkaList_length;
37 @Output() passEntry: EventEmitter<any> = new EventEmitter();
39 exTopicFields: Array<any> = [];
40 exTopicNewField: any = {};
41 protocols: Array<string> = ["SASL_PLAINTEXT"];
43 @ViewChild("k_name") k_name: ElementRef;
44 @ViewChild("k_login") k_login: ElementRef;
45 @ViewChild("k_pass") k_pass: ElementRef;
46 @ViewChild("k_enabled") k_enabled: ElementRef;
47 @ViewChild("k_brokerList") k_brokerList: ElementRef;
48 @ViewChild("k_zooKeeper") k_zooKeeper: ElementRef;
49 @ViewChild("k_group") k_group: ElementRef;
50 @ViewChild("k_secure") k_secure: ElementRef;
51 @ViewChild("k_securityProtocol") k_securityProtocol: ElementRef;
52 @ViewChild("k_includedTopic") k_includedTopic: ElementRef;
53 @ViewChild("k_excludedTopic") k_excludedTopic: ElementRef;
54 @ViewChild("k_consumerCount") k_consumerCount: ElementRef;
55 @ViewChild("k_timeout") k_timeout: ElementRef;
58 private activeModal: NgbActiveModal,
59 private kafkaApiService: RestApiService,
60 private spinner: NgxSpinnerService
65 this.kafkaInput = new Kafka();
68 name: this.kafka.name,
69 enabled: this.kafka.enabled,
70 brokerList: this.kafka.brokerList,
71 zooKeeper: this.kafka.zooKeeper,
72 group: this.kafka.group,
73 secure: this.kafka.secure,
74 login: this.kafka.login,
75 pass: this.kafka.pass,
76 securityProtocol: this.kafka.securityProtocol,
77 includedTopic: this.kafka.includedTopic,
78 excludedTopic: this.kafka.excludedTopic,
79 consumerCount: this.kafka.consumerCount,
80 timeout: this.kafka.timeout
82 this.kafkaInput = feed;
83 this.exTopicFields = [];
84 if (this.kafkaInput.excludedTopic != null) {
85 var feeds = this.kafkaInput.excludedTopic.split(",");
86 for (var i = 0; i < feeds.length; i++) {
87 var data = { item: feed[i] };
88 this.exTopicFields.push(data);
91 this.exTopicFields.push([]);
97 if (this.kafkaInput.name == '' || this.kafkaInput.name == undefined) {
100 this.kafka = this.kafkaInput;
101 this.kafka.securityProtocol = this.k_securityProtocol.nativeElement.value;
102 for (var i = 0; i < this.exTopicFields.length; i++) {
103 let item = this.exTopicFields[i].item;
105 this.kafka.excludedTopic = item;
107 this.kafka.excludedTopic = this.kafka.excludedTopic + "," + item;
110 console.log(this.kafka);
111 this.passEntry.emit(this.kafka);
116 this.exTopicFields.push(this.exTopicNewField);
117 this.exTopicNewField = {};
120 deleteExTopicField(index: number) {
121 if (this.exTopicFields.length > 1) {
122 this.exTopicFields.splice(index, 1);