implement IButtonWidget and IIconWidget
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
This commit is contained in:
@@ -31,16 +31,18 @@ use OCA\Deck\AppInfo\Application;
|
|||||||
use OCA\Deck\Db\Label;
|
use OCA\Deck\Db\Label;
|
||||||
use OCA\Deck\Service\OverviewService;
|
use OCA\Deck\Service\OverviewService;
|
||||||
use OCP\Dashboard\IAPIWidget;
|
use OCP\Dashboard\IAPIWidget;
|
||||||
|
use OCP\Dashboard\IButtonWidget;
|
||||||
|
use OCP\Dashboard\IIconWidget;
|
||||||
|
use OCP\Dashboard\Model\WidgetButton;
|
||||||
use OCP\Dashboard\Model\WidgetItem;
|
use OCP\Dashboard\Model\WidgetItem;
|
||||||
use OCP\IDateTimeFormatter;
|
use OCP\IDateTimeFormatter;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IURLGenerator;
|
use OCP\IURLGenerator;
|
||||||
use OCP\Util;
|
use OCP\Util;
|
||||||
|
|
||||||
class DeckWidget implements IAPIWidget {
|
class DeckWidget implements IAPIWidget, IButtonWidget, IIconWidget {
|
||||||
|
|
||||||
private IL10N $l10n;
|
private IL10N $l10n;
|
||||||
private ?string $userId;
|
|
||||||
private OverviewService $dashboardService;
|
private OverviewService $dashboardService;
|
||||||
private IURLGenerator $urlGenerator;
|
private IURLGenerator $urlGenerator;
|
||||||
private IDateTimeFormatter $dateTimeFormatter;
|
private IDateTimeFormatter $dateTimeFormatter;
|
||||||
@@ -48,10 +50,8 @@ class DeckWidget implements IAPIWidget {
|
|||||||
public function __construct(IL10N $l10n,
|
public function __construct(IL10N $l10n,
|
||||||
OverviewService $dashboardService,
|
OverviewService $dashboardService,
|
||||||
IDateTimeFormatter $dateTimeFormatter,
|
IDateTimeFormatter $dateTimeFormatter,
|
||||||
IURLGenerator $urlGenerator,
|
IURLGenerator $urlGenerator) {
|
||||||
?string $userId) {
|
|
||||||
$this->l10n = $l10n;
|
$this->l10n = $l10n;
|
||||||
$this->userId = $userId;
|
|
||||||
$this->dashboardService = $dashboardService;
|
$this->dashboardService = $dashboardService;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
$this->dateTimeFormatter = $dateTimeFormatter;
|
$this->dateTimeFormatter = $dateTimeFormatter;
|
||||||
@@ -85,11 +85,22 @@ class DeckWidget implements IAPIWidget {
|
|||||||
return 'icon-deck';
|
return 'icon-deck';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @inheritDoc
|
||||||
|
*/
|
||||||
|
public function getIconUrl(): string {
|
||||||
|
return $this->urlGenerator->getAbsoluteURL(
|
||||||
|
$this->urlGenerator->imagePath(Application::APP_ID, 'deck-dark.svg')
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function getUrl(): ?string {
|
public function getUrl(): ?string {
|
||||||
return null;
|
return $this->urlGenerator->getAbsoluteURL(
|
||||||
|
$this->urlGenerator->linkToRoute(Application::APP_ID . '.page.index')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,7 +114,7 @@ class DeckWidget implements IAPIWidget {
|
|||||||
* @inheritDoc
|
* @inheritDoc
|
||||||
*/
|
*/
|
||||||
public function getItems(string $userId, ?string $since = null, int $limit = 7): array {
|
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();
|
$nowTimestamp = (new Datetime())->getTimestamp();
|
||||||
$upcomingCards = array_filter($upcomingCards, static function(array $card) use ($nowTimestamp) {
|
$upcomingCards = array_filter($upcomingCards, static function(array $card) use ($nowTimestamp) {
|
||||||
if ($card['duedate']) {
|
if ($card['duedate']) {
|
||||||
@@ -142,4 +153,26 @@ class DeckWidget implements IAPIWidget {
|
|||||||
);
|
);
|
||||||
}, $upcomingCards);
|
}, $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')
|
||||||
|
),
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user