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';
10 selector: 'app-templ-mapp-listing',
11 templateUrl: './templ-mapp-listing.component.html',
12 styleUrls: ['./templ-mapp-listing.component.css']
14 export class TemplMappListingComponent implements OnInit {
15 @Output() showCreationViewParentNotification = new EventEmitter<any>();
16 private templateAndMappingMap = new Map<string, TemplateAndMapping>();
17 private templates: Template;
18 private mapping: Mapping;
23 private packageCreationStore: PackageCreationStore,
24 private templateStore: TemplateStore,
25 private route: ActivatedRoute
30 if (this.route.snapshot.paramMap.has('id')) {
31 this.isCreate = false;
33 this.packageCreationStore.state$.subscribe(cba => {
35 this.templates = cba.templates;
36 this.mapping = cba.mapping;
37 console.log(this.mapping);
38 let templateAndMapping;
39 this.templateAndMappingMap.clear();
40 this.templates.files.forEach((value, key) => {
41 templateAndMapping = new TemplateAndMapping();
42 templateAndMapping.isTemplate = true;
43 const isFromTemplate = true;
44 this.setIsMappingOrTemplate(key, templateAndMapping, isFromTemplate);
46 this.mapping.files.forEach((value, key) => {
47 templateAndMapping = new TemplateAndMapping();
48 templateAndMapping.isMapping = true;
49 const isFromTemplate = false;
50 this.setIsMappingOrTemplate(key, templateAndMapping, isFromTemplate);
52 console.log('hello there ');
53 console.log(this.templateAndMappingMap);
58 private setIsMappingOrTemplate(key: string, templateAndMapping: TemplateAndMapping, isFromTemplate: boolean) {
59 const nameOfFile = key.split('/')[1].split('.')[0].split('-')[0];
60 // const fullName = nameOfFile + ',' + key.split('.');
61 if (this.templateAndMappingMap.has(nameOfFile)) {
62 const templateAndMappingExisted = this.templateAndMappingMap.get(nameOfFile);
63 !isFromTemplate ? templateAndMappingExisted.isMapping = true : templateAndMappingExisted.isTemplate = true;
64 this.templateAndMappingMap.set(nameOfFile, templateAndMappingExisted);
66 this.templateAndMappingMap.set(nameOfFile, templateAndMapping);
72 this.showCreationViewParentNotification.emit('tell parent to open create views');
75 setSourceCodeEditor(key: string) {
76 this.currentFile = key;
77 const templateKey = 'Templates/' + key + '-template.vtl';
78 this.packageCreationStore.state$.subscribe(cba => {
79 console.log('cba ------');
82 console.log(this.templateAndMappingMap);
83 if (cba.templates && cba.templates.files.has(templateKey)) {
84 const fileContent = cba.templates.getValue(templateKey.trim());
85 console.log(fileContent);
86 const templateInfo = new TemplateInfo();
87 templateInfo.fileContent = fileContent;
88 templateInfo.fileName = templateKey;
89 this.templateStore.changeTemplateInfo(templateInfo);
91 const mappingKey = 'Templates/' + key + '-mapping.json';
92 if (cba.mapping && cba.mapping.files.has(mappingKey)) {
93 const obj = JSON.parse(cba.mapping.getValue(mappingKey));
94 const templateInfo = new TemplateInfo();
95 templateInfo.mapping = obj;
96 templateInfo.fileName = mappingKey;
97 templateInfo.type = 'mapping';
98 this.templateStore.changeTemplateInfo(templateInfo);
103 getKeys(templateAndMappingMap: Map<string, TemplateAndMapping>) {
104 return Array.from(this.templateAndMappingMap.keys());
107 getValue(file: string) {
108 return this.templateAndMappingMap.get(file);