From fbac64f0661eab9c2c0b24c83c4c74ecb39397ea Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 20 Jun 2022 10:49:50 +0200 Subject: [PATCH] Add dashboard widget: On this day Signed-off-by: Marcel Klehr --- lib/AppInfo/Application.php | 2 + lib/Dashboard/OnThisDay.php | 80 +++++++++++++++++++ .../Dashboard/DashboardOnThisDay.vue | 68 ++++++++++++++++ src/dashboard.js | 53 ++++++++++++ webpack.js | 2 + 5 files changed, 205 insertions(+) create mode 100644 lib/Dashboard/OnThisDay.php create mode 100644 src/components/Dashboard/DashboardOnThisDay.vue create mode 100644 src/dashboard.js diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index 029fcc80c..703fe1bf7 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -25,6 +25,7 @@ namespace OCA\Photos\AppInfo; +use OCA\Photos\Dashboard\OnThisDay; use OCA\DAV\Connector\Sabre\Principal; use OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; @@ -61,6 +62,7 @@ public function __construct() { } public function register(IRegistrationContext $context): void { + $context->registerDashboardWidget(OnThisDay::class); /** Register $principalBackend for the DAV collection */ $context->registerServiceAlias('principalBackend', Principal::class); $context->registerEventListener(NodeDeletedEvent::class, MoveToTrashListener::class); diff --git a/lib/Dashboard/OnThisDay.php b/lib/Dashboard/OnThisDay.php new file mode 100644 index 000000000..b3ed0105c --- /dev/null +++ b/lib/Dashboard/OnThisDay.php @@ -0,0 +1,80 @@ +l = $l; + $this->url = $url; + $this->initialState = $initialState; + } + + /** + * @inheritDoc + */ + public function getId(): string + { + return 'photos.onthisday'; + } + + /** + * @inheritDoc + */ + public function getTitle(): string + { + return $this->l->t('On This Day'); + } + + /** + * @inheritDoc + */ + public function getOrder(): int + { + return 20; + } + + /** + * @inheritDoc + */ + public function getIconClass(): string + { + return 'icon-calendar-dark'; + } + + /** + * @inheritDoc + */ + public function getUrl(): ?string + { + return $this->url->linkToRoute('photos.page.indexthisday'); + } + + /** + * @inheritDoc + */ + public function load(): void + { + Util::addScript('photos', 'photos-dashboard'); + $this->initialState->provideInitialState('photos', 'image-mimes', Application::IMAGE_MIMES); + $this->initialState->provideInitialState('photos', 'video-mimes', Application::VIDEO_MIMES); + } +} diff --git a/src/components/Dashboard/DashboardOnThisDay.vue b/src/components/Dashboard/DashboardOnThisDay.vue new file mode 100644 index 000000000..576afae8b --- /dev/null +++ b/src/components/Dashboard/DashboardOnThisDay.vue @@ -0,0 +1,68 @@ + + + + + + diff --git a/src/dashboard.js b/src/dashboard.js new file mode 100644 index 000000000..b72a135b8 --- /dev/null +++ b/src/dashboard.js @@ -0,0 +1,53 @@ +/** + * @copyright Copyright (c) 2019 John Molakvoæ + * + * @author John Molakvoæ + * + * @license AGPL-3.0-or-later + * + * 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 . + * + */ + +import { generateFilePath } from '@nextcloud/router' +import { getRequestToken } from '@nextcloud/auth' +import { translate, translatePlural } from '@nextcloud/l10n' +import Vue from 'vue' + +import store from './store' +import DashboardOnThisDay from './components/Dashboard/DashboardOnThisDay.vue' + +// CSP config for webpack dynamic chunk loading +// eslint-disable-next-line +__webpack_nonce__ = btoa(getRequestToken()) + +// Correct the root of the app for chunk loading +// OC.linkTo matches the apps folders +// OC.generateUrl ensure the index.php (or not) +// We do not want the index.php since we're loading files +// eslint-disable-next-line +__webpack_public_path__ = generateFilePath('photos', '', 'js/') + +Vue.prototype.t = translate +Vue.prototype.n = translatePlural + +window.addEventListener('DOMContentLoaded', () => { + OCA.Dashboard.register('photos.onthisday', (el) => { + global.PhotosOnThisDay = new Vue({ + el, + store, + render: h => h(DashboardOnThisDay), + }) + }) +}) diff --git a/webpack.js b/webpack.js index b955f1230..c786a5cdc 100644 --- a/webpack.js +++ b/webpack.js @@ -80,4 +80,6 @@ webpackConfig.plugins.push( }) ) +webpackConfig.entry.dashboard = path.resolve(path.join('src', 'dashboard.js')) + module.exports = webpackConfig