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;
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();
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"]
111 this.openDashboardModal(thisIndex);
114 openDashboardModal(thisIndex: number) {
116 this.selectedLangs = sessionStorage.getItem("selectedLang");
121 console.log(index, "index,add or edit");
122 this.tempDbDetail = new Dashboard();
124 modalRef = this.modalService.open(CreateDashboardComponent, {
128 modalRef.componentInstance.dashboard = this.dbs[index];
130 if(this.nameArr.length == 0 && this.dbs.length>0){
131 console.log("All types have been created, you cannot create existing types again.");
134 modalRef = this.modalService.open(CreateDashboardComponent, {
138 modalRef.componentInstance.dashboard = this.tempDbDetail;
142 modalRef.componentInstance.nameArr = this.nameArr;
143 modalRef.componentInstance.passEntry.subscribe(receiveEntry => {
144 this.tempDbDetail = receiveEntry;
145 let host = this.tempDbDetail.host;
146 console.log(receiveEntry);
148 // Db name found, to update db
149 this.dashboardApiService.upadteDashboard(this.tempDbDetail).subscribe(
152 if (res.statusCode == 200) {
153 this.dbs[index] = this.tempDbDetail;
154 if (this.selectedLangs == "en-us") {
155 tips = "Success updated."
156 } else if (this.selectedLangs == "zh-hans") {
158 } else if (this.selectedLangs == "zh-hant") {
161 this.notificationService.success('"' + host + '"' + tips);
163 if (this.selectedLangs == "en-us") {
164 tips = "Fail updated."
165 } else if (this.selectedLangs == "zh-hans") {
167 } else if (this.selectedLangs == "zh-hant") {
170 this.notificationService.error('"' + host + '"' + tips);
175 this.notificationService.error(err);
180 // Db name not found, to insert db
181 this.dashboardApiService.addDashboard(this.tempDbDetail).subscribe(
185 if (res.statusCode == 200) {
186 this.dbs.push(this.tempDbDetail);
187 this.dbs = [...this.dbs];
189 if (this.selectedLangs == "en-us") {
190 tips = "Success inserted."
191 } else if (this.selectedLangs == "zh-hans") {
193 } else if (this.selectedLangs == "zh-hant") {
196 this.notificationService.success('"' + host + '"' + tips);
198 if (this.selectedLangs == "en-us") {
199 tips = "Fail inserted."
200 } else if (this.selectedLangs == "zh-hans") {
202 } else if (this.selectedLangs == "zh-hant") {
205 this.notificationService.error('"' + host + '"' + tips);
210 this.notificationService.error(err);
218 deleteDashboard(thisIndex: number) {
219 this.selectedLangs = sessionStorage.getItem("selectedLang");
220 const index = thisIndex, host = this.dbs[thisIndex]["host"];
222 if (this.selectedLangs == "en-us") {
223 tips = "Are you sure you want to delete ";
224 } else if (this.selectedLangs == "zh-hans") {
226 } else if (this.selectedLangs == "zh-hant") {
229 const modalRef = this.modalService.open(AlertComponent, {
233 modalRef.componentInstance.dashboardDeteleModelShow = this.dashboardDeteleModelShow;
234 modalRef.componentInstance.message =
235 tips + '"'+host + '"' + ' ?';
236 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
238 this.dbs[thisIndex].enabled = false;
239 this.dashboardApiService.deleteDashboard(this.dbs[thisIndex]).subscribe(
242 if (res.statusCode == 200) {
243 // this.dbs[index].enabled = false;
244 this.dbs.splice(index, 1);
246 if (this.selectedLangs == "en-us") {
247 tips = "Success deleted."
248 } else if (this.selectedLangs == "zh-hans") {
250 } else if (this.selectedLangs == "zh-hant") {
253 this.notificationService.success('"' + host + '"' + tips);
255 this.dbs[thisIndex].enabled = true;
256 if (this.selectedLangs == "en-us") {
257 tips = "Fail deleted."
258 } else if (this.selectedLangs == "zh-hans") {
260 } else if (this.selectedLangs == "zh-hant") {
263 this.notificationService.error('"' + host + '"' + tips);
268 this.notificationService.error(err);
276 this.dashboardApiService.getDashboardName().subscribe(data => {
278 console.log(this.nameArr,"this.nameArr111");
280 console.log(this.nameArr,"this.nameArr222");