feat(files_external): Move script loading to CommonSettingsTrait to reduce duplicated code between admin and user settings

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
This commit is contained in:
Ferdinand Thiessen 2024-03-17 21:24:42 +01:00 committed by nextcloud-command
parent 5c652484e3
commit 4c8b9deca0
6 changed files with 62 additions and 1 deletions

View file

@ -122,6 +122,7 @@ return array(
'OCA\\Files_External\\Service\\UserStoragesService' => $baseDir . '/../lib/Service/UserStoragesService.php',
'OCA\\Files_External\\Service\\UserTrait' => $baseDir . '/../lib/Service/UserTrait.php',
'OCA\\Files_External\\Settings\\Admin' => $baseDir . '/../lib/Settings/Admin.php',
'OCA\\Files_External\\Settings\\CommonSettingsTrait' => $baseDir . '/../lib/Settings/CommonSettingsTrait.php',
'OCA\\Files_External\\Settings\\Personal' => $baseDir . '/../lib/Settings/Personal.php',
'OCA\\Files_External\\Settings\\PersonalSection' => $baseDir . '/../lib/Settings/PersonalSection.php',
'OCA\\Files_External\\Settings\\Section' => $baseDir . '/../lib/Settings/Section.php',

View file

@ -137,6 +137,7 @@ class ComposerStaticInitFiles_External
'OCA\\Files_External\\Service\\UserStoragesService' => __DIR__ . '/..' . '/../lib/Service/UserStoragesService.php',
'OCA\\Files_External\\Service\\UserTrait' => __DIR__ . '/..' . '/../lib/Service/UserTrait.php',
'OCA\\Files_External\\Settings\\Admin' => __DIR__ . '/..' . '/../lib/Settings/Admin.php',
'OCA\\Files_External\\Settings\\CommonSettingsTrait' => __DIR__ . '/..' . '/../lib/Settings/CommonSettingsTrait.php',
'OCA\\Files_External\\Settings\\Personal' => __DIR__ . '/..' . '/../lib/Settings/Personal.php',
'OCA\\Files_External\\Settings\\PersonalSection' => __DIR__ . '/..' . '/../lib/Settings/PersonalSection.php',
'OCA\\Files_External\\Settings\\Section' => __DIR__ . '/..' . '/../lib/Settings/Section.php',

View file

@ -15,6 +15,7 @@ use OCP\Encryption\IManager;
use OCP\Settings\ISettings;
class Admin implements ISettings {
use CommonSettingsTrait;
public function __construct(
private IManager $encryptionManager,
@ -40,6 +41,7 @@ class Admin implements ISettings {
'globalCredentialsUid' => '',
];
$this->loadScriptsAndStyles();
return new TemplateResponse('files_external', 'settings', $parameters, '');
}

View file

@ -0,0 +1,55 @@
<?php
declare(strict_types=1);
/**
* @copyright Copyright (c) 2024 Ferdinand Thiessen <opensource@fthiessen.de>
*
* @author Ferdinand Thiessen <opensource@fthiessen.de>
*
* @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/>.
*
*/
namespace OCA\Files_External\Settings;
use OCA\Files_External\Service\BackendService;
use OCP\Util;
trait CommonSettingsTrait {
protected BackendService $backendService;
/**
* Load the frontend script including the custom backend dependencies
*/
protected function loadScriptsAndStyles() {
Util::addScript('files_external', 'settings');
Util::addStyle('files_external', 'settings');
// load custom JS
foreach ($this->backendService->getAvailableBackends() as $backend) {
foreach ($backend->getCustomJs() as $script) {
Util::addScript('files_external', $script);
}
}
foreach ($this->backendService->getAuthMechanisms() as $authMechanism) {
foreach ($authMechanism->getCustomJs() as $script) {
Util::addScript('files_external', $script);
}
}
}
}

View file

@ -16,6 +16,7 @@ use OCP\IUserSession;
use OCP\Settings\ISettings;
class Personal implements ISettings {
use CommonSettingsTrait;
public function __construct(
private IManager $encryptionManager,
@ -43,6 +44,7 @@ class Personal implements ISettings {
'globalCredentials' => $this->globalAuth->getAuth($uid),
'globalCredentialsUid' => $uid,
];
$this->loadScriptsAndStyles();
return new TemplateResponse('files_external', 'settings', $parameters, '');
}

View file

@ -5,4 +5,4 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
// Empty template as Vue will take over the `id="conent"` of the base template element
// Empty template as Vue will take over the `id="content"` of the base template element