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");
67 this.initData().then(data => {
68 this.initDbsList(this.dbList).then(data => {
70 console.log(this.dbs, "dasboard-dbs[]")
77 this.dbList = await this.getDbList();
85 data = this.dashboardApiService.getDashboardList().toPromise();
89 async initDbsList(dbList: []) {
90 var d: Dashboard[] = [];
92 if (dbList.length > 0) {
93 for (var i = 0; i < dbList.length; i++) {
101 enabled: data["enabled"]
109 openDashboardModal(thisIndex: number) {
112 console.log(index, "index,add or edit");
113 modalRef = this.modalService.open(CreateDashboardComponent, {
117 modalRef.componentInstance.dashboard = this.dbs[index];
118 modalRef.componentInstance.passEntry.subscribe(receiveEntry => {
119 this.dbs[index] = receiveEntry;
120 let host = this.dbs[index].host;
121 let enabled = this.dbs[index].enabled;
122 console.log(receiveEntry);
123 if (enabled == true) {
124 // Db name found, to update db
125 this.dashboardApiService.createUpadteDashboard(this.dbs[index]).subscribe(
128 if (res.statusCode == 200) {
130 this.notificationService.success("SUCCESSFULLY_UPDATED");
132 this.notificationService.error("FAILED_UPDATED");
137 this.notificationService.error(err);
142 this.dashboardApiService.deleteDashboard(this.dbs[thisIndex]).subscribe(
145 if (res.statusCode == 200) {
147 this.notificationService.success("SUCCESSFULLY_DELETED");
149 this.dbs[thisIndex].enabled = true;
150 this.notificationService.error("FAILED_DELETED");
155 this.notificationService.error(err);