Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] Register dashboards, widgetGroups and widgets by PHP API #105

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Classes/Configuration/AbstractConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class AbstractConfiguration
{
public function __construct(array $properties)
public function __construct(array $properties = [])
{
foreach ($properties as $property => $value) {
if (property_exists($this, $property)) {
Expand Down
50 changes: 49 additions & 1 deletion Classes/Configuration/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Dashboard extends AbstractConfiguration
/**
* @var string
*/
protected $iconIdentifier = 'dashboard-dashboard';
protected $iconIdentifier = 'dashboard-default';

/**
* @var string
Expand All @@ -45,31 +45,79 @@ public function getIdentifier(): string
return $this->identifier;
}

/**
* @param string $identifier
*/
public function setIdentifier(string $identifier): void
{
$this->identifier = $identifier;
}

public function getExcludeFromWizard(): bool
{
return $this->excludeFromWizard;
}

/**
* @param bool $excludeFromWizard
*/
public function setExcludeFromWizard(bool $excludeFromWizard): void
{
$this->excludeFromWizard = $excludeFromWizard;
}

public function getIconIdentifier(): string
{
return $this->iconIdentifier;
}

/**
* @param string $iconIdentifier
*/
public function setIconIdentifier(string $iconIdentifier): void
{
$this->iconIdentifier = $iconIdentifier;
}

public function getLabel(): string
{
return $this->label;
}

/**
* @param string $label
*/
public function setLabel(string $label): void
{
$this->label = $label;
}

public function getDescription(): string
{
return $this->description;
}

/**
* @param string $description
*/
public function setDescription(string $description): void
{
$this->description = $description;
}

/**
* @return string[]
*/
public function getWidgets(): array
{
return $this->widgets;
}

/**
* @param string[] $widgets
*/
public function setWidgets(array $widgets): void
{
$this->widgets = $widgets;
}
}
24 changes: 24 additions & 0 deletions Classes/Configuration/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,40 @@ public function getIdentifier(): string
return $this->identifier;
}

/**
* @param string $identifier
*/
public function setIdentifier(string $identifier): void
{
$this->identifier = $identifier;
}

public function getClassname(): string
{
return $this->className;
}

/**
* @param string $className
*/
public function setClassName(string $className): void
{
$this->className = $className;
}

/**
* @return string[]
*/
public function getGroups(): array
{
return $this->groups;
}

/**
* @param string[] $groups
*/
public function setGroups(array $groups): void
{
$this->groups = $groups;
}
}
16 changes: 16 additions & 0 deletions Classes/Configuration/WidgetGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,24 @@ public function getIdentifier(): string
return $this->identifier;
}

/**
* @param string $identifier
*/
public function setIdentifier(string $identifier): void
{
$this->identifier = $identifier;
}

public function getLabel(): string
{
return $this->label;
}

/**
* @param string $label
*/
public function setLabel(string $label): void
{
$this->label = $label;
}
}
62 changes: 47 additions & 15 deletions Classes/DashboardConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ class DashboardConfiguration implements SingletonInterface
*/
protected $packageManager;

/**
* Array of all registered dashboards
*
* @var array
*/
protected $dashboards = [];

protected $widgetGroups = [];

protected $widgets = [];

public function __construct(PackageManager $packageManager = null)
{
$this->packageManager = $packageManager ?? GeneralUtility::makeInstance(PackageManager::class);
Expand Down Expand Up @@ -98,20 +109,27 @@ public function getWidgetsGroups(): array
}

/**
* Resolve all dashboard objects which have been found in the filesystem.
* Resolve all dashboard objects which have been found in the filesystem and registered by the API
*
* @param bool $useCache
* @return Dashboard[]
*/
protected function resolveAllExistingDashboards(bool $useCache = true): array
{
$dashboards = [];
$dashboardConfiguration = $this->getAllDashboardConfigurationFromFiles($useCache);
foreach ($dashboardConfiguration['Dashboard']['Dashboards'] ?? [] as $configuration) {
$dashboards[$configuration['identifier']] = GeneralUtility::makeInstance(Dashboard::class, $configuration);
$this->dashboards[$configuration['identifier']] = GeneralUtility::makeInstance(Dashboard::class, $configuration);
}
$this->firstLevelCacheDashboards = $dashboards;
return $dashboards;
$this->firstLevelCacheDashboards = $this->dashboards;
return $this->dashboards;
}

/**
* @param Dashboard $dashboardConfiguration
*/
public function registerDashboard(Dashboard $dashboardConfiguration): void
{
$this->dashboards[$dashboardConfiguration->getIdentifier()] = $dashboardConfiguration;
}

/**
Expand All @@ -122,30 +140,44 @@ protected function resolveAllExistingDashboards(bool $useCache = true): array
*/
protected function resolveAllExistingWidgets(bool $useCache = true): array
{
$widgets = [];
$dashboardConfiguration = $this->getAllDashboardConfigurationFromFiles($useCache);
foreach ($dashboardConfiguration['Dashboard']['Widgets'] ?? [] as $configuration) {
$widgets[$configuration['identifier']] = GeneralUtility::makeInstance(Widget::class, $configuration);
$this->widgets[$configuration['identifier']] = GeneralUtility::makeInstance(Widget::class, $configuration);
}
$this->firstLevelCacheWidgets = $widgets;
return $widgets;
$this->firstLevelCacheWidgets = $this->widgets;
return $this->widgets;
}

/**
* Resolve all widget groups objects which have been found in the filesystem.
* @param Widget $widgetConfiguration
*/
public function registerWidget(Widget $widgetConfiguration): void
{
$this->widgets[$widgetConfiguration->getIdentifier()] = $widgetConfiguration;
}

/**
* Resolve all widget groups objects which have been found in the filesystem and registered by the API
*
* @param bool $useCache
* @return Widget[]
* @return WidgetGroup[]
*/
protected function resolveAllExistingWidgetGroups(bool $useCache = true): array
{
$widgetsGroups = [];
$dashboardConfiguration = $this->getAllDashboardConfigurationFromFiles($useCache);
foreach ($dashboardConfiguration['Dashboard']['WidgetGroups'] ?? [] as $configuration) {
$widgetsGroups[$configuration['identifier']] = GeneralUtility::makeInstance(WidgetGroup::class, $configuration);
$this->widgetGroups[$configuration['identifier']] = GeneralUtility::makeInstance(WidgetGroup::class, $configuration);
}
$this->firstLevelCacheWidgetGroups = $widgetsGroups;
return $widgetsGroups;
$this->firstLevelCacheWidgetGroups = $this->widgetGroups;
return $this->widgetGroups;
}

/**
* @param WidgetGroup $widgetGroupConfiguration
*/
public function registerWidgetGroup(WidgetGroup $widgetGroupConfiguration): void
{
$this->widgetGroups[$widgetGroupConfiguration->getIdentifier()] = $widgetGroupConfiguration;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Templates/Dashboard/Main.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ <h1>
<f:if condition="{availableDashboards -> f:count()} > 1">
<f:for each="{availableDashboards}" as="dashboardConfig" key="dashboardKey">
<f:be.link route="dashboard" parameters="{action: 'setActiveDashboard', currentDashboard: dashboardKey}" class="dashboardTab {f:if(condition: '{dashboardKey} == {currentDashboard}', then: 'dashboardTab--active')}">
<f:translate key="{dashboardConfig.label}"/>
<f:translate key="{dashboardConfig.label}" default="{dashboardConfig.label}"/>
</f:be.link>
</f:for>
</f:if>
Expand Down