@@ -33,9 +33,9 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | interface IAPIWidget extends IWidget { |
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @return \OCP\Dashboard\Model\WidgetItem[] The widget items |
|
| 38 | - * @since 22.0.0 |
|
| 39 | - */ |
|
| 40 | - public function getItems(string $userId, ?string $since = null, int $limit = 7): array; |
|
| 36 | + /** |
|
| 37 | + * @return \OCP\Dashboard\Model\WidgetItem[] The widget items |
|
| 38 | + * @since 22.0.0 |
|
| 39 | + */ |
|
| 40 | + public function getItems(string $userId, ?string $since = null, int $limit = 7): array; |
|
| 41 | 41 | } |
@@ -39,111 +39,111 @@ |
||
| 39 | 39 | * |
| 40 | 40 | */ |
| 41 | 41 | final class WidgetItem implements JsonSerializable { |
| 42 | - /** @var string */ |
|
| 43 | - private $title = ''; |
|
| 44 | - |
|
| 45 | - /** @var string */ |
|
| 46 | - private $subtitle = ''; |
|
| 47 | - |
|
| 48 | - /** @var string */ |
|
| 49 | - private $link = ''; |
|
| 50 | - |
|
| 51 | - /** @var string */ |
|
| 52 | - private $iconUrl = ''; |
|
| 53 | - |
|
| 54 | - /** @var string |
|
| 55 | - * Timestamp or ID used by the dashboard API to avoid getting already retrieved items |
|
| 56 | - */ |
|
| 57 | - private $sinceId = ''; |
|
| 58 | - |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * WidgetItem constructor |
|
| 62 | - * |
|
| 63 | - * @since 22.0.0 |
|
| 64 | - * |
|
| 65 | - * @param string $type |
|
| 66 | - */ |
|
| 67 | - public function __construct(string $title = '', |
|
| 68 | - string $subtitle = '', |
|
| 69 | - string $link = '', |
|
| 70 | - string $iconUrl = '', |
|
| 71 | - string $sinceId = '') { |
|
| 72 | - $this->title = $title; |
|
| 73 | - $this->subtitle = $subtitle; |
|
| 74 | - $this->iconUrl = $iconUrl; |
|
| 75 | - $this->link = $link; |
|
| 76 | - $this->sinceId = $sinceId; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Get the item title |
|
| 81 | - * |
|
| 82 | - * @since 22.0.0 |
|
| 83 | - * |
|
| 84 | - * @return string |
|
| 85 | - */ |
|
| 86 | - public function getTitle(): string { |
|
| 87 | - return $this->title; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Get the item subtitle |
|
| 92 | - * |
|
| 93 | - * @since 22.0.0 |
|
| 94 | - * |
|
| 95 | - * @return string |
|
| 96 | - */ |
|
| 97 | - public function getSubtitle(): string { |
|
| 98 | - return $this->subtitle; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Get the item link |
|
| 103 | - * |
|
| 104 | - * @since 22.0.0 |
|
| 105 | - * |
|
| 106 | - * @return string |
|
| 107 | - */ |
|
| 108 | - public function getLink(): string { |
|
| 109 | - return $this->link; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Get the item icon URL |
|
| 114 | - * The icon should be a square svg or a jpg/png of at least 44x44px |
|
| 115 | - * |
|
| 116 | - * @since 22.0.0 |
|
| 117 | - * |
|
| 118 | - * @return string |
|
| 119 | - */ |
|
| 120 | - public function getIconUrl(): string { |
|
| 121 | - return $this->iconUrl; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Get the item since ID |
|
| 126 | - * |
|
| 127 | - * @since 22.0.0 |
|
| 128 | - * |
|
| 129 | - * @return string |
|
| 130 | - */ |
|
| 131 | - public function getSinceId(): string { |
|
| 132 | - return $this->sinceId; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @since 22.0.0 |
|
| 137 | - * |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function jsonSerialize(): array { |
|
| 141 | - return [ |
|
| 142 | - 'subtitle' => $this->getSubtitle(), |
|
| 143 | - 'title' => $this->getTitle(), |
|
| 144 | - 'link' => $this->getLink(), |
|
| 145 | - 'iconUrl' => $this->getIconUrl(), |
|
| 146 | - 'sinceId' => $this->getSinceId(), |
|
| 147 | - ]; |
|
| 148 | - } |
|
| 42 | + /** @var string */ |
|
| 43 | + private $title = ''; |
|
| 44 | + |
|
| 45 | + /** @var string */ |
|
| 46 | + private $subtitle = ''; |
|
| 47 | + |
|
| 48 | + /** @var string */ |
|
| 49 | + private $link = ''; |
|
| 50 | + |
|
| 51 | + /** @var string */ |
|
| 52 | + private $iconUrl = ''; |
|
| 53 | + |
|
| 54 | + /** @var string |
|
| 55 | + * Timestamp or ID used by the dashboard API to avoid getting already retrieved items |
|
| 56 | + */ |
|
| 57 | + private $sinceId = ''; |
|
| 58 | + |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * WidgetItem constructor |
|
| 62 | + * |
|
| 63 | + * @since 22.0.0 |
|
| 64 | + * |
|
| 65 | + * @param string $type |
|
| 66 | + */ |
|
| 67 | + public function __construct(string $title = '', |
|
| 68 | + string $subtitle = '', |
|
| 69 | + string $link = '', |
|
| 70 | + string $iconUrl = '', |
|
| 71 | + string $sinceId = '') { |
|
| 72 | + $this->title = $title; |
|
| 73 | + $this->subtitle = $subtitle; |
|
| 74 | + $this->iconUrl = $iconUrl; |
|
| 75 | + $this->link = $link; |
|
| 76 | + $this->sinceId = $sinceId; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Get the item title |
|
| 81 | + * |
|
| 82 | + * @since 22.0.0 |
|
| 83 | + * |
|
| 84 | + * @return string |
|
| 85 | + */ |
|
| 86 | + public function getTitle(): string { |
|
| 87 | + return $this->title; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Get the item subtitle |
|
| 92 | + * |
|
| 93 | + * @since 22.0.0 |
|
| 94 | + * |
|
| 95 | + * @return string |
|
| 96 | + */ |
|
| 97 | + public function getSubtitle(): string { |
|
| 98 | + return $this->subtitle; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Get the item link |
|
| 103 | + * |
|
| 104 | + * @since 22.0.0 |
|
| 105 | + * |
|
| 106 | + * @return string |
|
| 107 | + */ |
|
| 108 | + public function getLink(): string { |
|
| 109 | + return $this->link; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Get the item icon URL |
|
| 114 | + * The icon should be a square svg or a jpg/png of at least 44x44px |
|
| 115 | + * |
|
| 116 | + * @since 22.0.0 |
|
| 117 | + * |
|
| 118 | + * @return string |
|
| 119 | + */ |
|
| 120 | + public function getIconUrl(): string { |
|
| 121 | + return $this->iconUrl; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Get the item since ID |
|
| 126 | + * |
|
| 127 | + * @since 22.0.0 |
|
| 128 | + * |
|
| 129 | + * @return string |
|
| 130 | + */ |
|
| 131 | + public function getSinceId(): string { |
|
| 132 | + return $this->sinceId; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @since 22.0.0 |
|
| 137 | + * |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function jsonSerialize(): array { |
|
| 141 | + return [ |
|
| 142 | + 'subtitle' => $this->getSubtitle(), |
|
| 143 | + 'title' => $this->getTitle(), |
|
| 144 | + 'link' => $this->getLink(), |
|
| 145 | + 'iconUrl' => $this->getIconUrl(), |
|
| 146 | + 'sinceId' => $this->getSinceId(), |
|
| 147 | + ]; |
|
| 148 | + } |
|
| 149 | 149 | } |
@@ -37,50 +37,50 @@ |
||
| 37 | 37 | |
| 38 | 38 | class DashboardApiController extends OCSController { |
| 39 | 39 | |
| 40 | - /** @var IManager */ |
|
| 41 | - private $dashboardManager; |
|
| 42 | - /** @var IConfig */ |
|
| 43 | - private $config; |
|
| 44 | - /** @var string|null */ |
|
| 45 | - private $userId; |
|
| 40 | + /** @var IManager */ |
|
| 41 | + private $dashboardManager; |
|
| 42 | + /** @var IConfig */ |
|
| 43 | + private $config; |
|
| 44 | + /** @var string|null */ |
|
| 45 | + private $userId; |
|
| 46 | 46 | |
| 47 | - public function __construct(string $appName, |
|
| 48 | - IRequest $request, |
|
| 49 | - IManager $dashboardManager, |
|
| 50 | - IConfig $config, |
|
| 51 | - ?string $userId) { |
|
| 52 | - parent::__construct($appName, $request); |
|
| 47 | + public function __construct(string $appName, |
|
| 48 | + IRequest $request, |
|
| 49 | + IManager $dashboardManager, |
|
| 50 | + IConfig $config, |
|
| 51 | + ?string $userId) { |
|
| 52 | + parent::__construct($appName, $request); |
|
| 53 | 53 | |
| 54 | - $this->dashboardManager = $dashboardManager; |
|
| 55 | - $this->config = $config; |
|
| 56 | - $this->userId = $userId; |
|
| 57 | - } |
|
| 54 | + $this->dashboardManager = $dashboardManager; |
|
| 55 | + $this->config = $config; |
|
| 56 | + $this->userId = $userId; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Example request with Curl: |
|
| 61 | - * curl -u user:passwd http://my.nc/ocs/v2.php/apps/dashboard/api/v1/widget-items -H Content-Type:application/json -X GET -d '{"sinceIds":{"github_notifications":"2021-03-22T15:01:10Z"}}' |
|
| 62 | - * |
|
| 63 | - * @param array $sinceIds Array indexed by widget Ids, contains date/id from which we want the new items |
|
| 64 | - * @param int $limit Limit number of result items per widget |
|
| 65 | - * |
|
| 66 | - * @NoAdminRequired |
|
| 67 | - * @NoCSRFRequired |
|
| 68 | - */ |
|
| 69 | - public function getWidgetItems(array $sinceIds = [], int $limit = 7): DataResponse { |
|
| 70 | - $items = []; |
|
| 59 | + /** |
|
| 60 | + * Example request with Curl: |
|
| 61 | + * curl -u user:passwd http://my.nc/ocs/v2.php/apps/dashboard/api/v1/widget-items -H Content-Type:application/json -X GET -d '{"sinceIds":{"github_notifications":"2021-03-22T15:01:10Z"}}' |
|
| 62 | + * |
|
| 63 | + * @param array $sinceIds Array indexed by widget Ids, contains date/id from which we want the new items |
|
| 64 | + * @param int $limit Limit number of result items per widget |
|
| 65 | + * |
|
| 66 | + * @NoAdminRequired |
|
| 67 | + * @NoCSRFRequired |
|
| 68 | + */ |
|
| 69 | + public function getWidgetItems(array $sinceIds = [], int $limit = 7): DataResponse { |
|
| 70 | + $items = []; |
|
| 71 | 71 | |
| 72 | - $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); |
|
| 73 | - $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); |
|
| 72 | + $systemDefault = $this->config->getAppValue('dashboard', 'layout', 'recommendations,spreed,mail,calendar'); |
|
| 73 | + $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', $systemDefault)); |
|
| 74 | 74 | |
| 75 | - $widgets = $this->dashboardManager->getWidgets(); |
|
| 76 | - foreach ($widgets as $widget) { |
|
| 77 | - if ($widget instanceof IAPIWidget && in_array($widget->getId(), $userLayout)) { |
|
| 78 | - $items[$widget->getId()] = array_map(function (WidgetItem $item) { |
|
| 79 | - return $item->jsonSerialize(); |
|
| 80 | - }, $widget->getItems($this->userId, $sinceIds[$widget->getId()] ?? null, $limit)); |
|
| 81 | - } |
|
| 82 | - } |
|
| 75 | + $widgets = $this->dashboardManager->getWidgets(); |
|
| 76 | + foreach ($widgets as $widget) { |
|
| 77 | + if ($widget instanceof IAPIWidget && in_array($widget->getId(), $userLayout)) { |
|
| 78 | + $items[$widget->getId()] = array_map(function (WidgetItem $item) { |
|
| 79 | + return $item->jsonSerialize(); |
|
| 80 | + }, $widget->getItems($this->userId, $sinceIds[$widget->getId()] ?? null, $limit)); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - return new DataResponse($items); |
|
| 85 | - } |
|
| 84 | + return new DataResponse($items); |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -75,7 +75,7 @@ |
||
| 75 | 75 | $widgets = $this->dashboardManager->getWidgets(); |
| 76 | 76 | foreach ($widgets as $widget) { |
| 77 | 77 | if ($widget instanceof IAPIWidget && in_array($widget->getId(), $userLayout)) { |
| 78 | - $items[$widget->getId()] = array_map(function (WidgetItem $item) { |
|
| 78 | + $items[$widget->getId()] = array_map(function(WidgetItem $item) { |
|
| 79 | 79 | return $item->jsonSerialize(); |
| 80 | 80 | }, $widget->getItems($this->userId, $sinceIds[$widget->getId()] ?? null, $limit)); |
| 81 | 81 | } |
@@ -25,14 +25,14 @@ |
||
| 25 | 25 | * |
| 26 | 26 | */ |
| 27 | 27 | return [ |
| 28 | - 'routes' => [ |
|
| 29 | - ['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'], |
|
| 30 | - ['name' => 'dashboard#updateLayout', 'url' => '/layout', 'verb' => 'POST'], |
|
| 31 | - ['name' => 'dashboard#updateStatuses', 'url' => '/statuses', 'verb' => 'POST'], |
|
| 32 | - ['name' => 'dashboard#getBackground', 'url' => '/background', 'verb' => 'GET'], |
|
| 33 | - ['name' => 'dashboard#setBackground', 'url' => '/background/{type}', 'verb' => 'POST'], |
|
| 34 | - ], |
|
| 35 | - 'ocs' => [ |
|
| 36 | - ['name' => 'dashboardApi#getWidgetItems', 'url' => '/api/v1/widget-items', 'verb' => 'GET'], |
|
| 37 | - ] |
|
| 28 | + 'routes' => [ |
|
| 29 | + ['name' => 'dashboard#index', 'url' => '/', 'verb' => 'GET'], |
|
| 30 | + ['name' => 'dashboard#updateLayout', 'url' => '/layout', 'verb' => 'POST'], |
|
| 31 | + ['name' => 'dashboard#updateStatuses', 'url' => '/statuses', 'verb' => 'POST'], |
|
| 32 | + ['name' => 'dashboard#getBackground', 'url' => '/background', 'verb' => 'GET'], |
|
| 33 | + ['name' => 'dashboard#setBackground', 'url' => '/background/{type}', 'verb' => 'POST'], |
|
| 34 | + ], |
|
| 35 | + 'ocs' => [ |
|
| 36 | + ['name' => 'dashboardApi#getWidgetItems', 'url' => '/api/v1/widget-items', 'verb' => 'GET'], |
|
| 37 | + ] |
|
| 38 | 38 | ]; |