diff options
author | John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com> | 2020-09-01 07:51:29 +0300 |
---|---|---|
committer | npmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com> | 2020-10-16 10:10:00 +0300 |
commit | f612c264bbd21288e41866756bb151e133686df3 (patch) | |
tree | 364843f65670290064479d8b6385a2993bb13785 /lib | |
parent | 14addf399445650c53cf12238815e36ab9da5b3e (diff) |
Non-cropped layout
Signed-off-by: John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
Signed-off-by: npmbuildbot[bot] <npmbuildbot[bot]@users.noreply.github.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Controller/ApiController.php | 73 | ||||
-rw-r--r-- | lib/Controller/PageController.php | 36 |
2 files changed, 95 insertions, 14 deletions
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 @@ +<?php + +declare(strict_types=1); +/** + * @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com> + * + * @author John Molakvoæ <skjnldsv@protonmail.com> + * + * @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\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; } } |