search added

This commit is contained in:
Lucio Lelii 2023-03-16 16:15:10 +01:00
parent 4b4f14382d
commit 4f87f755b3
7 changed files with 117 additions and 71 deletions

View File

@ -37,44 +37,41 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
print("application function called")
var success = true
if CAPBridge.handleOpenUrl(url, options) {
success = ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}
guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
let params = components.queryItems else {
return false
}
let titles = params.filter { $0.name == "title" }
let descriptions = params.filter { $0.name == "description" }
let types = params.filter { $0.name == "type" }
let urls = params.filter { $0.name == "url" }
let webPaths = params.filter { $0.name == "webPath" }
store.shareItems.removeAll()
if (titles.count > 0){
for index in 0...titles.count-1 {
var shareItem: JSObject = JSObject()
shareItem["title"] = titles[index].value!
shareItem["description"] = descriptions[index].value!
shareItem["type"] = types[index].value!
shareItem["url"] = urls[index].value!
shareItem["webPath"] = webPaths[index].value!
store.shareItems.append(shareItem)
}
}
store.processed = false
let nc = NotificationCenter.default
nc.post(name: Notification.Name("triggerSendIntent"), object: nil )
return success
var success = true
if CAPBridge.handleOpenUrl(url, options) {
success = ApplicationDelegateProxy.shared.application(app, open: url, options: options)
}
guard let components = NSURLComponents(url: url, resolvingAgainstBaseURL: true),
let params = components.queryItems else {
return false
}
let titles = params.filter { $0.name == "title" }
let descriptions = params.filter { $0.name == "description" }
let types = params.filter { $0.name == "type" }
let urls = params.filter { $0.name == "url" }
let webPaths = params.filter { $0.name == "webPath" }
store.shareItems.removeAll()
if (titles.count > 0){
for index in 0...titles.count-1 {
var shareItem: JSObject = JSObject()
shareItem["title"] = titles[index].value!
shareItem["description"] = descriptions[index].value!
shareItem["type"] = types[index].value!
shareItem["url"] = urls[index].value!
shareItem["webPath"] = webPaths[index].value!
store.shareItems.append(shareItem)
}
}
store.processed = false
let nc = NotificationCenter.default
nc.post(name: Notification.Name("triggerSendIntent"), object: nil )
return success
}
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
// Called when the app was launched with an activity, including Universal Links.

View File

@ -21,7 +21,6 @@ class ShareViewController: UIViewController {
private var shareItems: [ShareItem] = []
override public func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
print("did appear called");
self.extensionContext!.completeRequest(returningItems: [], completionHandler: nil)
}
@ -78,7 +77,7 @@ class ShareViewController: UIViewController {
value: $0.webPath?.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed) ?? "")
]
}.flatMap({ $0 })
var urlComps = URLComponents(string: "d4sworkspace://share-input")!
var urlComps = URLComponents(string: "d4sworkspace:/")!
urlComps.queryItems = queryItems
var opened = openURL(urlComps.url!)
print("sending data %s",opened);

View File

@ -1,5 +1,6 @@
import { Injectable } from '@angular/core';
import { ModalController, ModalOptions, ToastController } from '@ionic/angular';
import { App } from '@capacitor/app';
import { isPlatform, LoadingController, ModalController, ModalOptions, ToastController } from '@ionic/angular';
import { ShareExtension } from 'capacitor-share-extension';
import { EventService } from './event.service';
import { UploadFile } from './model/actions/upload-file';
@ -15,9 +16,10 @@ export class D4sIntentService {
private toastController: ToastController,
private storagehub: StoragehubService,
private uploaderInfo: UploaderInfoService,
private event: EventService) { }
private event: EventService,
private loadingCtrl: LoadingController) { }
async checkIntent() {
try {
const result: any = await ShareExtension.checkSendIntentReceived();
@ -36,8 +38,8 @@ 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), (text: string) => this.presentToast(text), ShareExtension.finish);
var modalOptions: ModalOptions = new UploadFile().getModalOptions(this.storagehub, this.uploaderInfo, this.loadingCtrl, result.payload[0],
(id: string) => this.event.ReloadEvent.emit(id), (text: string) => this.presentToast(text), this.shareExtensionClose);
let modal = await this.modalCtrl.create(modalOptions);
await modal.present();
@ -56,4 +58,10 @@ export class D4sIntentService {
});
await toast.present();
}
async shareExtensionClose() {
ShareExtension.finish();
}
}

View File

@ -21,7 +21,7 @@ export class OpenFile {
Filesystem.deleteFile(
{
path: item.getTitle(),
directory: Directory.Documents
directory: Directory.Data
}).then(() => console.log("file deleted"));
this.pluginListener?.remove();
}).then((handler) => this.pluginListener = handler);
@ -52,7 +52,7 @@ export class OpenFile {
Filesystem.deleteFile(
{
path: this.item.getTitle(),
directory: Directory.Documents
directory: Directory.Data
});
})

View File

@ -1,4 +1,4 @@
import { ModalOptions } from "@ionic/angular";
import { LoadingController, ModalOptions } from "@ionic/angular";
import { StoragehubService } from "src/app/storagehub.service";
import { WsViewerComponent } from "src/app/ws-viewer/ws-viewer.component";
import { WSItem } from "../ws-item";
@ -9,7 +9,7 @@ export class UploadFile {
getModalOptions(storagehub: StoragehubService, uploaderInfo: UploaderInfoService, data: any, reload: Function, notify: Function, onSelectionFinished: Function): ModalOptions {
getModalOptions(storagehub: StoragehubService, uploaderInfo: UploaderInfoService, loading: LoadingController, data: any, reload: Function, notify: Function, onSelectionFinished: Function): ModalOptions {
return {
component: WsViewerComponent,
componentProps: {
@ -20,6 +20,7 @@ export class UploadFile {
onSelected: (destinationItem: WSItem) => {
const itemId = destinationItem.item.id;
this.showLoading(loading);
uploaderInfo.uploadStarted(itemId, data.title);
this.actionHandler(destinationItem, data, storagehub).then( obs => obs.subscribe({
next: () => {},
@ -30,6 +31,7 @@ export class UploadFile {
complete: () => {
notify(`uploaded file ${data.title}`);
uploaderInfo.uploadFinished(itemId, data.title),
loading.dismiss();
reload(itemId);
onSelectionFinished();
},
@ -42,6 +44,17 @@ export class UploadFile {
}
async showLoading(loadingCtrl: LoadingController) {
const loading = await loadingCtrl.create({
message: 'Uploading...',
duration: 100000,
spinner: 'circles',
});
loading.present();
return loading;
}
async actionHandler(destinationItem: WSItem, result: any, storagehub: StoragehubService) {
const pathDecodedWebPath = decodeURIComponent(result.webPath);

View File

@ -15,7 +15,7 @@
</ion-segment>
<ion-toolbar>
<ion-buttons slot="start">
<ion-back-button #backbutton [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>
@ -24,12 +24,13 @@
<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-progress-bar *ngIf="!filteredItems" type="indeterminate"></ion-progress-bar>
<ion-progress-bar *ngIf="!filtereBySearchItems" type="indeterminate"></ion-progress-bar>
</ion-toolbar>
<div>
<ion-buttons slot="start">
<ion-item>
<ion-select [interfaceOptions]="customSortAlertOptions" (ionChange)="changeSortName($event)" interface="alert" [value]="currentSortName">
<ion-select [interfaceOptions]="customSortAlertOptions" (ionChange)="changeSortName($event)" interface="alert"
[value]="currentSortName">
<ion-select-option [value]="sortName.Name"> Name </ion-select-option>
<ion-select-option [value]="sortName.LastModificationTime"> Last Modified </ion-select-option>
<ion-select-option [value]="sortName.Size"> Size </ion-select-option>
@ -37,8 +38,12 @@
</ion-item>
<ion-button (click)="changeSortType()"><mat-icon>{{ currentSortType }}</mat-icon></ion-button>
</ion-buttons>
<ion-buttons slot="end">
<ion-searchbar [disabled]="!filtereBySearchItems || (filtereBySearchItems.length == 0 && currentSearch.length==0)"
[debounce]="500" (ionClear)="searchCleared()" (ionChange)="searchItems($event)"></ion-searchbar>
</ion-buttons>
</div>
<input hidden type="file" #filepicker (change)="fileSelected($event)" />
<app-items-list [items]="filteredItems" [underUploadItem]="underUpload"
<app-items-list [items]="filtereBySearchItems" [underUploadItem]="underUpload"
(actionSheetClickedEvent)="presentActionSheet($event)" (itemClickedEvent)="itemClicked($event)"></app-items-list>
</ion-content>

View File

@ -33,7 +33,8 @@ export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit {
@Output() folderClickedEvent = new EventEmitter<WSItem>();
filteredItems: WSItem[] | undefined;
filteredBySegmentItems: WSItem[] | undefined;
filtereBySearchItems: WSItem[] | undefined;
_items: WSItem[] | undefined;
currentSortName = SortName.Name;
@ -41,7 +42,8 @@ export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit {
@Input() set items(items: WSItem[] | undefined) {
this._items = items?.sort(Sorting.getSortFunction(this.currentSortName, this.currentSortType));
this.filteredItems = this._items;
this.filteredBySegmentItems = this._items;
this.filtereBySearchItems = this._items
}
@Input() parentItem: WSItem | undefined = undefined;
@ -59,6 +61,7 @@ export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit {
}
underUpload: string[];
currentSearch: string = "";
@ViewChild('filepicker') uploader!: ElementRef;
@ -98,7 +101,6 @@ export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit {
ngOnDestroy(): void {
var p: IonBackButtonDelegate
this.reloadSubscription?.unsubscribe();
@ -111,21 +113,23 @@ export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit {
}
loadDocuments() {
this.filteredItems = undefined;
this.filtereBySearchItems = undefined;
if (this.parentItem) {
this.storagehub.getChildren(this.parentItem.item.id).then((obs) => obs.subscribe({
next: (res) => {
const tmpItems$: WSItem[] = []
const tmpFiltered$: WSItem[] = []
const tmpFilteredBySegment$: WSItem[] = []
var segmentFilterFunction = this.getSegmentFilterFunction();
res.forEach(i => {
var localItem = new WSItem(i);
tmpItems$.push(localItem);
if (segmentFilterFunction(localItem))
tmpFiltered$.push(localItem);
if (segmentFilterFunction(localItem)){
tmpFilteredBySegment$.push(localItem);
}
});
this._items = tmpItems$.sort(Sorting.getSortFunction(this.currentSortName, this.currentSortType));
this.filteredItems = tmpFiltered$.sort(Sorting.getSortFunction(this.currentSortName, this.currentSortType));
this.filteredBySegmentItems = tmpFilteredBySegment$.sort(Sorting.getSortFunction(this.currentSortName, this.currentSortType));
this.filtereBySearchItems = tmpFilteredBySegment$.filter(d => d.getTitle().toLowerCase().indexOf(this.currentSearch) > -1)
this.underUpload = this.getUnderUploadItems();
},
error: err => presentConnectionAlert(err, this.alertCtrl)
@ -142,7 +146,7 @@ export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit {
}
getSegmentFilterFunction(): (value: WSItem) => unknown {
getSegmentFilterFunction(): (value: WSItem) => boolean {
var filterItemFunction;
switch (this.selectedSegment) {
case "shared":
@ -162,15 +166,18 @@ export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit {
filterBy(value: string) {
if (value == this.selectedSegment) return;
this.filteredItems = undefined;
this.filtereBySearchItems = undefined;
this.selectedSegment = value;
if (this.selectedSegment == "all")
this.filteredItems = this._items;
else {
const tmpFiltered$: WSItem[] = []
this._items?.filter(this.getSegmentFilterFunction()).forEach((i) => tmpFiltered$.push(i));
this.filteredItems = tmpFiltered$;
}
this.filtereBySearchItems = this._items;
else
this.filteredBySegmentItems = this._items?.filter(this.getSegmentFilterFunction());
if (this.currentSearch.length != 0)
this.filtereBySearchItems = this.filteredBySegmentItems?.filter(d => d.getTitle().toLowerCase().indexOf(this.currentSearch) > -1);
else this.filtereBySearchItems = this.filteredBySegmentItems;
}
changeSortType() {
@ -190,7 +197,26 @@ export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit {
updateSort() {
this._items = this._items?.sort(Sorting.getSortFunction(this.currentSortName, this.currentSortType));
this.filteredItems = this.filteredItems?.sort(Sorting.getSortFunction(this.currentSortName, this.currentSortType));
if (this.selectedSegment == "all")
this.filteredBySegmentItems = this._items;
else
this.filteredBySegmentItems = this.filteredBySegmentItems?.sort(Sorting.getSortFunction(this.currentSortName, this.currentSortType));
if (this.currentSearch.length!=0 )
this.filtereBySearchItems = this.filtereBySearchItems?.sort(Sorting.getSortFunction(this.currentSortName, this.currentSortType));
else this.filtereBySearchItems = this.filteredBySegmentItems;
}
searchItems(event: any) {
const query: string = event.target.value.toLowerCase();
this.currentSearch = query;
this.filtereBySearchItems = this.filteredBySegmentItems?.filter(d => d.getTitle().toLowerCase().indexOf(query) > -1);
}
searchCleared(){
this.currentSearch = "";
this.filtereBySearchItems = this.filteredBySegmentItems
}
itemClicked(item: WSItem) {
@ -199,8 +225,6 @@ export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit {
else if (item.isFile()) {
new OpenFile(item).open(this.storagehub, this.fileOpener, this.loadingCtrl, this.alertCtrl);
}
}
addFile() {