From 4d2556d4cf014edfc5c609dfff5c52e963979b93 Mon Sep 17 00:00:00 2001 From: Ferdinand Thiessen Date: Wed, 28 Aug 2024 13:15:56 +0200 Subject: 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 --- .../Http/Template/PublicTemplateResponse.php | 47 +++++++++++++++------- 1 file changed, 33 insertions(+), 14 deletions(-) (limited to 'lib/public/AppFramework/Http/Template/PublicTemplateResponse.php') 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(); - } } -- cgit v1.2.3