<?php
- \OC_Util::addScript('dashboard', 'dashboard');
+ \OCP\Util::addScript('dashboard', 'dashboard');
?>
<div id="app"></div>
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\QueryException;
+use OCP\Dashboard\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IServerContainer;
/** @var Registry */
private $registry;
+ /** @var IManager */
+ private $dashboardManager;
+
/** @var IEventDispatcher */
private $eventDispatcher;
public function __construct(IServerContainer $container,
Registry $registry,
+ IManager $dashboardManager,
IEventDispatcher $eventListener,
ILogger $logger) {
$this->serverContainer = $container;
$this->registry = $registry;
+ $this->dashboardManager = $dashboardManager;
$this->eventDispatcher = $eventListener;
$this->logger = $logger;
}
*/
$this->registrationContext->delegateCapabilityRegistrations($apps);
$this->registrationContext->delegateCrashReporterRegistrations($apps, $this->registry);
+ $this->registrationContext->delegateDashboardPanelRegistrations($apps, $this->dashboardManager);
$this->registrationContext->delegateEventListenerRegistrations($this->eventDispatcher);
$this->registrationContext->delegateContainerRegistrations($apps);
$this->registrationContext->delegateMiddlewareRegistrations($apps);
use OC\Support\CrashReport\Registry;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
+use OCP\Dashboard\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use Throwable;
/** @var array[] */
private $crashReporters = [];
+ /** @var array[] */
+ private $dashboardPanels = [];
+
/** @var array[] */
private $services = [];
);
}
+ public function registerDashboardPanel(string $panelClass): void {
+ $this->context->registerDashboardPanel(
+ $this->appId,
+ $panelClass
+ );
+ }
+
public function registerService(string $name, callable $factory, bool $shared = true): void {
$this->context->registerService(
$this->appId,
];
}
+ public function registerDashboardPanel(string $appId, string $panelClass): void {
+ $this->dashboardPanels[] = [
+ 'appId' => $appId,
+ 'class' => $panelClass
+ ];
+ }
+
public function registerService(string $appId, string $name, callable $factory, bool $shared = true): void {
$this->services[] = [
"appId" => $appId,
}
}
+ /**
+ * @param App[] $apps
+ */
+ public function delegateDashboardPanelRegistrations(array $apps, IManager $dashboardManager): void {
+ foreach ($this->dashboardPanels as $panel) {
+ try {
+ $dashboardManager->lazyRegisterPanel($panel['class']);
+ } catch (Throwable $e) {
+ $appId = $panel['appId'];
+ $this->logger->logException($e, [
+ 'message' => "Error during dashboard registration of $appId: " . $e->getMessage(),
+ 'level' => ILogger::ERROR,
+ ]);
+ }
+ }
+ }
+
public function delegateEventListenerRegistrations(IEventDispatcher $eventDispatcher): void {
foreach ($this->eventListeners as $registration) {
try {
namespace OC\Dashboard;
+use OCP\AppFramework\QueryException;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IPanel;
+use OCP\IServerContainer;
class Manager implements IManager {
+
+ /** @var array */
+ private $lazyPanels = [];
+
+ /** @var IPanel[] */
private $panels = [];
+ /** @var IServerContainer */
+ private $serverContainer;
+
+ public function __construct(IServerContainer $serverContainer) {
+ $this->serverContainer = $serverContainer;
+ }
+
/**
* @inheritDoc
*/
$this->panels[$panel->getId()] = $panel;
}
+ public function lazyRegisterPanel(string $panelClass): void {
+ $this->lazyPanels[] = $panelClass;
+ }
+
+ public function loadLazyPanels(): void {
+ $classes = $this->lazyPanels;
+ foreach ($classes as $class) {
+ try {
+ /** @var IPanel $panel */
+ $panel = $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(),
+ 'level' => ILogger::FATAL,
+ ]);
+ }
+ /**
+ * Try to register the loaded reporter. Theoretically it could be of a wrong
+ * type, so we might get a TypeError here that we should catch.
+ */
+ try {
+ $this->registerPanel($panel);
+ } 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 crash reporter: ' . $e->getMessage(),
+ 'level' => ILogger::FATAL,
+ ]);
+ }
+ }
+ $this->lazyPanels = [];
+ }
+
public function getPanels(): array {
+ $this->loadLazyPanels();
return $this->panels;
}
}
*/
public function registerCrashReporter(string $reporterClass): void;
+ /**
+ * Register an implementation of \OCP\Dashboard\IPanel that
+ * will handle the implementation of a dashboard panel
+ *
+ * @param string $panelClass
+ * @return void
+ * @since 20.0.0
+ */
+ public function registerDashboardPanel(string $panelClass): void;
/**
* Register a service
*
*/
public function registerPanel(IPanel $panel): void;
+ /**
+ * @param string $panelClass
+ * @since 20.0.0
+ */
+ public function lazyRegisterPanel(string $panelClass): void;
+
/**
* @since 20.0.0
*
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
use OCP\AppFramework\QueryException;
+use OCP\Dashboard\IManager;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ILogger;
use OCP\IServerContainer;
/** @var Registry|MockObject */
private $crashReporterRegistry;
+ /** @var IManager|MockObject */
+ private $dashboardManager;
+
/** @var IEventDispatcher|MockObject */
private $eventDispatcher;
$this->appManager = $this->createMock(IAppManager::class);
$this->serverContainer = $this->createMock(IServerContainer::class);
$this->crashReporterRegistry = $this->createMock(Registry::class);
+ $this->dashboardManager = $this->createMock(IManager::class);
$this->eventDispatcher = $this->createMock(IEventDispatcher::class);
$this->logger = $this->createMock(ILogger::class);
$this->coordinator = new Coordinator(
$this->serverContainer,
$this->crashReporterRegistry,
+ $this->dashboardManager,
$this->eventDispatcher,
$this->logger
);