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 {DashboardApiService} from "src/app/core/services/dashboard-api.service";
26 import {AlertComponent} from "src/app/core/alert/alert.component";
29 import {ToastrNotificationService} from "src/app/core/services/toastr-notification.service";
31 import {NgxSpinnerService} from "ngx-spinner";
34 selector: 'app-dashboard-list',
35 templateUrl: './dashboard-list.component.html',
36 styleUrls: ['./dashboard-list.component.css']
38 export class DashboardListComponent implements OnInit {
39 @Output() passEntry: EventEmitter<any> = new EventEmitter();
41 dbs: Dashboard[] = [];
43 loading: Boolean = true;
45 tempDbDetail: Dashboard;
46 dashboardDeteleModelShow = true;
51 private adminService: AdminService,
52 private dashboardApiService: DashboardApiService,
53 private notificationService: ToastrNotificationService,
54 private modalService: NgbModal,
55 private spinner: NgxSpinnerService
58 this.adminService.setTitle("SIDEBAR.DASHBOARDLIST");
60 this.initData().then(data => {
61 this.initDbsList(this.dbList).then(data => {
63 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);