You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sidebarAction.ts 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /**
  2. * @copyright Copyright (c) 2023 John Molakvoæ <skjnldsv@protonmail.com>
  3. *
  4. * @author John Molakvoæ <skjnldsv@protonmail.com>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import { Permission, type Node, View, registerFileAction, FileAction, FileType } from '@nextcloud/files'
  23. import { translate as t } from '@nextcloud/l10n'
  24. import InformationSvg from '@mdi/svg/svg/information-variant.svg?raw'
  25. import logger from '../logger.js'
  26. export const ACTION_DETAILS = 'details'
  27. export const action = new FileAction({
  28. id: ACTION_DETAILS,
  29. displayName: () => t('files', 'Open details'),
  30. iconSvgInline: () => InformationSvg,
  31. // Sidebar currently supports user folder only, /files/USER
  32. enabled: (nodes: Node[]) => {
  33. // Only works on single node
  34. if (nodes.length !== 1) {
  35. return false
  36. }
  37. if (!nodes[0]) {
  38. return false
  39. }
  40. // Only work if the sidebar is available
  41. if (!window?.OCA?.Files?.Sidebar) {
  42. return false
  43. }
  44. return (nodes[0].root?.startsWith('/files/') && nodes[0].permissions !== Permission.NONE) ?? false
  45. },
  46. async exec(node: Node, view: View, dir: string) {
  47. try {
  48. // TODO: migrate Sidebar to use a Node instead
  49. await window.OCA.Files.Sidebar.open(node.path)
  50. // Silently update current fileid
  51. window.OCP.Files.Router.goToRoute(
  52. null,
  53. { view: view.id, fileid: node.fileid },
  54. { dir },
  55. true,
  56. )
  57. return null
  58. } catch (error) {
  59. logger.error('Error while opening sidebar', { error })
  60. return false
  61. }
  62. },
  63. order: -50,
  64. })
  65. registerFileAction(action)