2020-06-08 16:39:26 +03:00
|
|
|
<?php
|
2020-07-10 15:13:29 +03:00
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-08 16:39:26 +03:00
|
|
|
/**
|
|
|
|
* @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @author Julius Härtl <jus@bitgrid.net>
|
|
|
|
*
|
|
|
|
* @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\Dashboard\Controller;
|
|
|
|
|
2020-08-05 08:51:24 +03:00
|
|
|
use OCA\Files\Event\LoadSidebar;
|
2020-06-08 16:39:26 +03:00
|
|
|
use OCA\Viewer\Event\LoadViewer;
|
|
|
|
use OCP\AppFramework\Controller;
|
2020-06-15 09:18:50 +03:00
|
|
|
use OCP\AppFramework\Http\JSONResponse;
|
2020-06-08 16:39:26 +03:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
|
|
|
use OCP\Dashboard\IManager;
|
2020-08-04 16:20:05 +03:00
|
|
|
use OCP\Dashboard\IWidget;
|
|
|
|
use OCP\Dashboard\RegisterWidgetEvent;
|
2020-06-08 16:39:26 +03:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2020-06-15 09:18:50 +03:00
|
|
|
use OCP\IConfig;
|
2020-06-08 16:39:26 +03:00
|
|
|
use OCP\IInitialStateService;
|
|
|
|
use OCP\IRequest;
|
|
|
|
|
|
|
|
class DashboardController extends Controller {
|
|
|
|
|
|
|
|
/** @var IInitialStateService */
|
|
|
|
private $inititalStateService;
|
|
|
|
/** @var IEventDispatcher */
|
|
|
|
private $eventDispatcher;
|
|
|
|
/** @var IManager */
|
|
|
|
private $dashboardManager;
|
2020-06-15 09:18:50 +03:00
|
|
|
/** @var IConfig */
|
|
|
|
private $config;
|
|
|
|
/** @var string */
|
|
|
|
private $userId;
|
2020-06-08 16:39:26 +03:00
|
|
|
|
2020-06-24 14:00:22 +03:00
|
|
|
public function __construct(
|
2020-07-10 15:13:29 +03:00
|
|
|
string $appName,
|
2020-06-24 14:00:22 +03:00
|
|
|
IRequest $request,
|
|
|
|
IInitialStateService $initialStateService,
|
|
|
|
IEventDispatcher $eventDispatcher,
|
2020-06-15 09:18:50 +03:00
|
|
|
IManager $dashboardManager,
|
|
|
|
IConfig $config,
|
|
|
|
$userId
|
2020-06-24 14:00:22 +03:00
|
|
|
) {
|
2020-06-08 16:39:26 +03:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
|
|
|
$this->inititalStateService = $initialStateService;
|
|
|
|
$this->eventDispatcher = $eventDispatcher;
|
|
|
|
$this->dashboardManager = $dashboardManager;
|
2020-06-15 09:18:50 +03:00
|
|
|
$this->config = $config;
|
|
|
|
$this->userId = $userId;
|
2020-06-08 16:39:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoCSRFRequired
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @return TemplateResponse
|
|
|
|
*/
|
|
|
|
public function index(): TemplateResponse {
|
2020-08-05 08:51:24 +03:00
|
|
|
$this->eventDispatcher->dispatchTyped(new LoadSidebar());
|
|
|
|
if (class_exists(LoadViewer::class)) {
|
|
|
|
$this->eventDispatcher->dispatchTyped(new LoadViewer());
|
|
|
|
}
|
|
|
|
|
2020-08-04 16:20:05 +03:00
|
|
|
$this->eventDispatcher->dispatchTyped(new RegisterWidgetEvent($this->dashboardManager));
|
2020-06-08 16:39:26 +03:00
|
|
|
|
2020-08-04 16:05:16 +03:00
|
|
|
$userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', 'recommendations,spreed,mail,calendar'));
|
2020-08-04 16:20:05 +03:00
|
|
|
$widgets = array_map(function (IWidget $widget) {
|
2020-06-23 16:38:07 +03:00
|
|
|
return [
|
2020-08-04 16:20:05 +03:00
|
|
|
'id' => $widget->getId(),
|
|
|
|
'title' => $widget->getTitle(),
|
|
|
|
'iconClass' => $widget->getIconClass(),
|
|
|
|
'url' => $widget->getUrl()
|
2020-06-23 16:38:07 +03:00
|
|
|
];
|
2020-08-04 16:20:05 +03:00
|
|
|
}, $this->dashboardManager->getWidgets());
|
|
|
|
$this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets);
|
2020-06-15 09:18:50 +03:00
|
|
|
$this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout);
|
2020-07-31 14:27:43 +03:00
|
|
|
$this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
|
|
|
|
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
|
2020-06-08 16:39:26 +03:00
|
|
|
|
|
|
|
return new TemplateResponse('dashboard', 'index');
|
|
|
|
}
|
2020-06-15 09:18:50 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @NoAdminRequired
|
|
|
|
* @param string $layout
|
|
|
|
* @return JSONResponse
|
|
|
|
*/
|
|
|
|
public function updateLayout(string $layout): JSONResponse {
|
|
|
|
$this->config->setUserValue($this->userId, 'dashboard', 'layout', $layout);
|
|
|
|
return new JSONResponse(['layout' => $layout]);
|
|
|
|
}
|
2020-06-08 16:39:26 +03:00
|
|
|
}
|