Skip to content

Commit

Permalink
Allow use of filepicker filter
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher Ng <chrng8@gmail.com>
  • Loading branch information
Pytal committed Nov 1, 2022
1 parent 214ddee commit 466bbd3
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions lib/filepicker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/// <reference types="@nextcloud/typings" />

declare const OC: Nextcloud.v16.OC | Nextcloud.v17.OC | Nextcloud.v18.OC | Nextcloud.v19.OC | Nextcloud.v20.OC;
declare const OC: Nextcloud.v23.OC | Nextcloud.v24.OC;

export enum FilePickerType {
Choose = 1,
Expand All @@ -17,21 +17,24 @@ export class FilePicker {
private type: FilePickerType
private directoriesAllowed: boolean
private path?: string
private filter?: Nextcloud.v24.FilePickerFilter

public constructor(title: string,
multiSelect: boolean,
mimeTypeFilter: string[],
modal: boolean,
type: FilePickerType,
directoriesAllowed: boolean,
path?: string) {
path?: string,
filter?: Nextcloud.v24.FilePickerFilter) {
this.title = title
this.multiSelect = multiSelect
this.mimeTypeFiler = mimeTypeFilter
this.modal = modal
this.type = type
this.directoriesAllowed = directoriesAllowed
this.path = path
this.filter = filter
}

public pick(): Promise<string> {
Expand All @@ -45,8 +48,9 @@ export class FilePicker {
this.type,
this.path,
{
allowDirectoryChooser: this.directoriesAllowed
}
allowDirectoryChooser: this.directoriesAllowed,
filter: this.filter,
},
)
})
}
Expand All @@ -60,6 +64,7 @@ export class FilePickerBuilder {
private type: FilePickerType = FilePickerType.Choose
private directoriesAllowed: boolean = false
private path?: string
private filter?: Nextcloud.v24.FilePickerFilter

public constructor(title: string) {
this.title = title
Expand Down Expand Up @@ -100,6 +105,11 @@ export class FilePickerBuilder {
return this
}

public setFilter(filter: Nextcloud.v24.FilePickerFilter): FilePickerBuilder {
this.filter = filter
return this
}

public build(): FilePicker {
return new FilePicker(
this.title,
Expand All @@ -108,7 +118,8 @@ export class FilePickerBuilder {
this.modal,
this.type,
this.directoriesAllowed,
this.path
this.path,
this.filter,
)
}

Expand Down

0 comments on commit 466bbd3

Please sign in to comment.