Implement importing itself

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent d9fc378a1b
commit da169fc4e6

@ -1580,8 +1580,8 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f"
[[package]] [[package]]
name = "mediarepo-api" name = "mediarepo-api"
version = "0.5.3" version = "0.6.0"
source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=827ae9613d18b773a66c80ee803c4e112ca987b9#827ae9613d18b773a66c80ee803c4e112ca987b9" source = "git+https://github.com/Trivernis/mediarepo-api.git?rev=ddebf4bf0c3e96ede64182ff52bd84f134acc33a#ddebf4bf0c3e96ede64182ff52bd84f134acc33a"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"chrono", "chrono",
@ -2524,9 +2524,9 @@ dependencies = [
[[package]] [[package]]
name = "rmp-ipc" name = "rmp-ipc"
version = "0.9.0" version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6e9a9202fb951b3ca3088a4edd351774ef154efabb759d6aac2911cc1ae60c1" checksum = "87d2b669d0332e1478b88fdecf4c03cc0c8ce1d977a79eba848f4532213567e6"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"byteorder", "byteorder",

@ -30,7 +30,7 @@ features = ["env-filter"]
[dependencies.mediarepo-api] [dependencies.mediarepo-api]
git = "https://github.com/Trivernis/mediarepo-api.git" git = "https://github.com/Trivernis/mediarepo-api.git"
rev = "827ae9613d18b773a66c80ee803c4e112ca987b9" rev = "ddebf4bf0c3e96ede64182ff52bd84f134acc33a"
features = ["tauri-plugin"] features = ["tauri-plugin"]
[features] [features]

@ -0,0 +1,8 @@
export class AddFileOptions {
public read_tags_from_txt = false;
public delete_after_import = false;
constructor() {
}
}

@ -7,7 +7,7 @@
</mat-form-field> </mat-form-field>
<app-native-file-select [mode]="selectionType.value" (fileSelect)="this.setSelectedPaths($event)"></app-native-file-select> <app-native-file-select [mode]="selectionType.value" (fileSelect)="this.setSelectedPaths($event)"></app-native-file-select>
<button mat-stroked-button class="filled-button"> <button mat-stroked-button class="filled-button">
{{this.fileCount}} files found {{resolving? "Searching for files..." : this.fileCount + " files found"}}
<mat-progress-bar *ngIf="resolving" mode="indeterminate" color="primary"></mat-progress-bar> <mat-progress-bar *ngIf="resolving" mode="indeterminate" color="primary"></mat-progress-bar>
</button> </button>
@ -16,14 +16,17 @@
<button mat-flat-button class="filled-button">Tag parsing options</button> <button mat-flat-button class="filled-button">Tag parsing options</button>
<section class="binary-import-options"> <section class="binary-import-options">
<mat-checkbox [checked]="this.importTagsFromTxt" (change)="this.importTagsFromTxt = $event.checked">Import tags from <mat-checkbox [checked]="this.importOptions.read_tags_from_txt" (change)="this.importOptions.read_tags_from_txt = $event.checked">Import tags from
adjacent .txt tag files adjacent .txt tag files
</mat-checkbox> </mat-checkbox>
<mat-checkbox [checked]="this.deleteAfterImport" (change)="this.deleteAfterImport = $event.checked" color="warn"> <mat-checkbox [checked]="this.importOptions.delete_after_import" (change)="this.importOptions.delete_after_import = $event.checked" color="warn">
Delete files from original location after import Delete files from original location after import
</mat-checkbox> </mat-checkbox>
</section> </section>
<mat-divider></mat-divider> <mat-divider></mat-divider>
<button mat-flat-button color="primary" class="import-button">Import</button> <button mat-flat-button color="primary" class="import-button" [disabled]="importing || this.fileCount === 0" (click)="import()">
{{importing? "Importing..." : "Import"}}
</button>
<mat-progress-bar *ngIf="importing" mode="determinate" color="primary" [value]="this.importingProgress"></mat-progress-bar>

@ -1,7 +1,9 @@
import {Component} from '@angular/core'; import {Component, EventEmitter, Output} from '@angular/core';
import {FileOsMetadata} from "../../../../../models/FileOsMetadata"; import {FileOsMetadata} from "../../../../../models/FileOsMetadata";
import {ImportService} from "../../../../../services/import/import.service"; import {ImportService} from "../../../../../services/import/import.service";
import {ErrorBrokerService} from "../../../../../services/error-broker/error-broker.service"; import {ErrorBrokerService} from "../../../../../services/error-broker/error-broker.service";
import {AddFileOptions} from "../../../../../models/AddFileOptions";
import {File} from "../../../../../models/File";
@Component({ @Component({
selector: 'app-filesystem-import', selector: 'app-filesystem-import',
@ -10,12 +12,15 @@ import {ErrorBrokerService} from "../../../../../services/error-broker/error-bro
}) })
export class FilesystemImportComponent { export class FilesystemImportComponent {
@Output() fileImported = new EventEmitter<File>();
public fileCount: number = 0; public fileCount: number = 0;
public files: FileOsMetadata[] = []; public files: FileOsMetadata[] = [];
public importTagsFromTxt = true; public importOptions = new AddFileOptions();
public deleteAfterImport = false;
public resolving = false; public resolving = false;
public importing = false;
public importingProgress = 0;
constructor(private errorBroker: ErrorBrokerService, private importService: ImportService) { constructor(private errorBroker: ErrorBrokerService, private importService: ImportService) {
} }
@ -31,4 +36,22 @@ export class FilesystemImportComponent {
} }
this.resolving = false; this.resolving = false;
} }
public async import() {
this.importing = true;
this.importingProgress = 0;
for (const file of this.files) {
try {
const resultFile = await this.importService.addLocalFile(file, this.importOptions);
this.fileImported.emit(resultFile);
} catch (err) {
console.log(err);
this.errorBroker.showError(err);
}
this.importingProgress++;
}
this.importing = false;
}
} }

@ -12,7 +12,7 @@
<mat-divider></mat-divider> <mat-divider></mat-divider>
</div> </div>
<div class="import-configuration" fxFlex fxFlexFill> <div class="import-configuration" fxFlex fxFlexFill>
<app-filesystem-import></app-filesystem-import> <app-filesystem-import (fileImported)="this.fileImported.emit($event)"></app-filesystem-import>
</div> </div>
</div> </div>
</mat-tab> </mat-tab>

@ -1,5 +1,12 @@
import {Component, OnInit, ViewChild} from '@angular/core'; import {
Component,
EventEmitter,
OnInit,
Output,
ViewChild
} from '@angular/core';
import {MatTabGroup} from "@angular/material/tabs"; import {MatTabGroup} from "@angular/material/tabs";
import {File} from "../../../../models/File";
@Component({ @Component({
selector: 'app-import-tab-sidebar', selector: 'app-import-tab-sidebar',
@ -8,5 +15,6 @@ import {MatTabGroup} from "@angular/material/tabs";
}) })
export class ImportTabSidebarComponent { export class ImportTabSidebarComponent {
@Output() fileImported = new EventEmitter<File>();
constructor() { } constructor() { }
} }

@ -1,6 +1,6 @@
<mat-drawer-container> <mat-drawer-container>
<mat-drawer disableClose="true" mode="side" opened> <mat-drawer disableClose="true" mode="side" opened>
<app-import-tab-sidebar></app-import-tab-sidebar> <app-import-tab-sidebar (fileImported)="this.addFileFromImport($event)"></app-import-tab-sidebar>
</mat-drawer> </mat-drawer>
<mat-drawer-content> <mat-drawer-content>
<app-file-grid [files]="this.files" ></app-file-grid> <app-file-grid [files]="this.files" ></app-file-grid>

@ -16,7 +16,8 @@ mat-drawer {
width: 25%; width: 25%;
} }
app-import-tab-sidebar { app-import-tab-sidebar, app-file-gallery {
height: 100%; height: 100%;
width: 100%; width: 100%;
margin: 0;
} }

@ -6,13 +6,15 @@ import {File} from "../../../models/File";
templateUrl: './import-tab.component.html', templateUrl: './import-tab.component.html',
styleUrls: ['./import-tab.component.scss'] styleUrls: ['./import-tab.component.scss']
}) })
export class ImportTabComponent implements OnInit { export class ImportTabComponent {
public files: File[] = []; public files: File[] = [];
constructor() { } constructor() { }
ngOnInit(): void { public addFileFromImport(file: File) {
this.files.push(file);
this.files = [...this.files];
} }
} }

@ -1,6 +1,8 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import {FileOsMetadata} from "../../models/FileOsMetadata"; import {FileOsMetadata} from "../../models/FileOsMetadata";
import {invoke} from "@tauri-apps/api/tauri"; import {invoke} from "@tauri-apps/api/tauri";
import {AddFileOptions} from "../../models/AddFileOptions";
import {File} from "../../models/File";
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@ -9,7 +11,22 @@ export class ImportService {
constructor() { } constructor() { }
/**
* Resolves paths from the local file system into a list of files that can be imported
* @param {string[]} paths
* @returns {Promise<FileOsMetadata[]>}
*/
public async resolvePathsToFiles(paths: string[]): Promise<FileOsMetadata[]> { public async resolvePathsToFiles(paths: string[]): Promise<FileOsMetadata[]> {
return await invoke<FileOsMetadata[]>("plugin:mediarepo|resolve_paths_to_files", {paths}); return await invoke<FileOsMetadata[]>("plugin:mediarepo|resolve_paths_to_files", {paths});
} }
/**
* Imports a file from the local file system
* @param {FileOsMetadata} metadata
* @param {AddFileOptions} options
* @returns {Promise<File>}
*/
public async addLocalFile(metadata: FileOsMetadata, options: AddFileOptions): Promise<File> {
return await invoke<File>("plugin:mediarepo|add_local_file", {metadata, options});
}
} }

Loading…
Cancel
Save