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 @Output() showFullView = new EventEmitter<any>();
17 private templateAndMappingMap = new Map<string, TemplateAndMapping>();
18 private templates: Template;
19 private mapping: Mapping;
24 private packageCreationStore: PackageCreationStore,
25 private templateStore: TemplateStore,
26 private route: ActivatedRoute
31 if (this.route.snapshot.paramMap.has('id')) {
32 this.isCreate = false;
34 this.packageCreationStore.state$.subscribe(cba => {
36 this.templates = cba.templates;
37 this.mapping = cba.mapping;
38 console.log(this.mapping);
39 let templateAndMapping;
40 this.templateAndMappingMap.clear();
41 this.templates.files.forEach((value, key) => {
42 templateAndMapping = new TemplateAndMapping();
43 templateAndMapping.isTemplate = true;
44 const isFromTemplate = true;
45 this.setIsMappingOrTemplate(key, templateAndMapping, isFromTemplate);
47 this.mapping.files.forEach((value, key) => {
48 templateAndMapping = new TemplateAndMapping();
49 templateAndMapping.isMapping = true;
50 const isFromTemplate = false;
51 this.setIsMappingOrTemplate(key, templateAndMapping, isFromTemplate);
53 console.log('hello there ');
54 console.log(this.templateAndMappingMap);
59 private setIsMappingOrTemplate(key: string, templateAndMapping: TemplateAndMapping, isFromTemplate: boolean) {
60 const nameOfFile = key.split('/')[1].split('.')[0].split('-')[0];
61 // const fullName = nameOfFile + ',' + key.split('.');
62 if (this.templateAndMappingMap.has(nameOfFile)) {
63 const templateAndMappingExisted = this.templateAndMappingMap.get(nameOfFile);
64 !isFromTemplate ? templateAndMappingExisted.isMapping = true : templateAndMappingExisted.isTemplate = true;
65 this.templateAndMappingMap.set(nameOfFile, templateAndMappingExisted);
67 this.templateAndMappingMap.set(nameOfFile, templateAndMapping);
73 this.showCreationViewParentNotification.emit('tell parent to open create views');
76 this.showFullView.emit('show full view');
79 setSourceCodeEditor(key: string) {
80 this.currentFile = key;
81 const templateKey = 'Templates/' + key + '-template.vtl';
82 this.packageCreationStore.state$.subscribe(cba => {
83 console.log('cba ------');
86 console.log(this.templateAndMappingMap);
87 const templateInfo = new TemplateInfo();
88 if (cba.templates && cba.templates.files.has(templateKey)) {
89 const fileContent = cba.templates.getValue(templateKey.trim());
90 console.log(fileContent);
91 templateInfo.fileContent = fileContent;
92 templateInfo.fileName = templateKey;
93 templateInfo.type = 'template';
95 const mappingKey = 'Templates/' + key + '-mapping.json';
96 if (cba.mapping && cba.mapping.files.has(mappingKey)) {
97 const obj = JSON.parse(cba.mapping.getValue(mappingKey));
98 templateInfo.mapping = obj;
99 templateInfo.fileName = mappingKey;
100 templateInfo.type += 'mapping';
102 this.templateStore.changeTemplateInfo(templateInfo);
107 getKeys(templateAndMappingMap: Map<string, TemplateAndMapping>) {
108 return Array.from(this.templateAndMappingMap.keys());
111 getValue(file: string) {
112 return this.templateAndMappingMap.get(file);