From 127219fe342c8d6cc2a10ab5ba78d9519c052105 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 13 Jan 2022 22:58:59 +0100 Subject: [PATCH] Added more helper methods to WebNode. Also a render_menu() virtual. --- core/http/web_node.cpp | 22 +++++++++++++++++++++- core/http/web_node.h | 3 +++ modules/admin_panel/admin_panel.cpp | 1 + 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/core/http/web_node.cpp b/core/http/web_node.cpp index 5f1826b..6c7488d 100644 --- a/core/http/web_node.cpp +++ b/core/http/web_node.cpp @@ -4,8 +4,8 @@ #include "http_enums.h" #include "request.h" -#include "core/settings/settings.h" #include "core/http/web_server.h" +#include "core/settings/settings.h" #ifdef DATABASES_ENABLED #include "core/database/database.h" @@ -85,6 +85,16 @@ void WebNode::handle_error_send_request(Request *request, const int error_code) request->send(); } +void WebNode::render_menu(Request *request) { + WebNode *root = get_root(); + + if (root) { + root->_render_menu(request); + } +} +void WebNode::_render_menu(Request *request) { +} + void WebNode::create_validators() { } @@ -105,6 +115,16 @@ WebServer *WebNode::get_server() { return Object::cast_to(get_tree()); } +WebNode *WebNode::get_root() { + WebServer *s = get_server(); + + if (!s) { + return nullptr; + } + + return s->get_web_root(); +} + WebNode::WebNode() : Node() { // should look this up in parents when parented (and node parenting is implemented) diff --git a/core/http/web_node.h b/core/http/web_node.h index 8fde318..bfee9ca 100644 --- a/core/http/web_node.h +++ b/core/http/web_node.h @@ -35,6 +35,8 @@ public: virtual void handle_request_main(Request *request); virtual void _handle_request_main(Request *request); virtual void handle_error_send_request(Request *request, const int error_code); + virtual void render_menu(Request *request); + virtual void _render_menu(Request *request); virtual void create_validators(); @@ -44,6 +46,7 @@ public: virtual void create_default_entries(); WebServer *get_server(); + WebNode *get_root(); WebNode(); ~WebNode(); diff --git a/modules/admin_panel/admin_panel.cpp b/modules/admin_panel/admin_panel.cpp index 4c874da..226387e 100644 --- a/modules/admin_panel/admin_panel.cpp +++ b/modules/admin_panel/admin_panel.cpp @@ -32,6 +32,7 @@ void AdminPanel::handle_request_main(Request *request) { return; } + //render_menu(request); render_headers(request); render_segment_body_top(request); render_controller_panel(request, c);