android back button added

This commit is contained in:
Lucio Lelii 2023-03-15 17:16:06 +01:00
parent 925c231db4
commit 31e2e0c9b6
9 changed files with 73 additions and 25 deletions

View File

@ -16,12 +16,8 @@ export class LoginGuard implements CanActivate {
async canActivate() {
console.log("in the authguard");
var logged =this.auth.isAuthorized();
console.log("logged? "+logged);
if (logged) {
this.router.navigate(['tabs','ws']);
}

View File

@ -1,4 +1,9 @@
import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import { initialize } from '@ionic/core';
import { SplashScreen } from '@capacitor/splash-screen';
import { EventService } from './event.service';
import { App } from '@capacitor/app';
@Component({
selector: 'app-root',
@ -6,6 +11,16 @@ import { Component } from '@angular/core';
styleUrls: ['app.component.scss'],
})
export class AppComponent {
constructor(){}
constructor(private platform: Platform, private event: EventService){
this.initializeApp();
}
initializeApp(){
this.platform.ready().then(() => {
this.platform.backButton.subscribeWithPriority(10, () => {
this.event.BackButtonEvent.emit("{}");
});
SplashScreen.hide();
})
}
}

View File

@ -3,7 +3,7 @@ import { APP_INITIALIZER, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouteReuseStrategy } from '@angular/router';
import { KeycloakAngularModule, KeycloakService } from 'keycloak-angular';
import { IonicModule, IonicRouteStrategy, ModalController, ToastController } from '@ionic/angular';
import { IonicModule, IonicRouteStrategy, ModalController, Platform, ToastController } from '@ionic/angular';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import {initializeKeycloak} from './_helper/keycloak-init.factory'
@ -13,6 +13,7 @@ import {initializeIntent} from './_helper/intent-init.factory'
import { StoragehubService } from './storagehub.service';
import { EventService } from './event.service';
@NgModule({
declarations: [AppComponent],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule, HttpClientModule, HttpClientModule, KeycloakAngularModule],
@ -38,7 +39,7 @@ import { EventService } from './event.service';
})
export class AppModule {
constructor() {
}
constructor(){}
}

View File

@ -37,12 +37,10 @@ export class D4sIntentService {
if (result && result.payload && result.payload.length) {
console.log('Intent received: ', JSON.stringify(result.payload[0]));
var modalOptions: ModalOptions = new UploadFile().getModalOptions(this.storagehub, this.uploaderInfo, result.payload[0],
(id : string) =>{
this.event.ReloadEvent.emit(id);
ShareExtension.finish();
}, (text: string) => this.presentToast(text));
(id : string) => this.event.ReloadEvent.emit(id), (text: string) => this.presentToast(text), ShareExtension.finish);
let modal = await this.modalCtrl.create(modalOptions);
await modal.present();
} else {
console.log("nothing received");
}

View File

@ -5,9 +5,13 @@ import { EventEmitter, Injectable } from '@angular/core';
})
export class EventService {
private onGoBack : Function = ()=>{}
ReloadEvent = new EventEmitter<string>();
constructor() { }
BackButtonEvent = new EventEmitter<any>();
constructor() { }
}

View File

@ -9,7 +9,7 @@ export class UploadFile {
getModalOptions(storagehub: StoragehubService, uploaderInfo: UploaderInfoService, data: any, reload: Function, notify: Function): ModalOptions {
getModalOptions(storagehub: StoragehubService, uploaderInfo: UploaderInfoService, data: any, reload: Function, notify: Function, onSelectionFinished: Function): ModalOptions {
return {
component: WsViewerComponent,
componentProps: {
@ -19,14 +19,19 @@ export class UploadFile {
notSelectableIds: [],
onSelected: (destinationItem: WSItem) => {
const itemId = destinationItem.item.id;
uploaderInfo.uploadStarted(itemId, data.title);
this.actionHandler(destinationItem, data, storagehub).then( obs => obs.subscribe({
next: () => {},
error: err => uploaderInfo.uploadFinished(itemId, data.title),
error: err => {
uploaderInfo.uploadFinished(itemId, data.title);
notify(`error uploading file ${data.title} to workspace`);
},
complete: () => {
notify(`uploaded file ${data.title}`);
uploaderInfo.uploadFinished(itemId, data.title),
reload(itemId);
onSelectionFinished();
},
}

View File

@ -15,7 +15,7 @@
</ion-segment>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button [hidden]="root" text="" defaultHref="/">
<ion-back-button #backbutton [hidden]="root" text="" defaultHref="/">
<mat-icon>arrow_back_ios_new</mat-icon>
</ion-back-button>
</ion-buttons>

View File

@ -1,6 +1,6 @@
import { Component, OnInit, Input, CUSTOM_ELEMENTS_SCHEMA, Output, EventEmitter, ElementRef, ViewChild } from '@angular/core';
import { Component, OnInit, Input, CUSTOM_ELEMENTS_SCHEMA, Output, EventEmitter, ElementRef, ViewChild, OnDestroy, AfterViewInit } from '@angular/core';
import { AlertController, ToastController, IonicModule, ActionSheetController, ActionSheetButton, AlertOptions, ModalController, ModalOptions, LoadingController } from '@ionic/angular';
import { AlertController, ToastController, IonicModule, ActionSheetController, ActionSheetButton, AlertOptions, ModalController, ModalOptions, LoadingController, Platform, IonBackButtonDelegate, NavController } from '@ionic/angular';
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
import { StoragehubService } from '../storagehub.service';
@ -16,6 +16,7 @@ import { UploaderInfoService } from '../uploader-info.service';
import { EventService } from '../event.service';
import { OpenFile } from '../model/actions/open-file';
import { presentConnectionAlert } from '../_helper/utils';
import { Subscription } from 'rxjs';
@Component({
standalone: true,
@ -28,7 +29,7 @@ import { presentConnectionAlert } from '../_helper/utils';
CommonModule, IonicModule, MatIconModule, ItemsListComponent
]
})
export class ShowFolderComponent implements OnInit {
export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit {
@Output() folderClickedEvent = new EventEmitter<WSItem>();
@ -49,6 +50,8 @@ export class ShowFolderComponent implements OnInit {
@Input() root: boolean = false;
selectedSegment = "all";
public get sortName(): typeof SortName {
@ -58,7 +61,7 @@ export class ShowFolderComponent implements OnInit {
underUpload: string[];
@ViewChild('filepicker') uploader!: ElementRef;
customSortAlertOptions = {
header: 'Sort by',
translucent: true,
@ -73,17 +76,33 @@ export class ShowFolderComponent implements OnInit {
private uploaderInfo: UploaderInfoService,
private event: EventService,
private fileOpener: FileOpener,
private loadingCtrl: LoadingController
private loadingCtrl: LoadingController,
private navController: NavController
) {
this.underUpload = this.getUnderUploadItems();
}
ngAfterViewInit(): void {
}
backButtonSubscription: Subscription | undefined;
reloadSubscription: Subscription | undefined;
ngOnInit(): void {
this.event.ReloadEvent.subscribe((val) => {
this.reloadSubscription = this.event.ReloadEvent.subscribe((val) => {
console.log(`event received with value ${val} in item ${this.parentItem?.item.id}`);
if (val === this.parentItem?.item.id)
this.loadDocuments();
});
this.backButtonSubscription = this.event.BackButtonEvent.subscribe(() => this.onbackButtonPressed());
}
ngOnDestroy(): void {
var p: IonBackButtonDelegate
this.reloadSubscription?.unsubscribe();
this.backButtonSubscription?.unsubscribe();
}
getUnderUploadItems(): string[] {
@ -115,6 +134,14 @@ export class ShowFolderComponent implements OnInit {
}
}
onbackButtonPressed() {
if (!this.root) {
console.log("back clicked (not root)");
this.navController.pop();
} else console.log("back clicked (root)");
}
getSegmentFilterFunction(): (value: WSItem) => unknown {
var filterItemFunction;
switch (this.selectedSegment) {

View File

@ -2,6 +2,7 @@ import { CommonModule } from '@angular/common';
import { Component, Input, OnInit } from '@angular/core';
import { MatIconModule } from '@angular/material/icon';
import { IonicModule, ModalController } from '@ionic/angular';
import { EventService } from '../event.service';
import { Sorting, SortName, SortType } from '../model/sorting';
import { WSItem } from '../model/ws-item';
import { StoragehubService } from '../storagehub.service';
@ -19,7 +20,7 @@ import { StoragehubService } from '../storagehub.service';
export class WsViewerComponent implements OnInit {
constructor(private storagehub: StoragehubService,
private modalCtrl: ModalController) { }
private modalCtrl: ModalController, private eventService: EventService ) { }
@Input() notClickableIds: string[] = [];
@Input() notSelectableIds: string[] = [];
@ -39,6 +40,7 @@ export class WsViewerComponent implements OnInit {
this.loadDocuments();
}
loadDocuments() {
if (this.currentItem) {
this.storagehub.getChildren(this.currentItem.item.id).then( (obs) => obs.subscribe(
@ -89,7 +91,7 @@ export class WsViewerComponent implements OnInit {
var tmpitem = this.anchestors?.pop();
this.currentItem = tmpitem;
}
this.ngOnInit();
this.loadDocuments();
}
cancel() {