5c347ad0cb4890a39e72879b9bde5b35400de14d
[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  * @contributor Chunmeng Guo
26  *
27  */
28
29 import {Component, Input, Output, EventEmitter, ViewChild, ElementRef} from "@angular/core";
30 import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
31 import { Db } from "src/app/core/models/db.model";
32 import { AdminService } from "src/app/core/services/admin.service";
33 import {NgxSpinnerService} from "ngx-spinner";
34
35 @Component({
36   selector: "app-couchbase",
37   templateUrl: "./couchbase.component.html",
38   styleUrls: ["./couchbase.component.css"]
39 })
40 export class CouchbaseComponent {
41   @Output() passEntry: EventEmitter<any> = new EventEmitter();
42   @Input() editDb: Db;
43   @Input() db: Db;
44   @Input() dbList_length;
45   dbInput: Db;
46   dbTypeIdList: Array<string> = ["CB"];
47   @ViewChild("d_dbTypeId") d_dbTypeId: ElementRef;
48
49   defaultDbType: string;
50   dbInputTitle = "";
51   constructor(
52     public activeModal: NgbActiveModal,
53     public adminService: AdminService,
54     private spinner: NgxSpinnerService
55   ) { }
56
57   ngOnInit() {
58     if (this.editDb == null) {
59       this.dbInput = new Db();
60       const feed = {
61         id: null,
62         name: this.db.name,
63         enabled: this.db.enabled,
64         host: this.db.host,
65         port: this.db.port,
66         database: this.db.database,
67         encrypt: this.db.encrypt,
68         login: this.db.login,
69         pass: this.db.pass,
70         dbTypeId: this.db.dbTypeId
71       }
72       this.dbInput = feed;
73       this.dbInputTitle = "New Couchbase";
74       console.log("create db");
75
76     } else {
77       this.dbInput = this.editDb;
78       this.dbInputTitle = "Edit" + "-" + this.editDb.dbTypeId + "-" + this.editDb.name;
79       this.defaultDbType = this.dbInput.dbTypeId;
80       console.log("edit db");
81     }
82   }
83
84   passBack() {
85     this.spinner.show();
86     if (this.dbInput.name == '' || this.dbInput.name == undefined) {
87       return false;
88     }
89     this.editDb = this.dbInput;
90     this.editDb.dbTypeId = this.d_dbTypeId.nativeElement.value;
91     console.log(this.editDb, "db");
92     this.passEntry.emit(this.editDb);
93     setTimeout(() => {
94       this.spinner.hide();
95     }, 500);
96   }
97 }