|
|
|
@ -1,10 +1,10 @@
|
|
|
|
|
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Output} from "@angular/core";
|
|
|
|
|
import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit} from "@angular/core";
|
|
|
|
|
import {ImportService} from "../../../../../services/import/import.service";
|
|
|
|
|
import {LoggingService} from "../../../../../services/logging/logging.service";
|
|
|
|
|
import {AddFileOptions} from "../../../../../models/AddFileOptions";
|
|
|
|
|
import {File} from "../../../../../../api/models/File";
|
|
|
|
|
import {DialogFilter} from "@tauri-apps/api/dialog";
|
|
|
|
|
import {FileOsMetadata} from "../../../../../../api/api-types/files";
|
|
|
|
|
import {ImportTabState} from "../../../../../models/state/ImportTabState";
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
|
selector: "app-filesystem-import",
|
|
|
|
@ -12,10 +12,9 @@ import {FileOsMetadata} from "../../../../../../api/api-types/files";
|
|
|
|
|
styleUrls: ["./filesystem-import.component.scss"],
|
|
|
|
|
changeDetection: ChangeDetectionStrategy.OnPush
|
|
|
|
|
})
|
|
|
|
|
export class FilesystemImportComponent {
|
|
|
|
|
export class FilesystemImportComponent implements OnInit {
|
|
|
|
|
|
|
|
|
|
@Output() fileImported = new EventEmitter<File>();
|
|
|
|
|
@Output() importFinished = new EventEmitter<void>();
|
|
|
|
|
@Input() state!: ImportTabState;
|
|
|
|
|
|
|
|
|
|
public fileCount: number = 0;
|
|
|
|
|
public files: FileOsMetadata[] = [];
|
|
|
|
@ -45,12 +44,30 @@ export class FilesystemImportComponent {
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ngOnInit(): void {
|
|
|
|
|
this.state.selectedPaths.subscribe(paths => {
|
|
|
|
|
this.files = paths;
|
|
|
|
|
this.fileCount = paths.length;
|
|
|
|
|
});
|
|
|
|
|
this.state.importing.subscribe(importing => {
|
|
|
|
|
this.importing = importing;
|
|
|
|
|
this.changeDetector.markForCheck();
|
|
|
|
|
});
|
|
|
|
|
this.state.importedCount.subscribe(count => {
|
|
|
|
|
this.importingProgressTotal = count;
|
|
|
|
|
});
|
|
|
|
|
this.state.importingProgress.subscribe(prog => {
|
|
|
|
|
this.importingProgress = prog;
|
|
|
|
|
this.changeDetector.markForCheck();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async setSelectedPaths(paths: string[]) {
|
|
|
|
|
this.changeDetector.markForCheck();
|
|
|
|
|
this.resolving = true;
|
|
|
|
|
try {
|
|
|
|
|
this.files = await this.importService.resolvePathsToFiles(paths);
|
|
|
|
|
this.fileCount = this.files.length;
|
|
|
|
|
const selectedPaths = await this.importService.resolvePathsToFiles(paths);
|
|
|
|
|
this.state.selectedPaths.next(selectedPaths);
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
this.errorBroker.error(err);
|
|
|
|
@ -60,7 +77,7 @@ export class FilesystemImportComponent {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async import() {
|
|
|
|
|
this.importing = true;
|
|
|
|
|
this.state.importing.next(true);
|
|
|
|
|
|
|
|
|
|
this.importingProgress = 0;
|
|
|
|
|
let count = 0;
|
|
|
|
@ -71,17 +88,17 @@ export class FilesystemImportComponent {
|
|
|
|
|
file,
|
|
|
|
|
this.importOptions
|
|
|
|
|
);
|
|
|
|
|
this.fileImported.emit(resultFile);
|
|
|
|
|
this.state.addImportedFile(resultFile);
|
|
|
|
|
} catch (err: any) {
|
|
|
|
|
console.log(err);
|
|
|
|
|
this.errorBroker.error(err);
|
|
|
|
|
}
|
|
|
|
|
count++;
|
|
|
|
|
this.importingProgress = (count / this.fileCount) * 100;
|
|
|
|
|
this.importingProgressTotal = count;
|
|
|
|
|
this.state.importedCount.next(count);
|
|
|
|
|
this.state.importingProgress.next((count / this.fileCount) * 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.importing = false;
|
|
|
|
|
this.importFinished.emit();
|
|
|
|
|
this.state.importing.next(false);
|
|
|
|
|
this.state.selectedPaths.next([]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|