1 import {Component, EventEmitter, OnInit, Output} from '@angular/core';
2 import {FileSystemFileEntry, NgxFileDropEntry} from 'ngx-file-drop';
3 import {PackageCreationStore} from '../../package-creation.store';
6 selector: 'app-templ-mapp-creation',
7 templateUrl: './templ-mapp-creation.component.html',
8 styleUrls: ['./templ-mapp-creation.component.css']
10 export class TemplMappCreationComponent implements OnInit {
12 public uploadedFiles: FileSystemFileEntry[] = [];
13 private fileNames: Set<string> = new Set();
15 public files: NgxFileDropEntry[] = [];
18 constructor(private packageCreationStore: PackageCreationStore) {
24 public dropped(files: NgxFileDropEntry[]) {
26 for (const droppedFile of files) {
27 // Is it a file? & Not added before
28 if (droppedFile.fileEntry.isFile && !this.fileNames.has(droppedFile.fileEntry.name)) {
29 const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
30 this.uploadedFiles.push(fileEntry);
31 this.fileNames.add(fileEntry.name);
37 removeFile(fileIndex: number) {
38 /*const filename = 'Definitions/' + this.uploadedFiles[fileIndex].name;
39 this.packageCreationStore.removeFileFromDefinition(filename);
40 this.uploadedFiles.splice(fileIndex, 1);*/
44 for (const droppedFile of this.uploadedFiles) {
45 droppedFile.file((file: File) => {
46 const fileReader = new FileReader();
47 fileReader.onload = (e) => {
48 this.packageCreationStore.addTemplate('Templates/' + this.fileName,
49 fileReader.result.toString());
51 fileReader.readAsText(file);
57 public fileOver(event) {
61 public fileLeave(event) {
65 resetTheUploadedFiles() {
66 this.uploadedFiles = [];