diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2019-11-18 22:13:38 +0100 |
---|---|---|
committer | Roeland Jago Douma <roeland@famdouma.nl> | 2019-11-20 19:42:52 +0100 |
commit | 836e7305d02d718673848c2ea35fe194fd81142c (patch) | |
tree | 8ecf0de9ee42cec0669c058a6183e54a58a9e00d /apps/accessibility/lib | |
parent | 2b2626566c19280ff207cbfa2c0c235ecae2a79b (diff) | |
download | nextcloud-server-836e7305d02d718673848c2ea35fe194fd81142c.tar.gz nextcloud-server-836e7305d02d718673848c2ea35fe194fd81142c.zip |
Fix accessibility
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/accessibility/lib')
-rw-r--r-- | apps/accessibility/lib/Controller/ConfigController.php | 38 | ||||
-rw-r--r-- | apps/accessibility/lib/Settings/Personal.php | 31 |
2 files changed, 50 insertions, 19 deletions
diff --git a/apps/accessibility/lib/Controller/ConfigController.php b/apps/accessibility/lib/Controller/ConfigController.php index d98ba231fa8..589861163f1 100644 --- a/apps/accessibility/lib/Controller/ConfigController.php +++ b/apps/accessibility/lib/Controller/ConfigController.php @@ -102,16 +102,8 @@ class ConfigController extends OCSController { public function setConfig(string $key, $value): DataResponse { if ($key === 'theme' || $key === 'font' || $key === 'highcontrast') { - if ($value === false) { - $this->config->deleteUserValue($this->userId, $this->appName, $key); - $userValues = $this->config->getUserKeys($this->userId, $this->appName); - - // remove hash if no settings selected - if (count($userValues) === 1 && $userValues[0] === 'icons-css') { - $this->config->deleteUserValue($this->userId, $this->appName, 'icons-css'); - } - - return new DataResponse(); + if ($value === false || $value === '') { + throw new OCSBadRequestException('Invalid value: ' . $value); } $themes = $this->accessibilityProvider->getThemes(); @@ -133,4 +125,30 @@ class ConfigController extends OCSController { throw new OCSBadRequestException('Invalid key: ' . $key); } + /** + * @NoAdminRequired + * + * Unset theme or font config + * + * @param string $key theme or font + * @return DataResponse + * @throws Exception + */ + public function deleteConfig(string $key): DataResponse { + if ($key === 'theme' || $key === 'font' || $key === 'highcontrast') { + + $this->config->deleteUserValue($this->userId, $this->appName, $key); + $userValues = $this->config->getUserKeys($this->userId, $this->appName); + + // remove hash if no settings selected + if (count($userValues) === 1 && $userValues[0] === 'icons-css') { + $this->config->deleteUserValue($this->userId, $this->appName, 'icons-css'); + } + + return new DataResponse(); + } + + throw new OCSBadRequestException('Invalid key: ' . $key); + } + } diff --git a/apps/accessibility/lib/Settings/Personal.php b/apps/accessibility/lib/Settings/Personal.php index ef9fc407147..484f33cd064 100644 --- a/apps/accessibility/lib/Settings/Personal.php +++ b/apps/accessibility/lib/Settings/Personal.php @@ -27,10 +27,12 @@ namespace OCA\Accessibility\Settings; use OCA\Accessibility\AccessibilityProvider; use OCP\AppFramework\Http\TemplateResponse; use OCP\IConfig; +use OCP\IInitialStateService; use OCP\IL10N; use OCP\IURLGenerator; use OCP\IUserSession; use OCP\Settings\ISettings; +use OCP\Util; class Personal implements ISettings { @@ -52,6 +54,9 @@ class Personal implements ISettings { /** @var AccessibilityProvider */ private $accessibilityProvider; + /** @var IInitialStateService */ + private $initialStateService; + /** * Settings constructor. * @@ -67,13 +72,15 @@ class Personal implements ISettings { IUserSession $userSession, IL10N $l, IURLGenerator $urlGenerator, - AccessibilityProvider $accessibilityProvider) { + AccessibilityProvider $accessibilityProvider, + IInitialStateService $initialStateService) { $this->appName = $appName; $this->config = $config; $this->userSession = $userSession; $this->l = $l; $this->urlGenerator = $urlGenerator; $this->accessibilityProvider = $accessibilityProvider; + $this->initialStateService = $initialStateService; } /** @@ -81,19 +88,25 @@ class Personal implements ISettings { * @since 9.1 */ public function getForm() { + Util::addScript('accessibility', 'accessibility'); + Util::addStyle('accessibility', 'style'); - $serverData = [ + $availableConfig = [ 'themes' => $this->accessibilityProvider->getThemes(), 'fonts' => $this->accessibilityProvider->getFonts(), - 'highcontrast' => $this->accessibilityProvider->getHighContrast(), - 'selected' => [ - 'highcontrast' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'highcontrast', false), - 'theme' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false), - 'font' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false) - ] + 'highcontrast' => $this->accessibilityProvider->getHighContrast() + ]; + + $userConfig = [ + 'highcontrast' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'highcontrast', false), + 'theme' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'theme', false), + 'font' => $this->config->getUserValue($this->userSession->getUser()->getUID(), $this->appName, 'font', false) ]; - return new TemplateResponse($this->appName, 'settings-personal', ['serverData' => $serverData]); + $this->initialStateService->provideInitialState($this->appName, 'available-config', $availableConfig); + $this->initialStateService->provideInitialState($this->appName, 'user-config', $userConfig); + + return new TemplateResponse($this->appName, 'settings-personal'); } /** |