2 * ============LICENSE_START=======================================================
4 * ================================================================================
6 *=================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
25 * @contributor Chunmeng Guo
29 import { Component, OnInit, ViewChild, ElementRef } from "@angular/core";
30 import { Db } from "src/app/core/models/db.model";
31 import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
32 import { DatabaseAddModalComponent } from "src/app/views/database/database-list/database-add-modal/database-add-modal.component";
34 // DB modal components
35 import { RestApiService } from "src/app/core/services/rest-api.service";
38 import { AlertComponent } from "src/app/shared/components/alert/alert.component";
41 import { ToastrNotificationService } from "src/app/shared/components/toastr-notification/toastr-notification.service";
44 import { NgxSpinnerService } from "ngx-spinner";
45 import {CouchbaseComponent} from "src/app/views/database/database-list/dbs-modal/couchbase/couchbase.component";
46 import {DruidComponent} from "src/app/views/database/database-list/dbs-modal/druid/druid.component";
47 import {ElasticsearchComponent} from "src/app/views/database/database-list/dbs-modal/elasticsearch/elasticsearch.component";
48 import {MongodbComponent} from "src/app/views/database/database-list/dbs-modal/mongodb/mongodb.component";
49 import {HdfsComponent} from "src/app/views/database/database-list/dbs-modal/hdfs/hdfs.component";
52 selector: "app-database-list",
53 templateUrl: "./database-list.component.html",
54 styleUrls: ["./database-list.component.css"]
56 export class DatabaseListComponent implements OnInit {
57 pageFinished: Boolean = false;
63 loading: Boolean = true;
65 loadingIndicator: boolean = true;
69 <div class="d-flex justify-content-center">
71 <label class="dl-nodata">No Data</label>
77 @ViewChild("searchText") searchText: ElementRef;
80 private dbApiService: RestApiService,
81 private notificationService: ToastrNotificationService,
82 private modalService: NgbModal,
83 private spinner: NgxSpinnerService
85 this.initData().then(data => {
86 this.initDbsList(this.dbList).then(data => {
98 this.dbList = await this.getDbList(this.flag);
105 return this.dbApiService.getDbEncryptList(flag).toPromise();
109 async initDbsList(dbList: []) {
112 for (var i = 0; i < dbList.length; i++) {
113 let data = dbList[i];
117 enabled: data["enabled"],
120 database: data["database"],
121 encrypt: data["encrypt"],
122 login: data["login"],
124 dbTypeId: data["dbTypeId"],
131 // getDbDetail(name: string) {
132 // return this.restApiService.getDbDetail(name).toPromise();
136 const modalRef = this.modalService.open(DatabaseAddModalComponent, {
137 windowClass: "dl-md-modal",
141 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
144 //this.openDetailModal(receivedEntry);
149 updateFilter(searchValue) {
150 const val = searchValue.toLowerCase();
152 const temps = this.dbList.filter(function (d) {
153 return d.name.toLowerCase().indexOf(val) != -1 || !val;
160 const modalRef = this.modalService.open(DatabaseAddModalComponent, {
161 windowClass: "dl-md-modal dbs",
166 deleteDbModel(id: number) {
168 console.log("delete id", id);
169 const index = this.dbList.findIndex(t => t.id === id);
170 const modalRef = this.modalService.open(AlertComponent, {
174 modalRef.componentInstance.message = "ARE_YOU_SURE_DELETE";
175 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
177 this.dbApiService.deleteDb(id).subscribe(
180 if (JSON.stringify(res).length <= 2) {
181 this.dbList.splice(index, 1);
182 this.dbList = [...this.dbList];
184 this.notificationService.success("SUCCESSFULLY_DELETED");
188 this.notificationService.error("FAILED_DELETED");
194 this.notificationService.error(err);
201 updateDbModel(id: number, dbType: string) {
203 console.log(dbType, "dbType");
206 modalRef = this.modalService.open(CouchbaseComponent, {
210 this.editDbModal(id, modalRef);
214 modalRef = this.modalService.open(DruidComponent, {
218 this.editDbModal(id, modalRef);
222 modalRef = this.modalService.open(ElasticsearchComponent, {
226 this.editDbModal(id, modalRef);
230 modalRef = this.modalService.open(MongodbComponent, {
234 this.editDbModal(id, modalRef);
238 modalRef = this.modalService.open(HdfsComponent, {
242 this.editDbModal(id, modalRef);
251 editDbModal(id: number, modalRef) {
252 console.log("id", id);
253 const index = this.dbList.findIndex(t => t.id === id);
254 modalRef.componentInstance.editDb = this.dbList[index];
255 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
256 this.dbNew = receivedEntry;
258 .updateDb(this.dbNew)
261 if (res.statusCode == 200) {
262 this.dbList[index] = this.dbNew;
263 this.dbList = [...this.dbList];
264 this.notificationService.success("SUCCESSFULLY_UPDATED");
267 this.notificationService.error("FAILED_UPDATED");
273 this.notificationService.error(err);