Skip to content

Commit

Permalink
Merge pull request #39613 from nextcloud/feat/f2v/recent
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Aug 2, 2023
2 parents 6ec35e3 + 87b1719 commit 78856f3
Show file tree
Hide file tree
Showing 25 changed files with 495 additions and 248 deletions.
1 change: 0 additions & 1 deletion apps/files/js/merged-index.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"newfilemenu.js",
"operationprogressbar.js",
"recentfilelist.js",
"recentplugin.js",
"semaphore.js",
"sidebarpreviewmanager.js",
"sidebarpreviewtext.js",
Expand Down
121 changes: 0 additions & 121 deletions apps/files/js/recentplugin.js

This file was deleted.

9 changes: 0 additions & 9 deletions apps/files/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,6 @@ private function registerNavigation(IL10N $l10n): void {
'name' => $l10n->t('All files')
];
});
\OCA\Files\App::getNavigationManager()->add(function () use ($l10n) {
return [
'id' => 'recent',
'appname' => 'files',
'script' => 'recentlist.php',
'order' => 2,
'name' => $l10n->t('Recent')
];
});
}

private function registerHooks(): void {
Expand Down
37 changes: 0 additions & 37 deletions apps/files/recentlist.php

This file was deleted.

103 changes: 103 additions & 0 deletions apps/files/src/actions/openInFilesAction.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/**
* @copyright Copyright (c) 2023 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { action } from './openInFilesAction'
import { expect } from '@jest/globals'
import { File, Folder, Permission } from '@nextcloud/files'
import { DefaultType, FileAction } from '../../../files/src/services/FileAction'
import type { Navigation } from '../../../files/src/services/Navigation'

const view = {
id: 'files',
name: 'Files',
} as Navigation

const recentView = {
id: 'recent',
name: 'Recent',
} as Navigation

describe('Open in files action conditions tests', () => {
test('Default values', () => {
expect(action).toBeInstanceOf(FileAction)
expect(action.id).toBe('open-in-files-recent')
expect(action.displayName([], recentView)).toBe('Open in Files')
expect(action.iconSvgInline([], recentView)).toBe('')
expect(action.default).toBe(DefaultType.HIDDEN)
expect(action.order).toBe(-1000)
expect(action.inline).toBeUndefined()
})
})

describe('Open in files action enabled tests', () => {
test('Enabled with on valid view', () => {
expect(action.enabled).toBeDefined()
expect(action.enabled!([], recentView)).toBe(true)
})

test('Disabled on wrong view', () => {
expect(action.enabled).toBeDefined()
expect(action.enabled!([], view)).toBe(false)
})
})

describe('Open in files action execute tests', () => {
test('Open in files', async () => {
const goToRouteMock = jest.fn()
window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } }

const file = new File({
id: 1,
source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/foobar.txt',
owner: 'admin',
mime: 'text/plain',
root: '/files/admin',
permissions: Permission.ALL,
})

const exec = await action.exec(file, view, '/')

// Silent action
expect(exec).toBe(null)
expect(goToRouteMock).toBeCalledTimes(1)
expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { fileid: 1, dir: '/Foo', openfile: true })
})

test('Open in files with folder', async () => {
const goToRouteMock = jest.fn()
window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } }

const file = new Folder({
id: 1,
source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/Bar',
owner: 'admin',
root: '/files/admin',
permissions: Permission.ALL,
})

const exec = await action.exec(file, view, '/')

// Silent action
expect(exec).toBe(null)
expect(goToRouteMock).toBeCalledTimes(1)
expect(goToRouteMock).toBeCalledWith(null, { fileid: 1, view: 'files' }, { fileid: 1, dir: '/Foo/Bar', openfile: true })
})
})
57 changes: 57 additions & 0 deletions apps/files/src/actions/openInFilesAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/**
* @copyright Copyright (c) 2023 John Molakvoæ <[email protected]>
*
* @author John Molakvoæ <[email protected]>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { translate as t } from '@nextcloud/l10n'
import { FileType, type Node } from '@nextcloud/files'

import { registerFileAction, FileAction, DefaultType } from '../../../files/src/services/FileAction'

/**
* TODO: Move away from a redirect and handle
* navigation straight out of the recent view
*/
export const action = new FileAction({
id: 'open-in-files-recent',
displayName: () => t('files', 'Open in Files'),
iconSvgInline: () => '',

enabled: (nodes, view) => view.id === 'recent',

async exec(node: Node) {
let dir = node.dirname
if (node.type === FileType.Folder) {
dir = dir + '/' + node.basename
}

window.OCP.Files.Router.goToRoute(
null, // use default route
{ view: 'files', fileid: node.fileid },
{ dir, fileid: node.fileid, openfile: true },
)
return null
},

// Before openFolderAction
order: -1000,
default: DefaultType.HIDDEN,
})

registerFileAction(action)
9 changes: 8 additions & 1 deletion apps/files/src/components/FileEntry.vue
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ import { formatFileSize, Permission } from '@nextcloud/files'
import { Fragment } from 'vue-frag'
import { showError, showSuccess } from '@nextcloud/dialogs'
import { translate } from '@nextcloud/l10n'
import { generateUrl } from '@nextcloud/router'
import { vOnClickOutside } from '@vueuse/components'
import axios from '@nextcloud/axios'
import CancelablePromise from 'cancelable-promise'
Expand Down Expand Up @@ -367,10 +368,16 @@ export default Vue.extend({
},
previewUrl() {
try {
const url = new URL(window.location.origin + this.source.attributes.previewUrl)
const previewUrl = this.source.attributes.previewUrl
|| generateUrl('/core/preview?fileId={fileid}', {
fileid: this.source.fileid,
})
const url = new URL(window.location.origin + previewUrl)
// Request tiny previews
url.searchParams.set('x', '32')
url.searchParams.set('y', '32')
// Handle cropping
url.searchParams.set('a', this.cropPreviews === true ? '0' : '1')
return url.href
Expand Down
3 changes: 3 additions & 0 deletions apps/files/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import './actions/downloadAction'
import './actions/editLocallyAction'
import './actions/favoriteAction'
import './actions/openFolderAction'
import './actions/openInFilesAction.js'
import './actions/renameAction'
import './actions/sidebarAction'
import './actions/viewInFolderAction'
Expand All @@ -18,6 +19,7 @@ import NavigationService from './services/Navigation'
import NavigationView from './views/Navigation.vue'
import processLegacyFilesViews from './legacy/navigationMapper.js'
import registerFavoritesView from './views/favorites'
import registerRecentView from './views/recent'
import registerPreviewServiceWorker from './services/ServiceWorker.js'
import router from './router/router.js'
import RouterService from './services/RouterService'
Expand Down Expand Up @@ -78,6 +80,7 @@ FilesList.$mount('#app-content-vue')
// Init legacy and new files views
processLegacyFilesViews()
registerFavoritesView()
registerRecentView()

// Register preview service worker
registerPreviewServiceWorker()
Loading

0 comments on commit 78856f3

Please sign in to comment.