|
|
|
|
@ -4,8 +4,11 @@
|
|
|
|
|
*/
|
|
|
|
|
import type { IFileListFilterChip, INode } from '@nextcloud/files'
|
|
|
|
|
|
|
|
|
|
import { subscribe } from '@nextcloud/event-bus'
|
|
|
|
|
import { FileListFilter, registerFileListFilter } from '@nextcloud/files'
|
|
|
|
|
import { ShareType } from '@nextcloud/sharing'
|
|
|
|
|
import Vue from 'vue'
|
|
|
|
|
|
|
|
|
|
import FileListFilterAccount from '../components/FileListFilterAccount.vue'
|
|
|
|
|
|
|
|
|
|
export interface IAccountData {
|
|
|
|
|
@ -13,18 +16,28 @@ export interface IAccountData {
|
|
|
|
|
displayName: string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type CurrentInstance = Vue & { resetFilter: () => void, toggleAccount: (account: string) => void }
|
|
|
|
|
type CurrentInstance = Vue & {
|
|
|
|
|
resetFilter: () => void
|
|
|
|
|
setAvailableAccounts: (accounts: IAccountData[]) => void
|
|
|
|
|
toggleAccount: (account: string) => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* File list filter to filter by owner / sharee
|
|
|
|
|
*/
|
|
|
|
|
class AccountFilter extends FileListFilter {
|
|
|
|
|
|
|
|
|
|
private availableAccounts: IAccountData[]
|
|
|
|
|
private currentInstance?: CurrentInstance
|
|
|
|
|
private filterAccounts?: IAccountData[]
|
|
|
|
|
|
|
|
|
|
constructor() {
|
|
|
|
|
super('files_sharing:account', 100)
|
|
|
|
|
this.availableAccounts = []
|
|
|
|
|
|
|
|
|
|
subscribe('files:list:updated', ({ contents }) => {
|
|
|
|
|
this.updateAvailableAccounts(contents)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public mount(el: HTMLElement) {
|
|
|
|
|
@ -33,11 +46,11 @@ class AccountFilter extends FileListFilter {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const View = Vue.extend(FileListFilterAccount as never)
|
|
|
|
|
this.currentInstance = new View({
|
|
|
|
|
el,
|
|
|
|
|
})
|
|
|
|
|
.$on('update:accounts', this.setAccounts.bind(this))
|
|
|
|
|
this.currentInstance = new View({ el })
|
|
|
|
|
.$on('update:accounts', (accounts?: IAccountData[]) => this.setAccounts(accounts))
|
|
|
|
|
.$mount() as CurrentInstance
|
|
|
|
|
this.currentInstance
|
|
|
|
|
.setAvailableAccounts(this.availableAccounts)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public filter(nodes: INode[]): INode[] {
|
|
|
|
|
@ -70,6 +83,11 @@ class AccountFilter extends FileListFilter {
|
|
|
|
|
this.currentInstance?.resetFilter()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set accounts that should be filtered.
|
|
|
|
|
*
|
|
|
|
|
* @param accounts - Account to filter or undefined if inactive.
|
|
|
|
|
*/
|
|
|
|
|
public setAccounts(accounts?: IAccountData[]) {
|
|
|
|
|
this.filterAccounts = accounts
|
|
|
|
|
let chips: IFileListFilterChip[] = []
|
|
|
|
|
@ -85,6 +103,49 @@ class AccountFilter extends FileListFilter {
|
|
|
|
|
this.filterUpdated()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Update the accounts owning nodes or have nodes shared to them.
|
|
|
|
|
*
|
|
|
|
|
* @param nodes - The current content of the file list.
|
|
|
|
|
*/
|
|
|
|
|
protected updateAvailableAccounts(nodes: INode[]): void {
|
|
|
|
|
const available = new Map<string, IAccountData>()
|
|
|
|
|
|
|
|
|
|
for (const node of nodes) {
|
|
|
|
|
const owner = node.owner
|
|
|
|
|
if (owner && !available.has(owner)) {
|
|
|
|
|
available.set(owner, {
|
|
|
|
|
uid: owner,
|
|
|
|
|
displayName: node.attributes['owner-display-name'] ?? node.owner,
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ensure sharees is an array (if only one share then it is just an object)
|
|
|
|
|
const sharees: { id: string, 'display-name': string, type: ShareType }[] = [node.attributes.sharees?.sharee].flat().filter(Boolean)
|
|
|
|
|
for (const sharee of [sharees].flat()) {
|
|
|
|
|
// Skip link shares and other without user
|
|
|
|
|
if (sharee.id === '') {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
if (sharee.type !== ShareType.User && sharee.type !== ShareType.Remote) {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
// Add if not already added
|
|
|
|
|
if (!available.has(sharee.id)) {
|
|
|
|
|
available.set(sharee.id, {
|
|
|
|
|
uid: sharee.id,
|
|
|
|
|
displayName: sharee['display-name'],
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.availableAccounts = [...available.values()]
|
|
|
|
|
if (this.currentInstance) {
|
|
|
|
|
this.currentInstance.setAvailableAccounts(this.availableAccounts)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|