Skip to content

Commit ea46d1a

Browse files
committed
Add load method for apps to bootstrap their panels
Signed-off-by: Julius Härtl <jus@bitgrid.net>
1 parent ef24436 commit ea46d1a

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

lib/private/Dashboard/Manager.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@
2323

2424
namespace OC\Dashboard;
2525

26+
use InvalidArgumentException;
2627
use OCP\AppFramework\QueryException;
2728
use OCP\Dashboard\IManager;
2829
use OCP\Dashboard\IPanel;
2930
use OCP\ILogger;
3031
use OCP\IServerContainer;
32+
use Throwable;
3133

3234
class Manager implements IManager {
3335

@@ -46,7 +48,7 @@ public function __construct(IServerContainer $serverContainer) {
4648

4749
private function registerPanel(IPanel $panel): void {
4850
if (array_key_exists($panel->getId(), $this->panels)) {
49-
throw new \InvalidArgumentException('Dashboard panel with this id has already been registered');
51+
throw new InvalidArgumentException('Dashboard panel with this id has already been registered');
5052
}
5153

5254
$this->panels[$panel->getId()] = $panel;
@@ -88,6 +90,15 @@ public function loadLazyPanels(): void {
8890
'level' => ILogger::FATAL,
8991
]);
9092
}
93+
94+
try {
95+
$panel->load();
96+
} catch (Throwable $e) {
97+
\OC::$server->getLogger()->logException($e, [
98+
'message' => 'Error during dashboard panel loading: ' . $e->getMessage(),
99+
'level' => ILogger::FATAL,
100+
]);
101+
}
91102
}
92103
$this->lazyPanels = [];
93104
}

lib/public/Dashboard/IPanel.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,38 @@
3232
interface IPanel {
3333

3434
/**
35-
* @return string
35+
* @return string Unique id that identifies the panel, e.g. the app id
3636
* @since 20.0.0
3737
*/
3838
public function getId(): string;
3939

4040
/**
41-
* @return string
41+
* @return string User facing title of the panel
4242
* @since 20.0.0
4343
*/
4444
public function getTitle(): string;
4545

4646
/**
47-
* @return int
47+
* @return int Initial order for panel sorting
4848
* @since 20.0.0
4949
*/
5050
public function getOrder(): int;
5151

5252
/**
53-
* @return string
53+
* @return string css class that displays an icon next to the panel title
5454
* @since 20.0.0
5555
*/
5656
public function getIconClass(): string;
5757

5858
/**
59-
* @return string The absolute url to the apps own view
59+
* @return string|null The absolute url to the apps own view
6060
* @since 20.0.0
6161
*/
62-
public function getUrl(): string;
62+
public function getUrl(): ?string;
63+
64+
/**
65+
* Execute panel bootstrap code like loading scripts and providing initial state
66+
* @since 20.0.0
67+
*/
68+
public function load(): void;
6369
}

0 commit comments

Comments
 (0)