Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
chore: use Navigation from @nextcloud/files
Signed-off-by: John Molakvoæ <[email protected]>
  • Loading branch information
skjnldsv committed Aug 23, 2023
commit b4e71ad0fb282fbc9981924b9783ae6659a9e4fe
7 changes: 3 additions & 4 deletions apps/files/src/actions/deleteAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@
*/
import { action } from './deleteAction'
import { expect } from '@jest/globals'
import { File, Folder, Permission } from '@nextcloud/files'
import { File, Folder, Permission, View } from '@nextcloud/files'
import { FileAction } from '../services/FileAction'
import * as eventBus from '@nextcloud/event-bus'
import axios from '@nextcloud/axios'
import logger from '../logger'
import type { Navigation } from '../services/Navigation'

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

const trashbinView = {
id: 'trashbin',
name: 'Trashbin',
} as Navigation
} as View

describe('Delete action conditions tests', () => {
test('Default values', () => {
Expand Down
7 changes: 3 additions & 4 deletions apps/files/src/actions/deleteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,17 @@
*
*/
import { emit } from '@nextcloud/event-bus'
import { Permission, Node } from '@nextcloud/files'
import { Permission, Node, View } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import TrashCanSvg from '@mdi/svg/svg/trash-can.svg?raw'

import { registerFileAction, FileAction } from '../services/FileAction'
import logger from '../logger.js'
import type { Navigation } from '../services/Navigation'

export const action = new FileAction({
id: 'delete',
displayName(nodes: Node[], view: Navigation) {
displayName(nodes: Node[], view: View) {
return view.id === 'trashbin'
? t('files_trashbin', 'Delete permanently')
: t('files', 'Delete')
Expand All @@ -58,7 +57,7 @@ export const action = new FileAction({
return false
}
},
async execBatch(nodes: Node[], view: Navigation, dir: string) {
async execBatch(nodes: Node[], view: View, dir: string) {
return Promise.all(nodes.map(node => this.exec(node, view, dir)))
},

Expand Down
8 changes: 2 additions & 6 deletions apps/files/src/actions/downloadAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,13 @@
*/
import { action } from './downloadAction'
import { expect } from '@jest/globals'
import { File, Folder, Permission } from '@nextcloud/files'
import { File, Folder, Permission, View } from '@nextcloud/files'
import { FileAction } from '../services/FileAction'
import * as eventBus from '@nextcloud/event-bus'
import axios from '@nextcloud/axios'
import type { Navigation } from '../services/Navigation'
import logger from '../logger'

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

describe('Download action conditions tests', () => {
test('Default values', () => {
Expand Down
9 changes: 4 additions & 5 deletions apps/files/src/actions/downloadAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { Permission, Node, FileType } from '@nextcloud/files'
import { Permission, Node, FileType, View } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import ArrowDownSvg from '@mdi/svg/svg/arrow-down.svg?raw'

import { registerFileAction, FileAction, DefaultType } from '../services/FileAction'
import { registerFileAction, FileAction } from '../services/FileAction'
import { generateUrl } from '@nextcloud/router'
import type { Navigation } from '../services/Navigation'

const triggerDownload = function(url: string) {
const hiddenElement = document.createElement('a')
Expand Down Expand Up @@ -55,7 +54,7 @@ export const action = new FileAction({
.every(permission => (permission & Permission.READ) !== 0)
},

async exec(node: Node, view: Navigation, dir: string) {
async exec(node: Node, view: View, dir: string) {
if (node.type === FileType.Folder) {
downloadNodes(dir, [node])
return null
Expand All @@ -65,7 +64,7 @@ export const action = new FileAction({
return null
},

async execBatch(nodes: Node[], view: Navigation, dir: string) {
async execBatch(nodes: Node[], view: View, dir: string) {
if (nodes.length === 1) {
this.exec(nodes[0], view, dir)
return [null]
Expand Down
7 changes: 3 additions & 4 deletions apps/files/src/actions/editLocallyAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,15 @@
*/
import { action } from './editLocallyAction'
import { expect } from '@jest/globals'
import { File, Permission } from '@nextcloud/files'
import { DefaultType, FileAction } from '../services/FileAction'
import { File, Permission, View } from '@nextcloud/files'
import { FileAction } from '../services/FileAction'
import * as ncDialogs from '@nextcloud/dialogs'
import axios from '@nextcloud/axios'
import type { Navigation } from '../services/Navigation'

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

describe('Edit locally action conditions tests', () => {
test('Default values', () => {
Expand Down
9 changes: 4 additions & 5 deletions apps/files/src/actions/favoriteAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,24 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import * as favoriteAction from './favoriteAction'
import { action } from './favoriteAction'
import { expect } from '@jest/globals'
import { File, Permission } from '@nextcloud/files'
import { File, Permission, View } from '@nextcloud/files'
import { FileAction } from '../services/FileAction'
import * as eventBus from '@nextcloud/event-bus'
import * as favoriteAction from './favoriteAction'
import axios from '@nextcloud/axios'
import type { Navigation } from '../services/Navigation'
import logger from '../logger'

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

const favoriteView = {
id: 'favorites',
name: 'Favorites',
} as Navigation
} as View

global.window.OC = {
TAG_FAVORITE: '_$!<Favorite>!$_',
Expand Down
9 changes: 4 additions & 5 deletions apps/files/src/actions/favoriteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
import { emit } from '@nextcloud/event-bus'
import { generateUrl } from '@nextcloud/router'
import { Permission, type Node } from '@nextcloud/files'
import { Permission, type Node, View } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import Vue from 'vue'
Expand All @@ -31,14 +31,13 @@ import StarSvg from '@mdi/svg/svg/star.svg?raw'

import { registerFileAction, FileAction } from '../services/FileAction'
import logger from '../logger.js'
import type { Navigation } from '../services/Navigation'

// If any of the nodes is not favorited, we display the favorite action.
const shouldFavorite = (nodes: Node[]): boolean => {
return nodes.some(node => node.attributes.favorite !== 1)
}

export const favoriteNode = async (node: Node, view: Navigation, willFavorite: boolean): Promise<boolean> => {
export const favoriteNode = async (node: Node, view: View, willFavorite: boolean): Promise<boolean> => {
try {
// TODO: migrate to webdav tags plugin
const url = generateUrl('/apps/files/api/v1/files') + node.path
Expand Down Expand Up @@ -92,11 +91,11 @@ export const action = new FileAction({
&& nodes.every(node => node.permissions !== Permission.NONE)
},

async exec(node: Node, view: Navigation) {
async exec(node: Node, view: View) {
const willFavorite = shouldFavorite([node])
return await favoriteNode(node, view, willFavorite)
},
async execBatch(nodes: Node[], view: Navigation) {
async execBatch(nodes: Node[], view: View) {
const willFavorite = shouldFavorite(nodes)
return Promise.all(nodes.map(async node => await favoriteNode(node, view, willFavorite)))
},
Expand Down
6 changes: 2 additions & 4 deletions apps/files/src/actions/openFolderAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import type { Navigation } from '../services/Navigation'

import { expect } from '@jest/globals'
import { File, Folder, Node, Permission } from '@nextcloud/files'
import { File, Folder, Node, Permission, View } from '@nextcloud/files'

import { action } from './openFolderAction'
import { DefaultType, FileAction } from '../services/FileAction'

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

describe('Open folder action conditions tests', () => {
test('Default values', () => {
Expand Down
5 changes: 2 additions & 3 deletions apps/files/src/actions/openFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { Permission, Node, FileType } from '@nextcloud/files'
import { Permission, Node, FileType, View } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import FolderSvg from '@mdi/svg/svg/folder.svg?raw'

import type { Navigation } from '../services/Navigation'
import { join } from 'path'
import { registerFileAction, FileAction, DefaultType } from '../services/FileAction'

Expand Down Expand Up @@ -52,7 +51,7 @@ export const action = new FileAction({
&& (node.permissions & Permission.READ) !== 0
},

async exec(node: Node, view: Navigation, dir: string) {
async exec(node: Node, view: View, dir: string) {
if (!node || node.type !== FileType.Folder) {
return false
}
Expand Down
7 changes: 3 additions & 4 deletions apps/files/src/actions/openInFilesAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
*/
import { action } from './openInFilesAction'
import { expect } from '@jest/globals'
import { File, Folder, Permission } from '@nextcloud/files'
import { File, Folder, Permission, View } 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
} as View

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

describe('Open in files action conditions tests', () => {
test('Default values', () => {
Expand Down
5 changes: 2 additions & 3 deletions apps/files/src/actions/renameAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@
*/
import { action } from './renameAction'
import { expect } from '@jest/globals'
import { File, Permission } from '@nextcloud/files'
import { File, Permission, View } from '@nextcloud/files'
import { FileAction } from '../services/FileAction'
import * as eventBus from '@nextcloud/event-bus'
import type { Navigation } from '../services/Navigation'

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

describe('Rename action conditions tests', () => {
test('Default values', () => {
Expand Down
6 changes: 2 additions & 4 deletions apps/files/src/actions/sidebarAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import type { Navigation } from '../services/Navigation'

import { expect } from '@jest/globals'
import { File, Permission } from '@nextcloud/files'
import { File, Permission, View } from '@nextcloud/files'

import { action } from './sidebarAction'
import { FileAction } from '../services/FileAction'
Expand All @@ -31,7 +29,7 @@ import logger from '../logger'
const view = {
id: 'files',
name: 'Files',
} as Navigation
} as View

describe('Open sidebar action conditions tests', () => {
test('Default values', () => {
Expand Down
6 changes: 2 additions & 4 deletions apps/files/src/actions/sidebarAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import type { Navigation } from '../services/Navigation'

import { Permission, type Node } from '@nextcloud/files'
import { Permission, type Node, View } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import InformationSvg from '@mdi/svg/svg/information-variant.svg?raw'

Expand Down Expand Up @@ -54,7 +52,7 @@ export const action = new FileAction({
return (nodes[0].root?.startsWith('/files/') && nodes[0].permissions !== Permission.NONE) ?? false
},

async exec(node: Node, view: Navigation) {
async exec(node: Node, view: View) {
try {
// TODO: migrate Sidebar to use a Node instead
await window.OCA.Files.Sidebar.open(node.path)
Expand Down
5 changes: 2 additions & 3 deletions apps/files/src/actions/viewInFolderAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
*/
import { action } from './viewInFolderAction'
import { expect } from '@jest/globals'
import { File, Folder, Node, Permission } from '@nextcloud/files'
import { File, Folder, Node, Permission, View } from '@nextcloud/files'
import { FileAction } from '../services/FileAction'
import type { Navigation } from '../services/Navigation'

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

describe('View in folder action conditions tests', () => {
test('Default values', () => {
Expand Down
6 changes: 2 additions & 4 deletions apps/files/src/actions/viewInFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { Node, FileType, Permission } from '@nextcloud/files'
import { Node, FileType, Permission, View } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import FolderMoveSvg from '@mdi/svg/svg/folder-move.svg?raw'

import type { Navigation } from '../services/Navigation'
import { join } from 'path'
import { registerFileAction, FileAction } from '../services/FileAction'

export const action = new FileAction({
Expand Down Expand Up @@ -53,7 +51,7 @@ export const action = new FileAction({
return node.type === FileType.File
},

async exec(node: Node, view: Navigation, dir: string) {
async exec(node: Node, view: View, dir: string) {
if (!node || node.type !== FileType.File) {
return false
}
Expand Down
1 change: 0 additions & 1 deletion apps/files/src/components/FilesListHeader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ export default {
},
computed: {
enabled() {
console.debug('Enabled', this.header.id)
return this.header.enabled(this.currentFolder, this.currentView)
},
},
Expand Down
6 changes: 3 additions & 3 deletions apps/files/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import './actions/openInFilesAction.js'
import './actions/renameAction'
import './actions/sidebarAction'
import './actions/viewInFolderAction'
import './newMenu/newFolder'

import Vue from 'vue'
import { createPinia, PiniaVuePlugin } from 'pinia'
import { getNavigation } from '@nextcloud/files'

import FilesListView from './views/FilesList.vue'
import { NavigationService } from './services/Navigation'
import NavigationView from './views/Navigation.vue'
import registerFavoritesView from './views/favorites'
import registerRecentView from './views/recent'
Expand Down Expand Up @@ -47,8 +48,7 @@ Vue.use(PiniaVuePlugin)
const pinia = createPinia()

// Init Navigation Service
const Navigation = new NavigationService()
Object.assign(window.OCP.Files, { Navigation })
const Navigation = getNavigation()
Vue.prototype.$navigation = Navigation

// Init Files App Settings Service
Expand Down
Loading