Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] perf(dashboard): implement widget item api v2 #1299

Merged
merged 1 commit into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions js/activity-10.js

Large diffs are not rendered by default.

79 changes: 79 additions & 0 deletions js/activity-10.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* Vue.js v2.7.14
* (c) 2014-2022 Evan You
* Released under the MIT License.
*/

/*!
* escape-html
* Copyright(c) 2012-2013 TJ Holowaychuk
* Copyright(c) 2015 Andreas Lubbe
* Copyright(c) 2015 Tiancheng "Timothy" Gu
* MIT Licensed
*/

/*!
* focus-trap 7.2.0
* @license MIT, https://github.com/focus-trap/focus-trap/blob/master/LICENSE
*/

/*!
* tabbable 6.0.1
* @license MIT, https://github.com/focus-trap/tabbable/blob/master/LICENSE
*/

/*! @license DOMPurify 2.4.5 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/2.4.5/LICENSE */

/*! For license information please see NcAvatar.js.LICENSE.txt */

/*! For license information please see NcUserBubble.js.LICENSE.txt */

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* @copyright Copyright (c) 2021 Louis Chemineau <louis@chmn.me>
*
* @author Louis Chemineau <louis@chmn.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

//! authors : Tim Wood, Iskren Chernev, Moment.js contributors

//! license : MIT

//! moment.js

//! moment.js locale configuration

//! momentjs.com

//! version : 2.29.4
1 change: 1 addition & 0 deletions js/activity-10.js.map

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

63 changes: 63 additions & 0 deletions js/activity-568.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*!
* Determine if an object is a Buffer
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <https://feross.org>
* @license MIT
*/

/*!
* Vue.js v2.7.14
* (c) 2014-2022 Evan You
* Released under the MIT License.
*/

/*!
* escape-html
* Copyright(c) 2012-2013 TJ Holowaychuk
* Copyright(c) 2015 Andreas Lubbe
* Copyright(c) 2015 Tiancheng "Timothy" Gu
* MIT Licensed
*/

/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */

/**
* @copyright Copyright (c) 2021 Louis Chemineau <louis@chmn.me>
*
* @author Louis Chemineau <louis@chmn.me>
*
* @license AGPL-3.0-or-later
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

//! authors : Tim Wood, Iskren Chernev, Moment.js contributors

//! license : MIT

//! moment.js

//! moment.js locale configuration

//! momentjs.com

//! version : 2.29.4
1 change: 1 addition & 0 deletions js/activity-568.js.map

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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

Large diffs are not rendered by default.

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 <jakob.roehrl@web.de>
*
* @author Jakob Röhrl <jakob.roehrl@web.de>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @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;
}
}
Loading