Skip to content

Commit

Permalink
Merge pull request #1284 from nextcloud/perf/dashboard/item-api-v2
Browse files Browse the repository at this point in the history
perf(dashboard): implement widget item api v2
  • Loading branch information
st3iny authored Sep 5, 2023
2 parents 1ad4d91 + a5eef18 commit ca8ad16
Show file tree
Hide file tree
Showing 22 changed files with 61 additions and 260 deletions.
3 changes: 0 additions & 3 deletions js/activity-499.js

This file was deleted.

6 changes: 0 additions & 6 deletions js/activity-499.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion js/activity-499.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions js/activity-51.js

This file was deleted.

1 change: 0 additions & 1 deletion js/activity-51.js.map

This file was deleted.

3 changes: 3 additions & 0 deletions js/activity-568.js

Large diffs are not rendered by default.

File renamed without changes.
1 change: 1 addition & 0 deletions js/activity-568.js.map

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions js/activity-dashboard-lazy.js

This file was deleted.

5 changes: 0 additions & 5 deletions js/activity-dashboard-lazy.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion js/activity-dashboard-lazy.js.map

This file was deleted.

3 changes: 0 additions & 3 deletions js/activity-dashboard.js

This file was deleted.

31 changes: 0 additions & 31 deletions js/activity-dashboard.js.LICENSE.txt

This file was deleted.

1 change: 0 additions & 1 deletion js/activity-dashboard.js.map

This file was deleted.

4 changes: 2 additions & 2 deletions js/activity-sidebar.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/activity-sidebar.js.map

Large diffs are not rendered by default.

57 changes: 54 additions & 3 deletions lib/Dashboard/ActivityWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -111,7 +113,6 @@ public function getUrl(): ?string {
* @inheritDoc
*/
public function load(): void {
Util::addScript('activity', 'activity-dashboard');
}

/**
Expand Down Expand Up @@ -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
*/
Expand All @@ -156,4 +200,11 @@ public function getWidgetButtons(string $userId): array {
),
];
}

/**
* @inheritDoc
*/
public function getReloadInterval(): int {
return 30;
}
}
1 change: 0 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
},
"dependencies": {
"@mdi/svg": "^7.2.96",
"@nextcloud/auth": "^2.1.0",
"@nextcloud/axios": "^2.4.0",
"@nextcloud/dialogs": "^4.1.0",
"@nextcloud/initial-state": "^2.1.0",
Expand Down
51 changes: 0 additions & 51 deletions src/dashboard.js

This file was deleted.

142 changes: 0 additions & 142 deletions src/views/Dashboard.vue

This file was deleted.

1 change: 0 additions & 1 deletion webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const webpackConfig = require('@nextcloud/webpack-vue-config')

webpackConfig.entry = {
sidebar: path.join(__dirname, 'src', 'sidebar.js'),
dashboard: path.join(__dirname, 'src', 'dashboard.js'),
personalSettings: path.join(__dirname, 'src', 'settings-personal.js'),
adminSettings: path.join(__dirname, 'src', 'settings-admin.js'),
}
Expand Down

0 comments on commit ca8ad16

Please sign in to comment.