1 import {Component, OnInit} from '@angular/core';
2 import {FileSystemFileEntry, NgxFileDropEntry} from 'ngx-file-drop';
3 import {PackageCreationStore} from '../package-creation.store';
4 import {PackageCreationUtils} from '../package-creation.utils';
8 selector: 'app-imports-tab',
9 templateUrl: './imports-tab.component.html',
10 styleUrls: ['./imports-tab.component.css']
12 export class ImportsTabComponent implements OnInit {
14 public definitionFiles: Map<string, string> = new Map<string, string>();
15 public uploadedFiles: FileSystemFileEntry[] = [];
16 private fileNames: Set<string> = new Set();
18 public files: NgxFileDropEntry[] = [];
20 constructor(private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils) {
24 this.packageCreationStore.state$.subscribe(cbaPackage => {
25 if (cbaPackage.definitions && cbaPackage.definitions.imports && cbaPackage.definitions.imports.size > 0) {
26 this.definitionFiles = cbaPackage.definitions.imports;
31 public dropped(files: NgxFileDropEntry[]) {
33 for (const droppedFile of files) {
34 // Is it a file? & Not added before
35 if (droppedFile.fileEntry.isFile && !this.fileNames.has(droppedFile.fileEntry.name)) {
36 const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
37 this.uploadedFiles.push(fileEntry);
38 console.log(fileEntry.name);
39 this.fileNames.add(fileEntry.name);
45 removeFile(fileIndex: number) {
46 const filename = 'Definitions/' + this.uploadedFiles[fileIndex].name;
47 this.packageCreationStore.removeFileFromDefinition(filename);
48 this.uploadedFiles.splice(fileIndex, 1);
51 public fileOver(event) {
55 public fileLeave(event) {
60 for (const droppedFile of this.uploadedFiles) {
61 droppedFile.file((file: File) => {
62 const fileReader = new FileReader();
63 fileReader.onload = (e) => {
64 this.packageCreationStore.addDefinition('Definitions/' + droppedFile.name,
65 fileReader.result.toString());
67 fileReader.readAsText(file);
73 resetTheUploadedFiles() {
74 this.uploadedFiles = [];
77 textChanges(code: any, key: string) {
78 this.packageCreationStore.addDefinition(key, code);
81 changeDivShow(mapIndex: number) {
82 const divElement = document.getElementById('id-' + mapIndex) as HTMLElement;
83 if (divElement.getAttribute('class').includes('show')) {
84 divElement.setAttribute('class', 'collapse');
86 divElement.setAttribute('class', 'collapse show');
88 console.log(divElement.getAttribute('class'));