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 { NgbModal } from "@ng-bootstrap/ng-bootstrap";
29 import { NgxSpinnerService } from "ngx-spinner";
31 import { Template, newTemplate } from "src/app/core/models/template.model";
34 selector: 'app-new-template-modal',
35 templateUrl: './new-template-modal.component.html',
36 styleUrls: ['./new-template-modal.component.css']
38 export class NewTemplateModalComponent implements OnInit {
39 @Input() template: newTemplate;
40 @Input() templatelist_length;
41 templateInput: newTemplate
42 templatetypedata: Array<any> = [];
43 topicname: Array<any> = [];
44 @Output() passEntry: EventEmitter<any> = new EventEmitter();
45 @ViewChild("templatetype") templatetype: ElementRef;
46 @ViewChild("topic") topic: ElementRef;
49 public activeModal: NgbActiveModal,
50 public dashboardApiService: DashboardApiService,
51 private spinner: NgxSpinnerService,
52 private modalService: NgbModal,
55 inputtemplateName = null;
61 this.getTemplateTypeName();
63 this.templateInput = new Template();
65 name: this.template.name,
66 submitted: this.template.submitted,
67 body: this.template.body,
68 note: this.template.note,
69 topicName: this.template.topicName,
70 designType: this.template.designType,
71 designTypeName: this.template.designTypeName,
73 this.templateInput = feed;
76 this.dashboardApiService.getTopicName().subscribe(data => {
77 this.topicname = data;
81 getTemplateTypeName() {
82 this.dashboardApiService.getTemplateTypeName().subscribe(data => {
83 this.templatetypedata = data;
89 var file = (<HTMLInputElement>document.querySelector("#f-file")).files[0];
90 this.fileName = file.name;
91 var reader = new FileReader();
92 reader.onload = function () {
93 // console.log(this.result, "this.result");
94 thiss.templateInput.body = String(this.result);
96 reader.readAsText(file);
100 if (this.templateInput.name == '' || this.templateInput.name == undefined) {
103 this.template = this.templateInput;
105 // this.templatetypedata.map(item => {
106 // if (item.name === this.templatetype.nativeElement.value) {
107 // return this.template.designType = item.id;
111 this.template.designType = this.templatetypedata.filter(item => {
112 return item.name === this.templatetype.nativeElement.value;
115 this.template.designTypeName = this.templatetype.nativeElement.value;
116 this.template.topicName = this.topic.nativeElement.value;
117 this.template.submitted = false;
118 this.template.note = "";
119 this.passEntry.emit(this.template);