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) {
21 this.packageCreationStore.state$.subscribe(cbaPackage => {
22 if (cbaPackage.definitions && cbaPackage.definitions.imports && cbaPackage.definitions.imports.size > 0) {
23 this.definitionFiles = cbaPackage.definitions.imports;
32 public dropped(files: NgxFileDropEntry[]) {
34 for (const droppedFile of files) {
35 // Is it a file? & Not added before
36 if (droppedFile.fileEntry.isFile && !this.fileNames.has(droppedFile.fileEntry.name)) {
37 const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
38 this.uploadedFiles.push(fileEntry);
39 console.log(fileEntry.name);
40 this.fileNames.add(fileEntry.name);
46 removeFile(fileIndex: number) {
47 const filename = 'Definitions/' + this.uploadedFiles[fileIndex].name;
48 this.packageCreationStore.removeFileFromDefinition(filename);
49 this.uploadedFiles.splice(fileIndex, 1);
52 public fileOver(event) {
56 public fileLeave(event) {
61 for (const droppedFile of this.uploadedFiles) {
62 droppedFile.file((file: File) => {
63 const fileReader = new FileReader();
64 fileReader.onload = (e) => {
65 this.packageCreationStore.addDefinition('Definitions/' + droppedFile.name,
66 fileReader.result.toString());
68 fileReader.readAsText(file);
74 resetTheUploadedFiles() {
75 this.uploadedFiles = [];