From 31a14945296047cbdd17a90c223527f4e1ad951b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julius=20H=C3=A4rtl?= Date: Fri, 26 Jun 2020 16:01:52 +0200 Subject: [PATCH] Add load method for apps to bootstrap their panels MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julius Härtl --- lib/private/Dashboard/Manager.php | 13 ++++++++++++- lib/public/Dashboard/IPanel.php | 18 ++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/private/Dashboard/Manager.php b/lib/private/Dashboard/Manager.php index f9c857f831..c9185e0b83 100644 --- a/lib/private/Dashboard/Manager.php +++ b/lib/private/Dashboard/Manager.php @@ -23,11 +23,13 @@ namespace OC\Dashboard; +use InvalidArgumentException; use OCP\AppFramework\QueryException; use OCP\Dashboard\IManager; use OCP\Dashboard\IPanel; use OCP\ILogger; use OCP\IServerContainer; +use Throwable; class Manager implements IManager { @@ -46,7 +48,7 @@ class Manager implements IManager { private function registerPanel(IPanel $panel): void { if (array_key_exists($panel->getId(), $this->panels)) { - throw new \InvalidArgumentException('Dashboard panel with this id has already been registered'); + throw new InvalidArgumentException('Dashboard panel with this id has already been registered'); } $this->panels[$panel->getId()] = $panel; @@ -88,6 +90,15 @@ class Manager implements IManager { 'level' => ILogger::FATAL, ]); } + + try { + $panel->load(); + } catch (Throwable $e) { + \OC::$server->getLogger()->logException($e, [ + 'message' => 'Error during dashboard panel loading: ' . $e->getMessage(), + 'level' => ILogger::FATAL, + ]); + } } $this->lazyPanels = []; } diff --git a/lib/public/Dashboard/IPanel.php b/lib/public/Dashboard/IPanel.php index d7e7b15796..78c7d09c00 100644 --- a/lib/public/Dashboard/IPanel.php +++ b/lib/public/Dashboard/IPanel.php @@ -32,32 +32,38 @@ namespace OCP\Dashboard; interface IPanel { /** - * @return string + * @return string Unique id that identifies the panel, e.g. the app id * @since 20.0.0 */ public function getId(): string; /** - * @return string + * @return string User facing title of the panel * @since 20.0.0 */ public function getTitle(): string; /** - * @return int + * @return int Initial order for panel sorting * @since 20.0.0 */ public function getOrder(): int; /** - * @return string + * @return string css class that displays an icon next to the panel title * @since 20.0.0 */ public function getIconClass(): string; /** - * @return string The absolute url to the apps own view + * @return string|null The absolute url to the apps own view * @since 20.0.0 */ - public function getUrl(): string; + public function getUrl(): ?string; + + /** + * Execute panel bootstrap code like loading scripts and providing initial state + * @since 20.0.0 + */ + public function load(): void; }