aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-08-28 13:15:56 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-09-03 16:07:49 +0200
commit4d2556d4cf014edfc5c609dfff5c52e963979b93 (patch)
tree7a4f3e16a6bacdd863ba40f76a8884206064a0e9 /lib
parent7b6c78c81d4bd5e280f370b95ca2746cd8693882 (diff)
downloadnextcloud-server-4d2556d4cf014edfc5c609dfff5c52e963979b93.tar.gz
nextcloud-server-4d2556d4cf014edfc5c609dfff5c52e963979b93.zip
refactor(IMenuAction): Make public menu actions use the new Vue UI
This removes custom rendering code an replaces it with the declarative menu actions. Also adjust the template to allow the Vue UI to mount. Custom entries still are possible. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/public/AppFramework/Http/Template/ExternalShareMenuAction.php19
-rw-r--r--lib/public/AppFramework/Http/Template/IMenuAction.php7
-rw-r--r--lib/public/AppFramework/Http/Template/LinkMenuAction.php22
-rw-r--r--lib/public/AppFramework/Http/Template/PublicTemplateResponse.php47
-rw-r--r--lib/public/AppFramework/Http/Template/SimpleMenuAction.php28
5 files changed, 62 insertions, 61 deletions
diff --git a/lib/public/AppFramework/Http/Template/ExternalShareMenuAction.php b/lib/public/AppFramework/Http/Template/ExternalShareMenuAction.php
index cddf5d19171..a79ee4bbdfc 100644
--- a/lib/public/AppFramework/Http/Template/ExternalShareMenuAction.php
+++ b/lib/public/AppFramework/Http/Template/ExternalShareMenuAction.php
@@ -5,8 +5,6 @@
*/
namespace OCP\AppFramework\Http\Template;
-use OCP\Util;
-
/**
* Class LinkMenuAction
*
@@ -38,21 +36,4 @@ class ExternalShareMenuAction extends SimpleMenuAction {
$this->displayname = $displayname;
$this->shareName = $shareName;
}
-
- /**
- * @since 14.0.0
- */
- public function render(): string {
- return '<li>' .
- ' <button id="save-external-share" class="icon ' . Util::sanitizeHTML($this->getIcon()) . '" data-protected="false" data-owner-display-name="' . Util::sanitizeHTML($this->displayname) . '" data-owner="' . Util::sanitizeHTML($this->owner) . '" data-name="' . Util::sanitizeHTML($this->shareName) . '">' . Util::sanitizeHTML($this->getLabel()) . '</button>' .
- '</li>' .
- '<li id="external-share-menu-item" class="hidden">' .
- ' <span class="menuitem">' .
- ' <form class="save-form" action="#">' .
- ' <input type="text" id="remote_address" placeholder="user@yourNextcloud.org">' .
- ' <input type="submit" value=" " id="save-button-confirm" class="icon-confirm" disabled="disabled"></button>' .
- ' </form>' .
- ' </span>' .
- '</li>';
- }
}
diff --git a/lib/public/AppFramework/Http/Template/IMenuAction.php b/lib/public/AppFramework/Http/Template/IMenuAction.php
index d3962300923..50b346add86 100644
--- a/lib/public/AppFramework/Http/Template/IMenuAction.php
+++ b/lib/public/AppFramework/Http/Template/IMenuAction.php
@@ -18,12 +18,16 @@ interface IMenuAction {
public function getId(): string;
/**
+ * The translated label of the menu item.
+ *
* @since 14.0.0
* @return string
*/
public function getLabel(): string;
/**
+ * The link this menu item points to.
+ *
* @since 14.0.0
* @return string
*/
@@ -36,6 +40,9 @@ interface IMenuAction {
public function getPriority(): int;
/**
+ * Custom render function.
+ * The returned HTML will be wrapped within a listitem element (`<li>...</li>`).
+ *
* @since 14.0.0
* @return string
*/
diff --git a/lib/public/AppFramework/Http/Template/LinkMenuAction.php b/lib/public/AppFramework/Http/Template/LinkMenuAction.php
index 69e835f6b82..6ae1fcdf13b 100644
--- a/lib/public/AppFramework/Http/Template/LinkMenuAction.php
+++ b/lib/public/AppFramework/Http/Template/LinkMenuAction.php
@@ -5,8 +5,6 @@
*/
namespace OCP\AppFramework\Http\Template;
-use OCP\Util;
-
/**
* Class LinkMenuAction
*
@@ -22,24 +20,6 @@ class LinkMenuAction extends SimpleMenuAction {
* @since 14.0.0
*/
public function __construct(string $label, string $icon, string $link) {
- parent::__construct('directLink-container', $label, $icon, $link);
- }
-
- /**
- * @return string
- * @since 14.0.0
- */
- public function render(): string {
- return '<li>' .
- '<a id="directLink-container">' .
- '<span class="icon ' . Util::sanitizeHTML($this->getIcon()) . '"></span>' .
- '<label for="directLink">' . Util::sanitizeHTML($this->getLabel()) . '</label>' .
- '</a>' .
- '</li>' .
- '<li>' .
- '<span class="menuitem">' .
- '<input id="directLink" type="text" readonly="" value="' . Util::sanitizeHTML($this->getLink()) . '">' .
- '</span>' .
- '</li>';
+ parent::__construct('directLink', $label, $icon, $link);
}
}
diff --git a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
index c12cf087755..b89c84f297f 100644
--- a/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
+++ b/lib/public/AppFramework/Http/Template/PublicTemplateResponse.php
@@ -8,6 +8,7 @@ namespace OCP\AppFramework\Http\Template;
use InvalidArgumentException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\TemplateResponse;
+use OCP\IInitialStateService;
/**
* Class PublicTemplateResponse
@@ -20,6 +21,7 @@ use OCP\AppFramework\Http\TemplateResponse;
class PublicTemplateResponse extends TemplateResponse {
private $headerTitle = '';
private $headerDetails = '';
+ /** @var IMenuAction[] */
private $headerActions = [];
private $footerVisible = true;
@@ -33,9 +35,38 @@ class PublicTemplateResponse extends TemplateResponse {
* @param H $headers
* @since 14.0.0
*/
- public function __construct(string $appName, string $templateName, array $params = [], $status = Http::STATUS_OK, array $headers = []) {
+ public function __construct(
+ string $appName,
+ string $templateName,
+ array $params = [],
+ $status = Http::STATUS_OK,
+ array $headers = [],
+ ) {
parent::__construct($appName, $templateName, $params, 'public', $status, $headers);
- \OC_Util::addScript('core', 'public/publicpage');
+ \OCP\Util::addScript('core', 'public-page-menu');
+
+ $state = \OCP\Server::get(IInitialStateService::class);
+ $state->provideLazyInitialState('core', 'public-page-menu', function () {
+ $response = [];
+ foreach ($this->headerActions as $action) {
+ // First try in it is a custom action that provides rendered HTML
+ $rendered = $action->render();
+ if ($rendered === '') {
+ // If simple action, add the response data
+ if ($action instanceof SimpleMenuAction) {
+ $response[] = $action->getData();
+ }
+ } else {
+ // custom action so add the rendered output
+ $response[] = [
+ 'id' => $action->getId(),
+ 'label' => $action->getLabel(),
+ 'html' => $rendered,
+ ];
+ }
+ }
+ return $response;
+ });
}
/**
@@ -128,16 +159,4 @@ class PublicTemplateResponse extends TemplateResponse {
public function getFooterVisible(): bool {
return $this->footerVisible;
}
-
- /**
- * @return string
- * @since 14.0.0
- */
- public function render(): string {
- $params = array_merge($this->getParams(), [
- 'template' => $this,
- ]);
- $this->setParams($params);
- return parent::render();
- }
}
diff --git a/lib/public/AppFramework/Http/Template/SimpleMenuAction.php b/lib/public/AppFramework/Http/Template/SimpleMenuAction.php
index 2bb60975f26..4cbbd5302d7 100644
--- a/lib/public/AppFramework/Http/Template/SimpleMenuAction.php
+++ b/lib/public/AppFramework/Http/Template/SimpleMenuAction.php
@@ -5,8 +5,6 @@
*/
namespace OCP\AppFramework\Http\Template;
-use OCP\Util;
-
/**
* Class SimpleMenuAction
*
@@ -68,6 +66,8 @@ class SimpleMenuAction implements IMenuAction {
}
/**
+ * The icon CSS class to use.
+ *
* @return string
* @since 14.0.0
*/
@@ -92,14 +92,28 @@ class SimpleMenuAction implements IMenuAction {
}
/**
+ * Custom render function.
+ * The returned HTML must be wrapped within a listitem (`<li>...</li>`).
+ * * If an empty string is returned, the default design is used (based on the label and link specified).
* @return string
* @since 14.0.0
*/
public function render(): string {
- $detailContent = ($this->detail !== '') ? '&nbsp;<span class="download-size">(' . Util::sanitizeHTML($this->detail) . ')</span>' : '';
- return sprintf(
- '<li id="%s"><a href="%s"><span class="icon %s"></span>%s %s</a></li>',
- Util::sanitizeHTML($this->id), Util::sanitizeHTML($this->link), Util::sanitizeHTML($this->icon), Util::sanitizeHTML($this->label), $detailContent
- );
+ return '';
+ }
+
+ /**
+ * Return JSON data to let the frontend render the menu entry.
+ * @return array{id: string, label: string, href: string, icon: string, details: string|null}
+ * @since 31.0.0
+ */
+ public function getData(): array {
+ return [
+ 'id' => $this->id,
+ 'label' => $this->label,
+ 'href' => $this->link,
+ 'icon' => $this->icon,
+ 'details' => $this->detail,
+ ];
}
}