Skip to content

Commit

Permalink
fix widget api buttons
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 44127d4 commit 6449082
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions lib/Dashboard/DeckWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
use OCP\Util;

class DeckWidget implements IAPIWidget, IButtonWidget, IIconWidget {

private IL10N $l10n;
private OverviewService $dashboardService;
private IURLGenerator $urlGenerator;
Expand Down Expand Up @@ -117,14 +116,14 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
$upcomingCards = $this->dashboardService->findUpcomingCards($userId);
$nowTimestamp = (new Datetime())->getTimestamp();
$sinceTimestamp = $since !== null ? (new Datetime($since))->getTimestamp() : null;
$upcomingCards = array_filter($upcomingCards, static function(array $card) use ($nowTimestamp, $sinceTimestamp) {
$upcomingCards = array_filter($upcomingCards, static function (array $card) use ($nowTimestamp, $sinceTimestamp) {
if ($card['duedate']) {
$ts = (new Datetime($card['duedate']))->getTimestamp();
return $ts > $nowTimestamp && ($sinceTimestamp === null || $ts > $sinceTimestamp);
}
return false;
});
usort($upcomingCards, static function($a, $b) {
usort($upcomingCards, static function ($a, $b) {
$a = new Datetime($a['duedate']);
$ta = $a->getTimestamp();
$b = new Datetime($b['duedate']);
Expand All @@ -134,13 +133,13 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
$upcomingCards = array_slice($upcomingCards, 0, $limit);
$urlGenerator = $this->urlGenerator;
$dateTimeFormatter = $this->dateTimeFormatter;
return array_map(static function(array $card) use ($urlGenerator, $dateTimeFormatter) {
return array_map(static function (array $card) use ($urlGenerator, $dateTimeFormatter) {
$formattedDueDate = $dateTimeFormatter->formatDateTime(new DateTime($card['duedate']));
return new WidgetItem(
$card['title'] . ' (' . $formattedDueDate . ')',
implode(
', ',
array_map(static function(Label $label) {
array_map(static function (Label $label) {
return $label->jsonSerialize()['title'];
}, $card['labels'])
),
Expand All @@ -160,19 +159,12 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
*/
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')
$this->l10n->t('Load more')
),
];
}
Expand Down

0 comments on commit 6449082

Please sign in to comment.