Skip to content

Commit

Permalink
Merge pull request #39955 from nextcloud/fix/files-lib
Browse files Browse the repository at this point in the history
  • Loading branch information
skjnldsv authored Aug 23, 2023
2 parents c9a197e + 7d46eb0 commit 590b1d9
Show file tree
Hide file tree
Showing 78 changed files with 257 additions and 774 deletions.
8 changes: 3 additions & 5 deletions apps/files/src/actions/deleteAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,20 @@
*/
import { action } from './deleteAction'
import { expect } from '@jest/globals'
import { File, Folder, Permission } from '@nextcloud/files'
import { FileAction } from '../services/FileAction'
import { File, Folder, Permission, View, FileAction } from '@nextcloud/files'
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
8 changes: 3 additions & 5 deletions apps/files/src/actions/deleteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,16 @@
*
*/
import { emit } from '@nextcloud/event-bus'
import { Permission, Node } from '@nextcloud/files'
import { Permission, Node, View, registerFileAction, FileAction } 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 +56,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
9 changes: 2 additions & 7 deletions apps/files/src/actions/downloadAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,12 @@
*/
import { action } from './downloadAction'
import { expect } from '@jest/globals'
import { File, Folder, Permission } 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'
import { File, Folder, Permission, View, FileAction } from '@nextcloud/files'

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

describe('Download action conditions tests', () => {
test('Default values', () => {
Expand Down
11 changes: 4 additions & 7 deletions apps/files/src/actions/downloadAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { Permission, Node, FileType } from '@nextcloud/files'
import { generateUrl } from '@nextcloud/router'
import { registerFileAction, FileAction, 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 { generateUrl } from '@nextcloud/router'
import type { Navigation } from '../services/Navigation'

const triggerDownload = function(url: string) {
const hiddenElement = document.createElement('a')
hiddenElement.download = ''
Expand Down Expand Up @@ -55,7 +52,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 +62,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
6 changes: 2 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,14 @@
*/
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, FileAction } from '@nextcloud/files'
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
11 changes: 5 additions & 6 deletions apps/files/src/actions/editLocallyAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@
*
*/
import { encodePath } from '@nextcloud/paths'
import { Permission, type Node } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import LaptopSvg from '@mdi/svg/svg/laptop.svg?raw'

import { generateOcsUrl } from '@nextcloud/router'
import { getCurrentUser } from '@nextcloud/auth'
import { registerFileAction, FileAction, DefaultType } from '../services/FileAction'
import { registerFileAction, FileAction, Permission, type Node } from '@nextcloud/files'
import { showError } from '@nextcloud/dialogs'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'

import LaptopSvg from '@mdi/svg/svg/laptop.svg?raw'

const openLocalClient = async function(path: string) {
const link = generateOcsUrl('apps/files/api/v1') + '/openlocaleditor?format=json'
Expand Down
10 changes: 4 additions & 6 deletions apps/files/src/actions/favoriteAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,23 @@
* 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 { FileAction } from '../services/FileAction'
import { File, Permission, View, FileAction } from '@nextcloud/files'
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
10 changes: 4 additions & 6 deletions apps/files/src/actions/favoriteAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,22 @@
*/
import { emit } from '@nextcloud/event-bus'
import { generateUrl } from '@nextcloud/router'
import { Permission, type Node } from '@nextcloud/files'
import { Permission, type Node, View, registerFileAction, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import axios from '@nextcloud/axios'
import Vue from 'vue'

import StarOutlineSvg from '@mdi/svg/svg/star-outline.svg?raw'
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 +90,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
7 changes: 2 additions & 5 deletions apps/files/src/actions/openFolderAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,15 @@
* 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, DefaultType, FileAction } 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
9 changes: 3 additions & 6 deletions apps/files/src/actions/openFolderAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { Permission, Node, FileType } from '@nextcloud/files'
import { join } from 'path'
import { Permission, Node, FileType, View, registerFileAction, FileAction, DefaultType } 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'

export const action = new FileAction({
id: 'open-folder',
displayName(files: Node[]) {
Expand All @@ -52,7 +49,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
8 changes: 3 additions & 5 deletions apps/files/src/actions/openInFilesAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,17 @@
*/
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'
import { File, Folder, Permission, View, DefaultType, FileAction } from '@nextcloud/files'

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
2 changes: 1 addition & 1 deletion apps/files/src/actions/openInFilesAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import { translate as t } from '@nextcloud/l10n'
import { FileType, type Node } from '@nextcloud/files'

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

/**
* TODO: Move away from a redirect and handle
Expand Down
6 changes: 2 additions & 4 deletions apps/files/src/actions/renameAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
*/
import { action } from './renameAction'
import { expect } from '@jest/globals'
import { File, Permission } from '@nextcloud/files'
import { FileAction } from '../services/FileAction'
import { File, Permission, View, FileAction } from '@nextcloud/files'
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/renameAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import { Permission, type Node } from '@nextcloud/files'
import { emit } from '@nextcloud/event-bus'
import { Permission, type Node, registerFileAction, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import PencilSvg from '@mdi/svg/svg/pencil.svg?raw'

import { emit } from '@nextcloud/event-bus'
import { registerFileAction, FileAction } from '../services/FileAction'

export const ACTION_DETAILS = 'details'

export const action = new FileAction({
Expand Down
7 changes: 2 additions & 5 deletions apps/files/src/actions/sidebarAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +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, Permission } from '@nextcloud/files'
import { File, Permission, View, FileAction } from '@nextcloud/files'

import { action } from './sidebarAction'
import { FileAction } from '../services/FileAction'
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
7 changes: 2 additions & 5 deletions apps/files/src/actions/sidebarAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@
* 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, registerFileAction, FileAction } from '@nextcloud/files'
import { translate as t } from '@nextcloud/l10n'
import InformationSvg from '@mdi/svg/svg/information-variant.svg?raw'

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

export const ACTION_DETAILS = 'details'
Expand Down Expand Up @@ -54,7 +51,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
6 changes: 2 additions & 4 deletions apps/files/src/actions/viewInFolderAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,12 @@
*/
import { action } from './viewInFolderAction'
import { expect } from '@jest/globals'
import { File, Folder, Node, Permission } from '@nextcloud/files'
import { FileAction } from '../services/FileAction'
import type { Navigation } from '../services/Navigation'
import { File, Folder, Node, Permission, View, FileAction } from '@nextcloud/files'

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

describe('View in folder action conditions tests', () => {
test('Default values', () => {
Expand Down
Loading

0 comments on commit 590b1d9

Please sign in to comment.