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, OnInit, ViewChild, ElementRef} from '@angular/core';
17 import {DashboardApiService} from "src/app/core/services/dashboard-api.service";
18 import {NgbModal} from "@ng-bootstrap/ng-bootstrap";
19 import {Template,newTemplate} from "src/app/core/models/template.model";
21 import {NgxSpinnerService} from "ngx-spinner";
24 import {NewTemplateModalComponent} from "./new-template-modal/new-template-modal.component";
25 import {EditTemplateModalComponent} from "./edit-template-modal/edit-template-modal.component";
26 import {AlertComponent} from "src/app/core/alert/alert.component";
28 import {ToastrNotificationService} from "src/app/core/services/toastr-notification.service";
31 selector: 'app-template-list',
32 templateUrl: './template-list.component.html',
33 styleUrls: ['./template-list.component.css']
35 export class TemplateListComponent {
36 template_list: any = [];
37 templates: Template[] = [];
38 temps: Template[] = [];
39 Template_New: Template;
40 Template_Newbody: newTemplate;
41 dashboardDeteleModelShow = true;
42 loadingIndicator: boolean = true;
45 <div class="d-flex justify-content-center">
47 <label class="dl-nodata">No Data</label>
52 @ViewChild("searchText") searchText: ElementRef;
54 private modalService: NgbModal,
55 private dashboardApiService: DashboardApiService,
56 private spinner: NgxSpinnerService,
57 private notificationService: ToastrNotificationService,
60 this.loadingIndicator = false;
63 this.initData().then(data => {
64 this.initTemplateList(this.template_list).then(
66 // for cache of datatable
67 this.temps = [...data];
68 this.templates = data;
82 this.template_list = [];
83 this.template_list = await this.getTemplateList();
84 this.Template_New = new Template();
85 this.Template_Newbody = new newTemplate();
91 return this.dashboardApiService.getTemplateAll().toPromise();
94 async initTemplateList(template_list: []) {
95 var t: Template[] = [];
96 for (var i = 0; i < template_list.length; i++) {
97 let data = template_list[i];
101 submitted: data["submitted"],
104 topic: data["topic"],
105 designType: data["designType"],
114 const modalRef = this.modalService.open(NewTemplateModalComponent, {
115 windowClass: "dl-md-modal templatess",
118 this.Template_New = new Template();
119 this.Template_Newbody = new newTemplate();
120 modalRef.componentInstance.template = this.Template_Newbody;
121 modalRef.componentInstance.templatelist_length = this.template_list.length;
122 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
123 this.Template_Newbody = receivedEntry;
124 let name = this.Template_Newbody.name;
125 this.dashboardApiService
126 .createNewTemplate(this.Template_Newbody)
129 if (res.statusCode == 200) {
130 this.Template_New = res.returnBody;
131 console.log(this.Template_New,"this.Template_New add Success");
132 this.template_list.push(this.Template_New);
133 this.template_list = [...this.template_list];
134 console.log(this.template_list, "this.template_list,inserted");
135 this.notificationService.success("SUCCESSFULLY_CREARED");
137 this.notificationService.error("FAILED_CREARED");
142 this.notificationService.error(err);
150 const emitType = event.type;
151 if(emitType == "dblclick"){
152 console.log('Activate Event', event);
153 let id = event.row.id;
154 this.editTemplateModal(id);
159 editTemplateModal(id) {
160 const index = this.template_list.findIndex(t => t.id === id);
161 // const name = this.template_list[index].name;
162 const modalRef = this.modalService.open(EditTemplateModalComponent, {
163 windowClass: "dl-md-modal templatess",
166 modalRef.componentInstance.edittemplate = this.template_list[index];
167 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
168 const name = receivedEntry.name;
169 this.Template_New = receivedEntry;
170 this.dashboardApiService
171 .updateNewTemplate(this.Template_New)
175 if (res.statusCode == 200) {
176 this.template_list[index] = this.Template_New;
177 this.template_list = [...this.template_list];
178 console.log(this.template_list, "this.template_list,update");
179 this.notificationService.success("SUCCESSFULLY_UPDATED");
181 this.notificationService.error("FAILED_UPDATED");
186 this.notificationService.error(err);
193 deleteTemplateModel(id: number) {
194 const index = this.template_list.findIndex(t => t.id === id);
195 const modalRef = this.modalService.open(AlertComponent, {
199 const name = this.template_list[index].name;
200 // modalRef.componentInstance.dashboardDeteleModelShow = this.dashboardDeteleModelShow;
201 modalRef.componentInstance.message = "ARE_YOU_SURE_DELETE";
202 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
204 this.dashboardApiService.DeleteTemplate(id).subscribe(
206 console.log(res,"template detele res");
207 console.log(JSON.stringify(res).length,"JSON.stringify(res).length");
208 if (JSON.stringify(res).length<=2) {
209 console.log("Success deleted template");
210 this.template_list.splice(index, 1);
211 this.template_list = [...this.template_list];
212 this.notificationService.success("SUCCESSFULLY_DELETED");
214 console.log("Fail deleted template");
215 this.notificationService.error("FAILED_DELETED");
221 this.notificationService.error(err);
229 deployTemplate(id: number) {
230 const index = this.template_list.findIndex(t => t.id === id);
231 const name = this.template_list[index].name;
232 const body = this.template_list[index];
234 this.dashboardApiService.deployTemplateKibana(id, body).subscribe(
237 console.log(res,"template deploy res");
238 console.log(JSON.stringify(res).length,"JSON.stringify(res).length");
239 if (JSON.stringify(res).length<=2) {
240 this.notificationService.success("Deploy_SUCCESSFULLY");
242 this.notificationService.error("Deploy_FAILED");
247 this.notificationService.error(err);
252 updateFilter(searchValue) {
253 const val = searchValue.toLowerCase();
255 const temps = this.temps.filter(function (d) {
256 return d.name.toLowerCase().indexOf(val) !== -1 || !val;
259 this.template_list = temps;