added upload with temp file

This commit is contained in:
Lucio Lelii 2023-02-26 16:34:34 +01:00
parent cb74165073
commit 795dfe8e63
8 changed files with 63 additions and 48 deletions

View File

@ -5,11 +5,11 @@ import { WSItem } from "../ws-item";
export abstract class Action {
getAlertOptions(item: WSItem, storagehub: StoragehubService, postOp?: Function): AlertOptions | undefined{
getAlertOptions(item: WSItem, storagehub: StoragehubService, postOp?: Function, notify?: Function): AlertOptions | undefined{
return undefined;
}
getModalOptions(item: WSItem, storagehub: StoragehubService, postOp?: Function): ModalOptions | undefined{
getModalOptions(item: WSItem, storagehub: StoragehubService, postOp?: Function, notify?: Function): ModalOptions | undefined{
return undefined;
}

View File

@ -7,26 +7,29 @@ import { Action } from "./action";
export class CopyAction extends Action {
override getModalOptions(item: WSItem, storagehub: StoragehubService, reload: Function): ModalOptions | undefined {
override getModalOptions(item: WSItem, storagehub: StoragehubService, reload: Function, notify: Function): ModalOptions | undefined {
return {
component: WsViewerComponent,
componentProps: {
finishLabel: "Copy here",
title: "Select destination folder for "+item.getTitle(),
title: "Select destination folder for " + item.getTitle(),
notClickableIds: [item.item.id],
notSelectableIds: [item.item.parentId],
onSelected: (destinationItem:WSItem) =>{
this.actionHandler({item: item, destinationItem: destinationItem}, storagehub).subscribe(
() => reload()
onSelected: (destinationItem: WSItem) => {
this.actionHandler({ item: item, destinationItem: destinationItem }, storagehub).subscribe(
() => {
reload();
notify(`${item.getTitle()} copied`);
}
)
}
}
};
};
}
actionHandler(data: {item: WSItem, destinationItem : WSItem}, storagehub: StoragehubService): Observable<any> {
actionHandler(data: { item: WSItem, destinationItem: WSItem }, storagehub: StoragehubService): Observable<any> {
return storagehub.copyItem(data.destinationItem.item.id, data.item.item.id, data.item.item.name);
}

View File

@ -8,7 +8,7 @@ import { Action } from "./action";
export class MoveAction extends Action {
override getModalOptions(item: WSItem, storagehub: StoragehubService, reload: Function): ModalOptions | undefined {
override getModalOptions(item: WSItem, storagehub: StoragehubService, reload: Function, notify: Function): ModalOptions | undefined {
return {
component: WsViewerComponent,
componentProps: {
@ -18,7 +18,10 @@ export class MoveAction extends Action {
notSelectableIds: [item.item.parentId],
onSelected: (destinationItem:WSItem) =>{
this.actionHandler({item: item, destinationItem: destinationItem}, storagehub).subscribe(
() => reload()
() => {
reload();
notify(`${item.getTitle()} moved`);
}
)
}
}

View File

@ -5,6 +5,8 @@ export class WSItem {
item: Item;
type: string;
temporary: boolean =false;
constructor(item: Item) {
this.item = item;
const tempType$ = this.getType(item);

View File

@ -6,14 +6,25 @@
</ion-back-button>
</ion-buttons>
<ion-title> {{ !root && parentItem ? parentItem.getTitle() : tabName }} </ion-title>
<ion-buttons *ngIf="parentItem" slot="end">
<ion-button (click)="createFolder()"><mat-icon>create_new_folder</mat-icon></ion-button>
<ion-button (click)="addFile()"><mat-icon>upload_file</mat-icon></ion-button>
</ion-buttons>
</ion-toolbar>
<input hidden type="file" #filepicker (change)="fileSelected($event)" />
<ion-text color="medium" *ngIf="items.length == 0" class="ion-padding ion-text-center">
<ion-text color="medium" *ngIf="items.length == 0 && underUploadItem.length == 0" class="ion-padding ion-text-center">
<p>Empty folder</p>
</ion-text>
<ion-list>
<ion-item disabled *ngFor="let u of underUploadItem">
<mat-icon slot="start">description</mat-icon>
<ion-label text-wrap>{{ u }}</ion-label>
<ion-spinner name="lines-small"></ion-spinner>
</ion-item>
<ion-item *ngFor="let i of items">
<mat-icon slot="start">{{ i.getIconInfo() }}</mat-icon>
<ion-label text-wrap (click)="itemClicked(i)">
@ -25,22 +36,7 @@
</ion-label>
<mat-icon (click)="presentActionSheet(i)" slot="end">more_horiz</mat-icon>
</ion-item>
</ion-item>
</ion-list>
<ion-fab *ngIf="parentItem" vertical="top" horizontal="end" slot="fixed" size="small">
<ion-fab-button>
<ion-icon name="add"></ion-icon>
</ion-fab-button>
<ion-fab-list side="bottom">
<ion-fab-button (click)="createFolder()">
<mat-icon>create_new_folder</mat-icon>
</ion-fab-button>
<ion-fab-button (click)="addFile()">
<mat-icon>upload_file</mat-icon>
</ion-fab-button>
</ion-fab-list>
</ion-fab>
</ion-content>

View File

@ -1,19 +1,16 @@
import { Component, OnInit, Input, CUSTOM_ELEMENTS_SCHEMA, Output, EventEmitter, ElementRef, ViewChild, ChangeDetectorRef } from '@angular/core';
import { Component, OnInit, Input, CUSTOM_ELEMENTS_SCHEMA, Output, EventEmitter, ElementRef, ViewChild } from '@angular/core';
import { Platform, AlertController, ToastController, IonicModule, ActionSheetController, ActionSheetButton, AlertOptions, ModalController, ModalOptions } from '@ionic/angular';
import { AlertController, ToastController, IonicModule, ActionSheetController, ActionSheetButton, AlertOptions, ModalController, ModalOptions } from '@ionic/angular';
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
import { Router, ActivatedRoute } from '@angular/router';
import { StoragehubService } from '../storagehub.service';
import { CommonModule } from '@angular/common';
import { Item } from '../model/item.model';
import { MatIconModule } from '@angular/material/icon';
import { WSItem } from '../model/ws-item';
import { Action } from '../model/actions/action';
import { CreateFolderAction } from '../model/actions/create-folder';
import { Actions } from '../model/actions/actions';
import { WsViewerComponent } from '../ws-viewer/ws-viewer.component';
import { BehaviorSubject } from 'rxjs';
@Component({
standalone: true,
@ -38,13 +35,17 @@ export class ShowFolderComponent implements OnInit {
@Input() root: boolean = false;
underUploadItem: string[] = [];
@ViewChild('filepicker') uploader!: ElementRef;
constructor(
private actionSheetCtrl: ActionSheetController,
private storagehub: StoragehubService,
private alertCtrl: AlertController,
private modalCtrl: ModalController
private modalCtrl: ModalController,
private toastController: ToastController
) { }
ngOnInit(): void {
@ -53,7 +54,6 @@ export class ShowFolderComponent implements OnInit {
loadDocuments() {
if (this.parentItem) {
console.log("loadDoc called");
this.storagehub.getChildren(this.parentItem.item.id).subscribe(
(res) => {
const tmpItems$: WSItem[] = []
@ -70,7 +70,6 @@ export class ShowFolderComponent implements OnInit {
}
addFile() {
console.log("add fiel called");
this.uploader.nativeElement.click();
}
@ -78,10 +77,14 @@ export class ShowFolderComponent implements OnInit {
const selected = $event.target.files[0];
if (selected && this.parentItem) {
this.underUploadItem= [selected.name];
const upload$ = this.storagehub.uploadFile(this.parentItem.item.id, selected.name, selected);
upload$.subscribe(
suc => this.loadDocuments()
);
upload$.subscribe({
next: () => this.loadDocuments(),
error: () => this.underUploadItem = [],
complete: () => this.underUploadItem = []
});
}
}
@ -112,7 +115,6 @@ export class ShowFolderComponent implements OnInit {
});
const actionSheet = await this.actionSheetCtrl.create({
header: `${item.item.title}`,
mode: 'ios',
translucent: true,
@ -134,12 +136,21 @@ export class ShowFolderComponent implements OnInit {
await modal.present();
}
async presentToast(text: string) {
const toast = await this.toastController.create({
message: text,
duration: 1500
});
await toast.present();
}
async actionHandler(action: Action, item: WSItem) {
var alertOptions: undefined | AlertOptions = action.getAlertOptions(item, this.storagehub, () => { this.loadDocuments() });
var alertOptions: undefined | AlertOptions = action.getAlertOptions(item, this.storagehub, () => this.loadDocuments());
if (alertOptions) {
await this.presentAlertControl(alertOptions);
} else {
var modalOptions: undefined | ModalOptions = action.getModalOptions(item, this.storagehub, () => { this.loadDocuments() });
var modalOptions: undefined | ModalOptions = action.getModalOptions(item, this.storagehub,
() => this.loadDocuments(), (text: string) => this.presentToast(text));
if (modalOptions)
await this.presentModal(modalOptions);
else

View File

@ -76,7 +76,7 @@ export class StoragehubService {
formData.append("name", name);
formData.append("description", "");
formData.append("file",file);
return this.http.post(uploadURL, formData, {observe: 'body', responseType: 'text'}).pipe(
return this.http.post(uploadURL, formData, {observe: 'events', responseType: 'text', reportProgress: true}).pipe(
catchError(this.error)
);
}

View File

@ -1,7 +1,7 @@
import { CommonModule } from '@angular/common';
import { Component, Input, OnInit } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { IonicModule, LoadingController, ModalController } from '@ionic/angular';
import { IonicModule, LoadingController, ModalController, ToastController } from '@ionic/angular';
import { WSItem } from '../model/ws-item';
import { StoragehubService } from '../storagehub.service';
@ -18,7 +18,7 @@ import { StoragehubService } from '../storagehub.service';
export class WsViewerComponent implements OnInit {
constructor(private storagehub: StoragehubService, private modalCtrl: ModalController,
private loadingCtrl: LoadingController) { }
) { }
@Input() notClickableIds: string[] = [];
@Input() notSelectableIds: string[] = [];