36ea1dc6bea77411eb2cb51d36593bad34f0e094
[dcaegen2/services.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : DataLake
4  * ================================================================================
5  * Copyright 2019 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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 /**
22  *
23  * @author Ekko Chang
24  *
25  */
26
27 import {
28   Component,
29   OnInit,
30   Input,
31   Output,
32   EventEmitter,
33   ViewChild,
34   ElementRef
35 } from "@angular/core";
36 import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
37 import { RestApiService } from "src/app/core/services/rest-api.service";
38 import { Topic } from "src/app/core/models/topic.model";
39
40 @Component({
41   selector: "app-topic-config-modal",
42   templateUrl: "./topic-config-modal.component.html",
43   styleUrls: ["./topic-config-modal.component.css"]
44 })
45 export class TopicConfigModalComponent implements OnInit {
46   @Input() topic: Topic;
47   @Input() title: string;
48   @Output() passEntry: EventEmitter<any> = new EventEmitter();
49
50   // page elements
51   dbs: any = [];
52   dataFormats: Array<string> = ["JSON", "XML"];
53   tempSeletedDbs: any = [];
54   tempEnabled: boolean;
55   tempSaveRaw: boolean;
56   @ViewChild("t_login") t_login: ElementRef;
57   @ViewChild("t_password") t_password: ElementRef;
58   @ViewChild("t_dataFormat") t_dataFormat: ElementRef;
59   @ViewChild("t_ttl") t_ttl: ElementRef;
60
61   constructor(
62     public activeModal: NgbActiveModal,
63     private restApiService: RestApiService
64   ) {
65     this.getDbs();
66   }
67
68   ngOnInit() {
69     // for display
70     this.topic.sinkdbs.forEach(item => {
71       this.tempSeletedDbs.push(item);
72     });
73     this.tempEnabled = this.topic.enabled;
74     this.tempSaveRaw = this.topic.saveRaw;
75   }
76
77   getDbs() {
78     this.dbs = [];
79     this.restApiService.getDbList().subscribe((data: {}) => {
80       //console.log(data);
81       this.dbs = data;
82     });
83   }
84
85   updateSelectedDB(event: any, name: string) {
86     if (event.target.checked) {
87       console.log("checked");
88       if (!this.tempSeletedDbs.find(db => db === name)) {
89         this.tempSeletedDbs.push(name);
90       }
91     } else {
92       console.log("unchecked");
93       const index = this.tempSeletedDbs.indexOf(name, 0);
94       if (index > -1) {
95         this.tempSeletedDbs.splice(index, 1);
96       }
97     }
98   }
99
100   passBack() {
101     this.topic.enabled = this.tempEnabled;
102     this.topic.login = this.t_login.nativeElement.value;
103     this.topic.password = this.t_password.nativeElement.value;
104     this.topic.sinkdbs = this.tempSeletedDbs;
105     this.topic.dataFormat = this.t_dataFormat.nativeElement.value;
106     this.topic.ttl = this.t_ttl.nativeElement.value;
107     this.topic.saveRaw = this.tempSaveRaw;
108
109     console.log("==================================");
110     console.log("Update topic name: " + this.topic.name);
111     console.log("Update topic login: " + this.topic.login);
112     console.log("Update topic password: " + this.topic.password);
113     console.log("Update topic sinkdbs: " + this.topic.sinkdbs);
114     console.log("Update topic enabled: " + this.topic.enabled);
115     console.log("Update topic saveRaw: " + this.topic.saveRaw);
116     console.log("Update topic dataFormat: " + this.topic.dataFormat);
117     console.log("Update topic ttl: " + this.topic.ttl);
118     console.log("==================================");
119
120     this.passEntry.emit(this.topic);
121   }
122 }