allow filtering dashboard items api by widgets

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/33658/head
Robin Appelman 3 years ago committed by Julien Veyssier
parent 0e5944748d
commit 7f52a99ffb
No known key found for this signature in database
GPG Key ID: 4141FEE162030638
  1. 12
      apps/dashboard/lib/Controller/DashboardApiController.php

@ -64,19 +64,23 @@ class DashboardApiController extends OCSController {
*
* @param array $sinceIds Array indexed by widget Ids, contains date/id from which we want the new items
* @param int $limit Limit number of result items per widget
* @param string[] $widgets Limit results to specific widgets
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function getWidgetItems(array $sinceIds = [], int $limit = 7): DataResponse {
public function getWidgetItems(array $sinceIds = [], int $limit = 7, array $widgets = []): DataResponse {
$showWidgets = $widgets;
$items = [];
$systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar');
$userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault));
if ($showWidgets === []) {
$systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar');
$showWidgets = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault));
}
$widgets = $this->dashboardManager->getWidgets();
foreach ($widgets as $widget) {
if ($widget instanceof IAPIWidget && in_array($widget->getId(), $userLayout)) {
if ($widget instanceof IAPIWidget && in_array($widget->getId(), $showWidgets)) {
$items[$widget->getId()] = array_map(function (WidgetItem $item) {
return $item->jsonSerialize();
}, $widget->getItems($this->userId, $sinceIds[$widget->getId()] ?? null, $limit));

Loading…
Cancel
Save