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 { DashboardApiService } from "src/app/core/services/dashboard-api.service";
27 import { Template } from "src/app/core/models/template.model";
28 import { NgbModal } from "@ng-bootstrap/ng-bootstrap";
31 import { NgxSpinnerService } from "ngx-spinner";
34 selector: 'app-edit-template-modal',
35 templateUrl: './edit-template-modal.component.html',
36 styleUrls: ['./edit-template-modal.component.css']
38 export class EditTemplateModalComponent implements OnInit {
39 @Input() edittemplate: Template;
40 templateInput: Template;
41 defaultDesigntype: String;
42 defaultTopicname: String;
43 templatetypedata: Array<any> = [];
44 topicname: Array<any> = [];
45 @Output() passEntry: EventEmitter<any> = new EventEmitter();
47 @ViewChild("templatetype") templatetype: ElementRef;
48 @ViewChild("topic") topic: ElementRef;
51 public activeModal: NgbActiveModal,
52 public dashboardApiService: DashboardApiService,
53 private spinner: NgxSpinnerService,
54 private modalService: NgbModal,
57 inputtemplateName = null;
58 templateInputTitle = "";
63 this.templateInput = new Template();
65 id: this.edittemplate.id,
66 name: this.edittemplate.name,
67 submitted: this.edittemplate.submitted,
68 body: this.edittemplate.body,
69 note: this.edittemplate.note,
70 topicName: this.edittemplate.topicName,
71 designType: this.edittemplate.designType,
72 designTypeName: this.edittemplate.designTypeName,
74 this.templateInput = feed;
75 this.templateInputTitle = "" + this.edittemplate.name;
77 this.getTemplateTypeName();
80 this.dashboardApiService.getTopicName().subscribe(data => {
81 this.topicname = data;
85 getTemplateTypeName() {
86 this.dashboardApiService.getTemplateTypeName().subscribe(data => {
87 this.templatetypedata = data;
88 this.getDefaultOptions();
93 this.templatetypedata.map(item => {
94 if (item.id === this.templateInput.designType) {
95 return this.defaultDesigntype = item.name;
98 this.defaultTopicname = this.templateInput.topicName;
103 var file = (<HTMLInputElement>document.querySelector("#f-file")).files[0];
104 this.fileName = file.name;
105 var reader = new FileReader();
106 reader.onload = function () {
107 thiss.templateInput.body = String(this.result);
109 reader.readAsText(file);
114 if (this.templateInput.name == '' || this.templateInput.name == undefined) {
117 this.edittemplate = this.templateInput;
118 // this.templatetypedata.map(item => {
119 // if (item.name === this.templatetype.nativeElement.value) {
120 // return this.edittemplate.designType = item.id;
123 this.edittemplate.designType = this.templatetypedata.filter(item => {
124 return item.name === this.templatetype.nativeElement.value;
127 this.edittemplate.designTypeName = this.templatetype.nativeElement.value;
128 this.edittemplate.topicName = this.topic.nativeElement.value;
129 this.passEntry.emit(this.edittemplate);