2020-06-08 09:39:26 -04:00
|
|
|
<?php
|
2020-07-10 08:13:29 -04:00
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2020-06-08 09:39:26 -04:00
|
|
|
/**
|
2024-05-27 11:39:07 -04:00
|
|
|
* SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2020-06-08 09:39:26 -04:00
|
|
|
*/
|
|
|
|
|
namespace OCA\Dashboard\Controller;
|
|
|
|
|
|
2024-01-19 17:12:25 -05:00
|
|
|
use OCA\Dashboard\Service\DashboardService;
|
2020-06-08 09:39:26 -04:00
|
|
|
use OCP\AppFramework\Controller;
|
2020-08-12 04:02:33 -04:00
|
|
|
use OCP\AppFramework\Http;
|
2024-05-05 02:19:37 -04:00
|
|
|
use OCP\AppFramework\Http\Attribute\FrontpageRoute;
|
2024-07-25 07:14:45 -04:00
|
|
|
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
|
|
|
|
|
use OCP\AppFramework\Http\Attribute\NoCSRFRequired;
|
2024-01-18 04:38:37 -05:00
|
|
|
use OCP\AppFramework\Http\Attribute\OpenAPI;
|
2020-06-08 09:39:26 -04:00
|
|
|
use OCP\AppFramework\Http\TemplateResponse;
|
2021-02-10 14:00:04 -05:00
|
|
|
use OCP\AppFramework\Services\IInitialState;
|
2024-07-11 07:22:46 -04:00
|
|
|
use OCP\Dashboard\IIconWidget;
|
2020-06-08 09:39:26 -04:00
|
|
|
use OCP\Dashboard\IManager;
|
2020-08-04 09:20:05 -04:00
|
|
|
use OCP\Dashboard\IWidget;
|
2020-06-08 09:39:26 -04:00
|
|
|
use OCP\EventDispatcher\IEventDispatcher;
|
2020-06-15 02:18:50 -04:00
|
|
|
use OCP\IConfig;
|
2023-12-19 11:01:21 -05:00
|
|
|
use OCP\IL10N;
|
2020-06-08 09:39:26 -04:00
|
|
|
use OCP\IRequest;
|
|
|
|
|
|
2024-01-18 04:38:37 -05:00
|
|
|
#[OpenAPI(scope: OpenAPI::SCOPE_IGNORE)]
|
2020-06-08 09:39:26 -04:00
|
|
|
class DashboardController extends Controller {
|
|
|
|
|
|
2020-06-24 07:00:22 -04:00
|
|
|
public function __construct(
|
2020-07-10 08:13:29 -04:00
|
|
|
string $appName,
|
2020-06-24 07:00:22 -04:00
|
|
|
IRequest $request,
|
2023-07-08 13:02:43 -04:00
|
|
|
private IInitialState $initialState,
|
|
|
|
|
private IEventDispatcher $eventDispatcher,
|
|
|
|
|
private IManager $dashboardManager,
|
|
|
|
|
private IConfig $config,
|
2024-02-28 13:15:01 -05:00
|
|
|
private IL10N $l10n,
|
2024-01-19 17:12:25 -05:00
|
|
|
private ?string $userId,
|
|
|
|
|
private DashboardService $service,
|
2020-06-24 07:00:22 -04:00
|
|
|
) {
|
2020-06-08 09:39:26 -04:00
|
|
|
parent::__construct($appName, $request);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return TemplateResponse
|
|
|
|
|
*/
|
2024-07-25 07:14:45 -04:00
|
|
|
#[NoCSRFRequired]
|
|
|
|
|
#[NoAdminRequired]
|
2024-05-05 02:19:37 -04:00
|
|
|
#[FrontpageRoute(verb: 'GET', url: '/')]
|
2020-06-08 09:39:26 -04:00
|
|
|
public function index(): TemplateResponse {
|
2020-08-18 08:11:02 -04:00
|
|
|
\OCP\Util::addStyle('dashboard', 'dashboard');
|
2022-02-17 05:57:34 -05:00
|
|
|
\OCP\Util::addScript('dashboard', 'main', 'theming');
|
2021-12-03 09:12:18 -05:00
|
|
|
|
2020-08-04 09:20:05 -04:00
|
|
|
$widgets = array_map(function (IWidget $widget) {
|
2020-06-23 09:38:07 -04:00
|
|
|
return [
|
2020-08-04 09:20:05 -04:00
|
|
|
'id' => $widget->getId(),
|
|
|
|
|
'title' => $widget->getTitle(),
|
|
|
|
|
'iconClass' => $widget->getIconClass(),
|
2024-07-11 07:22:46 -04:00
|
|
|
'iconUrl' => $widget instanceof IIconWidget ? $widget->getIconUrl() : '',
|
2020-08-04 09:20:05 -04:00
|
|
|
'url' => $widget->getUrl()
|
2020-06-23 09:38:07 -04:00
|
|
|
];
|
2020-08-04 09:20:05 -04:00
|
|
|
}, $this->dashboardManager->getWidgets());
|
2020-08-31 11:44:30 -04:00
|
|
|
|
2022-09-15 15:02:23 -04:00
|
|
|
$this->initialState->provideInitialState('panels', $widgets);
|
2024-01-19 17:12:25 -05:00
|
|
|
$this->initialState->provideInitialState('statuses', $this->service->getStatuses());
|
|
|
|
|
$this->initialState->provideInitialState('layout', $this->service->getLayout());
|
2024-03-27 10:39:15 -04:00
|
|
|
$this->initialState->provideInitialState('appStoreEnabled', $this->config->getSystemValueBool('appstoreenabled', true));
|
2022-09-15 15:02:23 -04:00
|
|
|
$this->initialState->provideInitialState('firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
|
2020-07-31 07:27:43 -04:00
|
|
|
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
|
2020-06-08 09:39:26 -04:00
|
|
|
|
2022-07-16 03:58:33 -04:00
|
|
|
$response = new TemplateResponse('dashboard', 'index', [
|
|
|
|
|
'id-app-content' => '#app-dashboard',
|
|
|
|
|
'id-app-navigation' => null,
|
2023-12-19 11:01:21 -05:00
|
|
|
'pageTitle' => $this->l10n->t('Dashboard'),
|
2022-07-16 03:58:33 -04:00
|
|
|
]);
|
2020-08-20 03:00:03 -04:00
|
|
|
|
|
|
|
|
// For the weather widget we should allow the geolocation
|
|
|
|
|
$featurePolicy = new Http\FeaturePolicy();
|
|
|
|
|
$featurePolicy->addAllowedGeoLocationDomain('\'self\'');
|
|
|
|
|
$response->setFeaturePolicy($featurePolicy);
|
|
|
|
|
|
|
|
|
|
return $response;
|
2020-06-08 09:39:26 -04:00
|
|
|
}
|
|
|
|
|
}
|