2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   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, ViewChild, ElementRef } from "@angular/core";
 
  28 import { Db } from "../../../core/models/db.model";
 
  29 import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
 
  30 import { DatabaseAddModalComponent } from "./database-add-modal/database-add-modal.component";
 
  32 // DB modal components
 
  33 import { RestApiService } from "src/app/core/services/rest-api.service";
 
  36 import { CouchbaseComponent } from "./dbs-modal/couchbase/couchbase.component";
 
  37 import { DruidComponent } from "./dbs-modal/druid/druid.component";
 
  38 import { ElasticsearchComponent } from "./dbs-modal/elasticsearch/elasticsearch.component";
 
  39 import { MongodbComponent } from "./dbs-modal/mongodb/mongodb.component";
 
  40 import { HdfsComponent } from "./dbs-modal/hdfs/hdfs.component";
 
  41 import { AlertComponent } from "src/app/shared/components/alert/alert.component";
 
  44 import { ToastrNotificationService } from "src/app/shared/components/toastr-notification/toastr-notification.service";
 
  47 import { NgxSpinnerService } from "ngx-spinner";
 
  50   selector: "app-database-list",
 
  51   templateUrl: "./database-list.component.html",
 
  52   styleUrls: ["./database-list.component.css"]
 
  54 export class DatabaseListComponent implements OnInit {
 
  55   pageFinished: Boolean = false;
 
  60   loading: Boolean = true;
 
  65     private restApiService: RestApiService,
 
  66     private notificationService: ToastrNotificationService,
 
  67     private modalService: NgbModal,
 
  68     private spinner: NgxSpinnerService
 
  70     this.initData().then(data => {
 
  71       this.initDbsList(this.dbList).then(data => {
 
  83     this.dbList = await this.getDbList();
 
  92     data = this.restApiService.getDbList().toPromise();
 
  97   async initDbsList(dbList: []) {
 
 100     if (dbList.length > 0) {
 
 101       for (var i = 0; i < dbList.length; i++) {
 
 102         let data = await this.getDbDetail(dbList[i]);
 
 105           enabled: data.enabled,
 
 108           database: data.database,
 
 109           encrypt: data.encrypt,
 
 119   getDbDetail(name: string) {
 
 120     return this.restApiService.getDbDetail(name).toPromise();
 
 124     const modalRef = this.modalService.open(DatabaseAddModalComponent, {
 
 125       windowClass: "dl-md-modal",
 
 129     modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
 
 132         this.openDetailModal(receivedEntry);
 
 137   openDetailModal(name: string) {
 
 142         modalRef = this.modalService.open(CouchbaseComponent, {
 
 149         modalRef = this.modalService.open(DruidComponent, {
 
 155       case "Elasticsearch": {
 
 156         modalRef = this.modalService.open(ElasticsearchComponent, {
 
 163         modalRef = this.modalService.open(MongodbComponent, {
 
 170         modalRef = this.modalService.open(HdfsComponent, {
 
 181     index = this.dbs.findIndex(d => d.name === name);
 
 182     this.tempDbDetail = new Db();
 
 184       modalRef.componentInstance.db = this.dbs[index];
 
 186       modalRef.componentInstance.db = this.tempDbDetail;
 
 188     modalRef.componentInstance.passEntry.subscribe(receiveEntry => {
 
 189       this.tempDbDetail = receiveEntry;
 
 190       let enabled = receiveEntry.enabled;
 
 191       console.log(this.tempDbDetail, "this.tempDbDetail");
 
 192       if (enabled == true) {
 
 193         this.restApiService.upadteDb(this.tempDbDetail).subscribe(
 
 196             if (res.statusCode == 200) {
 
 197               this.dbs[index] = this.tempDbDetail;
 
 198               this.notificationService.success("SUCCESSFULLY_UPDATED");
 
 200               this.notificationService.error("FAILED_UPDATED");
 
 205             this.notificationService.error(err);
 
 210         this.restApiService.upadteDb(this.dbs[index]).subscribe(
 
 213             if (res.statusCode == 200) {
 
 214               this.dbs[index] = this.tempDbDetail;
 
 215               this.notificationService.success("SUCCESSFULLY_DELETED");
 
 217               this.dbs[index].encrypt = true;
 
 222             this.notificationService.error(err);