Add file count to importing progress

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/14/head
trivernis 3 years ago
parent 7189f65afd
commit 1df5c9e8ed
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -1,10 +1,11 @@
import {Component, EventEmitter, Input, Output} from "@angular/core"; import {ChangeDetectionStrategy, Component, EventEmitter, Input, Output} from "@angular/core";
import {File} from "../../../../../api/models/File"; import {File} from "../../../../../api/models/File";
@Component({ @Component({
selector: "app-import-tab-sidebar", selector: "app-import-tab-sidebar",
templateUrl: "./import-tab-sidebar.component.html", templateUrl: "./import-tab-sidebar.component.html",
styleUrls: ["./import-tab-sidebar.component.scss"] styleUrls: ["./import-tab-sidebar.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class ImportTabSidebarComponent { export class ImportTabSidebarComponent {

@ -1,11 +1,12 @@
import {Component, Input, OnInit} from "@angular/core"; import {ChangeDetectionStrategy, ChangeDetectorRef, Component, Input, OnInit} from "@angular/core";
import {File} from "../../../../api/models/File"; import {File} from "../../../../api/models/File";
import {TabState} from "../../../models/TabState"; import {TabState} from "../../../models/TabState";
@Component({ @Component({
selector: "app-import-tab", selector: "app-import-tab",
templateUrl: "./import-tab.component.html", templateUrl: "./import-tab.component.html",
styleUrls: ["./import-tab.component.scss"] styleUrls: ["./import-tab.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class ImportTabComponent implements OnInit { export class ImportTabComponent implements OnInit {
@ -16,7 +17,7 @@ export class ImportTabComponent implements OnInit {
private newFiles: File[] = []; private newFiles: File[] = [];
constructor() { constructor(private changeDetector: ChangeDetectorRef) {
} }
public ngOnInit(): void { public ngOnInit(): void {
@ -29,19 +30,8 @@ export class ImportTabComponent implements OnInit {
* @returns {Promise<void>} * @returns {Promise<void>}
*/ */
public async addFileFromImport(file: File) { public async addFileFromImport(file: File) {
this.newFiles.push(file); this.state.files.next([...this.state.files.value, file]);
if (this.newFiles.length % 50 === 0) { // refresh every 50 pictures this.changeDetector.markForCheck();
this.refreshFileView();
}
}
/**
* Refreshes the file view
* @returns {Promise<void>}
*/
public refreshFileView() {
this.state.files.next([...this.state.files.value, ...this.newFiles]);
this.newFiles = [];
} }
public onFileSelect(files: File[]) { public onFileSelect(files: File[]) {
@ -62,4 +52,8 @@ export class ImportTabComponent implements OnInit {
return undefined; return undefined;
} }
} }
public refreshFileView(): void {
this.changeDetector.markForCheck();
}
} }

@ -1,10 +1,11 @@
import {Component, EventEmitter, Output} from "@angular/core"; import {ChangeDetectionStrategy, Component, EventEmitter, Output} from "@angular/core";
import {File} from "../../../../../api/models/File"; import {File} from "../../../../../api/models/File";
@Component({ @Component({
selector: "app-file-import", selector: "app-file-import",
templateUrl: "./file-import.component.html", templateUrl: "./file-import.component.html",
styleUrls: ["./file-import.component.scss"] styleUrls: ["./file-import.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush,
}) })
export class FileImportComponent { export class FileImportComponent {

@ -29,7 +29,7 @@
<button (click)="import()" [disabled]="importing || this.fileCount === 0" class="import-button" color="primary" <button (click)="import()" [disabled]="importing || this.fileCount === 0" class="import-button" color="primary"
mat-flat-button> mat-flat-button>
{{importing ? "Importing..." : "Import"}} {{importing ? "Importing... (" + this.importingProgressTotal + "/" + this.fileCount + ")" : "Import"}}
</button> </button>
<mat-progress-bar *ngIf="importing" [value]="this.importingProgress" color="primary" <mat-progress-bar *ngIf="importing" [value]="this.importingProgress" color="primary"
mode="determinate"></mat-progress-bar> mode="determinate"></mat-progress-bar>

@ -1,4 +1,4 @@
import {Component, EventEmitter, Output} from "@angular/core"; import {ChangeDetectionStrategy, ChangeDetectorRef, Component, EventEmitter, Output} from "@angular/core";
import {ImportService} from "../../../../../services/import/import.service"; import {ImportService} from "../../../../../services/import/import.service";
import {LoggingService} from "../../../../../services/logging/logging.service"; import {LoggingService} from "../../../../../services/logging/logging.service";
import {AddFileOptions} from "../../../../../models/AddFileOptions"; import {AddFileOptions} from "../../../../../models/AddFileOptions";
@ -9,7 +9,8 @@ import {FileOsMetadata} from "../../../../../../api/api-types/files";
@Component({ @Component({
selector: "app-filesystem-import", selector: "app-filesystem-import",
templateUrl: "./filesystem-import.component.html", templateUrl: "./filesystem-import.component.html",
styleUrls: ["./filesystem-import.component.scss"] styleUrls: ["./filesystem-import.component.scss"],
changeDetection: ChangeDetectionStrategy.OnPush
}) })
export class FilesystemImportComponent { export class FilesystemImportComponent {
@ -35,11 +36,17 @@ export class FilesystemImportComponent {
public resolving = false; public resolving = false;
public importing = false; public importing = false;
public importingProgress = 0; public importingProgress = 0;
public importingProgressTotal = 0;
constructor(private errorBroker: LoggingService, private importService: ImportService) { constructor(
private changeDetector: ChangeDetectorRef,
private errorBroker: LoggingService,
private importService: ImportService
) {
} }
public async setSelectedPaths(paths: string[]) { public async setSelectedPaths(paths: string[]) {
this.changeDetector.markForCheck();
this.resolving = true; this.resolving = true;
try { try {
this.files = await this.importService.resolvePathsToFiles(paths); this.files = await this.importService.resolvePathsToFiles(paths);
@ -49,6 +56,7 @@ export class FilesystemImportComponent {
this.errorBroker.error(err); this.errorBroker.error(err);
} }
this.resolving = false; this.resolving = false;
this.changeDetector.markForCheck();
} }
public async import() { public async import() {
@ -70,6 +78,7 @@ export class FilesystemImportComponent {
} }
count++; count++;
this.importingProgress = (count / this.fileCount) * 100; this.importingProgress = (count / this.fileCount) * 100;
this.importingProgressTotal = count;
} }
this.importing = false; this.importing = false;

Loading…
Cancel
Save