Browse Source

move widget options into a Option class

Signed-off-by: Robin Appelman <robin@icewind.nl>
tags/v25.0.0beta7
Robin Appelman 1 year ago
parent
commit
d9e75f00b1
No account linked to committer's email address

+ 5
- 3
apps/dashboard/lib/Controller/DashboardApiController.php View File

@@ -30,10 +30,11 @@ use OCP\AppFramework\OCSController;
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;

@@ -106,6 +107,7 @@ class DashboardApiController extends OCSController {
$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(),
@@ -113,11 +115,11 @@ class DashboardApiController extends OCSController {
'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(),

+ 2
- 0
lib/composer/composer/autoload_classmap.php View File

@@ -197,11 +197,13 @@ return array(
'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',

+ 2
- 0
lib/composer/composer/autoload_static.php View File

@@ -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',

lib/public/Dashboard/IItemOptionWidget.php → lib/public/Dashboard/IOptionWidget.php View File

@@ -22,16 +22,16 @@ declare(strict_types=1);
*/
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;
}

+ 3
- 3
lib/public/Dashboard/Model/WidgetButton.php View File

@@ -29,9 +29,9 @@ namespace OCP\Dashboard\Model;
* @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;

+ 61
- 0
lib/public/Dashboard/Model/WidgetOptions.php View File

@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);
/**
* @copyright Copyright (c) 2022 Robin Appelman <robin@icewind.nl>
*
* @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;
}
}

Loading…
Cancel
Save