2     Copyright (C) 2019 CMCC, Inc. and others. All rights reserved.
 
   4     Licensed under the Apache License, Version 2.0 (the "License");
 
   5     you may not use this file except in compliance with the License.
 
   6     You may obtain a copy of the License at
 
   8             http://www.apache.org/licenses/LICENSE-2.0
 
  10     Unless required by applicable law or agreed to in writing, software
 
  11     distributed under the License is distributed on an "AS IS" BASIS,
 
  12     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  13     See the License for the specific language governing permissions and
 
  14     limitations under the License.
 
  16 import { Component, EventEmitter, OnInit, Output } from '@angular/core';
 
  17 import { Dashboard } from "../../core/models/dashboard.model";
 
  18 import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
 
  19 import { CreateDashboardComponent } from "./create-dashboard/create-dashboard.component";
 
  21 import { AdminService } from "../../core/services/admin.service";
 
  23 // DB modal components
 
  24 import { RestApiService } from "src/app/core/services/rest-api.service";
 
  27 import { ToastrNotificationService } from "src/app/core/services/toastr-notification.service";
 
  29 import { NgxSpinnerService } from "ngx-spinner";
 
  32   selector: 'app-dashboard-list',
 
  33   templateUrl: './dashboard-list.component.html',
 
  34   styleUrls: ['./dashboard-list.component.css']
 
  36 export class DashboardListComponent implements OnInit {
 
  37   @Output() passEntry: EventEmitter<any> = new EventEmitter();
 
  39   dbs: Dashboard[] = [];
 
  41   loading: Boolean = true;
 
  43   tempDbDetail: Dashboard;
 
  44   dashboardDeteleModelShow = true;
 
  49     private adminService: AdminService,
 
  50     private dashboardApiService: RestApiService,
 
  51     private notificationService: ToastrNotificationService,
 
  52     private modalService: NgbModal,
 
  53     private spinner: NgxSpinnerService
 
  56     this.adminService.setTitle("SIDEBAR.DASHBOARDLIST");
 
  65     this.initData().then(data => {
 
  66       this.initDbsList(this.dbList).then(data => {
 
  68         console.log(this.dbs, "dasboard-dbs[]")
 
  75     this.dbList = await this.getDbList();
 
  83     data = this.dashboardApiService.getDashboardList().toPromise();
 
  87   async initDbsList(dbList: []) {
 
  88     var d: Dashboard[] = [];
 
  90     if (dbList.length > 0) {
 
  91       for (var i = 0; i < dbList.length; i++) {
 
  99           enabled: data["enabled"]
 
 107   openDashboardModal(thisIndex: number) {
 
 110     console.log(index, "index,add or edit");
 
 111     modalRef = this.modalService.open(CreateDashboardComponent, {
 
 115     modalRef.componentInstance.dashboard = this.dbs[index];
 
 116     modalRef.componentInstance.passEntry.subscribe(receiveEntry => {
 
 117       this.dbs[index] = receiveEntry;
 
 118       let host = this.dbs[index].host;
 
 119       let enabled = this.dbs[index].enabled;
 
 120       console.log(receiveEntry);
 
 121       if (enabled == true) {
 
 122         // Db name found, to update db
 
 123         this.dashboardApiService.createUpadteDashboard(this.dbs[index]).subscribe(
 
 126             if (res.statusCode == 200) {
 
 128               this.notificationService.success("SUCCESSFULLY_UPDATED");
 
 130               this.notificationService.error("FAILED_UPDATED");
 
 135             this.notificationService.error(err);
 
 140         this.dashboardApiService.deleteDashboard(this.dbs[thisIndex]).subscribe(
 
 143             if (res.statusCode == 200) {
 
 145               this.notificationService.success("SUCCESSFULLY_DELETED");
 
 147               this.dbs[thisIndex].enabled = true;
 
 148               this.notificationService.error("FAILED_DELETED");
 
 153             this.notificationService.error(err);