Skip to content

Commit

Permalink
implement IButtonWidget and IIconWidget
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
  • Loading branch information
Julien Veyssier committed Sep 16, 2022
1 parent e29ac75 commit 0c95e7c
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions lib/Dashboard/DeckWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,27 +31,27 @@
use OCA\Deck\Db\Label;
use OCA\Deck\Service\OverviewService;
use OCP\Dashboard\IAPIWidget;
use OCP\Dashboard\IButtonWidget;
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\Model\WidgetButton;
use OCP\Dashboard\Model\WidgetItem;
use OCP\IDateTimeFormatter;
use OCP\IL10N;
use OCP\IURLGenerator;
use OCP\Util;

class DeckWidget implements IAPIWidget {
class DeckWidget implements IAPIWidget, IButtonWidget, IIconWidget {

private IL10N $l10n;
private ?string $userId;
private OverviewService $dashboardService;
private IURLGenerator $urlGenerator;
private IDateTimeFormatter $dateTimeFormatter;

public function __construct(IL10N $l10n,
OverviewService $dashboardService,
IDateTimeFormatter $dateTimeFormatter,
IURLGenerator $urlGenerator,
?string $userId) {
IURLGenerator $urlGenerator) {
$this->l10n = $l10n;
$this->userId = $userId;
$this->dashboardService = $dashboardService;
$this->urlGenerator = $urlGenerator;
$this->dateTimeFormatter = $dateTimeFormatter;
Expand Down Expand Up @@ -85,11 +85,22 @@ public function getIconClass(): string {
return 'icon-deck';
}

/**
* @inheritDoc
*/
public function getIconUrl(): string {
return $this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->imagePath(Application::APP_ID, 'deck-dark.svg')
);
}

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

/**
Expand All @@ -103,7 +114,7 @@ public function load(): void {
* @inheritDoc
*/
public function getItems(string $userId, ?string $since = null, int $limit = 7): array {
$upcomingCards = $this->dashboardService->findUpcomingCards($this->userId);
$upcomingCards = $this->dashboardService->findUpcomingCards($userId);
$nowTimestamp = (new Datetime())->getTimestamp();
$upcomingCards = array_filter($upcomingCards, static function(array $card) use ($nowTimestamp) {
if ($card['duedate']) {
Expand Down Expand Up @@ -142,4 +153,26 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
);
}, $upcomingCards);
}

/**
* @inheritDoc
*/
public function getWidgetButtons(string $userId): array {
return [
new WidgetButton(
WidgetButton::TYPE_NEW,
$this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkToRoute(Application::APP_ID . '.page.index')
),
$this->l10n->t('Add card')
),
new WidgetButton(
WidgetButton::TYPE_MORE,
$this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkToRoute(Application::APP_ID . '.page.index')
),
$this->l10n->t('Add card')
),
];
}
}

0 comments on commit 0c95e7c

Please sign in to comment.