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.
24 } from "@angular/core";
25 import { NgbActiveModal } from "@ng-bootstrap/ng-bootstrap";
26 import { RestApiService } from "src/app/core/services/rest-api.service";
27 import { Template } from "src/app/core/models/template.model";
30 import { NgxSpinnerService } from "ngx-spinner";
33 selector: 'app-edit-template-modal',
34 templateUrl: './edit-template-modal.component.html',
35 styleUrls: ['./edit-template-modal.component.css']
37 export class EditTemplateModalComponent implements OnInit {
38 @Input() edittemplate: Template;
39 templateInput: Template;
40 defaultDesigntype: String;
41 defaultTopicname: String;
42 templatetypedata: Array<any> = [];
43 topicname: Array<any> = [];
44 dbList: Array<any> = [];
45 tempSeletedDbs: any = [];
46 @Output() passEntry: EventEmitter<any> = new EventEmitter();
48 @ViewChild("templatetype") templatetype: ElementRef;
49 @ViewChild("topic") topic: ElementRef;
52 public activeModal: NgbActiveModal,
53 public dashboardApiService: RestApiService,
54 private spinner: NgxSpinnerService,
57 inputtemplateName = null;
58 templateInputTitle = "";
63 this.templateInput = new Template();
66 id: this.edittemplate.id,
67 name: this.edittemplate.name,
68 submitted: this.edittemplate.submitted,
69 body: this.edittemplate.body,
70 note: this.edittemplate.note,
71 topicName: this.edittemplate.topicName,
72 designType: this.edittemplate.designType,
73 designTypeName: this.edittemplate.designTypeName,
74 dbs: this.edittemplate.dbs,
76 this.templateInput = feed;
77 this.templateInputTitle = "" + this.edittemplate.name;
78 this.tempSeletedDbs = this.templateInput.dbs.map(item => { return Number(item) });
81 this.getTemplateTypeName();
84 this.dashboardApiService.getTopicsFromFeeder().subscribe(data => {
85 this.topicname = data;
90 this.dashboardApiService.getTempDbList().subscribe(data => {
91 Object.keys(data).map(item => {
92 this.dbList.push({ key: item, name: data[item] })
97 updateSelectedDB(event: any, name: any) {
98 if (event.target.checked) {
99 if (!this.tempSeletedDbs.find(db => db === name)) {
100 this.tempSeletedDbs.push(Number(name.key));
103 const index = this.tempSeletedDbs.indexOf(+name.key, 0);
105 this.tempSeletedDbs.splice(index, 1);
110 getTemplateTypeName() {
111 this.dashboardApiService.getTemplateTypeName().subscribe(data => {
112 this.templatetypedata = data;
113 this.getDefaultOptions();
117 getDefaultOptions() {
118 this.templatetypedata.map(item => {
119 if (item.id === this.templateInput.designType) {
120 return this.defaultDesigntype = item.name;
123 this.defaultTopicname = this.templateInput.topicName;
128 var file = (<HTMLInputElement>document.querySelector("#f-file")).files[0];
129 this.fileName = file.name;
130 var reader = new FileReader();
131 reader.onload = function () {
132 thiss.templateInput.body = String(this.result);
134 reader.readAsText(file);
139 if (this.templateInput.name == '' || this.templateInput.name == undefined) {
142 this.edittemplate = this.templateInput;
143 // this.templatetypedata.map(item => {
144 // if (item.name === this.templatetype.nativeElement.value) {
145 // return this.edittemplate.designType = item.id;
148 this.edittemplate.designType = this.templatetypedata.filter(item => {
149 return item.name === this.templatetype.nativeElement.value;
152 this.edittemplate.designTypeName = this.templatetype.nativeElement.value;
153 this.edittemplate.topicName = this.topic.nativeElement.value;
154 this.edittemplate.dbs = this.tempSeletedDbs;
155 this.passEntry.emit(this.edittemplate);