diff options
-rw-r--r-- | lib/Controller/DirectViewController.php | 12 | ||||
-rw-r--r-- | lib/Controller/DocumentController.php | 16 | ||||
-rw-r--r-- | lib/Controller/TDocumentInitialState.php | 48 | ||||
-rw-r--r-- | src/document.js | 6 | ||||
-rw-r--r-- | src/helpers/coolParameters.js | 5 |
5 files changed, 69 insertions, 18 deletions
diff --git a/lib/Controller/DirectViewController.php b/lib/Controller/DirectViewController.php index b837d39e..514a7716 100644 --- a/lib/Controller/DirectViewController.php +++ b/lib/Controller/DirectViewController.php @@ -35,6 +35,7 @@ use OCP\AppFramework\Http\ContentSecurityPolicy; use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\RedirectResponse; use OCP\AppFramework\Http\TemplateResponse; +use OCP\AppFramework\Services\IInitialState; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\Node; @@ -44,6 +45,8 @@ use OCP\ILogger; use OCP\IRequest; class DirectViewController extends Controller { + use TDocumentInitialState; + /** @var IRootFolder */ private $rootFolder; @@ -68,12 +71,16 @@ class DirectViewController extends Controller { /** @var ILogger */ private $logger; + /** @var IInitialState */ + private $initialState; + public function __construct( $appName, IRequest $request, IRootFolder $rootFolder, TokenManager $tokenManager, DirectMapper $directMapper, + IInitialState $initialState, IConfig $config, AppConfig $appConfig, TemplateManager $templateManager, @@ -85,6 +92,7 @@ class DirectViewController extends Controller { $this->rootFolder = $rootFolder; $this->tokenManager = $tokenManager; $this->directMapper = $directMapper; + $this->initialState = $initialState; $this->config = $config; $this->appConfig = $appConfig; $this->templateManager = $templateManager; @@ -171,6 +179,7 @@ class DirectViewController extends Controller { 'direct' => true, ]; + $this->provideDocumentInitialState($wopi); $response = new TemplateResponse('richdocuments', 'documents', $params, 'base'); $policy = new ContentSecurityPolicy(); $policy->allowInlineScript(true); @@ -226,6 +235,7 @@ class DirectViewController extends Controller { $params['token'] = $token; $params['urlsrc'] = $urlSrc; + $this->provideDocumentInitialState($wopi); $response = new TemplateResponse('richdocuments', 'documents', $params, 'base'); $policy = new ContentSecurityPolicy(); $policy->allowInlineScript(true); @@ -235,7 +245,7 @@ class DirectViewController extends Controller { } } catch (\Exception $e) { $this->logger->logException($e, ['app'=>'richdocuments']); - $response = $this->renderErrorPage('Failed to open the requested file.'); + return $this->renderErrorPage('Failed to open the requested file.'); } return new TemplateResponse('core', '403', [], 'guest'); diff --git a/lib/Controller/DocumentController.php b/lib/Controller/DocumentController.php index 1ed67f21..c946c66c 100644 --- a/lib/Controller/DocumentController.php +++ b/lib/Controller/DocumentController.php @@ -44,6 +44,8 @@ use OCP\Share\IManager; use OC\Files\Type\TemplateManager; class DocumentController extends Controller { + use TDocumentInitialState; + /** @var string */ private $uid; /** @var IL10N */ @@ -179,20 +181,6 @@ class DocumentController extends Controller { $response->setFeaturePolicy($featurePolicy); } - private function provideDocumentInitialState(Wopi $wopi) { - $this->initialState->provideInitialState('wopi', $wopi); - $this->initialState->provideInitialState('uiDefaults', [ - 'UIMode' => $this->config->getAppValue(Application::APPNAME, 'uiDefaults-UIMode', 'classic') - ]); - $logoSet = $this->config->getAppValue('theming', 'logoheaderMime', '') !== ''; - if (!$logoSet) { - $logoSet = $this->config->getAppValue('theming', 'logoMime', '') !== ''; - } - $this->initialState->provideInitialState('theming-customLogo', ($logoSet ? - \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getThemingDefaults()->getLogo()) - : false)); - } - /** * @NoAdminRequired * diff --git a/lib/Controller/TDocumentInitialState.php b/lib/Controller/TDocumentInitialState.php new file mode 100644 index 00000000..bfd1070f --- /dev/null +++ b/lib/Controller/TDocumentInitialState.php @@ -0,0 +1,48 @@ +<?php +/* + * @copyright Copyright (c) 2021 Julius Härtl <jus@bitgrid.net> + * + * @author Julius Härtl <jus@bitgrid.net> + * + * @license GNU AGPL version 3 or any later version + * + * 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/>. + * + */ + +declare(strict_types=1); + +namespace OCA\Richdocuments\Controller; + +use OCA\Richdocuments\AppInfo\Application; +use OCA\Richdocuments\Db\Wopi; + +trait TDocumentInitialState { + + private function provideDocumentInitialState(Wopi $wopi): void { + $this->initialState->provideInitialState('wopi', $wopi); + $this->initialState->provideInitialState('theme', $this->config->getAppValue(Application::APPNAME, 'theme', '')); + $this->initialState->provideInitialState('uiDefaults', [ + 'UIMode' => $this->config->getAppValue(Application::APPNAME, 'uiDefaults-UIMode', 'classic') + ]); + $logoSet = $this->config->getAppValue('theming', 'logoheaderMime', '') !== ''; + if (!$logoSet) { + $logoSet = $this->config->getAppValue('theming', 'logoMime', '') !== ''; + } + $this->initialState->provideInitialState('theming-customLogo', ($logoSet ? + \OC::$server->getURLGenerator()->getAbsoluteURL(\OC::$server->getThemingDefaults()->getLogo()) + : false)); + } + +} diff --git a/src/document.js b/src/document.js index 674f5ee7..55270991 100644 --- a/src/document.js +++ b/src/document.js @@ -3,7 +3,7 @@ import { getRootUrl } from '@nextcloud/router' import { getRequestToken } from '@nextcloud/auth' import Config from './services/config.tsx' import { setGuestName, shouldAskForGuestName } from './helpers/guestName' -import { getUIDefaults, generateCSSVarTokens } from './helpers/coolParameters' +import { getUIDefaults, generateCSSVarTokens, getCollaboraTheme } from './helpers/coolParameters' import PostMessageService from './services/postMessage.tsx' import { @@ -186,7 +186,7 @@ const documentsMain = { + '<input name="access_token" value="' + accessToken + '" type="hidden"/>' + '<input name="ui_defaults" value="' + getUIDefaults() + '" type="hidden"/>' + '<input name="css_variables" value="' + generateCSSVarTokens() + '" type="hidden"/>' - + '<input name="theme" value="nextcloud" type="hidden"/>' + + '<input name="theme" value="' + getCollaboraTheme() + '" type="hidden"/>' + '</form>' // iframe that contains the Collabora Online Viewer @@ -241,7 +241,7 @@ const documentsMain = { + '<input name="access_token" value="' + accessToken + '" type="hidden"/>' + '<input name="ui_defaults" value="' + getUIDefaults() + '" type="hidden"/>' + '<input name="css_variables" value="' + generateCSSVarTokens() + '" type="hidden"/>' - + '<input name="theme" value="nextcloud" type="hidden"/>' + + '<input name="theme" value="' + getCollaboraTheme() + '" type="hidden"/>' + '</form>' // iframe that contains the Collabora Online diff --git a/src/helpers/coolParameters.js b/src/helpers/coolParameters.js index 4cd7446b..e5e93276 100644 --- a/src/helpers/coolParameters.js +++ b/src/helpers/coolParameters.js @@ -37,6 +37,10 @@ const getUIDefaults = () => { return uiDefaults } +const getCollaboraTheme = () => { + return loadState('richdocuments', 'theme', '') +} + const generateCSSVarTokens = () => { /* NC versus COOL */ const cssVarMap = { @@ -85,5 +89,6 @@ const generateCSSVarTokens = () => { export { getUIDefaults, + getCollaboraTheme, generateCSSVarTokens, } |