Skip to content

Commit 558001f

Browse files
committed
fixup! Add docs for new dashboard api
1 parent 6413716 commit 558001f

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

developer_manual/digging_deeper/dashboard.rst

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22
Dashboard
33
=========
44

5-
The dashboard app aims to provide the user with a general overview of their
6-
Nextcloud and show information that is currently important.
5+
The dashboard app aims to provide the user with a general overview of their
6+
Nextcloud and shows information that is currently important.
77

88
App developers can integrate into the dashboard app and provide their own panels.
99

1010

1111
Register a dashboard panels
12-
===========================
12+
---------------------------
1313

14-
A dashboard panel is represented by a class implementing the `OCP\\Dashboard\\IPanel`
15-
interface. This class will be instantiated whenever the dashboard is loaded, so
16-
scripts and initial state that your panel needs can be added in the constructor.
14+
A dashboard panel is represented by a class implementing the `OCP\\Dashboard\\IPanel`
15+
interface. This class will be instantiated whenever the dashboard is loaded.
16+
Any bootstrap code that is needed for the panel can be implemented inside
17+
of the `load` method and will be called when the dashboard is loaded.
1718

1819
.. code-block:: php
1920
@@ -34,32 +35,57 @@ scripts and initial state that your panel needs can be added in the constructor.
3435
IL10N $l10n,
3536
IURLGenerator $urlGenerator
3637
) {
38+
$this->initialStateService = $initialStateService;
3739
$this->l10n = $l10n;
3840
$this->urlGenerator = $urlGenerator;
39-
40-
$initialStateService->provideInitialState('myapp', 'myData', []);
41-
\OCP\Util::addScript('myapp', 'dashboard');
4241
}
4342
44-
public function getId(): string {
43+
/**
44+
* @return string Unique id that identifies the panel, e.g. the app id
45+
* @since 20.0.0
46+
*/ public function getId(): string {
4547
return 'myapppanelid';
4648
}
4749
50+
/**
51+
* @return string User facing title of the panel
52+
* @since 20.0.0
53+
*/
4854
public function getTitle(): string {
4955
return $this->l10n->t('My app');
5056
}
5157
58+
/**
59+
* @return int Initial order for panel sorting
60+
* @since 20.0.0
61+
*/
5262
public function getOrder(): int {
5363
return 0;
5464
}
5565
66+
/**
67+
* @return string css class that displays an icon next to the panel title
68+
* @since 20.0.0
69+
*/
5670
public function getIconClass(): string {
5771
return 'icon-class';
5872
}
5973
74+
/**
75+
* @return string|null The absolute url to the apps own view
76+
* @since 20.0.0
77+
*/
6078
public function getUrl(): string {
6179
return $this->urlGenerator->linkToRouteAbsolute('myapp.view.index');
6280
}
81+
82+
/**
83+
* Execute panel bootstrap code like loading scripts and providing initial state
84+
*/
85+
public function load(): void {
86+
$initialStateService->provideInitialState('myapp', 'myData', []);
87+
\OCP\Util::addScript('myapp', 'dashboard');
88+
}
6389
}
6490
6591
@@ -95,16 +121,16 @@ The class needs to be registered during the app bootstrap.
95121
}
96122
}
97123
98-
For compatibility reasons the panel registration can also be performed by
99-
listening to the `OCP\\Dashboard\\RegisterPanelEvent` for apps that still
124+
For compatibility reasons the panel registration can also be performed by
125+
listening to the `OCP\\Dashboard\\RegisterPanelEvent` for apps that still
100126
need to support older versions where the new app boostrap flow is not available,
101127
however this method is deprecated and will be removed once Nextcloud 19 is EOL.
102128

103129
.. code-block:: php
104130
105131
use OCP\Dashboard\RegisterPanelEvent;
106132
use OCP\EventDispatcher\IEventDispatcher;
107-
133+
108134
class Application extends App {
109135
public function __construct(array $urlParams = []) {
110136
parent::__construct(self::APP_ID, $urlParams);
@@ -121,15 +147,15 @@ however this method is deprecated and will be removed once Nextcloud 19 is EOL.
121147
122148
123149
Provide a user interface
124-
========================
150+
------------------------
125151

126-
The user interface can be registered though the public `OCA.Dashboard.register`
127-
JavaScript method. The first parameter represents the panel id that has already
128-
been specified in the `IPanel` implementation. The callback parameter will be
152+
The user interface can be registered though the public `OCA.Dashboard.register`
153+
JavaScript method. The first parameter represents the panel id that has already
154+
been specified in the `IPanel` implementation. The callback parameter will be
129155
called to render the panel in the frontend. The user interface can be added to
130156
the provided DOM element `el`.
131157

132-
The following example shows how a Vue.js component could be used to render the
158+
The following example shows how a Vue.js component could be used to render the
133159
panel user interface, however this approach works for any other framework as well
134160
as plain JavaScript as well:
135161

0 commit comments

Comments
 (0)