Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/deck.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJulien Veyssier <eneiluj@posteo.net>2022-09-06 21:51:31 +0300
committerJulien Veyssier <eneiluj@posteo.net>2022-09-16 14:35:21 +0300
commit0c95e7ca1efd527689010a64fedc2ae740e22ac2 (patch)
tree4592974ce62310a880b56ee96c53d18be410feff /lib
parente29ac75f3daba3cb431d99c106f1fd6aab3f04ab (diff)
implement IButtonWidget and IIconWidget
Signed-off-by: Julien Veyssier <eneiluj@posteo.net>
Diffstat (limited to 'lib')
-rw-r--r--lib/Dashboard/DeckWidget.php47
1 files changed, 40 insertions, 7 deletions
diff --git a/lib/Dashboard/DeckWidget.php b/lib/Dashboard/DeckWidget.php
index 9e8e1099..80c9ccca 100644
--- a/lib/Dashboard/DeckWidget.php
+++ b/lib/Dashboard/DeckWidget.php
@@ -31,16 +31,18 @@ use OCA\Deck\AppInfo\Application;
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;
@@ -48,10 +50,8 @@ class DeckWidget implements IAPIWidget {
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;
@@ -88,8 +88,19 @@ class DeckWidget implements IAPIWidget {
/**
* @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')
+ );
}
/**
@@ -103,7 +114,7 @@ class DeckWidget implements IAPIWidget {
* @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']) {
@@ -142,4 +153,26 @@ class DeckWidget implements IAPIWidget {
);
}, $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')
+ ),
+ ];
+ }
}