summaryrefslogtreecommitdiffstats
path: root/apps/dashboard/lib
diff options
context:
space:
mode:
authorJulius Härtl <jus@bitgrid.net>2020-08-14 16:22:22 +0200
committerJulius Härtl <jus@bitgrid.net>2020-08-19 17:07:27 +0200
commitb49f814faa08be51d4008f4b367a797cf95002a7 (patch)
treeebf517d9ca3e2688f80e1175ac3bbbaadd43e94d /apps/dashboard/lib
parent2535e0ec044b0500edf9b00afb544da5c69bf8eb (diff)
downloadnextcloud-server-b49f814faa08be51d4008f4b367a797cf95002a7.tar.gz
nextcloud-server-b49f814faa08be51d4008f4b367a797cf95002a7.zip
Implement background reset and proper shipped setting
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Diffstat (limited to 'apps/dashboard/lib')
-rw-r--r--apps/dashboard/lib/Controller/DashboardController.php19
-rw-r--r--apps/dashboard/lib/Service/BackgroundService.php29
2 files changed, 38 insertions, 10 deletions
diff --git a/apps/dashboard/lib/Controller/DashboardController.php b/apps/dashboard/lib/Controller/DashboardController.php
index f6fea2aaf45..1c11ca24518 100644
--- a/apps/dashboard/lib/Controller/DashboardController.php
+++ b/apps/dashboard/lib/Controller/DashboardController.php
@@ -33,11 +33,13 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\FileDisplayResponse;
use OCP\AppFramework\Http\JSONResponse;
+use OCP\AppFramework\Http\NotFoundResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget;
use OCP\Dashboard\RegisterWidgetEvent;
use OCP\EventDispatcher\IEventDispatcher;
+use OCP\Files\NotFoundException;
use OCP\IConfig;
use OCP\IInitialStateService;
use OCP\IRequest;
@@ -105,6 +107,7 @@ class DashboardController extends Controller {
$this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout);
$this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
$this->inititalStateService->provideInitialState('dashboard', 'shippedBackgrounds', BackgroundService::SHIPPED_BACKGROUNDS);
+ $this->inititalStateService->provideInitialState('dashboard', 'background', $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default'));
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
return new TemplateResponse('dashboard', 'index');
@@ -123,16 +126,20 @@ class DashboardController extends Controller {
/**
* @NoAdminRequired
*/
- public function setBackground($path = null, $url = null): JSONResponse {
+ public function setBackground($path = null, $url = null, $shipped = null): JSONResponse {
// FIXME: store current version of the background and return the result
// FIXME: handle shipped backgrounds avoid file duplication
// FIXME: allow to reset to default ones
+ if ($shipped !== null) {
+ $this->backgroundService->setShippedBackground($shipped);
+ }
if ($path !== null) {
$this->backgroundService->setFileBackground($path);
}
if ($url !== null) {
$this->backgroundService->setUrlBackground($url);
}
+ $this->backgroundService->setDefaultBackground();
return new JSONResponse([]);
}
@@ -140,9 +147,13 @@ class DashboardController extends Controller {
* @NoAdminRequired
* @NoCSRFRequired
*/
- public function getBackground(): FileDisplayResponse {
+ public function getBackground() {
$file = $this->backgroundService->getBackground();
- $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
- return $response;
+ if ($file !== null) {
+ $response = new FileDisplayResponse($file, Http::STATUS_OK, ['Content-Type' => $file->getMimeType()]);
+ $response->cacheFor(24 * 60 * 60);
+ return $response;
+ }
+ return new NotFoundResponse();
}
}
diff --git a/apps/dashboard/lib/Service/BackgroundService.php b/apps/dashboard/lib/Service/BackgroundService.php
index 2046513851f..06e0a451b88 100644
--- a/apps/dashboard/lib/Service/BackgroundService.php
+++ b/apps/dashboard/lib/Service/BackgroundService.php
@@ -32,6 +32,7 @@ use OCP\Files\IAppData;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFile;
+use OCP\IConfig;
class BackgroundService {
@@ -64,7 +65,7 @@ class BackgroundService {
'yana-sichikova-sergey-ovachev-stone-flower-2k.jpg',
];
- public function __construct(IRootFolder $rootFolder, IAppData $appData, $userId) {
+ public function __construct(IRootFolder $rootFolder, IAppData $appData, IConfig $config, $userId) {
if ($userId === null) {
return;
}
@@ -74,14 +75,26 @@ class BackgroundService {
} catch (NotFoundException $e) {
$this->dashboardUserFolder = $appData->newFolder($userId);
}
+ $this->config = $config;
+ $this->userId = $userId;
+ }
+
+ public function setDefaultBackground() {
+ $this->config->deleteUserValue($this->userId, 'dashboard', 'background');
}
public function setFileBackground($path) {
+ $this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom');
$file = $this->userFolder->get($path);
$newFile = $this->dashboardUserFolder->newFile('background.jpg', $file->fopen('r'));
}
+ public function setShippedBackground($fileName) {
+ $this->config->setUserValue($this->userId, 'dashboard', 'background', $fileName);
+ }
+
public function setUrlBackground($url) {
+ $this->config->setUserValue($this->userId, 'dashboard', 'background', 'custom');
if (substr($url, 0, 1) === '/') {
$url = \OC::$server->getURLGenerator()->getAbsoluteURL($url);
}
@@ -92,11 +105,15 @@ class BackgroundService {
$newFile = $this->dashboardUserFolder->newFile('background.jpg', $content);
}
- /**
- * @throws NotFoundException
- */
- public function getBackground(): ISimpleFile {
- return $this->dashboardUserFolder->getFile('background.jpg');
+ public function getBackground() {
+ $background = $this->config->getUserValue($this->userId, 'dashboard', 'background', 'default');
+ if ($background === 'custom') {
+ try {
+ return $this->dashboardUserFolder->getFile('background.jpg');
+ } catch (NotFoundException $e) {
+ }
+ }
+ return null;
}
}