@@ -180,9 +180,83 @@ as plain JavaScript:
180180 Dashboard API for clients
181181---------------------------------------
182182
183- +++++++++++++++++
184- Implement the API
185- +++++++++++++++++
183+ To provide more information about your widget through the dashboard API for clients, you can implement
184+ those additional interfaces:
185+
186+ * IButtonWidget to add buttons to be rendered by the client in the widget
187+ * IIconWidget to set the widget icon URL
188+ * IOptionWidget to set additional options
189+ * IAPIWidget to actually provide the widget content (the item list)
190+
191+ +++++++++++++++++++++++++++
192+ The IButtonWidget interface
193+ +++++++++++++++++++++++++++
194+
195+
196+ The IButtonWidget interface adds the **getWidgetButtons ** method to provide a list of buttons
197+ to be displayed by the clients in the widget.
198+ Those buttons let you define actions that can be triggered from the widget in the clients.
199+
200+ There are 3 types of buttons:
201+
202+ * WidgetButton::TYPE_NEW To let users create new elements in your app
203+ * WidgetButton::TYPE_MORE To let users see more information
204+ * WidgetButton::TYPE_SETUP If the widget requires some configuration
205+
206+ .. code-block :: php
207+
208+ public function getWidgetButtons(string $userId): array {
209+ return [
210+ new WidgetButton(
211+ WidgetButton::TYPE_NEW,
212+ 'https://somewhere.org',
213+ $this->l10n->t('Create new element')
214+ ),
215+ new WidgetButton(
216+ WidgetButton::TYPE_MORE,
217+ 'https://my.nextcloud.org/apps/your-app/',
218+ $this->l10n->t('More notifications')
219+ ),
220+ new WidgetButton(
221+ WidgetButton::TYPE_SETUP,
222+ 'https://my.nextcloud.org/apps/settings/user',
223+ $this->l10n->t('Configure')
224+ ),
225+ ];
226+ }
227+
228+ +++++++++++++++++++++++++++
229+ The IIconWidget interface
230+ +++++++++++++++++++++++++++
231+
232+ The IIconWidget interface adds the **getIconUrl ** method to provide the URL to the widget icon. In the following example
233+ it returns the URL to the img/app.svg file in your app.
234+
235+ .. code-block :: php
236+
237+ public function getIconUrl(): string {
238+ return $this->urlGenerator->getAbsoluteURL(
239+ $this->urlGenerator->imagePath(Application::APP_ID, 'app.svg')
240+ );
241+ }
242+
243+ +++++++++++++++++++++++++++
244+ The IOptionWidget interface
245+ +++++++++++++++++++++++++++
246+
247+ The IOptionWidget interface adds the **getWidgetOptions ** method to provide additional widget options. It returns
248+ a WidgetOptions object which only contains the **roundItemIcons ** boolean value for now. This tells the clients if
249+ the widget item icons should be rounded or kept as squares.
250+
251+ .. code-block :: php
252+
253+ public function getWidgetOptions(): WidgetOptions {
254+ return new WidgetOptions(true);
255+ }
256+
257+ +++++++++++++++++++++++++++
258+ The IAPIWidget interface
259+ +++++++++++++++++++++++++++
186260
187261If you want your widget content to be accessible with the dashboard API for Nextcloud clients,
188262it must implement the `OCP\\Dashboard\\IAPIWidget ` interface rather than `OCP\\Dashboard\\IWidget `.
@@ -219,7 +293,63 @@ This interface contains an extra `getItems` method which returns an array of `OC
219293Use the API
220294+++++++++++
221295
222- From the client point of view, the dashboard widget items can then be obtained with this kind of request:
296+ The list of enabled widgets can be requested like that:
297+
298+ .. code-block :: bash
299+
300+ curl -u user:passwd https://my.nextcloud.org/ocs/v2.php/apps/dashboard/api/v1/widgets \
301+ -H " Accept: application/json" \
302+ -X GET
303+
304+ Example response:
305+
306+ .. code-block :: json
307+
308+ {
309+ "ocs" : {
310+ "meta" : {
311+ "status" : " ok" ,
312+ "statuscode" : 200 ,
313+ "message" : " OK"
314+ },
315+ "data" : {
316+ "spreed" : {
317+ "id" : " spreed" ,
318+ "title" : " Talk mentions" ,
319+ "order" : 10 ,
320+ "icon_class" : " dashboard-talk-icon" ,
321+ "icon_url" : " https://my.nextcloud.org/apps/spreed/img/app-dark.svg" ,
322+ "widget_url" : " https://my.nextcloud.org/index.php/apps/spreed/" ,
323+ "item_icons_round" : true ,
324+ "buttons" : [
325+ {
326+ "type" : " more" ,
327+ "text" : " More unread mentions" ,
328+ "link" : " https://my.nextcloud.org/index.php/apps/spreed/"
329+ }
330+ ]
331+ },
332+ "github_notifications" : {
333+ "id" : " github_notifications" ,
334+ "title" : " GitHub notifications" ,
335+ "order" : 10 ,
336+ "icon_class" : " icon-github" ,
337+ "icon_url" : " https://my.nextcloud.org/apps/integration_github/img/app-dark.svg" ,
338+ "widget_url" : " https://my.nextcloud.org/index.php/settings/user/connected-accounts" ,
339+ "item_icons_round" : true ,
340+ "buttons" : [
341+ {
342+ "type" : " more" ,
343+ "text" : " More notifications" ,
344+ "link" : " https://github.com/notifications"
345+ }
346+ ]
347+ },
348+ }
349+ }
350+ }
351+
352+ The items list for each enabled widgets can be requested like that:
223353
224354.. code-block :: bash
225355
@@ -230,3 +360,58 @@ From the client point of view, the dashboard widget items can then be obtained w
230360
231361 If your client periodically gets widget items content with this API,
232362include the latest `sinceId ` for each widget to avoid getting the items you already have.
363+
364+ Example response:
365+
366+ .. code-block :: json
367+
368+ {
369+ "ocs" : {
370+ "meta" : {
371+ "status" : " ok" ,
372+ "statuscode" : 200 ,
373+ "message" : " OK"
374+ },
375+ "data" : {
376+ "github_notifications" : [
377+ {
378+ "subtitle" : " nextcloud-docker-dev#87" ,
379+ "title" : " Improve getting started" ,
380+ "link" : " https://github.com/juliushaertl/nextcloud-docker-dev/pull/87" ,
381+ "iconUrl" : " https://my.nextcloud.org/index.php/apps/integration_github/avatar/juliushaertl" ,
382+ "sinceId" : " 2022-10-13T12:34:19Z"
383+ },
384+ {
385+ "subtitle" : " integration_github" ,
386+ "title" : " v1.0.11" ,
387+ "link" : " https://github.com/nextcloud/integration_github/releases" ,
388+ "iconUrl" : " https://my.nextcloud.org/index.php/apps/integration_github/avatar/nextcloud" ,
389+ "sinceId" : " 2022-10-13T12:32:04Z"
390+ },
391+ {
392+ "subtitle" : " text#3209" ,
393+ "title" : " Rich workspaces: If there is no Readme.md, don’t show editor placeholder but move into \" +\" menu" ,
394+ "link" : " https://github.com/nextcloud/text/issues/3209" ,
395+ "iconUrl" : " https://my.nextcloud.org/index.php/apps/integration_github/avatar/nextcloud" ,
396+ "sinceId" : " 2022-10-13T12:14:39Z"
397+ }
398+ ],
399+ "spreed" : [
400+ {
401+ "subtitle" : " - Send chat messages without notifying the recipients in case it is not urgent" ,
402+ "title" : " Talk updates ✅" ,
403+ "link" : " https://my.nextcloud.org/index.php/call/hw39yxkp" ,
404+ "iconUrl" : " https://my.nextcloud.org/core/img/actions/group.svg" ,
405+ "sinceId" : " "
406+ },
407+ {
408+ "subtitle" : " @roberto What's up?" ,
409+ "title" : " Jane" ,
410+ "link" : " https://my.nextcloud.org/index.php/call/z87agy2o" ,
411+ "iconUrl" : " https://my.nextcloud.org/index.php/avatar/toto/64" ,
412+ "sinceId" : " "
413+ }
414+ ]
415+ }
416+ }
417+ }
0 commit comments