From a5a8655bebb8652206ea5aa886699f706739e1fe Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Thu, 21 Sep 2023 12:15:11 +0200 Subject: fix: avoid side-effect imports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- .../lib/Listener/LoadAdditionalListener.php | 2 + .../src/actions/enterCredentialsAction.ts | 4 +- .../src/actions/inlineStorageCheckAction.ts | 4 +- .../src/actions/openInFilesAction.ts | 4 +- apps/files_external/src/init.ts | 81 ++++++++++++++++++++++ apps/files_external/src/main.ts | 75 -------------------- 6 files changed, 86 insertions(+), 84 deletions(-) create mode 100644 apps/files_external/src/init.ts delete mode 100644 apps/files_external/src/main.ts (limited to 'apps/files_external') diff --git a/apps/files_external/lib/Listener/LoadAdditionalListener.php b/apps/files_external/lib/Listener/LoadAdditionalListener.php index e5cb5e96d0a..5f56a14c4ce 100644 --- a/apps/files_external/lib/Listener/LoadAdditionalListener.php +++ b/apps/files_external/lib/Listener/LoadAdditionalListener.php @@ -50,6 +50,8 @@ class LoadAdditionalListener implements IEventListener { $allowUserMounting = $this->config->getAppValue('files_external', 'allow_user_mounting', 'no') === 'yes'; $this->initialState->provideInitialState('allowUserMounting', $allowUserMounting); + + Util::addInitScript(Application::APP_ID, 'init'); Util::addScript(Application::APP_ID, 'main', 'files'); } } diff --git a/apps/files_external/src/actions/enterCredentialsAction.ts b/apps/files_external/src/actions/enterCredentialsAction.ts index 49b0ab4076e..eeb2f5f8793 100644 --- a/apps/files_external/src/actions/enterCredentialsAction.ts +++ b/apps/files_external/src/actions/enterCredentialsAction.ts @@ -31,7 +31,7 @@ import axios from '@nextcloud/axios' import LoginSvg from '@mdi/svg/svg/login.svg?raw' import Vue from 'vue' -import { registerFileAction, FileAction, DefaultType } from '@nextcloud/files' +import { FileAction, DefaultType } from '@nextcloud/files' import { STORAGE_STATUS, isMissingAuthConfig } from '../utils/credentialsUtils' import { isNodeExternalStorage } from '../utils/externalStorageUtils' @@ -106,5 +106,3 @@ export const action = new FileAction({ default: DefaultType.DEFAULT, inline: () => true, }) - -registerFileAction(action) diff --git a/apps/files_external/src/actions/inlineStorageCheckAction.ts b/apps/files_external/src/actions/inlineStorageCheckAction.ts index fa2f567b1f7..46e38eab47e 100644 --- a/apps/files_external/src/actions/inlineStorageCheckAction.ts +++ b/apps/files_external/src/actions/inlineStorageCheckAction.ts @@ -32,7 +32,7 @@ import '../css/fileEntryStatus.scss' import { getStatus, type StorageConfig } from '../services/externalStorage' import { isMissingAuthConfig, STORAGE_STATUS } from '../utils/credentialsUtils' import { isNodeExternalStorage } from '../utils/externalStorageUtils' -import { registerFileAction, FileAction } from '@nextcloud/files' +import { FileAction } from '@nextcloud/files' export const action = new FileAction({ id: 'check-external-storage', @@ -92,5 +92,3 @@ export const action = new FileAction({ order: 10, }) - -registerFileAction(action) diff --git a/apps/files_external/src/actions/openInFilesAction.ts b/apps/files_external/src/actions/openInFilesAction.ts index 0359e81998d..8033caed123 100644 --- a/apps/files_external/src/actions/openInFilesAction.ts +++ b/apps/files_external/src/actions/openInFilesAction.ts @@ -25,7 +25,7 @@ import type { StorageConfig } from '../services/externalStorage' import { generateUrl } from '@nextcloud/router' import { translate as t } from '@nextcloud/l10n' -import { registerFileAction, FileAction, DefaultType } from '@nextcloud/files' +import { FileAction, DefaultType } from '@nextcloud/files' import { STORAGE_STATUS } from '../utils/credentialsUtils' export const action = new FileAction({ @@ -71,5 +71,3 @@ export const action = new FileAction({ order: -1000, default: DefaultType.HIDDEN, }) - -registerFileAction(action) diff --git a/apps/files_external/src/init.ts b/apps/files_external/src/init.ts new file mode 100644 index 00000000000..ccce2448dfe --- /dev/null +++ b/apps/files_external/src/init.ts @@ -0,0 +1,81 @@ +/** + * @copyright Copyright (c) 2023 John Molakvoæ + * + * @author John Molakvoæ + * + * @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 . + * + */ +import { loadState } from '@nextcloud/initial-state' +import { translate as t } from '@nextcloud/l10n' +import { View, getNavigation, Column, registerFileAction } from '@nextcloud/files' +import FolderNetworkSvg from '@mdi/svg/svg/folder-network.svg?raw' + +import { action as enterCredentialsAction } from './actions/enterCredentialsAction' +import { action as inlineStorageCheckAction } from './actions/inlineStorageCheckAction' +import { action as openInFilesAction } from './actions/openInFilesAction' +import { getContents } from './services/externalStorage' + +const allowUserMounting = loadState('files_external', 'allowUserMounting', false) + +// Register view +const Navigation = getNavigation() +Navigation.register(new View({ + id: 'extstoragemounts', + name: t('files_external', 'External storage'), + caption: t('files_external', 'List of external storage.'), + + emptyCaption: allowUserMounting + ? t('files_external', 'There is no external storage configured. You can configure them in your Personal settings.') + : t('files_external', 'There is no external storage configured and you don\'t have the permission to configure them.'), + emptyTitle: t('files_external', 'No external storage'), + + icon: FolderNetworkSvg, + order: 30, + + columns: [ + new Column({ + id: 'storage-type', + title: t('files_external', 'Storage type'), + render(node) { + const backend = node.attributes?.backend || t('files_external', 'Unknown') + const span = document.createElement('span') + span.textContent = backend + return span + }, + }), + new Column({ + id: 'scope', + title: t('files_external', 'Scope'), + render(node) { + const span = document.createElement('span') + let scope = t('files_external', 'Personal') + if (node.attributes?.scope === 'system') { + scope = t('files_external', 'System') + } + span.textContent = scope + return span + }, + }), + ], + + getContents, +})) + +// Register actions +registerFileAction(enterCredentialsAction) +registerFileAction(inlineStorageCheckAction) +registerFileAction(openInFilesAction) diff --git a/apps/files_external/src/main.ts b/apps/files_external/src/main.ts deleted file mode 100644 index c85dd371f51..00000000000 --- a/apps/files_external/src/main.ts +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @copyright Copyright (c) 2023 John Molakvoæ - * - * @author John Molakvoæ - * - * @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 . - * - */ -import { translate as t } from '@nextcloud/l10n' -import { loadState } from '@nextcloud/initial-state' -import FolderNetworkSvg from '@mdi/svg/svg/folder-network.svg?raw' - -import './actions/enterCredentialsAction' -import './actions/inlineStorageCheckAction' -import './actions/openInFilesAction' -import { getContents } from './services/externalStorage' -import { View, getNavigation, Column } from '@nextcloud/files' - -const allowUserMounting = loadState('files_external', 'allowUserMounting', false) - -const Navigation = getNavigation() -Navigation.register(new View({ - id: 'extstoragemounts', - name: t('files_external', 'External storage'), - caption: t('files_external', 'List of external storage.'), - - emptyCaption: allowUserMounting - ? t('files_external', 'There is no external storage configured. You can configure them in your Personal settings.') - : t('files_external', 'There is no external storage configured and you don\'t have the permission to configure them.'), - emptyTitle: t('files_external', 'No external storage'), - - icon: FolderNetworkSvg, - order: 30, - - columns: [ - new Column({ - id: 'storage-type', - title: t('files_external', 'Storage type'), - render(node) { - const backend = node.attributes?.backend || t('files_external', 'Unknown') - const span = document.createElement('span') - span.textContent = backend - return span - }, - }), - new Column({ - id: 'scope', - title: t('files_external', 'Scope'), - render(node) { - const span = document.createElement('span') - let scope = t('files_external', 'Personal') - if (node.attributes?.scope === 'system') { - scope = t('files_external', 'System') - } - span.textContent = scope - return span - }, - }), - ], - - getContents, -})) -- cgit v1.2.3