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;
43 selectedLangs = sessionStorage.getItem("selectedLang");
46 <div class="d-flex justify-content-center">
48 <label class="dl-nodata">No Data</label>
53 @ViewChild("searchText") searchText: ElementRef;
56 private modalService: NgbModal,
57 private dashboardApiService: DashboardApiService,
58 private spinner: NgxSpinnerService,
59 private notificationService: ToastrNotificationService,
62 this.loadingIndicator = false;
65 this.initData().then(data => {
66 this.initTemplateList(this.template_list).then(
68 // for cache of datatable
69 this.temps = [...data];
70 this.templates = data;
84 this.template_list = [];
85 this.template_list = await this.getTemplateList();
86 this.Template_New = new Template();
87 this.Template_Newbody = new newTemplate();
93 return this.dashboardApiService.getTemplateAll().toPromise();
96 async initTemplateList(template_list: []) {
97 var t: Template[] = [];
98 for (var i = 0; i < template_list.length; i++) {
99 let data = template_list[i];
103 submitted: data["submitted"],
106 topic: data["topic"],
107 designType: data["designType"],
115 this.selectedLangs = sessionStorage.getItem("selectedLang");
117 const modalRef = this.modalService.open(NewTemplateModalComponent, {
118 windowClass: "dl-md-modal",
121 this.Template_New = new Template();
122 this.Template_Newbody = new newTemplate();
123 modalRef.componentInstance.template = this.Template_Newbody;
124 modalRef.componentInstance.selectedLangs = this.selectedLangs;
125 modalRef.componentInstance.templatelist_length = this.template_list.length;
126 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
127 this.Template_Newbody = receivedEntry;
128 let name = this.Template_Newbody.name;
129 this.dashboardApiService
130 .createNewTemplate(this.Template_Newbody)
133 if (res.statusCode == 200) {
134 this.Template_New = res.returnBody;
135 console.log(this.Template_New,"this.Template_New add Success");
136 this.template_list.push(this.Template_New);
137 this.template_list = [...this.template_list];
138 console.log(this.template_list, "this.template_list,inserted");
139 if (this.selectedLangs == "en-us") {
140 tips = "Success inserted."
141 } else if (this.selectedLangs == "zh-hans") {
143 } else if (this.selectedLangs == "zh-hant") {
146 this.notificationService.success('"' + name + '"' + tips);
148 if (this.selectedLangs == "en-us") {
149 tips = "Fail inserted."
150 } else if (this.selectedLangs == "zh-hans") {
152 } else if (this.selectedLangs == "zh-hant") {
155 this.notificationService.error('"' + name + '"' + tips);
160 this.notificationService.error(err);
167 editTemplateModal(id: number) {
168 this.selectedLangs = sessionStorage.getItem("selectedLang");
170 const index = this.template_list.findIndex(t => t.id === id);
171 // const name = this.template_list[index].name;
172 const modalRef = this.modalService.open(EditTemplateModalComponent, {
173 windowClass: "dl-md-modal",
176 modalRef.componentInstance.selectedLangs = this.selectedLangs;
177 modalRef.componentInstance.edittemplate = this.template_list[index];
178 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
179 const name = receivedEntry.name;
180 this.Template_New = receivedEntry;
181 this.dashboardApiService
182 .updateNewTemplate(this.Template_New)
186 if (res.statusCode == 200) {
187 this.template_list[index] = this.Template_New;
188 this.template_list = [...this.template_list];
189 console.log(this.template_list, "this.template_list,update");
190 if (this.selectedLangs == "en-us") {
191 tips = "Success updated."
192 } else if (this.selectedLangs == "zh-hans") {
194 } else if (this.selectedLangs == "zh-hant") {
197 this.notificationService.success('"' + name + '"' + tips);
200 if (this.selectedLangs == "en-us") {
201 tips = "Fail updated."
202 } else if (this.selectedLangs == "zh-hans") {
204 } else if (this.selectedLangs == "zh-hant") {
207 this.notificationService.error('"' + name + '"' + tips);
212 this.notificationService.error(err);
219 deleteTemplateModel(id: number) {
220 this.selectedLangs = sessionStorage.getItem("selectedLang");
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 index = this.template_list.findIndex(t => t.id === id);
230 const modalRef = this.modalService.open(AlertComponent, {
234 const name = this.template_list[index].name;
235 // modalRef.componentInstance.dashboardDeteleModelShow = this.dashboardDeteleModelShow;
236 modalRef.componentInstance.message =
237 tips + '"' + name + '"' + ' ?';
238 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
240 this.dashboardApiService.DeleteTemplate(id).subscribe(
242 console.log(res,"template detele res");
243 console.log(JSON.stringify(res).length,"JSON.stringify(res).length");
244 if (JSON.stringify(res).length<=2) {
245 console.log("Success deleted template");
246 this.template_list.splice(index, 1);
247 this.template_list = [...this.template_list];
248 if (this.selectedLangs == "en-us") {
249 tips = "Success deleted."
250 } else if (this.selectedLangs == "zh-hans") {
252 } else if (this.selectedLangs == "zh-hant") {
255 this.notificationService.success('"' + name + '"' + tips);
257 console.log("Fail deleted template");
258 if (this.selectedLangs == "en-us") {
259 tips = "Fail deleted."
260 } else if (this.selectedLangs == "zh-hans") {
262 } else if (this.selectedLangs == "zh-hant") {
265 this.notificationService.error('"' + name + '"' + tips);
271 this.notificationService.error(err);
279 deployTemplate(id: number) {
280 this.selectedLangs = sessionStorage.getItem("selectedLang");
282 const index = this.template_list.findIndex(t => t.id === id);
283 const name = this.template_list[index].name;
284 const body = this.template_list[index];
286 // this.dashboardApiService.deployTemplate(id).subscribe(
288 // console.log(res,"reshost");
289 // const host = res.source.host,
290 // port = res.source.port;
291 // if (res.status == "success") {
294 this.dashboardApiService.deployTemplateKibana(id, body).subscribe(
297 console.log(res,"template deploy res");
298 console.log(JSON.stringify(res).length,"JSON.stringify(res).length");
299 if (JSON.stringify(res).length<=2) {
300 if (this.selectedLangs == "en-us") {
301 tips = "Success deploy."
302 } else if (this.selectedLangs == "zh-hans") {
304 } else if (this.selectedLangs == "zh-hant") {
307 this.notificationService.success('"' + name + '"' + tips);
309 if (this.selectedLangs == "en-us") {
310 tips = "Fail deleted."
311 } else if (this.selectedLangs == "zh-hans") {
313 } else if (this.selectedLangs == "zh-hant") {
316 this.notificationService.error('"' + name + '"' + tips);
321 this.notificationService.error(err);
325 // this.spinner.hide();
326 // this.notificationService.error( name + " Fail deploy.");
330 // this.spinner.hide();
331 // this.notificationService.error(err);
337 updateFilter(searchValue) {
338 const val = searchValue.toLowerCase();
340 const temps = this.temps.filter(function (d) {
341 return d.name.toLowerCase().indexOf(val) !== -1 || !val;
344 this.template_list = temps;