1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
import { Component, OnInit } from '@angular/core';
import { FileSystemFileEntry, NgxFileDropEntry } from 'ngx-file-drop';
import { PackageCreationStore } from '../package-creation.store';
import { PackageCreationUtils } from '../package-creation.utils';
@Component({
selector: 'app-imports-tab',
templateUrl: './imports-tab.component.html',
styleUrls: ['./imports-tab.component.css']
})
export class ImportsTabComponent implements OnInit {
public definitionFiles: Map<string, string> = new Map<string, string>();
public uploadedFiles: FileSystemFileEntry[] = [];
private fileNames: Set<string> = new Set();
fileToDelete: any = {};
public files: NgxFileDropEntry[] = [];
constructor(private packageCreationStore: PackageCreationStore, private packageCreationUtils: PackageCreationUtils) {
}
ngOnInit(): void {
this.packageCreationStore.state$.subscribe(cbaPackage => {
if (cbaPackage.definitions && cbaPackage.definitions.imports && cbaPackage.definitions.imports.size > 0) {
this.definitionFiles = cbaPackage.definitions.imports;
}
});
}
public dropped(files: NgxFileDropEntry[]) {
this.files = files;
for (const droppedFile of files) {
// Is it a file? & Not added before
if (droppedFile.fileEntry.isFile) {
const fileEntry = droppedFile.fileEntry as FileSystemFileEntry;
this.uploadedFiles.push(fileEntry);
console.log(fileEntry.name);
this.fileNames.add(fileEntry.name);
}
}
}
initDelete(file) {
console.log(file);
this.fileToDelete = file;
}
removeFile() {
const filename = this.fileToDelete.key;
this.packageCreationStore.removeFileFromDefinition(filename);
for (let i = 0; i < this.uploadedFiles.length; i++) {
console.log(this.uploadedFiles[i]);
if (this.uploadedFiles[i].name === filename) {
this.uploadedFiles.splice(i, 1);
break;
}
}
}
public fileOver(event) {
console.log(event);
}
public fileLeave(event) {
console.log(event);
}
setFilesToStore() {
for (const droppedFile of this.uploadedFiles) {
droppedFile.file((file: File) => {
const fileReader = new FileReader();
fileReader.onload = (e) => {
this.packageCreationStore.addDefinition('Definitions/' + droppedFile.name,
fileReader.result.toString());
};
fileReader.readAsText(file);
});
}
}
resetTheUploadedFiles() {
this.uploadedFiles = [];
}
textChanges(code: any, key: string) {
this.packageCreationStore.addDefinition(key, code);
}
changeDivShow(mapIndex: number) {
const divElement = document.getElementById('id-' + mapIndex) as HTMLElement;
if (divElement.getAttribute('class').includes('show')) {
divElement.setAttribute('class', 'collapse');
} else {
divElement.setAttribute('class', 'collapse show');
}
console.log(divElement.getAttribute('class'));
}
}
|