Skip to content

Commit

Permalink
move widget options into a Option class
Browse files Browse the repository at this point in the history
Signed-off-by: Robin Appelman <[email protected]>
  • Loading branch information
icewind1991 committed Sep 13, 2022
1 parent 2302ca1 commit 2600d0b
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 11 deletions.
8 changes: 5 additions & 3 deletions apps/dashboard/lib/Controller/DashboardApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
use OCP\AppFramework\Http\DataResponse;
use OCP\Dashboard\IButtonWidget;
use OCP\Dashboard\IIconWidget;
use OCP\Dashboard\IItemOptionWidget;
use OCP\Dashboard\IOptionWidget;
use OCP\Dashboard\IManager;
use OCP\Dashboard\IWidget;
use OCP\Dashboard\Model\WidgetButton;
use OCP\Dashboard\Model\WidgetOptions;
use OCP\IConfig;
use OCP\IRequest;

Expand Down Expand Up @@ -106,18 +107,19 @@ public function getWidgets(): DataResponse {
$widgets = $this->dashboardManager->getWidgets();

$items = array_map(function (IWidget $widget) {
$options = ($widget instanceof IOptionWidget) ? $widget->getWidgetOptions() : WidgetOptions::getDefault();
$data = [
'id' => $widget->getId(),
'title' => $widget->getTitle(),
'order' => $widget->getOrder(),
'icon_class' => $widget->getIconClass(),
'icon_url' => ($widget instanceof IIconWidget) ? $widget->getIconUrl() : '',
'widget_url' => $widget->getUrl(),
'item_icons_round' => ($widget instanceof IItemOptionWidget) ? $widget->getItemIconsRound() : false,
'item_icons_round' => $options->withRoundItemIcons(),
];
if ($widget instanceof IButtonWidget) {
$data += [
'buttons' => array_map(function(WidgetButton $button) {
'buttons' => array_map(function (WidgetButton $button) {
return [
'type' => $button->getType(),
'text' => $button->getText(),
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,13 @@
'OCP\\Dashboard\\IDashboardWidget' => $baseDir . '/lib/public/Dashboard/IDashboardWidget.php',
'OCP\\Dashboard\\IIconWidget' => $baseDir . '/lib/public/Dashboard/IIconWidget.php',
'OCP\\Dashboard\\IManager' => $baseDir . '/lib/public/Dashboard/IManager.php',
'OCP\\Dashboard\\IOptionWidget' => $baseDir . '/lib/public/Dashboard/IOptionWidget.php',
'OCP\\Dashboard\\IWidget' => $baseDir . '/lib/public/Dashboard/IWidget.php',
'OCP\\Dashboard\\Model\\IWidgetConfig' => $baseDir . '/lib/public/Dashboard/Model/IWidgetConfig.php',
'OCP\\Dashboard\\Model\\IWidgetRequest' => $baseDir . '/lib/public/Dashboard/Model/IWidgetRequest.php',
'OCP\\Dashboard\\Model\\WidgetButton' => $baseDir . '/lib/public/Dashboard/Model/WidgetButton.php',
'OCP\\Dashboard\\Model\\WidgetItem' => $baseDir . '/lib/public/Dashboard/Model/WidgetItem.php',
'OCP\\Dashboard\\Model\\WidgetOptions' => $baseDir . '/lib/public/Dashboard/Model/WidgetOptions.php',
'OCP\\Dashboard\\Model\\WidgetSetting' => $baseDir . '/lib/public/Dashboard/Model/WidgetSetting.php',
'OCP\\Dashboard\\Model\\WidgetSetup' => $baseDir . '/lib/public/Dashboard/Model/WidgetSetup.php',
'OCP\\Dashboard\\Model\\WidgetTemplate' => $baseDir . '/lib/public/Dashboard/Model/WidgetTemplate.php',
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,13 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Dashboard\\IDashboardWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IDashboardWidget.php',
'OCP\\Dashboard\\IIconWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IIconWidget.php',
'OCP\\Dashboard\\IManager' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IManager.php',
'OCP\\Dashboard\\IOptionWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IOptionWidget.php',
'OCP\\Dashboard\\IWidget' => __DIR__ . '/../../..' . '/lib/public/Dashboard/IWidget.php',
'OCP\\Dashboard\\Model\\IWidgetConfig' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/IWidgetConfig.php',
'OCP\\Dashboard\\Model\\IWidgetRequest' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/IWidgetRequest.php',
'OCP\\Dashboard\\Model\\WidgetButton' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetButton.php',
'OCP\\Dashboard\\Model\\WidgetItem' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetItem.php',
'OCP\\Dashboard\\Model\\WidgetOptions' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetOptions.php',
'OCP\\Dashboard\\Model\\WidgetSetting' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetSetting.php',
'OCP\\Dashboard\\Model\\WidgetSetup' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetSetup.php',
'OCP\\Dashboard\\Model\\WidgetTemplate' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetTemplate.php',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
*/
namespace OCP\Dashboard;

use OCP\Dashboard\Model\WidgetOptions;

/**
* Allow getting widget options
*
* @since 25.0.0
*/
interface IItemOptionWidget extends IWidget {
interface IOptionWidget extends IWidget {
/**
* Should the item icons be rendered round (or raw/square) by the clients?
*
* @return bool
* Get additional options for the widget
*/
public function getItemIconsRound(): bool;
public function getWidgetOptions(): WidgetOptions;
}
6 changes: 3 additions & 3 deletions lib/public/Dashboard/Model/WidgetButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
* @since 25.0.0
*/
class WidgetButton {
const TYPE_NEW = 'new';
const TYPE_MORE = 'more';
const TYPE_SETUP = 'setup';
public const TYPE_NEW = 'new';
public const TYPE_MORE = 'more';
public const TYPE_SETUP = 'setup';

private string $type;
private string $link;
Expand Down
61 changes: 61 additions & 0 deletions lib/public/Dashboard/Model/WidgetOptions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Robin Appelman <[email protected]>
*
* @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\Model;

/**
* Option for displaying a widget
*
* @since 25.0.0
*/
class WidgetOptions {
private bool $roundItemIcons;

/**
* @param bool $roundItemIcons
* @since 25.0.0
*/
public function __construct(bool $roundItemIcons) {
$this->roundItemIcons = $roundItemIcons;
}

/**
* Get the default set of options
*
* @return WidgetOptions
* @since 25.0.0
*/
public static function getDefault(): WidgetOptions {
return new WidgetOptions(false);
}

/**
* Whether the clients should render icons for widget items as round icons
*
* @return bool
* @since 25.0.0
*/
public function withRoundItemIcons(): bool {
return $this->roundItemIcons;
}
}

0 comments on commit 2600d0b

Please sign in to comment.