1 import { Component, EventEmitter, OnInit, Output } from '@angular/core';
2 import { PackageCreationStore } from '../../package-creation.store';
3 import { Mapping, Template } from '../../mapping-models/CBAPacakge.model';
4 import { TemplateInfo, TemplateStore } from '../../template.store';
5 import { TemplateAndMapping } from '../TemplateAndMapping';
6 import { ActivatedRoute } from '@angular/router';
7 import { SharedService } from '../shared-service';
11 selector: 'app-templ-mapp-listing',
12 templateUrl: './templ-mapp-listing.component.html',
13 styleUrls: ['./templ-mapp-listing.component.css']
15 export class TemplMappListingComponent implements OnInit {
16 @Output() showCreationViewParentNotification = new EventEmitter<any>();
17 @Output() showFullView = new EventEmitter<any>();
18 private templateAndMappingMap = new Map<string, TemplateAndMapping>();
19 private templates: Template;
20 private mapping: Mapping;
26 private packageCreationStore: PackageCreationStore,
27 private templateStore: TemplateStore,
28 private route: ActivatedRoute,
29 private sharedService: SharedService
34 if (this.route.snapshot.paramMap.has('id')) {
35 this.isCreate = false;
36 this.sharedService.isEdit().subscribe(res => {
41 this.packageCreationStore.state$.subscribe(cba => {
43 this.templates = cba.templates;
44 this.mapping = cba.mapping;
45 console.log(this.mapping);
46 let templateAndMapping;
47 this.templateAndMappingMap.clear();
48 this.templates.files.forEach((value, key) => {
49 templateAndMapping = new TemplateAndMapping();
50 templateAndMapping.isTemplate = true;
51 const isFromTemplate = true;
52 this.setIsMappingOrTemplate(key, templateAndMapping, isFromTemplate);
54 this.mapping.files.forEach((value, key) => {
55 templateAndMapping = new TemplateAndMapping();
56 templateAndMapping.isMapping = true;
57 const isFromTemplate = false;
58 this.setIsMappingOrTemplate(key, templateAndMapping, isFromTemplate);
60 console.log('hello there ');
61 console.log(this.templateAndMappingMap);
66 private setIsMappingOrTemplate(key: string, templateAndMapping: TemplateAndMapping, isFromTemplate: boolean) {
67 const nameOfFile = key.split('/')[1].split('.')[0].split('-')[0];
68 // const fullName = nameOfFile + ',' + key.split('.');
69 if (this.templateAndMappingMap.has(nameOfFile)) {
70 const templateAndMappingExisted = this.templateAndMappingMap.get(nameOfFile);
71 !isFromTemplate ? templateAndMappingExisted.isMapping = true : templateAndMappingExisted.isTemplate = true;
72 this.templateAndMappingMap.set(nameOfFile, templateAndMappingExisted);
74 this.templateAndMappingMap.set(nameOfFile, templateAndMapping);
80 this.showCreationViewParentNotification.emit('tell parent to open create views');
81 console.log('disable edit mode');
82 this.sharedService.disableEdit();
86 this.showFullView.emit('show full view');
89 setSourceCodeEditor(key: string) {
90 this.currentFile = key;
91 const templateKey = 'Templates/' + key + '-template.vtl';
92 this.packageCreationStore.state$.subscribe(cba => {
93 console.log('cba ------');
96 console.log(this.templateAndMappingMap);
97 const templateInfo = new TemplateInfo();
98 if (cba.templates && cba.templates.files.has(templateKey)) {
99 const fileContent = cba.templates.getValue(templateKey.trim());
100 console.log(fileContent);
101 templateInfo.fileContent = fileContent;
102 templateInfo.fileName = templateKey;
103 templateInfo.type = 'template';
105 const mappingKey = 'Templates/' + key + '-mapping.json';
106 if (cba.mapping && cba.mapping.files.has(mappingKey)) {
107 const obj = JSON.parse(cba.mapping.getValue(mappingKey));
108 templateInfo.mapping = obj;
109 templateInfo.fileName = mappingKey;
110 templateInfo.type += 'mapping';
112 this.templateStore.changeTemplateInfo(templateInfo);
114 this.sharedService.enableEdit();
118 getKeys(templateAndMappingMap: Map<string, TemplateAndMapping>) {
119 return Array.from(this.templateAndMappingMap.keys());
122 getValue(file: string) {
123 return this.templateAndMappingMap.get(file);