From f612c264bbd21288e41866756bb151e133686df3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20Molakvo=C3=A6=20=28skjnldsv=29?= Date: Tue, 1 Sep 2020 06:51:29 +0200 Subject: Non-cropped layout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) Signed-off-by: npmbuildbot[bot] --- lib/Controller/ApiController.php | 73 +++++++++++++++++++++++++++++++++++++++ lib/Controller/PageController.php | 36 +++++++++++-------- 2 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 lib/Controller/ApiController.php (limited to 'lib') diff --git a/lib/Controller/ApiController.php b/lib/Controller/ApiController.php new file mode 100644 index 00000000..84566e5c --- /dev/null +++ b/lib/Controller/ApiController.php @@ -0,0 +1,73 @@ + + * + * @author John Molakvoæ + * + * @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 . + * + */ + +namespace OCA\Photos\Controller; + +use OCA\Photos\AppInfo\Application; +use OCP\AppFramework\Controller; +use OCP\AppFramework\Http; +use OCP\AppFramework\Http\JSONResponse; +use OCP\IConfig; +use OCP\IRequest; +use OCP\IUserSession; + +class ApiController extends Controller { + + /** @var IConfig */ + private $config; + + /** @var IUserSession */ + private $userSession; + + public function __construct(IRequest $request, + IConfig $config, + IUserSession $userSession) { + parent::__construct(Application::APP_ID, $request); + + $this->config = $config; + $this->userSession = $userSession; + } + + /** + * @NoAdminRequired + * + * update preferences (user setting) + * + * @param string key the identifier to change + * @param string value the value to set + * + * @return JSONResponse an empty JSONResponse with respective http status code + */ + public function setUserConfig(string $key, string $value): JSONResponse { + $user = $this->userSession->getUser(); + if (is_null($user)) { + return new JSONResponse([], Http::STATUS_PRECONDITION_FAILED); + } + + $userId = $user->getUid(); + $this->config->setUserValue($userId, Application::APP_ID, $key, $value); + return new JSONResponse([], Http::STATUS_OK); + } +} diff --git a/lib/Controller/PageController.php b/lib/Controller/PageController.php index 3cf92ad6..7422b56f 100644 --- a/lib/Controller/PageController.php +++ b/lib/Controller/PageController.php @@ -28,40 +28,45 @@ namespace OCA\Photos\Controller; use OCA\Files\Event\LoadSidebar; use OCA\Photos\AppInfo\Application; use OCA\Viewer\Event\LoadViewer; +use OCP\App\IAppManager; use OCP\AppFramework\Controller; use OCP\AppFramework\Http\TemplateResponse; use OCP\EventDispatcher\IEventDispatcher; +use OCP\IConfig; use OCP\IInitialStateService; use OCP\IRequest; +use OCP\IUserSession; use OCP\Util; -use OCP\IConfig; -use OCP\App\IAppManager; class PageController extends Controller { - protected $appName; + /** @var IAppManager */ + private $appManager; /** @var IEventDispatcher */ private $eventDispatcher; + /** @var IConfig */ + private $config; + /** @var IInitialStateService */ private $initialStateService; - /** @var IAppManager */ - private $appManager; + /** @var IUserSession */ + private $userSession; - public function __construct($appName, + public function __construct(IRequest $request, IAppManager $appManager, - IRequest $request, IEventDispatcher $eventDispatcher, IConfig $config, - IInitialStateService $initialStateService) { - parent::__construct($appName, $request); + IInitialStateService $initialStateService, + IUserSession $userSession) { + parent::__construct(Application::APP_ID, $request); - $this->appName = $appName; $this->appManager = $appManager; $this->eventDispatcher = $eventDispatcher; - $this->initialStateService = $initialStateService; $this->config = $config; + $this->initialStateService = $initialStateService; + $this->userSession = $userSession; } /** @@ -72,17 +77,20 @@ class PageController extends Controller { * @return TemplateResponse */ public function index(): TemplateResponse { + $user = $this->userSession->getUser(); + $this->eventDispatcher->dispatch(LoadSidebar::class, new LoadSidebar()); $this->eventDispatcher->dispatch(LoadViewer::class, new LoadViewer()); $this->initialStateService->provideInitialState($this->appName, 'image-mimes', Application::IMAGE_MIMES); $this->initialStateService->provideInitialState($this->appName, 'video-mimes', Application::VIDEO_MIMES); $this->initialStateService->provideInitialState($this->appName, 'maps', $this->appManager->isEnabledForUser('maps') === true); + $this->initialStateService->provideInitialState($this->appName, 'croppedLayout', $this->config->getUserValue($user->getUid(), Application::APP_ID, 'croppedLayout', 'false')); - Util::addScript($this->appName, 'photos-main'); - Util::addStyle($this->appName, 'icons'); + Util::addScript(Application::APP_ID, 'photos-main'); + Util::addStyle(Application::APP_ID, 'icons'); - $response = new TemplateResponse($this->appName, 'main'); + $response = new TemplateResponse(Application::APP_ID, 'main'); return $response; } } -- cgit v1.2.3