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;
55 private modalService: NgbModal,
56 private dashboardApiService: DashboardApiService,
57 private spinner: NgxSpinnerService,
58 private notificationService: ToastrNotificationService,
61 this.loadingIndicator = false;
64 this.initData().then(data => {
65 this.initTemplateList(this.template_list).then(
67 // for cache of datatable
68 this.temps = [...data];
69 this.templates = data;
83 this.template_list = [];
84 this.template_list = await this.getTemplateList();
85 this.Template_New = new Template();
86 this.Template_Newbody = new newTemplate();
92 return this.dashboardApiService.getTemplateAll().toPromise();
95 async initTemplateList(template_list: []) {
96 var t: Template[] = [];
97 for (var i = 0; i < template_list.length; i++) {
98 let data = template_list[i];
102 submitted: data["submitted"],
105 topic: data["topic"],
106 designType: data["designType"],
114 this.selectedLangs = sessionStorage.getItem("selectedLang");
116 const modalRef = this.modalService.open(NewTemplateModalComponent, {
117 windowClass: "dl-md-modal templatess",
120 this.Template_New = new Template();
121 this.Template_Newbody = new newTemplate();
122 modalRef.componentInstance.template = this.Template_Newbody;
123 modalRef.componentInstance.selectedLangs = this.selectedLangs;
124 modalRef.componentInstance.templatelist_length = this.template_list.length;
125 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
126 this.Template_Newbody = receivedEntry;
127 let name = this.Template_Newbody.name;
128 this.dashboardApiService
129 .createNewTemplate(this.Template_Newbody)
132 if (res.statusCode == 200) {
133 this.Template_New = res.returnBody;
134 console.log(this.Template_New,"this.Template_New add Success");
135 this.template_list.push(this.Template_New);
136 this.template_list = [...this.template_list];
137 console.log(this.template_list, "this.template_list,inserted");
138 if (this.selectedLangs == "en-us") {
139 tips = "Successfully created."
140 } else if (this.selectedLangs == "zh-hans") {
142 } else if (this.selectedLangs == "zh-hant") {
145 this.notificationService.success(tips);
147 if (this.selectedLangs == "en-us") {
148 tips = "Fail created."
149 } else if (this.selectedLangs == "zh-hans") {
151 } else if (this.selectedLangs == "zh-hant") {
154 this.notificationService.error(tips);
159 this.notificationService.error(err);
167 const emitType = event.type;
168 if(emitType == "dblclick"){
169 console.log('Activate Event', event);
170 let id = event.row.id;
171 this.editTemplateModal(id);
176 editTemplateModal(id) {
177 this.selectedLangs = sessionStorage.getItem("selectedLang");
179 const index = this.template_list.findIndex(t => t.id === id);
180 // const name = this.template_list[index].name;
181 const modalRef = this.modalService.open(EditTemplateModalComponent, {
182 windowClass: "dl-md-modal templatess",
185 modalRef.componentInstance.selectedLangs = this.selectedLangs;
186 modalRef.componentInstance.edittemplate = this.template_list[index];
187 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
188 const name = receivedEntry.name;
189 this.Template_New = receivedEntry;
190 this.dashboardApiService
191 .updateNewTemplate(this.Template_New)
195 if (res.statusCode == 200) {
196 this.template_list[index] = this.Template_New;
197 this.template_list = [...this.template_list];
198 console.log(this.template_list, "this.template_list,update");
199 if (this.selectedLangs == "en-us") {
200 tips = "Successfully updated."
201 } else if (this.selectedLangs == "zh-hans") {
203 } else if (this.selectedLangs == "zh-hant") {
206 this.notificationService.success('"' + name + '"' + tips);
209 if (this.selectedLangs == "en-us") {
210 tips = "Fail updated."
211 } else if (this.selectedLangs == "zh-hans") {
213 } else if (this.selectedLangs == "zh-hant") {
216 this.notificationService.error('"' + name + '"' + tips);
221 this.notificationService.error(err);
228 deleteTemplateModel(id: number) {
229 this.selectedLangs = sessionStorage.getItem("selectedLang");
231 if (this.selectedLangs == "en-us") {
232 tips = "Are you sure you want to delete ";
233 } else if (this.selectedLangs == "zh-hans") {
235 } else if (this.selectedLangs == "zh-hant") {
238 const index = this.template_list.findIndex(t => t.id === id);
239 const modalRef = this.modalService.open(AlertComponent, {
243 const name = this.template_list[index].name;
244 // modalRef.componentInstance.dashboardDeteleModelShow = this.dashboardDeteleModelShow;
245 modalRef.componentInstance.message =
246 tips + '"' + name + '"' + ' ?';
247 modalRef.componentInstance.passEntry.subscribe(receivedEntry => {
249 this.dashboardApiService.DeleteTemplate(id).subscribe(
251 console.log(res,"template detele res");
252 console.log(JSON.stringify(res).length,"JSON.stringify(res).length");
253 if (JSON.stringify(res).length<=2) {
254 console.log("Success deleted template");
255 this.template_list.splice(index, 1);
256 this.template_list = [...this.template_list];
257 if (this.selectedLangs == "en-us") {
258 tips = "Successfully deleted."
259 } else if (this.selectedLangs == "zh-hans") {
261 } else if (this.selectedLangs == "zh-hant") {
264 this.notificationService.success(tips);
266 console.log("Fail deleted template");
267 if (this.selectedLangs == "en-us") {
268 tips = "Fail deleted."
269 } else if (this.selectedLangs == "zh-hans") {
271 } else if (this.selectedLangs == "zh-hant") {
274 this.notificationService.error(tips);
280 this.notificationService.error(err);
288 deployTemplate(id: number) {
289 this.selectedLangs = sessionStorage.getItem("selectedLang");
291 const index = this.template_list.findIndex(t => t.id === id);
292 const name = this.template_list[index].name;
293 const body = this.template_list[index];
295 // this.dashboardApiService.deployTemplate(id).subscribe(
297 // console.log(res,"reshost");
298 // const host = res.source.host,
299 // port = res.source.port;
300 // if (res.status == "success") {
303 this.dashboardApiService.deployTemplateKibana(id, body).subscribe(
306 console.log(res,"template deploy res");
307 console.log(JSON.stringify(res).length,"JSON.stringify(res).length");
308 if (JSON.stringify(res).length<=2) {
309 if (this.selectedLangs == "en-us") {
310 tips = "deploy successful."
311 } else if (this.selectedLangs == "zh-hans") {
313 } else if (this.selectedLangs == "zh-hant") {
316 this.notificationService.success('"' + name + '"' + tips);
318 if (this.selectedLangs == "en-us") {
319 tips = "deploy fail."
320 } else if (this.selectedLangs == "zh-hans") {
322 } else if (this.selectedLangs == "zh-hant") {
325 this.notificationService.error('"' + name + '"' + tips);
330 this.notificationService.error(err);
334 // this.spinner.hide();
335 // this.notificationService.error( name + " Fail deploy.");
339 // this.spinner.hide();
340 // this.notificationService.error(err);
346 updateFilter(searchValue) {
347 const val = searchValue.toLowerCase();
349 const temps = this.temps.filter(function (d) {
350 return d.name.toLowerCase().indexOf(val) !== -1 || !val;
353 this.template_list = temps;