30665d874bed0a56c477a8de3b4b446d0e91cf18
[dcaegen2/services.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : DataLake
4  * ================================================================================
5  * Copyright 2019 QCT
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
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 /**
22  *
23  * @author Ekko Chang
24  *
25  * @contributor Chunmeng Guo
26  *
27  */
28
29 import {Component, Output, EventEmitter, ViewChild, ElementRef} from "@angular/core";
30 import {NgbActiveModal, NgbModal} from "@ng-bootstrap/ng-bootstrap";
31 import {CouchbaseComponent} from "src/app/views/database/database-list/dbs-modal/couchbase/couchbase.component";
32 import {DruidComponent} from "src/app/views/database/database-list/dbs-modal/druid/druid.component";
33 import {ElasticsearchComponent} from "src/app/views/database/database-list/dbs-modal/elasticsearch/elasticsearch.component";
34 import {MongodbComponent} from "src/app/views/database/database-list/dbs-modal/mongodb/mongodb.component";
35 import {HdfsComponent} from "src/app/views/database/database-list/dbs-modal/hdfs/hdfs.component";
36 import {Db} from "src/app/core/models/db.model";
37 import {RestApiService} from "src/app/core/services/rest-api.service";
38 import {ToastrNotificationService} from "src/app/shared/components/toastr-notification/toastr-notification.service";
39 import {NgxSpinnerService} from "ngx-spinner";
40
41 @Component({
42   selector: "app-database-add-modal",
43   templateUrl: "./database-add-modal.component.html",
44   styleUrls: ["./database-add-modal.component.css"]
45 })
46 export class DatabaseAddModalComponent {
47   @Output() passEntry: EventEmitter<any> = new EventEmitter();
48   seletedItem: string = "";
49   dbList: any = [];
50   dbs: Db[] = [];
51   loading: Boolean = true;
52   dbNew: Db;
53   db_NewBody: Db;
54   constructor(
55     public activeModal: NgbActiveModal,
56     private spinner: NgxSpinnerService,
57     private notificationService: ToastrNotificationService,
58     private modalService: NgbModal,
59     private dbApiService: RestApiService
60   ) {}
61
62   ngOnInit() {}
63
64   clickItem(name: string) {
65     this.seletedItem = name;
66   }
67
68   passBack() {
69     console.log(this.seletedItem, "next");
70     this.openNewModal(this.seletedItem);
71   }
72
73   newDb(modalRef) {
74     this.dbNew = new Db();
75     this.db_NewBody = new Db();
76     modalRef.componentInstance.db = this.db_NewBody;
77     modalRef.componentInstance.dbList_length = this.dbList.length;
78     modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
79       this.db_NewBody = receivedEntry;
80       this.dbApiService
81         .createDb(this.db_NewBody)
82         .subscribe(
83           res => {
84             this.spinner.hide();
85             if (res.statusCode == 200) {
86               this.dbNew = res.returnBody;
87               this.dbList.push(this.dbNew);
88               this.dbList = [...this.dbList];
89               this.notificationService.success("SUCCESSFULLY_CREARED");
90             } else {
91               this.notificationService.error("FAILED_CREARED");
92             }
93             modalRef.close();
94           },
95           err => {
96             this.spinner.hide();
97             this.notificationService.error(err);
98             modalRef.close();
99           }
100         );
101     });
102   }
103
104   openNewModal(name: string) {
105     var modalRef;
106
107     switch (name) {
108       case "Couchbase": {
109         modalRef = this.modalService.open(CouchbaseComponent, {
110           size: "lg",
111           centered: true
112         });
113         this.newDb(modalRef);
114         break;
115       }
116       case "Druid": {
117         modalRef = this.modalService.open(DruidComponent, {
118           size: "lg",
119           centered: true
120         });
121         this.newDb(modalRef);
122         break;
123       }
124       case "Elasticsearch": {
125         modalRef = this.modalService.open(ElasticsearchComponent, {
126           size: "lg",
127           centered: true
128         });
129         this.newDb(modalRef);
130         break;
131       }
132       case "MongoDB": {
133         modalRef = this.modalService.open(MongodbComponent, {
134           size: "lg",
135           centered: true
136         });
137         this.newDb(modalRef);
138         break;
139       }
140       case "HDFS": {
141         modalRef = this.modalService.open(HdfsComponent, {
142           size: "lg",
143           centered: true
144         });
145         this.newDb(modalRef);
146         break;
147       }
148       default: {
149         break;
150       }
151     }
152   }
153 }