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 selectedLangs = sessionStorage.getItem("selectedLang");
47 dashboardDeteleModelShow = true;
52 private adminService: AdminService,
53 private dashboardApiService: DashboardApiService,
54 private notificationService: ToastrNotificationService,
55 private modalService: NgbModal,
56 private spinner: NgxSpinnerService
59 this.adminService.setTitle("SIDEBAR.DASHBOARDLIST");
61 this.initData().then(data => {
62 this.initDbsList(this.dbList).then(data => {
64 console.log(this.dbs, "dasboard-dbs[]")
76 this.dbList = await this.getDbList();
84 data = this.dashboardApiService.getDashboardList().toPromise();
88 async initDbsList(dbList: []) {
89 var d: Dashboard[] = [];
91 if (dbList.length > 0) {
92 for (var i = 0; i < dbList.length; i++) {
100 enabled: data["enabled"]
108 openDashboardModal(thisIndex: number) {
110 this.selectedLangs = sessionStorage.getItem("selectedLang");
113 console.log(index, "index,add or edit");
114 modalRef = this.modalService.open(CreateDashboardComponent, {
118 modalRef.componentInstance.dashboard = this.dbs[index];
119 modalRef.componentInstance.passEntry.subscribe(receiveEntry => {
120 this.dbs[index] = receiveEntry;
121 let host = this.dbs[index].host;
122 let enabled = this.dbs[index].enabled;
123 console.log(receiveEntry);
124 if (enabled == true) {
125 // Db name found, to update db
126 this.dashboardApiService.createUpadteDashboard(this.dbs[index]).subscribe(
129 if (res.statusCode == 200) {
131 if (this.selectedLangs == "en-us") {
132 tips = "Success updated."
133 } else if (this.selectedLangs == "zh-hans") {
135 } else if (this.selectedLangs == "zh-hant") {
138 this.notificationService.success('"' + host + '"' + tips);
140 if (this.selectedLangs == "en-us") {
141 tips = "Fail updated."
142 } else if (this.selectedLangs == "zh-hans") {
144 } else if (this.selectedLangs == "zh-hant") {
147 this.notificationService.error('"' + host + '"' + tips);
152 this.notificationService.error(err);
157 this.dashboardApiService.deleteDashboard(this.dbs[thisIndex]).subscribe(
160 if (res.statusCode == 200) {
162 if (this.selectedLangs == "en-us") {
163 tips = "Success deleted."
164 } else if (this.selectedLangs == "zh-hans") {
166 } else if (this.selectedLangs == "zh-hant") {
169 this.notificationService.success('"' + host + '"' + tips);
171 this.dbs[thisIndex].enabled = true;
172 if (this.selectedLangs == "en-us") {
173 tips = "Fail deleted."
174 } else if (this.selectedLangs == "zh-hans") {
176 } else if (this.selectedLangs == "zh-hant") {
179 this.notificationService.error('"' + host + '"' + tips);
184 this.notificationService.error(err);