From a77aed871a75f625bc2830206ca88176f163c791 Mon Sep 17 00:00:00 2001 From: Richard Steinmetz Date: Tue, 24 Nov 2020 16:06:19 +0100 Subject: [PATCH] Add unread mail dashboard widget Signed-off-by: Richard Steinmetz --- lib/AppInfo/Application.php | 6 ++-- lib/Dashboard/ImportantMailWidget.php | 44 +++++++++++++++++++++++++ lib/Dashboard/MailWidget.php | 19 ++--------- lib/Dashboard/UnreadMailWidget.php | 44 +++++++++++++++++++++++++ lib/Listener/DashboardPanelListener.php | 7 ++-- src/{views => components}/Dashboard.vue | 8 ++++- src/main-dashboard.js | 11 +++++-- src/views/DashboardImportant.vue | 36 ++++++++++++++++++++ src/views/DashboardUnread.vue | 36 ++++++++++++++++++++ 9 files changed, 188 insertions(+), 23 deletions(-) create mode 100644 lib/Dashboard/ImportantMailWidget.php create mode 100644 lib/Dashboard/UnreadMailWidget.php rename src/{views => components}/Dashboard.vue (96%) create mode 100644 src/views/DashboardImportant.vue create mode 100644 src/views/DashboardUnread.vue diff --git a/lib/AppInfo/Application.php b/lib/AppInfo/Application.php index bf6edfdb7c..d81684cb6f 100644 --- a/lib/AppInfo/Application.php +++ b/lib/AppInfo/Application.php @@ -32,7 +32,8 @@ use OCA\Mail\Contracts\IMailSearch; use OCA\Mail\Contracts\IMailTransmission; use OCA\Mail\Contracts\IUserPreferences; -use OCA\Mail\Dashboard\MailWidget; +use OCA\Mail\Dashboard\ImportantMailWidget; +use OCA\Mail\Dashboard\UnreadMailWidget; use OCA\Mail\Events\DraftSavedEvent; use OCA\Mail\Events\MailboxesSynchronizedEvent; use OCA\Mail\Events\SynchronizationEvent; @@ -113,7 +114,8 @@ public function register(IRegistrationContext $context): void { $context->registerMiddleWare(ErrorMiddleware::class); $context->registerMiddleWare(ProvisioningMiddleware::class); - $context->registerDashboardWidget(MailWidget::class); + $context->registerDashboardWidget(ImportantMailWidget::class); + $context->registerDashboardWidget(UnreadMailWidget::class); $context->registerSearchProvider(Provider::class); // bypass Horde Translation system diff --git a/lib/Dashboard/ImportantMailWidget.php b/lib/Dashboard/ImportantMailWidget.php new file mode 100644 index 0000000000..faef4209c0 --- /dev/null +++ b/lib/Dashboard/ImportantMailWidget.php @@ -0,0 +1,44 @@ + + * + * @author Richard Steinmetz + * + * @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 . + * + */ + +namespace OCA\Mail\Dashboard; + +class ImportantMailWidget extends MailWidget { + + /** + * @inheritDoc + */ + public function getId(): string { + return 'mail'; + } + + /** + * @inheritDoc + */ + public function getTitle(): string { + return $this->l10n->t('Important mail'); + } +} diff --git a/lib/Dashboard/MailWidget.php b/lib/Dashboard/MailWidget.php index 1c2fc833af..194bc4ae71 100644 --- a/lib/Dashboard/MailWidget.php +++ b/lib/Dashboard/MailWidget.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2020 Julius Härtl * * @author Julius Härtl + * @author Richard Steinmetz * * @license GNU AGPL version 3 or any later version * @@ -34,10 +35,10 @@ use OCP\IURLGenerator; use OCP\Util; -class MailWidget implements IWidget { +abstract class MailWidget implements IWidget { /** @var IL10N */ - private $l10n; + protected $l10n; /** @var IURLGenerator */ private $urlGenerator; @@ -63,20 +64,6 @@ public function __construct(IL10N $l10n, $this->userId = $userId; } - /** - * @inheritDoc - */ - public function getId(): string { - return Application::APP_ID; - } - - /** - * @inheritDoc - */ - public function getTitle(): string { - return $this->l10n->t('Important mail'); - } - /** * @inheritDoc */ diff --git a/lib/Dashboard/UnreadMailWidget.php b/lib/Dashboard/UnreadMailWidget.php new file mode 100644 index 0000000000..a58054388c --- /dev/null +++ b/lib/Dashboard/UnreadMailWidget.php @@ -0,0 +1,44 @@ + + * + * @author Richard Steinmetz + * + * @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 . + * + */ + +namespace OCA\Mail\Dashboard; + +class UnreadMailWidget extends MailWidget { + + /** + * @inheritDoc + */ + public function getId(): string { + return 'mail-unread'; + } + + /** + * @inheritDoc + */ + public function getTitle(): string { + return $this->l10n->t('Unread mail'); + } +} diff --git a/lib/Listener/DashboardPanelListener.php b/lib/Listener/DashboardPanelListener.php index e5917829b9..dc7ec1d23d 100644 --- a/lib/Listener/DashboardPanelListener.php +++ b/lib/Listener/DashboardPanelListener.php @@ -6,6 +6,7 @@ * @copyright Copyright (c) 2020 Julius Härtl * * @author Julius Härtl + * @author Richard Steinmetz * * @license GNU AGPL version 3 or any later version * @@ -28,7 +29,8 @@ namespace OCA\Mail\Listener; -use OCA\Mail\Dashboard\MailWidget; +use OCA\Mail\Dashboard\ImportantMailWidget; +use OCA\Mail\Dashboard\UnreadMailWidget; use OCP\Dashboard\RegisterWidgetEvent; use OCP\EventDispatcher\Event; use OCP\EventDispatcher\IEventListener; @@ -43,6 +45,7 @@ public function handle(Event $event): void { return; } - $event->registerWidget(MailWidget::class); + $event->registerWidget(ImportantMailWidget::class); + $event->registerWidget(UnreadMailWidget::class); } } diff --git a/src/views/Dashboard.vue b/src/components/Dashboard.vue similarity index 96% rename from src/views/Dashboard.vue rename to src/components/Dashboard.vue index 04f4fd898a..79db82b532 100644 --- a/src/views/Dashboard.vue +++ b/src/components/Dashboard.vue @@ -74,6 +74,12 @@ export default { DashboardWidgetItem, EmptyContent, }, + props: { + query: { + type: String, + required: true, + }, + }, data() { return { messages: [], @@ -113,7 +119,7 @@ export default { }) await Promise.all(inboxes.map(async(mailbox) => { - const messages = await fetchEnvelopes(mailbox.databaseId, 'is:important', undefined, 10) + const messages = await fetchEnvelopes(mailbox.databaseId, this.query, undefined, 10) this.messages = this.messages !== null ? [...this.messages, ...messages] : messages this.fetchedAccounts++ })) diff --git a/src/main-dashboard.js b/src/main-dashboard.js index 9eb22157ba..8a5461ba1d 100644 --- a/src/main-dashboard.js +++ b/src/main-dashboard.js @@ -2,6 +2,7 @@ * @copyright Copyright (c) 2020 Julius Härtl * * @author Julius Härtl + * @author Richard Steinmetz * * @license GNU AGPL version 3 or any later version * @@ -25,7 +26,8 @@ import { getRequestToken } from '@nextcloud/auth' import { generateFilePath } from '@nextcloud/router' import Nextcloud from './mixins/Nextcloud' -import Dashboard from './views/Dashboard' +import DashboardImportant from './views/DashboardImportant' +import DashboardUnread from './views/DashboardUnread' // eslint-disable-next-line camelcase __webpack_nonce__ = btoa(getRequestToken()) @@ -38,7 +40,12 @@ document.addEventListener('DOMContentLoaded', function() { const register = OCA?.Dashboard?.register || (() => {}) register('mail', (el) => { - const View = Vue.extend(Dashboard) + const View = Vue.extend(DashboardImportant) + new View().$mount(el) + }) + + register('mail-unread', (el) => { + const View = Vue.extend(DashboardUnread) new View().$mount(el) }) }) diff --git a/src/views/DashboardImportant.vue b/src/views/DashboardImportant.vue new file mode 100644 index 0000000000..2cbbe7a20d --- /dev/null +++ b/src/views/DashboardImportant.vue @@ -0,0 +1,36 @@ + + + + + diff --git a/src/views/DashboardUnread.vue b/src/views/DashboardUnread.vue new file mode 100644 index 0000000000..b874a3a1c0 --- /dev/null +++ b/src/views/DashboardUnread.vue @@ -0,0 +1,36 @@ + + + + +