-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
perf(dashboard): implement widget item api v2
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
* @copyright Copyright (c) 2021 Jakob Röhrl <[email protected]> | ||
* | ||
* @author Jakob Röhrl <[email protected]> | ||
* @author Richard Steinmetz <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
|
@@ -32,14 +33,15 @@ | |
use OCP\Dashboard\IAPIWidget; | ||
use OCP\Dashboard\IButtonWidget; | ||
use OCP\Dashboard\IIconWidget; | ||
use OCP\Dashboard\IReloadableWidget; | ||
use OCP\Dashboard\Model\WidgetButton; | ||
use OCP\Dashboard\Model\WidgetItem; | ||
use OCP\Dashboard\Model\WidgetItems; | ||
use OCP\IDateTimeFormatter; | ||
use OCP\IL10N; | ||
use OCP\IURLGenerator; | ||
use OCP\Util; | ||
|
||
class ActivityWidget implements IAPIWidget, IButtonWidget, IIconWidget { | ||
class ActivityWidget implements IAPIWidget, IButtonWidget, IIconWidget, IReloadableWidget { | ||
private Data $data; | ||
private IL10N $l10n; | ||
private GroupHelper $helper; | ||
|
@@ -111,7 +113,6 @@ public function getUrl(): ?string { | |
* @inheritDoc | ||
*/ | ||
public function load(): void { | ||
Util::addScript('activity', 'activity-dashboard'); | ||
} | ||
|
||
/** | ||
|
@@ -142,6 +143,49 @@ public function getItems(string $userId, ?string $since = null, int $limit = 7): | |
}, array_slice($activities['data'], 0, $limit)); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getItemsV2(string $userId, ?string $since = null, int $limit = 7): WidgetItems { | ||
// we set the limit to 50 here because data->get might return less activity entries | ||
// in the end we take the first 7 of'em | ||
$activities = $this->data->get( | ||
$this->helper, | ||
$this->settings, | ||
$userId, | ||
$since ? (int) $since : 0, | ||
50, | ||
'desc', | ||
'by', | ||
'', | ||
0 | ||
); | ||
$items = array_map(function (array $activity) { | ||
$userAvatarUrl = ''; | ||
if ($activity['user'] !== '') { | ||
$userAvatarUrl = $this->urlGenerator->getAbsoluteURL( | ||
$this->urlGenerator->linkToRoute('core.avatar.getAvatar', [ | ||
'userId' => $activity['user'], | ||
'size' => 512, | ||
]) | ||
); | ||
} | ||
|
||
return new WidgetItem( | ||
$activity['subject'], | ||
$this->dateTimeFormatter->formatTimeSpan($activity['timestamp']), | ||
$activity['link'], | ||
$userAvatarUrl, | ||
(string) $activity['activity_id'], | ||
$activity['icon'], | ||
); | ||
}, array_slice($activities['data'], 0, $limit)); | ||
return new WidgetItems( | ||
$items, | ||
empty($items) ? $this->l10n->t('No activities') : '', | ||
); | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
|
@@ -156,4 +200,11 @@ public function getWidgetButtons(string $userId): array { | |
), | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function getReloadInterval(): int { | ||
return 30; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
This file was deleted.
This file was deleted.