b67dff19273b1ebce4567ae54d9730b027ab9acd
[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 { AdminService } from "src/app/core/services/admin.service";
39 import { Topic } from "src/app/core/models/topic.model";
40
41 @Component({
42   selector: "app-topic-config-modal",
43   templateUrl: "./topic-config-modal.component.html",
44   styleUrls: ["./topic-config-modal.component.css"]
45 })
46 export class TopicConfigModalComponent implements OnInit {
47   @Input() topic: Topic;
48   @Input() title: string;
49   @Output() passEntry: EventEmitter<any> = new EventEmitter();
50
51   // page elements
52   dbs: any = [];
53   dataFormats: Array<string> = ["JSON", "XML"];
54   tempSeletedDbs: any = [];
55   tempEnabled: boolean;
56   tempSaveRaw: boolean;
57   @ViewChild("t_login") t_login: ElementRef;
58   @ViewChild("t_password") t_password: ElementRef;
59   @ViewChild("t_dataFormat") t_dataFormat: ElementRef;
60   @ViewChild("t_ttl") t_ttl: ElementRef;
61
62   constructor(
63     public activeModal: NgbActiveModal,
64     public adminService: AdminService,
65     private restApiService: RestApiService
66   ) {
67     this.getDbs();
68   }
69
70   ngOnInit() {
71     // for display
72     this.topic.sinkdbs.forEach(item => {
73       this.tempSeletedDbs.push(item);
74     });
75     this.tempEnabled = this.topic.enabled;
76     this.tempSaveRaw = this.topic.saveRaw;
77   }
78
79   getDbs() {
80     this.dbs = [];
81     this.restApiService.getDbList().subscribe((data: {}) => {
82       this.dbs = data;
83     });
84   }
85
86   updateSelectedDB(event: any, name: string) {
87     if (event.target.checked) {
88       if (!this.tempSeletedDbs.find(db => db === name)) {
89         this.tempSeletedDbs.push(name);
90       }
91     } else {
92       const index = this.tempSeletedDbs.indexOf(name, 0);
93       if (index > -1) {
94         this.tempSeletedDbs.splice(index, 1);
95       }
96     }
97   }
98
99   passBack() {
100     this.topic.enabled = this.tempEnabled;
101     this.topic.login = this.t_login.nativeElement.value;
102     this.topic.password = this.t_password.nativeElement.value;
103     this.topic.sinkdbs = this.tempSeletedDbs;
104     this.topic.dataFormat = this.t_dataFormat.nativeElement.value;
105     this.topic.ttl = this.t_ttl.nativeElement.value;
106     this.topic.saveRaw = this.tempSaveRaw;
107
108     this.passEntry.emit(this.topic);
109   }
110 }