Skip to content

Commit

Permalink
Implement dashboard panel
Browse files Browse the repository at this point in the history
Signed-off-by: Julius Härtl <[email protected]>
  • Loading branch information
juliusknorr authored and ChristophWurst committed Aug 10, 2020
1 parent 1530f48 commit e7ab9f2
Show file tree
Hide file tree
Showing 9 changed files with 440 additions and 0 deletions.
1 change: 1 addition & 0 deletions img/newsletter.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use OCA\Mail\Http\Middleware\ErrorMiddleware;
use OCA\Mail\Http\Middleware\ProvisioningMiddleware;
use OCA\Mail\Listener\AddressCollectionListener;
use OCA\Mail\Listener\DashboardPanelListener;
use OCA\Mail\Listener\DeleteDraftListener;
use OCA\Mail\Listener\DraftMailboxCreatorListener;
use OCA\Mail\Listener\FlagRepliedMessageListener;
Expand All @@ -59,6 +60,7 @@
use OCA\Mail\Service\UserPreferenceSevice;
use OCP\AppFramework\App;
use OCP\AppFramework\IAppContainer;
use OCP\Dashboard\RegisterWidgetEvent;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\User\Events\UserDeletedEvent;
use OCP\Util;
Expand Down Expand Up @@ -115,5 +117,6 @@ private function registerEvents(IAppContainer $container): void {
$dispatcher->addServiceListener(SaveDraftEvent::class, DraftMailboxCreatorListener::class);
$dispatcher->addServiceListener(SynchronizationEvent::class, AccountSynchronizedThreadUpdaterListener::class);
$dispatcher->addServiceListener(UserDeletedEvent::class, UserDeletedListener::class);
$dispatcher->addServiceListener(RegisterWidgetEvent::class, DashboardPanelListener::class);
}
}
112 changes: 112 additions & 0 deletions lib/Dashboard/MailWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @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\Mail\Dashboard;

use OCA\Mail\AppInfo\Application;
use OCA\Mail\Service\AccountService;
use OCP\AppFramework\Services\IInitialState;
use OCP\Dashboard\IWidget;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Util;

class MailWidget implements IWidget {

/** @var IL10N */
private $l10n;

/** @var IURLGenerator */
private $urlGenerator;

/** @var AccountService */
private $accountService;

/** @var IInitialState */
private $initialState;

/** @var string|null */
private $userId;

public function __construct(IL10N $l10n,
IURLGenerator $urlGenerator,
AccountService $accountService,
IInitialState $initialState,
?string $userId) {
$this->l10n = $l10n;
$this->urlGenerator = $urlGenerator;
$this->accountService = $accountService;
$this->initialState = $initialState;
$this->userId = $userId;
}

/**
* @inheritDoc
*/
public function getId(): string {
return Application::APP_ID;
}

/**
* @inheritDoc
*/
public function getTitle(): string {
return $this->l10n->t('Important mail');
}

/**
* @inheritDoc
*/
public function getOrder(): int {
return 4;
}

/**
* @inheritDoc
*/
public function getIconClass(): string {
return 'icon-mail';
}

/**
* @inheritDoc
*/
public function getUrl(): ?string {
return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->linkToRoute('mail.page.index'));
}

/**
* @inheritDoc
*/
public function load(): void {
Util::addScript(Application::APP_ID, 'dashboard');

$this->initialState->provideInitialState(
'mail-accounts',
$this->accountService->findByUserId($this->userId)
);
}
}
48 changes: 48 additions & 0 deletions lib/Listener/DashboardPanelListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2020 Julius Härtl <[email protected]>
*
* @author Julius Härtl <[email protected]>
*
* @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\Mail\Listener;

use OCA\Mail\Dashboard\MailWidget;
use OCP\Dashboard\RegisterWidgetEvent;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;

class DashboardPanelListener implements IEventListener {

/**
* @inheritDoc
*/
public function handle(Event $event): void {
if (!($event instanceof RegisterWidgetEvent)) {
return;
}

$event->registerWidget(MailWidget::class);
}
}
Loading

0 comments on commit e7ab9f2

Please sign in to comment.