Skip to content

Commit

Permalink
implement IButtonWidget and IIconWidget in user_status
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 7, 2022
1 parent 90bff96 commit 19b5052
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions apps/user_status/lib/Dashboard/UserStatusWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
use OCA\UserStatus\Service\StatusService;
use OCP\AppFramework\Services\IInitialState;
use OCP\Dashboard\IAPIWidget;
use OCP\Dashboard\IButtonWidget;
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\Model\WidgetItem;
use OCP\IDateTimeFormatter;
use OCP\IL10N;
Expand All @@ -44,7 +46,7 @@
*
* @package OCA\UserStatus
*/
class UserStatusWidget implements IAPIWidget {
class UserStatusWidget implements IAPIWidget, IButtonWidget, IIconWidget {
private IL10N $l10n;
private IDateTimeFormatter $dateTimeFormatter;
private IURLGenerator $urlGenerator;
Expand Down Expand Up @@ -108,6 +110,15 @@ public function getIconClass(): string {
return 'icon-user-status';
}

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

/**
* @inheritDoc
*/
Expand All @@ -123,7 +134,7 @@ public function load(): void {

$currentUser = $this->userSession->getUser();
if ($currentUser === null) {
$this->initialStateService->provideInitialState(Application::APP_ID, 'dashboard_data', []);
$this->initialStateService->provideInitialState('dashboard_data', []);
return;
}
$currentUserId = $currentUser->getUID();
Expand Down Expand Up @@ -175,7 +186,7 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
$formattedDate = $this->dateTimeFormatter->formatTimeSpan($widgetData['timestamp']);
return new WidgetItem(
$widgetData['displayName'],
$widgetData['icon'] . ' ' . $widgetData['message'] . ', ' . $formattedDate,
$widgetData['icon'] . ($widgetData['icon'] ? ' ' : '') . $widgetData['message'] . ', ' . $formattedDate,
// https://nextcloud.local/index.php/u/julien
$this->urlGenerator->getAbsoluteURL(
$this->urlGenerator->linkToRoute('core.ProfilePage.index', ['targetUserId' => $widgetData['userId']])
Expand All @@ -187,4 +198,11 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7):
);
}, $widgetItemsData);
}

/**
* @inheritDoc
*/
public function getWidgetButtons(string $userId): array {
return [];
}
}

0 comments on commit 19b5052

Please sign in to comment.