diff options
author | Julius Härtl <jus@bitgrid.net> | 2019-12-06 16:09:18 +0300 |
---|---|---|
committer | Julius Härtl <jus@bitgrid.net> | 2019-12-06 16:09:18 +0300 |
commit | 797e29ccf94d253c70879f75ea92a1f812b76572 (patch) | |
tree | 0978bdeb1b0952986d0f5de6d136d2cf28f1b4ba /lib | |
parent | 18b3840d77a4c81243dbb53c9c0a814f3908a236 (diff) |
Persist setting for rich workspace
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AppInfo/Application.php | 42 | ||||
-rw-r--r-- | lib/Controller/SettingsController.php | 69 |
2 files changed, 110 insertions, 1 deletions
diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 954a32e1a..5aef1e367 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -28,12 +28,24 @@ use OCA\Text\DirectEditing\TextDirectEditor; use OCP\AppFramework\App; use OCP\DirectEditing\RegisterDirectEditorEvent; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IInitialStateService; class Application extends App { const APP_NAME = 'text'; + /** @var IInitialStateService */ + private $initialStateService; + /** + * @var \OCP\IUserSession + */ + private $userSession; + /** + * @var \OCP\IConfig + */ + private $config; + /** * Application constructor. @@ -45,12 +57,40 @@ class Application extends App { parent::__construct(self::APP_NAME, $params); $container = $this->getContainer(); + $server = $container->getServer(); /** @var IEventDispatcher $eventDispatcher */ - $eventDispatcher = $this->getContainer()->getServer()->query(IEventDispatcher::class); + $eventDispatcher = $server->query(IEventDispatcher::class); + $this->initialStateService = $server->query(IInitialStateService::class); + $this->userSession = $server->getUserSession(); + $this->config = $this->getContainer()->getServer()->getConfig(); + $eventDispatcher->addListener(RegisterDirectEditorEvent::class, function (RegisterDirectEditorEvent $event) use ($container) { $editor = $container->query(TextDirectEditor::class); $event->register($editor); }); + + if ($this->userSession->isLoggedIn()) { + $eventDispatcher->addListener('OCA\Files::loadAdditionalScripts', function () use ($initialStateService) { + \OCP\Util::addScript('text', 'files'); + \OCP\Util::addStyle('text', 'icons'); + + $this->initialStateService->provideInitialState( + self::APP_NAME, + 'workspace_available', + $this->config->getAppValue(self::APP_NAME, 'workspace_available', true) + ); + $this->initialStateService->provideInitialState( + self::APP_NAME, + 'workspace_enabled', + $this->config->getUserValue($this->userSession->getUser()->getUID(), self::APP_NAME, 'workspace_enabled', '1') === '1' + ); + }); + } + + $eventDispatcher->addListener('OCA\Files_Sharing::loadAdditionalScripts', function () { + \OCP\Util::addScript('text', 'public'); + \OCP\Util::addStyle('text', 'icons'); + }); } } diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php new file mode 100644 index 000000000..125ac8f7e --- /dev/null +++ b/lib/Controller/SettingsController.php @@ -0,0 +1,69 @@ +<?php +/** + * @copyright Copyright (c) 2019 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/>. + * + */ + +namespace OCA\Text\Controller; + + +use OCA\Activity\Data; +use OCA\Text\AppInfo\Application; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\DataResponse; +use OCP\IConfig; +use OCP\IRequest; + +class SettingsController extends Controller { + + /** + * @var IConfig + */ + private $config; + + const ACCEPTED_KEYS = [ + 'workspace_enabled' + ]; + + public function __construct($appName, IRequest $request, IConfig $config, $userId) { + parent::__construct($appName, $request); + + $this->config = $config; + $this->userId = $userId; + } + + /** + * @NoAdminRequired + * @param string $key + * @param string $value + * @return DataResponse + * @throws \OCP\PreConditionNotMetException + */ + public function updateConfig(string $key, $value) { + if (!in_array($key, self::ACCEPTED_KEYS, true)) { + return new DataResponse(['message' => 'Invalid config key'], Http::STATUS_BAD_REQUEST); + } + $this->config->setUserValue($this->userId, Application::APP_NAME, $key, $value); + return new DataResponse([ + $key => $value + ]); + } +} |