Fix accessibility

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
pull/17994/head
John Molakvoæ (skjnldsv) 5 years ago committed by Roeland Jago Douma
parent 2b2626566c
commit 836e7305d0
No known key found for this signature in database
GPG Key ID: F941078878347C0C
  1. 7
      apps/accessibility/appinfo/routes.php
  2. 2
      apps/accessibility/js/accessibility.js
  3. 2
      apps/accessibility/js/accessibility.js.map
  4. 38
      apps/accessibility/lib/Controller/ConfigController.php
  5. 31
      apps/accessibility/lib/Settings/Personal.php
  6. 3
      apps/accessibility/src/Accessibility.vue
  7. 3
      apps/accessibility/templates/settings-personal.php

@ -35,7 +35,12 @@ return [
[
'name' => 'Config#setConfig',
'url' => '/api/v1/config/{key}',
'verb' => 'POST',
'verb' => 'PUT',
],
[
'name' => 'Config#deleteConfig',
'url' => '/api/v1/config/{key}',
'verb' => 'DELETE',
],
]
];

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

@ -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);
}
}

@ -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');
}
/**

@ -118,9 +118,10 @@ export default {
*/
async selectItem(type, id) {
try {
const isDelete = id === ''
await axios({
url: generateOcsUrl('apps/accessibility/api/v1/config', 2) + type,
method: id === '' ? 'DELETE' : 'POST',
method: isDelete ? 'DELETE' : 'PUT',
data: {
value: id
}

@ -21,9 +21,6 @@
*
*/
script('accessibility', 'accessibility');
style('accessibility', 'style');
?>
<span id="serverData" data-server="<?php p(json_encode($_['serverData']));?>"></span>
<span id="accessibility"></span>
Loading…
Cancel
Save