From 9a7215c567327670b34eec5b565b9d62114c2fc8 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 2123a2e42..28360f0ea 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 OCP\AppFramework\App; use OCP\AppFramework\Bootstrap\IBootContext; use OCP\AppFramework\Bootstrap\IBootstrap; @@ -58,6 +59,7 @@ public function __construct() { } public function register(IRegistrationContext $context): void { + $context->registerDashboardWidget(OnThisDay::class); } public function boot(IBootContext $context): void { 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 846cfb6f8..f1821d5be 100644 --- a/webpack.js +++ b/webpack.js @@ -78,4 +78,6 @@ webpackConfig.plugins.push( }) ) +webpackConfig.entry.dashboard = path.resolve(path.join('src', 'dashboard.js')) + module.exports = webpackConfig