Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
implement IButtonWidget and IIconWidget
Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
Julien Veyssier committed Sep 16, 2022
commit 0c95e7ca1efd527689010a64fedc2ae740e22ac2
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')
),
];
}
}