]> source.dussan.org Git - nextcloud-server.git/commitdiff
Refactor API to match the widget wording
authorJulius Härtl <jus@bitgrid.net>
Tue, 4 Aug 2020 13:20:05 +0000 (15:20 +0200)
committerJulius Härtl <jus@bitgrid.net>
Wed, 5 Aug 2020 15:03:38 +0000 (17:03 +0200)
Signed-off-by: Julius Härtl <jus@bitgrid.net>
apps/dashboard/lib/Controller/DashboardController.php
lib/private/AppFramework/Bootstrap/RegistrationContext.php
lib/private/Dashboard/Manager.php
lib/public/AppFramework/Bootstrap/IRegistrationContext.php
lib/public/Dashboard/IManager.php
lib/public/Dashboard/IPanel.php [deleted file]
lib/public/Dashboard/IWidget.php [new file with mode: 0644]
lib/public/Dashboard/RegisterPanelEvent.php [deleted file]
lib/public/Dashboard/RegisterWidgetEvent.php [new file with mode: 0644]

index 06ce063b0a5c7e8fa7834602633085d829f1b4f2..07cfaf071e250b5030df4560cdc0a13c8895d55d 100644 (file)
@@ -32,8 +32,8 @@ use OCP\AppFramework\Controller;
 use OCP\AppFramework\Http\JSONResponse;
 use OCP\AppFramework\Http\TemplateResponse;
 use OCP\Dashboard\IManager;
-use OCP\Dashboard\IPanel;
-use OCP\Dashboard\RegisterPanelEvent;
+use OCP\Dashboard\IWidget;
+use OCP\Dashboard\RegisterWidgetEvent;
 use OCP\EventDispatcher\IEventDispatcher;
 use OCP\IConfig;
 use OCP\IInitialStateService;
@@ -76,18 +76,18 @@ class DashboardController extends Controller {
         * @return TemplateResponse
         */
        public function index(): TemplateResponse {
-               $this->eventDispatcher->dispatchTyped(new RegisterPanelEvent($this->dashboardManager));
+               $this->eventDispatcher->dispatchTyped(new RegisterWidgetEvent($this->dashboardManager));
 
                $userLayout = explode(',', $this->config->getUserValue($this->userId, 'dashboard', 'layout', 'recommendations,spreed,mail,calendar'));
-               $panels = array_map(function (IPanel $panel) {
+               $widgets = array_map(function (IWidget $widget) {
                        return [
-                               'id' => $panel->getId(),
-                               'title' => $panel->getTitle(),
-                               'iconClass' => $panel->getIconClass(),
-                               'url' => $panel->getUrl()
+                               'id' => $widget->getId(),
+                               'title' => $widget->getTitle(),
+                               'iconClass' => $widget->getIconClass(),
+                               'url' => $widget->getUrl()
                        ];
-               }, $this->dashboardManager->getPanels());
-               $this->inititalStateService->provideInitialState('dashboard', 'panels', $panels);
+               }, $this->dashboardManager->getWidgets());
+               $this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets);
                $this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout);
                $this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
                $this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');
index efcf9175b978e9fd02e0305e8eccc197889e05e4..4c37209739e5620e219febc723ce3fa7be3f38d2 100644 (file)
@@ -100,10 +100,10 @@ class RegistrationContext {
                                );
                        }
 
-                       public function registerDashboardPanel(string $panelClass): void {
+                       public function registerDashboardWidget(string $widgetClass): void {
                                $this->context->registerDashboardPanel(
                                        $this->appId,
-                                       $panelClass
+                                       $widgetClass
                                );
                        }
 
@@ -282,7 +282,7 @@ class RegistrationContext {
        public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
                foreach ($this->dashboardPanels as $panel) {
                        try {
-                               $dashboardManager->lazyRegisterPanel($panel['class']);
+                               $dashboardManager->lazyRegisterWidget($panel['class']);
                        } catch (Throwable $e) {
                                $appId = $panel['appId'];
                                $this->logger->logException($e, [
index 0c285a8b53d1fa3be21d3b21648af0325445efe8..fda4c8b3893179a85c893576d9d5c416b0d367c8 100644 (file)
@@ -29,7 +29,7 @@ namespace OC\Dashboard;
 use InvalidArgumentException;
 use OCP\AppFramework\QueryException;
 use OCP\Dashboard\IManager;
-use OCP\Dashboard\IPanel;
+use OCP\Dashboard\IWidget;
 use OCP\ILogger;
 use OCP\IServerContainer;
 use Throwable;
@@ -37,10 +37,10 @@ use Throwable;
 class Manager implements IManager {
 
        /** @var array */
-       private $lazyPanels = [];
+       private $lazyWidgets = [];
 
-       /** @var IPanel[] */
-       private $panels = [];
+       /** @var IWidget[] */
+       private $widgets = [];
 
        /** @var IServerContainer */
        private $serverContainer;
@@ -49,31 +49,31 @@ class Manager implements IManager {
                $this->serverContainer = $serverContainer;
        }
 
-       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');
+       private function registerWidget(IWidget $widget): void {
+               if (array_key_exists($widget->getId(), $this->widgets)) {
+                       throw new InvalidArgumentException('Dashboard widget with this id has already been registered');
                }
 
-               $this->panels[$panel->getId()] = $panel;
+               $this->widgets[$widget->getId()] = $widget;
        }
 
-       public function lazyRegisterPanel(string $panelClass): void {
-               $this->lazyPanels[] = $panelClass;
+       public function lazyRegisterWidget(string $widgetClass): void {
+               $this->lazyWidgets[] = $widgetClass;
        }
 
        public function loadLazyPanels(): void {
-               $classes = $this->lazyPanels;
+               $classes = $this->lazyWidgets;
                foreach ($classes as $class) {
                        try {
-                               /** @var IPanel $panel */
-                               $panel = $this->serverContainer->query($class);
+                               /** @var IWidget $widget */
+                               $widget = $this->serverContainer->query($class);
                        } catch (QueryException $e) {
                                /*
                                 * There is a circular dependency between the logger and the registry, so
                                 * we can not inject it. Thus the static call.
                                 */
                                \OC::$server->getLogger()->logException($e, [
-                                       'message' => 'Could not load lazy dashbaord panel: ' . $e->getMessage(),
+                                       'message' => 'Could not load lazy dashbaord widget: ' . $e->getMessage(),
                                        'level' => ILogger::FATAL,
                                ]);
                        }
@@ -82,32 +82,32 @@ class Manager implements IManager {
                         * type, so we might get a TypeError here that we should catch.
                         */
                        try {
-                               $this->registerPanel($panel);
+                               $this->registerWidget($widget);
                        } catch (Throwable $e) {
                                /*
                                 * There is a circular dependency between the logger and the registry, so
                                 * we can not inject it. Thus the static call.
                                 */
                                \OC::$server->getLogger()->logException($e, [
-                                       'message' => 'Could not register lazy dashboard panel: ' . $e->getMessage(),
+                                       'message' => 'Could not register lazy dashboard widget: ' . $e->getMessage(),
                                        'level' => ILogger::FATAL,
                                ]);
                        }
 
                        try {
-                               $panel->load();
+                               $widget->load();
                        } catch (Throwable $e) {
                                \OC::$server->getLogger()->logException($e, [
-                                       'message' => 'Error during dashboard panel loading: ' . $e->getMessage(),
+                                       'message' => 'Error during dashboard widget loading: ' . $e->getMessage(),
                                        'level' => ILogger::FATAL,
                                ]);
                        }
                }
-               $this->lazyPanels = [];
+               $this->lazyWidgets = [];
        }
 
-       public function getPanels(): array {
+       public function getWidgets(): array {
                $this->loadLazyPanels();
-               return $this->panels;
+               return $this->widgets;
        }
 }
index 94e3aed17e2e0037c159cacbe7c33b5b9d816587..0acf0c038bbccddca67d8ee506a2870c5eec44d2 100644 (file)
@@ -59,11 +59,11 @@ interface IRegistrationContext {
         * Register an implementation of \OCP\Dashboard\IPanel that
         * will handle the implementation of a dashboard panel
         *
-        * @param string $panelClass
+        * @param string $widgetClass
         * @return void
         * @since 20.0.0
         */
-       public function registerDashboardPanel(string $panelClass): void;
+       public function registerDashboardWidget(string $widgetClass): void;
        /**
         * Register a service
         *
index 985c8c7838f876162caff04162ac7b4025965ae6..81b1bb0dffee7fcc02f026a69350300924fadc88 100644 (file)
@@ -35,15 +35,15 @@ namespace OCP\Dashboard;
 interface IManager {
 
        /**
-        * @param string $panelClass
+        * @param string $widgetClass
         * @since 20.0.0
         */
-       public function lazyRegisterPanel(string $panelClass): void;
+       public function lazyRegisterWidget(string $widgetClass): void;
 
        /**
         * @since 20.0.0
         *
-        * @return IPanel[]
+        * @return IWidget[]
         */
-       public function getPanels(): array;
+       public function getWidgets(): array;
 }
diff --git a/lib/public/Dashboard/IPanel.php b/lib/public/Dashboard/IPanel.php
deleted file mode 100644 (file)
index 59d88f7..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
- *
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCP\Dashboard;
-
-/**
- * Interface IPanel
- *
- * @package OCP\Dashboard
- * @since 20.0.0
- */
-interface IPanel {
-
-       /**
-        * @return string Unique id that identifies the panel, e.g. the app id
-        * @since 20.0.0
-        */
-       public function getId(): string;
-
-       /**
-        * @return string User facing title of the panel
-        * @since 20.0.0
-        */
-       public function getTitle(): string;
-
-       /**
-        * @return int Initial order for panel sorting
-        * @since 20.0.0
-        */
-       public function getOrder(): int;
-
-       /**
-        * @return string css class that displays an icon next to the panel title
-        * @since 20.0.0
-        */
-       public function getIconClass(): string;
-
-       /**
-        * @return string|null The absolute url to the apps own view
-        * @since 20.0.0
-        */
-       public function getUrl(): ?string;
-
-       /**
-        * Execute panel bootstrap code like loading scripts and providing initial state
-        * @since 20.0.0
-        */
-       public function load(): void;
-}
diff --git a/lib/public/Dashboard/IWidget.php b/lib/public/Dashboard/IWidget.php
new file mode 100644 (file)
index 0000000..42e2c7d
--- /dev/null
@@ -0,0 +1,72 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCP\Dashboard;
+
+/**
+ * Interface IWidget
+ *
+ * @package OCP\Dashboard
+ * @since 20.0.0
+ */
+interface IWidget {
+
+       /**
+        * @return string Unique id that identifies the widget, e.g. the app id
+        * @since 20.0.0
+        */
+       public function getId(): string;
+
+       /**
+        * @return string User facing title of the widget
+        * @since 20.0.0
+        */
+       public function getTitle(): string;
+
+       /**
+        * @return int Initial order for widget sorting
+        * @since 20.0.0
+        */
+       public function getOrder(): int;
+
+       /**
+        * @return string css class that displays an icon next to the widget title
+        * @since 20.0.0
+        */
+       public function getIconClass(): string;
+
+       /**
+        * @return string|null The absolute url to the apps own view
+        * @since 20.0.0
+        */
+       public function getUrl(): ?string;
+
+       /**
+        * Execute widget bootstrap code like loading scripts and providing initial state
+        * @since 20.0.0
+        */
+       public function load(): void;
+}
diff --git a/lib/public/Dashboard/RegisterPanelEvent.php b/lib/public/Dashboard/RegisterPanelEvent.php
deleted file mode 100644 (file)
index 2bd1571..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-/**
- * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
- *
- * @author Julius Härtl <jus@bitgrid.net>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-namespace OCP\Dashboard;
-
-use OCP\EventDispatcher\Event;
-
-/**
- * Class RegisterPanelEvent
- *
- * This event is dispatched to allow apps supporting older Nextcloud versions to
- * still register their dashboard panels so that they are only constructed when
- * they are needed. Deprecated right away so we can drop it again after 19 is EOL
- * and backward compatible apps can use OCP\AppFramework\Bootstrap\IBootstrap
- *
- * @package OCP\Dashboard
- * @since 20.0.0
- * @deprecated 20.0.0
- */
-class RegisterPanelEvent extends Event {
-       private $manager;
-
-       public function __construct(IManager $manager) {
-               parent::__construct();
-
-               $this->manager = $manager;
-       }
-
-       /**
-        * @param string $panelClass
-        * @since 20.0.0
-        */
-       public function registerPanel(string $panelClass) {
-               $this->manager->lazyRegisterPanel($panelClass);
-       }
-}
diff --git a/lib/public/Dashboard/RegisterWidgetEvent.php b/lib/public/Dashboard/RegisterWidgetEvent.php
new file mode 100644 (file)
index 0000000..0267a9e
--- /dev/null
@@ -0,0 +1,59 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright Copyright (c) 2020 Julius Härtl <jus@bitgrid.net>
+ *
+ * @author Julius Härtl <jus@bitgrid.net>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCP\Dashboard;
+
+use OCP\EventDispatcher\Event;
+
+/**
+ * Class RegisterPanelEvent
+ *
+ * This event is dispatched to allow apps supporting older Nextcloud versions to
+ * still register their dashboard panels so that they are only constructed when
+ * they are needed. Deprecated right away so we can drop it again after 19 is EOL
+ * and backward compatible apps can use OCP\AppFramework\Bootstrap\IBootstrap
+ *
+ * @package OCP\Dashboard
+ * @since 20.0.0
+ * @deprecated 20.0.0
+ */
+class RegisterWidgetEvent extends Event {
+       private $manager;
+
+       public function __construct(IManager $manager) {
+               parent::__construct();
+
+               $this->manager = $manager;
+       }
+
+       /**
+        * @param string $panelClass
+        * @since 20.0.0
+        */
+       public function registerWidget(string $panelClass) {
+               $this->manager->lazyRegisterWidget($panelClass);
+       }
+}