mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 17:23:59 -04:00
change widget button api to support multiple button types
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
79adca6b8b
commit
a3912e264a
5 changed files with 92 additions and 22 deletions
|
|
@ -32,6 +32,7 @@ use OCP\Dashboard\IButtonWidget;
|
|||
use OCP\Dashboard\IIconWidget;
|
||||
use OCP\Dashboard\IManager;
|
||||
use OCP\Dashboard\IWidget;
|
||||
use OCP\Dashboard\Model\WidgetButton;
|
||||
use OCP\IConfig;
|
||||
use OCP\IRequest;
|
||||
|
||||
|
|
@ -114,11 +115,13 @@ class DashboardApiController extends OCSController {
|
|||
];
|
||||
if ($widget instanceof IButtonWidget) {
|
||||
$data += [
|
||||
'button' => [
|
||||
'text' => $widget->getButtonText(),
|
||||
'icon_url' => $widget->getButtonIconUrl(),
|
||||
'url' => $widget->getUrl(),
|
||||
],
|
||||
'buttons' => array_map(function(WidgetButton $button) {
|
||||
return [
|
||||
'type' => $button->getType(),
|
||||
'text' => $button->getText(),
|
||||
'link' => $button->getLink(),
|
||||
];
|
||||
}, $widget->getWidgetButtons($this->userId)),
|
||||
];
|
||||
}
|
||||
return $data;
|
||||
|
|
|
|||
|
|
@ -200,6 +200,7 @@ return array(
|
|||
'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\\WidgetSetting' => $baseDir . '/lib/public/Dashboard/Model/WidgetSetting.php',
|
||||
'OCP\\Dashboard\\Model\\WidgetSetup' => $baseDir . '/lib/public/Dashboard/Model/WidgetSetup.php',
|
||||
|
|
|
|||
|
|
@ -233,6 +233,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
|
|||
'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\\WidgetSetting' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetSetting.php',
|
||||
'OCP\\Dashboard\\Model\\WidgetSetup' => __DIR__ . '/../../..' . '/lib/public/Dashboard/Model/WidgetSetup.php',
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@ declare(strict_types=1);
|
|||
*/
|
||||
namespace OCP\Dashboard;
|
||||
|
||||
use OCP\Dashboard\Model\WidgetButton;
|
||||
|
||||
/**
|
||||
* Adds a button to the dashboard api representation
|
||||
*
|
||||
|
|
@ -29,23 +31,11 @@ namespace OCP\Dashboard;
|
|||
*/
|
||||
interface IButtonWidget extends IWidget {
|
||||
/**
|
||||
* Get the absolute url for the button target
|
||||
* Get the buttons to show on the widget
|
||||
*
|
||||
* @return string
|
||||
* @param string $userId
|
||||
* @return WidgetButton[]
|
||||
* @since 25.0.0
|
||||
*/
|
||||
public function getButtonUrl(): string;
|
||||
|
||||
/**
|
||||
* Get the absolute url for the button icon
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getButtonIconUrl(): ?string;
|
||||
|
||||
/**
|
||||
* Get the text to show in the button
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getButtonText(): string;
|
||||
public function getWidgetButtons(string $userId): array;
|
||||
}
|
||||
|
|
|
|||
75
lib/public/Dashboard/Model/WidgetButton.php
Normal file
75
lib/public/Dashboard/Model/WidgetButton.php
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
<?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;
|
||||
|
||||
/**
|
||||
* Button for a dashboard widget
|
||||
*
|
||||
* @since 25.0.0
|
||||
*/
|
||||
class WidgetButton {
|
||||
const TYPE_NEW = 'new';
|
||||
const TYPE_MORE = 'more';
|
||||
const TYPE_SETUP = 'setup';
|
||||
|
||||
private string $type;
|
||||
private string $link;
|
||||
private string $text;
|
||||
|
||||
public function __construct(string $type, string $link, string $text) {
|
||||
$this->type = $type;
|
||||
$this->link = $link;
|
||||
$this->text = $text;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the button type, either "new", "more" or "setup"
|
||||
*
|
||||
* @return string
|
||||
* @since 25.0.0
|
||||
*/
|
||||
public function getType(): string {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the absolute url the buttons links to
|
||||
*
|
||||
* @return string
|
||||
* @since 25.0.0
|
||||
*/
|
||||
public function getLink(): string {
|
||||
return $this->link;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the translated text for the button
|
||||
*
|
||||
* @return string
|
||||
* @since 25.0.0
|
||||
*/
|
||||
public function getText(): string {
|
||||
return $this->text;
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue