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 @Output() passEntry: EventEmitter<any> = new EventEmitter();
46 @ViewChild("templatetype") templatetype: ElementRef;
47 @ViewChild("topic") topic: ElementRef;
50 public activeModal: NgbActiveModal,
51 public dashboardApiService: RestApiService,
52 private spinner: NgxSpinnerService,
55 inputtemplateName = null;
56 templateInputTitle = "";
61 this.templateInput = new Template();
63 id: this.edittemplate.id,
64 name: this.edittemplate.name,
65 submitted: this.edittemplate.submitted,
66 body: this.edittemplate.body,
67 note: this.edittemplate.note,
68 topicName: this.edittemplate.topicName,
69 designType: this.edittemplate.designType,
70 designTypeName: this.edittemplate.designTypeName,
72 this.templateInput = feed;
73 this.templateInputTitle = "" + this.edittemplate.name;
75 this.getTemplateTypeName();
78 this.dashboardApiService.getTopicsFromFeeder().subscribe(data => {
79 this.topicname = data;
83 getTemplateTypeName() {
84 this.dashboardApiService.getTemplateTypeName().subscribe(data => {
85 this.templatetypedata = data;
86 this.getDefaultOptions();
91 this.templatetypedata.map(item => {
92 if (item.id === this.templateInput.designType) {
93 return this.defaultDesigntype = item.name;
96 this.defaultTopicname = this.templateInput.topicName;
101 var file = (<HTMLInputElement>document.querySelector("#f-file")).files[0];
102 this.fileName = file.name;
103 var reader = new FileReader();
104 reader.onload = function () {
105 thiss.templateInput.body = String(this.result);
107 reader.readAsText(file);
112 if (this.templateInput.name == '' || this.templateInput.name == undefined) {
115 this.edittemplate = this.templateInput;
116 // this.templatetypedata.map(item => {
117 // if (item.name === this.templatetype.nativeElement.value) {
118 // return this.edittemplate.designType = item.id;
121 this.edittemplate.designType = this.templatetypedata.filter(item => {
122 return item.name === this.templatetype.nativeElement.value;
125 this.edittemplate.designTypeName = this.templatetype.nativeElement.value;
126 this.edittemplate.topicName = this.topic.nativeElement.value;
127 this.passEntry.emit(this.edittemplate);