Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@
<td
v-for="column in columns"
:key="column.id"
:class="`files-list__row-${currentView.id}-${column.id}`"
:class="`files-list__row-${activeView.id}-${column.id}`"
class="files-list__row-column-custom"
:data-cy-files-list-row-column-custom="column.id"
@click="openDetailsIfAvailable">
<CustomElementRender
:current-view="currentView"
:current-view="activeView"
:render="column.render"
:source="source" />
</td>
Expand All @@ -116,9 +116,8 @@ import FileEntryCheckbox from './FileEntry/FileEntryCheckbox.vue'
import FileEntryName from './FileEntry/FileEntryName.vue'
import FileEntryPreview from './FileEntry/FileEntryPreview.vue'
import { useFileListWidth } from '../composables/useFileListWidth.ts'
import { useNavigation } from '../composables/useNavigation.ts'
import { useRouteParameters } from '../composables/useRouteParameters.ts'
import { useActionsMenuStore } from '../store/actionsmenu.ts'
import { useActiveStore } from '../store/active.ts'
import { useDragAndDropStore } from '../store/dragging.ts'
import { useFilesStore } from '../store/files.ts'
import { useRenamingStore } from '../store/renaming.ts'
Expand Down Expand Up @@ -160,24 +159,23 @@ export default defineComponent({
const renamingStore = useRenamingStore()
const selectionStore = useSelectionStore()
const filesListWidth = useFileListWidth()
// The file list is guaranteed to be only shown with active view - thus we can set the `loaded` flag
const { currentView } = useNavigation(true)

const {
directory: currentDir,
fileId: currentFileId,
} = useRouteParameters()
activeFolder,
activeNode,
activeView,
} = useActiveStore()

return {
actionsMenuStore,
activeFolder,
activeNode,
activeView,
draggingStore,
filesListWidth,
filesStore,
renamingStore,
selectionStore,

currentDir,
currentFileId,
currentView,
filesListWidth,
}
},

Expand Down Expand Up @@ -208,7 +206,7 @@ export default defineComponent({
if (this.filesListWidth < 512 || this.compact) {
return []
}
return this.currentView.columns || []
return this.activeView.columns || []
},

mime() {
Expand Down Expand Up @@ -281,7 +279,12 @@ export default defineComponent({
return
}

this.defaultFileAction?.exec(this.source, this.currentView, this.currentDir)
this.defaultFileAction?.exec({
nodes: [this.source],
folder: this.activeFolder!,
contents: this.nodes,
view: this.activeView!,
})
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion apps/files/src/components/FileEntry/FileEntryActions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export default defineComponent({
}
return this.enabledFileActions.filter((action) => {
try {
return action?.inline?.(this.source, this.currentView)
return action?.inline?.({ nodes: [this.source], view: this.currentView }) === true
} catch (error) {
logger.error('Error while checking if action is inline', { action, error })
return false
Expand Down
25 changes: 13 additions & 12 deletions apps/files/src/components/FileEntryGrid.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@
<!-- Actions -->
<FileEntryActions
ref="actions"
v-model:opened="openedMenu"
:class="`files-list__row-actions-${uniqueId}`"
:grid-mode="true"
:opened.sync="openedMenu"
:source="source" />
</tr>
</template>
Expand All @@ -79,9 +79,9 @@ import FileEntryActions from './FileEntry/FileEntryActions.vue'
import FileEntryCheckbox from './FileEntry/FileEntryCheckbox.vue'
import FileEntryName from './FileEntry/FileEntryName.vue'
import FileEntryPreview from './FileEntry/FileEntryPreview.vue'
import { useNavigation } from '../composables/useNavigation.ts'
import { useRouteParameters } from '../composables/useRouteParameters.ts'
import { useFileListWidth } from '../composables/useFileListWidth.ts'
import { useActionsMenuStore } from '../store/actionsmenu.ts'
import { useActiveStore } from '../store/active.ts'
import { useDragAndDropStore } from '../store/dragging.ts'
import { useFilesStore } from '../store/files.ts'
import { useRenamingStore } from '../store/renaming.ts'
Expand Down Expand Up @@ -111,23 +111,24 @@ export default defineComponent({
const filesStore = useFilesStore()
const renamingStore = useRenamingStore()
const selectionStore = useSelectionStore()
// The file list is guaranteed to be only shown with active view - thus we can set the `loaded` flag
const { currentView } = useNavigation(true)
const filesListWidth = useFileListWidth()

const {
directory: currentDir,
fileId: currentFileId,
} = useRouteParameters()
activeFolder,
activeNode,
activeView,
} = useActiveStore()

return {
actionsMenuStore,
activeFolder,
activeNode,
activeView,
draggingStore,
filesListWidth,
filesStore,
renamingStore,
selectionStore,

currentDir,
currentFileId,
currentView,
}
},

Expand Down
23 changes: 19 additions & 4 deletions apps/files/src/components/FileEntryMixin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default defineComponent({
},

isActive() {
return String(this.fileid) === String(this.currentFileId)
return String(this.fileid) === String(this.activeNode.fileid)
},

/**
Expand Down Expand Up @@ -378,14 +378,29 @@ export default defineComponent({
event.preventDefault()
event.stopPropagation()
// Execute the first default action if any
this.defaultFileAction.exec(this.source, this.currentView, this.currentDir)
this.defaultFileAction.exec({
nodes: [this.source],
folder: this.activeFolder!,
contents: this.nodes,
view: this.activeView!,
})
},

openDetailsIfAvailable(event) {
event.preventDefault()
event.stopPropagation()
if (sidebarAction?.enabled?.([this.source], this.currentView)) {
sidebarAction.exec(this.source, this.currentView, this.currentDir)
if (sidebarAction?.enabled?.({
nodes: [this.source],
folder: this.activeFolder!,
contents: this.nodes,
view: this.activeView!,
})) {
sidebarAction.exec({
nodes: [this.source],
folder: this.activeFolder!,
contents: this.nodes,
view: this.activeView!,
})
}
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export default defineComponent({
})

// Dispatch action execution
const results = await action.execBatch(this.nodes, this.currentView, this.directory)
const results = await action.execBatch({ nodes: this.nodes, directory: this.directory })

// Check if all actions returned null
if (!results.some((result) => result !== null)) {
Expand Down
21 changes: 18 additions & 3 deletions apps/files/src/components/FilesListVirtual.vue
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,19 @@ export default defineComponent({
// Open the sidebar for the given URL fileid
// iif we just loaded the app.
const node = this.nodes.find((n) => n.fileid === fileId) as NcNode
if (node && sidebarAction?.enabled?.([node], this.currentView)) {
if (node && sidebarAction?.enabled?.({
nodes: [node],
folder: this.currentFolder,
view: this.currentView,
contents: this.nodes,
})) {
logger.debug('Opening sidebar on file ' + node.path, { node })
sidebarAction.exec(node, this.currentView, this.currentFolder.path)
sidebarAction.exec({
nodes: [node],
folder: this.currentFolder,
view: this.currentView,
contents: this.nodes,
})
return
}
logger.warn(`Failed to open sidebar on file ${fileId}, file isn't cached yet !`, { fileId, node })
Expand Down Expand Up @@ -393,7 +403,12 @@ export default defineComponent({
// So if there is an enabled default action, so execute it
if (defaultAction) {
logger.debug('Opening file ' + node.path, { node })
return await defaultAction.exec(node, this.currentView, this.currentFolder.path)
return await defaultAction.exec({
nodes: [node],
view: this.currentView,
folder: this.currentFolder,
contents: this.nodes,
})
}
}
// The file is either a folder or has no default action other than downloading
Expand Down
3 changes: 2 additions & 1 deletion apps/files/src/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { addNewFileMenuEntry, registerDavProperty, registerFileAction } from '@nextcloud/files'
import { addNewFileMenuEntry, registerFileAction } from '@nextcloud/files'
import { registerDavProperty } from '@nextcloud/files/dav'
import { isPublicShare } from '@nextcloud/sharing/public'
import { registerConvertActions } from './actions/convertAction.ts'
import { action as deleteAction } from './actions/deleteAction.ts'
Expand Down
6 changes: 4 additions & 2 deletions apps/files/src/services/DropService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import type { Upload } from '@nextcloud/upload'
import type { RootDirectory } from './DropServiceUtils.ts'

import { showError, showInfo, showSuccess, showWarning } from '@nextcloud/dialogs'
import { davRootPath, NodeStatus } from '@nextcloud/files'
import { NodeStatus } from '@nextcloud/files'
import { getRootPath } from '@nextcloud/files/dav'
import { translate as t } from '@nextcloud/l10n'
import { joinPaths } from '@nextcloud/paths'
import { getUploader, hasConflict } from '@nextcloud/upload'
Expand Down Expand Up @@ -125,8 +126,9 @@ export async function onDropExternalFiles(root: RootDirectory, destination: Fold
// If the file is a directory, we need to create it first
// then browse its tree and upload its contents.
if (file instanceof Directory) {
const absolutePath = joinPaths(davRootPath, destination.path, relativePath)
const absolutePath = joinPaths(getRootPath(), destination.path, relativePath)
try {
ge
logger.debug('Processing directory', { relativePath })
await createDirectoryIfNotExists(absolutePath)
await uploadDirectoryContents(file, relativePath)
Expand Down
8 changes: 4 additions & 4 deletions apps/files/src/services/DropServiceUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { FileStat, ResponseDataDetailed } from 'webdav'

import { showInfo, showWarning } from '@nextcloud/dialogs'
import { emit } from '@nextcloud/event-bus'
import { davGetClient, davGetDefaultPropfind, davResultToNode } from '@nextcloud/files'
import { getClient, getDefaultPropfind, resultToNode } from '@nextcloud/files/dav'
import { translate as t } from '@nextcloud/l10n'
import { openConflictPicker } from '@nextcloud/upload'
import logger from '../logger.ts'
Expand Down Expand Up @@ -135,13 +135,13 @@ function readDirectory(directory: FileSystemDirectoryEntry): Promise<FileSystemE
* @param absolutePath
*/
export async function createDirectoryIfNotExists(absolutePath: string) {
const davClient = davGetClient()
const davClient = getClient()
const dirExists = await davClient.exists(absolutePath)
if (!dirExists) {
logger.debug('Directory does not exist, creating it', { absolutePath })
await davClient.createDirectory(absolutePath, { recursive: true })
const stat = await davClient.stat(absolutePath, { details: true, data: davGetDefaultPropfind() }) as ResponseDataDetailed<FileStat>
emit('files:node:created', davResultToNode(stat.data))
const stat = await davClient.stat(absolutePath, { details: true, data: getDefaultPropfind() }) as ResponseDataDetailed<FileStat>
emit('files:node:created', resultToNode(stat.data))
}
}

Expand Down
7 changes: 4 additions & 3 deletions apps/files/src/services/Favorites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
import type { ContentsWithRoot } from '@nextcloud/files'

import { getCurrentUser } from '@nextcloud/auth'
import { davRemoteURL, davRootPath, Folder, getFavoriteNodes, Permission } from '@nextcloud/files'
import { Folder, Permission } from '@nextcloud/files'
import { getFavoriteNodes, getRemoteURL, getRootPath } from '@nextcloud/files/dav'
import { CancelablePromise } from 'cancelable-promise'
import { getContents as filesContents } from './Files.ts'
import { client } from './WebdavClient.ts'
Expand All @@ -32,8 +33,8 @@ export function getContents(path = '/'): CancelablePromise<ContentsWithRoot> {
contents,
folder: new Folder({
id: 0,
source: `${davRemoteURL}${davRootPath}`,
root: davRootPath,
source: `${getRemoteURL()}${getRootPath()}`,
root: getRootPath(),
owner: getCurrentUser()?.uid || null,
permissions: Permission.READ,
}),
Expand Down
16 changes: 5 additions & 11 deletions apps/files/src/services/Files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { ContentsWithRoot, File, Folder, Node } from '@nextcloud/files'
import type { ContentsWithRoot, File, Folder } from '@nextcloud/files'
import type { FileStat, ResponseDataDetailed } from 'webdav'

import { resultToNode as davResultToNode, defaultRootPath, getDefaultPropfind } from '@nextcloud/files/dav'
import { getDefaultPropfind, getRootPath, resultToNode } from '@nextcloud/files/dav'
import { CancelablePromise } from 'cancelable-promise'
import { join } from 'path'
import logger from '../logger.ts'
Expand All @@ -14,12 +14,6 @@ import { getPinia } from '../store/index.ts'
import { useSearchStore } from '../store/search.ts'
import { client } from './WebdavClient.ts'
import { searchNodes } from './WebDavSearch.ts'
/**
* Slim wrapper over `@nextcloud/files` `davResultToNode` to allow using the function with `Array.map`
*
* @param stat The result returned by the webdav library
*/
export const resultToNode = (stat: FileStat): Node => davResultToNode(stat)

/**
* Get contents implementation for the files view.
Expand Down Expand Up @@ -49,7 +43,7 @@ export function getContents(path = '/'): CancelablePromise<ContentsWithRoot> {
* @param path - The path to get the contents
*/
export function defaultGetContents(path: string): CancelablePromise<ContentsWithRoot> {
path = join(defaultRootPath, path)
path = join(getRootPath(), path)
const controller = new AbortController()
const propfindPayload = getDefaultPropfind()

Expand All @@ -66,7 +60,7 @@ export function defaultGetContents(path: string): CancelablePromise<ContentsWith

const root = contentsResponse.data[0]
const contents = contentsResponse.data.slice(1)
if (root.filename !== path && `${root.filename}/` !== path) {
if (root?.filename !== path && `${root?.filename}/` !== path) {
logger.debug(`Exepected "${path}" but got filename "${root.filename}" instead.`)
throw new Error('Root node does not match requested path')
}
Expand Down Expand Up @@ -99,7 +93,7 @@ async function getLocalSearch(path: string, query: string, signal: AbortSignal):
const filesStore = useFilesStore(getPinia())
let folder = filesStore.getDirectoryByPath('files', path)
if (!folder) {
const rootPath = join(defaultRootPath, path)
const rootPath = join(getRootPath(), path)
const stat = await client.stat(rootPath, { details: true }) as ResponseDataDetailed<FileStat>
folder = resultToNode(stat.data) as Folder
}
Expand Down
4 changes: 2 additions & 2 deletions apps/files/src/services/FolderTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type { CancelablePromise } from 'cancelable-promise'

import { getCurrentUser } from '@nextcloud/auth'
import axios from '@nextcloud/axios'
import { davRemoteURL } from '@nextcloud/files'
import { getRemoteURL } from '@nextcloud/files/dav'
import { getCanonicalLocale, getLanguage } from '@nextcloud/l10n'
import { dirname, encodePath, joinPaths } from '@nextcloud/paths'
import { generateOcsUrl } from '@nextcloud/router'
Expand All @@ -34,7 +34,7 @@ export interface TreeNode {

export const folderTreeId = 'folders'

export const sourceRoot = `${davRemoteURL}/files/${getCurrentUser()?.uid}`
export const sourceRoot = `${getRemoteURL()}/files/${getCurrentUser()?.uid}`

const collator = Intl.Collator(
[getLanguage(), getCanonicalLocale()],
Expand Down
Loading
Loading