Fix accessibility

Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
This commit is contained in:
John Molakvoæ (skjnldsv) 2019-11-18 22:13:38 +01:00 committed by Roeland Jago Douma
parent 2b2626566c
commit 836e7305d0
No known key found for this signature in database
GPG Key ID: F941078878347C0C
7 changed files with 60 additions and 26 deletions

View File

@ -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

View File

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

View File

@ -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()
];
return new TemplateResponse($this->appName, 'settings-personal', ['serverData' => $serverData]);
$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)
];
$this->initialStateService->provideInitialState($this->appName, 'available-config', $availableConfig);
$this->initialStateService->provideInitialState($this->appName, 'user-config', $userConfig);
return new TemplateResponse($this->appName, 'settings-personal');
}
/**

View File

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

View File

@ -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>