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;
22 private packageCreationStore: PackageCreationStore,
23 private templateStore: TemplateStore,
24 private route: ActivatedRoute
29 if (this.route.snapshot.paramMap.has('id')) {
30 this.isCreate = false;
32 this.packageCreationStore.state$.subscribe(cba => {
34 this.templates = cba.templates;
35 this.mapping = cba.mapping;
36 console.log(this.mapping);
37 let templateAndMapping;
38 this.templateAndMappingMap.clear();
39 this.templates.files.forEach((value, key) => {
40 templateAndMapping = new TemplateAndMapping();
41 templateAndMapping.isTemplate = true;
42 const isFromTemplate = true;
43 this.setIsMappingOrTemplate(key, templateAndMapping, isFromTemplate);
45 this.mapping.files.forEach((value, key) => {
46 templateAndMapping = new TemplateAndMapping();
47 templateAndMapping.isMapping = true;
48 const isFromTemplate = false;
49 this.setIsMappingOrTemplate(key, templateAndMapping, isFromTemplate);
51 console.log('hello there ');
52 console.log(this.templateAndMappingMap);
57 private setIsMappingOrTemplate(key: string, templateAndMapping: TemplateAndMapping, isFromTemplate: boolean) {
58 const nameOfFile = key.split('/')[1].split('.')[0].split('-')[0];
59 // const fullName = nameOfFile + ',' + key.split('.');
60 if (this.templateAndMappingMap.has(nameOfFile)) {
61 const templateAndMappingExisted = this.templateAndMappingMap.get(nameOfFile);
62 !isFromTemplate ? templateAndMappingExisted.isMapping = true : templateAndMappingExisted.isTemplate = true;
63 this.templateAndMappingMap.set(nameOfFile, templateAndMappingExisted);
65 this.templateAndMappingMap.set(nameOfFile, templateAndMapping);
71 this.showCreationViewParentNotification.emit('tell parent to open create views');
74 setSourceCodeEditor(key: string) {
75 const templateKey = 'Templates/' + key + '-template.vtl';
76 this.packageCreationStore.state$.subscribe(cba => {
77 console.log('cba ------');
80 console.log(this.templateAndMappingMap);
81 if (cba.templates && cba.templates.files.has(templateKey)) {
82 const fileContent = cba.templates.getValue(templateKey.trim());
83 console.log(fileContent);
84 const templateInfo = new TemplateInfo();
85 templateInfo.fileContent = fileContent;
86 templateInfo.fileName = templateKey;
87 this.templateStore.changeTemplateInfo(templateInfo);
89 const mappingKey = 'Templates/' + key + '-mapping.json';
90 if (cba.mapping && cba.mapping.files.has(mappingKey)) {
91 const obj = JSON.parse(cba.mapping.getValue(mappingKey));
92 const templateInfo = new TemplateInfo();
93 templateInfo.mapping = obj;
94 templateInfo.fileName = mappingKey;
95 templateInfo.type = 'mapping';
96 this.templateStore.changeTemplateInfo(templateInfo);
101 getKeys(templateAndMappingMap: Map<string, TemplateAndMapping>) {
102 return Array.from(this.templateAndMappingMap.keys());
105 getValue(file: string) {
106 return this.templateAndMappingMap.get(file);