Refactor API to match the widget wording

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl 2020-08-04 15:20:05 +02:00
parent 6accf4d857
commit 018be662f4
No known key found for this signature in database
GPG Key ID: 4C614C6ED2CDE6DF
7 changed files with 50 additions and 50 deletions

View File

@ -32,8 +32,8 @@ use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\JSONResponse; use OCP\AppFramework\Http\JSONResponse;
use OCP\AppFramework\Http\TemplateResponse; use OCP\AppFramework\Http\TemplateResponse;
use OCP\Dashboard\IManager; use OCP\Dashboard\IManager;
use OCP\Dashboard\IPanel; use OCP\Dashboard\IWidget;
use OCP\Dashboard\RegisterPanelEvent; use OCP\Dashboard\RegisterWidgetEvent;
use OCP\EventDispatcher\IEventDispatcher; use OCP\EventDispatcher\IEventDispatcher;
use OCP\IConfig; use OCP\IConfig;
use OCP\IInitialStateService; use OCP\IInitialStateService;
@ -76,18 +76,18 @@ class DashboardController extends Controller {
* @return TemplateResponse * @return TemplateResponse
*/ */
public function index(): 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')); $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 [ return [
'id' => $panel->getId(), 'id' => $widget->getId(),
'title' => $panel->getTitle(), 'title' => $widget->getTitle(),
'iconClass' => $panel->getIconClass(), 'iconClass' => $widget->getIconClass(),
'url' => $panel->getUrl() 'url' => $widget->getUrl()
]; ];
}, $this->dashboardManager->getPanels()); }, $this->dashboardManager->getWidgets());
$this->inititalStateService->provideInitialState('dashboard', 'panels', $panels); $this->inititalStateService->provideInitialState('dashboard', 'panels', $widgets);
$this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout); $this->inititalStateService->provideInitialState('dashboard', 'layout', $userLayout);
$this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1'); $this->inititalStateService->provideInitialState('dashboard', 'firstRun', $this->config->getUserValue($this->userId, 'dashboard', 'firstRun', '1') === '1');
$this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0'); $this->config->setUserValue($this->userId, 'dashboard', 'firstRun', '0');

View File

@ -100,10 +100,10 @@ class RegistrationContext {
); );
} }
public function registerDashboardPanel(string $panelClass): void { public function registerDashboardWidget(string $widgetClass): void {
$this->context->registerDashboardPanel( $this->context->registerDashboardPanel(
$this->appId, $this->appId,
$panelClass $widgetClass
); );
} }
@ -282,7 +282,7 @@ class RegistrationContext {
public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void { public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
foreach ($this->dashboardPanels as $panel) { foreach ($this->dashboardPanels as $panel) {
try { try {
$dashboardManager->lazyRegisterPanel($panel['class']); $dashboardManager->lazyRegisterWidget($panel['class']);
} catch (Throwable $e) { } catch (Throwable $e) {
$appId = $panel['appId']; $appId = $panel['appId'];
$this->logger->logException($e, [ $this->logger->logException($e, [

View File

@ -29,7 +29,7 @@ namespace OC\Dashboard;
use InvalidArgumentException; use InvalidArgumentException;
use OCP\AppFramework\QueryException; use OCP\AppFramework\QueryException;
use OCP\Dashboard\IManager; use OCP\Dashboard\IManager;
use OCP\Dashboard\IPanel; use OCP\Dashboard\IWidget;
use OCP\ILogger; use OCP\ILogger;
use OCP\IServerContainer; use OCP\IServerContainer;
use Throwable; use Throwable;
@ -37,10 +37,10 @@ use Throwable;
class Manager implements IManager { class Manager implements IManager {
/** @var array */ /** @var array */
private $lazyPanels = []; private $lazyWidgets = [];
/** @var IPanel[] */ /** @var IWidget[] */
private $panels = []; private $widgets = [];
/** @var IServerContainer */ /** @var IServerContainer */
private $serverContainer; private $serverContainer;
@ -49,31 +49,31 @@ class Manager implements IManager {
$this->serverContainer = $serverContainer; $this->serverContainer = $serverContainer;
} }
private function registerPanel(IPanel $panel): void { private function registerWidget(IWidget $widget): void {
if (array_key_exists($panel->getId(), $this->panels)) { if (array_key_exists($widget->getId(), $this->widgets)) {
throw new InvalidArgumentException('Dashboard panel with this id has already been registered'); 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 { public function lazyRegisterWidget(string $widgetClass): void {
$this->lazyPanels[] = $panelClass; $this->lazyWidgets[] = $widgetClass;
} }
public function loadLazyPanels(): void { public function loadLazyPanels(): void {
$classes = $this->lazyPanels; $classes = $this->lazyWidgets;
foreach ($classes as $class) { foreach ($classes as $class) {
try { try {
/** @var IPanel $panel */ /** @var IWidget $widget */
$panel = $this->serverContainer->query($class); $widget = $this->serverContainer->query($class);
} catch (QueryException $e) { } catch (QueryException $e) {
/* /*
* There is a circular dependency between the logger and the registry, so * There is a circular dependency between the logger and the registry, so
* we can not inject it. Thus the static call. * we can not inject it. Thus the static call.
*/ */
\OC::$server->getLogger()->logException($e, [ \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, 'level' => ILogger::FATAL,
]); ]);
} }
@ -82,32 +82,32 @@ class Manager implements IManager {
* type, so we might get a TypeError here that we should catch. * type, so we might get a TypeError here that we should catch.
*/ */
try { try {
$this->registerPanel($panel); $this->registerWidget($widget);
} catch (Throwable $e) { } catch (Throwable $e) {
/* /*
* There is a circular dependency between the logger and the registry, so * There is a circular dependency between the logger and the registry, so
* we can not inject it. Thus the static call. * we can not inject it. Thus the static call.
*/ */
\OC::$server->getLogger()->logException($e, [ \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, 'level' => ILogger::FATAL,
]); ]);
} }
try { try {
$panel->load(); $widget->load();
} catch (Throwable $e) { } catch (Throwable $e) {
\OC::$server->getLogger()->logException($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, 'level' => ILogger::FATAL,
]); ]);
} }
} }
$this->lazyPanels = []; $this->lazyWidgets = [];
} }
public function getPanels(): array { public function getWidgets(): array {
$this->loadLazyPanels(); $this->loadLazyPanels();
return $this->panels; return $this->widgets;
} }
} }

View File

@ -59,11 +59,11 @@ interface IRegistrationContext {
* Register an implementation of \OCP\Dashboard\IPanel that * Register an implementation of \OCP\Dashboard\IPanel that
* will handle the implementation of a dashboard panel * will handle the implementation of a dashboard panel
* *
* @param string $panelClass * @param string $widgetClass
* @return void * @return void
* @since 20.0.0 * @since 20.0.0
*/ */
public function registerDashboardPanel(string $panelClass): void; public function registerDashboardWidget(string $widgetClass): void;
/** /**
* Register a service * Register a service
* *

View File

@ -35,15 +35,15 @@ namespace OCP\Dashboard;
interface IManager { interface IManager {
/** /**
* @param string $panelClass * @param string $widgetClass
* @since 20.0.0 * @since 20.0.0
*/ */
public function lazyRegisterPanel(string $panelClass): void; public function lazyRegisterWidget(string $widgetClass): void;
/** /**
* @since 20.0.0 * @since 20.0.0
* *
* @return IPanel[] * @return IWidget[]
*/ */
public function getPanels(): array; public function getWidgets(): array;
} }

View File

@ -27,33 +27,33 @@ declare(strict_types=1);
namespace OCP\Dashboard; namespace OCP\Dashboard;
/** /**
* Interface IPanel * Interface IWidget
* *
* @package OCP\Dashboard * @package OCP\Dashboard
* @since 20.0.0 * @since 20.0.0
*/ */
interface IPanel { interface IWidget {
/** /**
* @return string Unique id that identifies the panel, e.g. the app id * @return string Unique id that identifies the widget, e.g. the app id
* @since 20.0.0 * @since 20.0.0
*/ */
public function getId(): string; public function getId(): string;
/** /**
* @return string User facing title of the panel * @return string User facing title of the widget
* @since 20.0.0 * @since 20.0.0
*/ */
public function getTitle(): string; public function getTitle(): string;
/** /**
* @return int Initial order for panel sorting * @return int Initial order for widget sorting
* @since 20.0.0 * @since 20.0.0
*/ */
public function getOrder(): int; public function getOrder(): int;
/** /**
* @return string css class that displays an icon next to the panel title * @return string css class that displays an icon next to the widget title
* @since 20.0.0 * @since 20.0.0
*/ */
public function getIconClass(): string; public function getIconClass(): string;
@ -65,7 +65,7 @@ interface IPanel {
public function getUrl(): ?string; public function getUrl(): ?string;
/** /**
* Execute panel bootstrap code like loading scripts and providing initial state * Execute widget bootstrap code like loading scripts and providing initial state
* @since 20.0.0 * @since 20.0.0
*/ */
public function load(): void; public function load(): void;

View File

@ -40,7 +40,7 @@ use OCP\EventDispatcher\Event;
* @since 20.0.0 * @since 20.0.0
* @deprecated 20.0.0 * @deprecated 20.0.0
*/ */
class RegisterPanelEvent extends Event { class RegisterWidgetEvent extends Event {
private $manager; private $manager;
public function __construct(IManager $manager) { public function __construct(IManager $manager) {
@ -53,7 +53,7 @@ class RegisterPanelEvent extends Event {
* @param string $panelClass * @param string $panelClass
* @since 20.0.0 * @since 20.0.0
*/ */
public function registerPanel(string $panelClass) { public function registerWidget(string $panelClass) {
$this->manager->lazyRegisterPanel($panelClass); $this->manager->lazyRegisterWidget($panelClass);
} }
} }