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';
8 selector: 'app-templ-mapp-listing',
9 templateUrl: './templ-mapp-listing.component.html',
10 styleUrls: ['./templ-mapp-listing.component.css']
12 export class TemplMappListingComponent implements OnInit {
13 @Output() showCreationViewParentNotification = new EventEmitter<any>();
14 private templateAndMappingMap = new Map<string, TemplateAndMapping>();
15 private templates: Template;
16 private mapping: Mapping;
18 constructor(private packageCreationStore: PackageCreationStore, private templateStore: TemplateStore) {
22 this.packageCreationStore.state$.subscribe(cba => {
24 this.templates = cba.templates;
25 this.mapping = cba.mapping;
26 let templateAndMapping;
27 this.templateAndMappingMap.clear();
28 this.templates.files.forEach((value, key) => {
29 templateAndMapping = new TemplateAndMapping();
30 templateAndMapping.isTemplate = true;
31 const isFromTemplate = true;
32 this.setIsMappingOrTemplate(key, templateAndMapping, isFromTemplate);
34 this.mapping.files.forEach((value, key) => {
35 templateAndMapping = new TemplateAndMapping();
36 templateAndMapping.isMapping = true;
37 const isFromTemplate = false;
38 this.setIsMappingOrTemplate(key, templateAndMapping, isFromTemplate);
40 console.log('hello there ');
41 console.log(this.templateAndMappingMap);
46 private setIsMappingOrTemplate(key: string, templateAndMapping: TemplateAndMapping, isFromTemplate: boolean) {
47 const nameOfFile = key.split('/')[1].split('.')[0].split('-')[0];
48 const fullName = nameOfFile + ',' + key;
49 if (this.templateAndMappingMap.has(fullName)) {
50 const templateAndMappingExisted = this.templateAndMappingMap.get(fullName);
51 !isFromTemplate ? templateAndMappingExisted.isMapping = true : templateAndMappingExisted.isTemplate = true;
52 this.templateAndMappingMap.set(fullName, templateAndMappingExisted);
55 this.templateAndMappingMap.set(fullName, templateAndMapping);
61 this.showCreationViewParentNotification.emit('tell parent to open create views');
64 setSourceCodeEditor(key: string) {
65 this.packageCreationStore.state$.subscribe(cba => {
67 console.log(cba.templates);
69 const fileContent = cba.templates.getValue(key.trim());
70 console.log(fileContent);
71 const templateInfo = new TemplateInfo();
72 templateInfo.fileContent = fileContent;
73 templateInfo.fileName = key;
74 this.templateStore.changeTemplateInfo(templateInfo);
79 getKeys(templateAndMappingMap: Map<string, TemplateAndMapping>) {
80 return Array.from(this.templateAndMappingMap.keys());
83 getValue(file: string) {
84 return this.templateAndMappingMap.get(file);