2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2019 - 2020 QCT
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
27 import { Component, OnInit, Input, ViewChild } from "@angular/core";
29 import { NgbActiveModal, NgbTypeahead } from "@ng-bootstrap/ng-bootstrap";
30 import { RestApiService } from "src/app/core/services/rest-api.service";
31 import { AdminService } from "src/app/core/services/admin.service";
32 import { Topic } from "src/app/core/models/topic.model";
39 } from "rxjs/operators";
40 import { from, Subject, Observable, merge } from "rxjs";
41 import { Kafka } from "src/app/core/models/kafka.model";
42 import { Db } from "src/app/core/models/db.model";
45 selector: "app-topic-modal",
46 templateUrl: "./topic-modal.component.html",
47 styleUrls: ["./topic-modal.component.css"]
49 export class TopicModalComponent implements OnInit {
51 @Input() mode: string;
52 @Input() selectedIndex: number;
54 dataFormats: Array<string> = ["JSON", "XML"];
55 idExFields: Array<any> = [];
56 idExNewField: any = {};
58 kafkas: Array<Kafka> = [];
60 dbTypeIds: Array<string> = [];
63 @ViewChild("instance") instance: NgbTypeahead;
64 focus$ = new Subject<string>();
65 click$ = new Subject<string>();
66 newTopicList: Array<string>;
68 search = (text$: Observable<string>) => {
69 const debouncedText$ = text$.pipe(
71 distinctUntilChanged()
73 const clicksWithClosedPopup$ = this.click$.pipe(
74 filter(() => !this.instance.isPopupOpen())
76 const inputFocus$ = this.focus$;
78 return merge(debouncedText$, inputFocus$, clicksWithClosedPopup$).pipe(
82 : this.newTopicList.filter(
83 v => v.toLowerCase().indexOf(term.toLowerCase()) > -1
91 public activeModal: NgbActiveModal,
92 public adminService: AdminService,
93 private restApiService: RestApiService
97 // Get ID extration field
99 if (this.data.messageIdPath != null) {
100 let feed = this.data.messageIdPath.split(",");
101 for (let i = 0; i < feed.length; i++) {
102 let data = { item: feed[i] };
103 this.idExFields.push(data);
106 this.idExFields.push([]);
117 if (this.mode === "new") {
118 this.getNewTopicList();
123 const get_kafkas = this.restApiService.getAllKafka().pipe(
124 mergeMap(ks => from(ks)),
128 this.data.kafkas.toString().includes(k.id.toString())
130 k.checkedToSave = true;
132 k.checkedToSave = false;
138 get_kafkas.subscribe();
142 const get_dbs = this.restApiService.getAllDbs().pipe(
143 mergeMap(dbs => from(dbs)),
145 if (!this.dbTypeIds.includes(db.dbTypeId)) {
146 this.dbTypeIds.push(db.dbTypeId);
150 this.data.sinkdbs.toString().includes(db.id.toString())
152 db.checkedToSave = true;
154 db.checkedToSave = false;
164 const get_topicName = this.restApiService.getTopicNames().pipe(
166 this.newTopicList = names;
170 get_topicName.subscribe();
173 onChabgeSelKafka(checked: boolean, id: string | number) {
175 if (!this.data.kafkas) this.data.kafkas = [];
178 // Add kafka_id into topic.kafkas
181 !this.data.kafkas.toString().includes(id.toString())
183 this.data.kafkas.push(id.toString());
186 // Remove kafka_id from topic.kafkas
189 this.data.kafkas.toString().includes(id.toString())
191 this.data.kafkas.forEach((k_id, index) => {
192 if (k_id.toString() === id.toString()) {
193 this.data.kafkas.splice(index, 1);
201 onChabgeSelDb(checked: boolean, id: string | number) {
203 if (!this.data.sinkdbs) this.data.sinkdbs = [];
206 // Add db_id into topic.sinkdbs
209 !this.data.sinkdbs.toString().includes(id.toString())
211 this.data.sinkdbs.push(id.toString());
214 // Remove db_id from "topic.sinkdbs"
217 this.data.sinkdbs.toString().includes(id.toString())
219 this.data.sinkdbs.forEach((db_id, index) => {
220 if (db_id.toString() === id.toString()) {
221 this.data.sinkdbs.splice(index, 1);
229 onClickAddIdField() {
230 this.idExFields.push(this.idExNewField);
231 this.idExNewField = {};
234 onClickDelIdField(index: number) {
235 if (this.idExFields.length > 1) {
236 this.idExFields.splice(index, 1);
240 onChangeSaveIdField() {
241 this.data.messageIdPath = "";
242 for (let i = 0; i < this.idExFields.length; i++) {
244 this.data.messageIdPath = this.idExFields[i].item;
246 this.data.messageIdPath += "," + this.idExFields[i].item;
251 onClickMatTab(index: number) {
252 this.selectedIndex = index;
256 let flag: boolean = false;
258 if (this.mode === "new") flag = true;