752bd510b25150ac975b58b8505739d33201e50d
[ccsdk/cds.git] /
1 import {Component, EventEmitter, OnInit, Output} from '@angular/core';
2 import {FileSystemFileEntry, NgxFileDropEntry} from 'ngx-file-drop';
3 import {PackageCreationStore} from '../../package-creation.store';
4
5 @Component({
6     selector: 'app-templ-mapp-creation',
7     templateUrl: './templ-mapp-creation.component.html',
8     styleUrls: ['./templ-mapp-creation.component.css']
9 })
10 export class TemplMappCreationComponent implements OnInit {
11
12     public uploadedFiles: FileSystemFileEntry[] = [];
13     private fileNames: Set<string> = new Set();
14
15     public files: NgxFileDropEntry[] = [];
16     fileName: any;
17
18     constructor(private packageCreationStore: PackageCreationStore) {
19     }
20
21     ngOnInit() {
22     }
23
24     public dropped(files: NgxFileDropEntry[]) {
25         this.files = files;
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);
32
33             }
34         }
35     }
36
37     removeFile(fileIndex: number) {
38         /*const filename = 'Definitions/' + this.uploadedFiles[fileIndex].name;
39         this.packageCreationStore.removeFileFromDefinition(filename);
40         this.uploadedFiles.splice(fileIndex, 1);*/
41     }
42
43     setFilesToStore() {
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());
50                 };
51                 fileReader.readAsText(file);
52             });
53
54         }
55     }
56
57     public fileOver(event) {
58         console.log(event);
59     }
60
61     public fileLeave(event) {
62         console.log(event);
63     }
64
65     resetTheUploadedFiles() {
66         this.uploadedFiles = [];
67     }
68 }