From 4f87f755b352e16e1039287f90858766a82eef63 Mon Sep 17 00:00:00 2001 From: Lucio Lelii Date: Thu, 16 Mar 2023 16:15:10 +0100 Subject: [PATCH] search added --- ios/App/App/AppDelegate.swift | 71 +++++++++---------- ios/App/upload/ShareViewController.swift | 3 +- src/app/d4s-intent.service.ts | 18 +++-- src/app/model/actions/open-file.ts | 4 +- src/app/model/actions/upload-file.ts | 17 ++++- .../show-folder/show-folder.component.html | 13 ++-- src/app/show-folder/show-folder.component.ts | 62 +++++++++++----- 7 files changed, 117 insertions(+), 71 deletions(-) diff --git a/ios/App/App/AppDelegate.swift b/ios/App/App/AppDelegate.swift index e6a6964..1fa43c1 100644 --- a/ios/App/App/AppDelegate.swift +++ b/ios/App/App/AppDelegate.swift @@ -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. diff --git a/ios/App/upload/ShareViewController.swift b/ios/App/upload/ShareViewController.swift index 7c1d68b..14baa3a 100644 --- a/ios/App/upload/ShareViewController.swift +++ b/ios/App/upload/ShareViewController.swift @@ -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); diff --git a/src/app/d4s-intent.service.ts b/src/app/d4s-intent.service.ts index fe2d841..318d86f 100644 --- a/src/app/d4s-intent.service.ts +++ b/src/app/d4s-intent.service.ts @@ -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(); + } + } diff --git a/src/app/model/actions/open-file.ts b/src/app/model/actions/open-file.ts index 5dfed9e..b231f08 100644 --- a/src/app/model/actions/open-file.ts +++ b/src/app/model/actions/open-file.ts @@ -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 }); }) diff --git a/src/app/model/actions/upload-file.ts b/src/app/model/actions/upload-file.ts index 53c4eaa..a20ffae 100644 --- a/src/app/model/actions/upload-file.ts +++ b/src/app/model/actions/upload-file.ts @@ -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); diff --git a/src/app/show-folder/show-folder.component.html b/src/app/show-folder/show-folder.component.html index ff52574..4e2b8f0 100644 --- a/src/app/show-folder/show-folder.component.html +++ b/src/app/show-folder/show-folder.component.html @@ -15,7 +15,7 @@ - + arrow_back_ios_new @@ -24,12 +24,13 @@ create_new_folder upload_file - +
- + Name Last Modified Size @@ -37,8 +38,12 @@ {{ currentSortType }} + + +
- \ No newline at end of file diff --git a/src/app/show-folder/show-folder.component.ts b/src/app/show-folder/show-folder.component.ts index 1b0d5cb..3b339b7 100644 --- a/src/app/show-folder/show-folder.component.ts +++ b/src/app/show-folder/show-folder.component.ts @@ -33,7 +33,8 @@ export class ShowFolderComponent implements OnInit, OnDestroy, AfterViewInit { @Output() folderClickedEvent = new EventEmitter(); - 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() {