]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add load method for apps to bootstrap their panels
authorJulius Härtl <jus@bitgrid.net>
Fri, 26 Jun 2020 14:01:52 +0000 (16:01 +0200)
committerJulius Härtl <jus@bitgrid.net>
Wed, 15 Jul 2020 07:28:11 +0000 (09:28 +0200)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
lib/private/Dashboard/Manager.php
lib/public/Dashboard/IPanel.php

index f9c857f831f27d0ae68de2d8907a7334006e063e..c9185e0b832764dd69e1deecb8a5ded02ef97f07 100644 (file)
 
 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 = [];
        }
index d7e7b157964e36ea93cfb9587ecc9d343180bb51..78c7d09c009b86e3c6896a7effc277b51cbba373 100644 (file)
@@ -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;
 }