From 629ab517aa92b9c1625f399b9f79349197a7f171 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 14 Nov 2021 21:37:04 +0100 Subject: [PATCH] BuildingController is now inherited from AdminController, and set up the admin panel module. --- app/buildings/building_controller.cpp | 97 ++++++++++++++++++++++++++- app/buildings/building_controller.h | 17 +++-- app/mourne_application.cpp | 11 +++ app/mourne_application.h | 6 ++ 4 files changed, 125 insertions(+), 6 deletions(-) diff --git a/app/buildings/building_controller.cpp b/app/buildings/building_controller.cpp index 2b17025..2020421 100644 --- a/app/buildings/building_controller.cpp +++ b/app/buildings/building_controller.cpp @@ -7,11 +7,106 @@ #include "core/http/request.h" #include "core/http/session_manager.h" +#include "building_model.h" #include "building_model.h" void BuildingController::handle_request_default(Request *request) { } +void BuildingController::admin_handle_request_main(Request *request) { + String seg = request->get_current_path_segment(); + + if (seg == "") { + admin_render_building_list(request); + return; + } + + request->send_error(404); +} +String BuildingController::admin_get_section_name() { + return "Building Editor"; +} +void BuildingController::admin_add_section_links(Vector *links) { + links->push_back(AdminSectionLinkInfo("Editor", "")); +} +bool BuildingController::admin_full_render() { + return false; +} + +void BuildingController::admin_render_building_list(Request *request) { + Vector > buildings = BuildingModel::get_singleton()->get_all(); + + HTMLBuilder b; + + b.div()->cls("back")->f()->a()->href(request->get_url_root_parent())->f()->w("<--- Back")->ca()->cdiv(); + b.br(); + b.h4()->f()->w("Building Editor")->ch4(); + b.br(); + b.div()->cls("top_menu")->f()->a()->href(request->get_url_root("new"))->f()->w("Create New")->ca()->cdiv(); + b.br(); + + b.div()->cls("list_container"); + + for (int i = 0; i < buildings.size(); ++i) { + Ref building = buildings[i]; + + if (!building.is_valid()) { + continue; + } + + b.div()->cls("row"); + { + //b.a()->href(request->get_url_root("permission_editor/") + String::num(r->id)); + + + } + b.cdiv(); + } + + b.cdiv(); + +/* + + +
+ + + + +
+ +
+ +
+ [] +
+
+ [Rank: ] +
+
+ [N Rank: ] +
+
+ +
+
+ Edit +
+
+ + +
+*/ + + + + request->body += b.result; +} + void BuildingController::migrate() { BuildingModel::get_singleton()->migrate(); } @@ -24,7 +119,7 @@ BuildingController *BuildingController::get_singleton() { } BuildingController::BuildingController() : - Object() { + AdminController() { if (_self) { printf("BuildingController::BuildingController(): Error! self is not null!/n"); diff --git a/app/buildings/building_controller.h b/app/buildings/building_controller.h index 30e2481..fd2b704 100644 --- a/app/buildings/building_controller.h +++ b/app/buildings/building_controller.h @@ -4,22 +4,29 @@ #include "core/string.h" #include "core/containers/vector.h" -#include "core/object.h" +#include "modules/admin_panel/admin_controller.h" #include "building.h" class Request; class FormValidator; -class BuildingController : public Object { - RCPP_OBJECT(BuildingController, Object); +class BuildingController : public AdminController { + RCPP_OBJECT(BuildingController, AdminController); public: + void handle_request_default(Request *request); + + void admin_handle_request_main(Request *request); + String admin_get_section_name(); + void admin_add_section_links(Vector *links); + bool admin_full_render(); + + void admin_render_building_list(Request *request); + void migrate(); virtual void add_default_data(); - virtual void handle_request_default(Request *request); - static BuildingController *get_singleton(); BuildingController(); diff --git a/app/mourne_application.cpp b/app/mourne_application.cpp index fbab8a8..9847b99 100644 --- a/app/mourne_application.cpp +++ b/app/mourne_application.cpp @@ -16,6 +16,7 @@ #include "modules/users/user.h" #include "modules/users/user_controller.h" +#include "modules/admin_panel/admin_panel.h" #include "buildings/building_initializer.h" #include "village/village_initializer.h" @@ -220,12 +221,17 @@ void MourneApplication::user_page_func(Object *instance, Request *request) { UserController::get_singleton()->handle_request_default(request); } +void MourneApplication::admin_page_func(Object *instance, Request *request) { + AdminPanel::get_singleton()->handle_request_main(request); +} + void MourneApplication::setup_routes() { DWebApplication::setup_routes(); index_func = HandlerInstance(index); main_route_map["village"] = HandlerInstance(village_page_func); main_route_map["user"] = HandlerInstance(user_page_func); + main_route_map["admin"] = HandlerInstance(admin_page_func); } void MourneApplication::setup_middleware() { @@ -276,10 +282,15 @@ MourneApplication::MourneApplication() : BuildingInitializer::allocate_all(); VillageInitializer::allocate_all(); + _admin_panel = new AdminPanel(); + _admin_panel->register_admin_controller("buildings", BuildingController::get_singleton()); + + compile_menu(); } MourneApplication::~MourneApplication() { + delete _admin_panel; VillageInitializer::free_all(); BuildingInitializer::free_all(); diff --git a/app/mourne_application.h b/app/mourne_application.h index d32917c..481f3a6 100644 --- a/app/mourne_application.h +++ b/app/mourne_application.h @@ -10,6 +10,8 @@ #include "modules/paged_article/paged_article.h" #include "modules/paged_list/paged_list.h" +class AdminPanel; + #define ENSURE_LOGIN(request) \ if (!is_logged_in(request)) { \ request->send_redirect("/user/login"); \ @@ -46,6 +48,8 @@ public: static void village_page_func(Object *instance, Request *request); static void user_page_func(Object *instance, Request *request); + static void admin_page_func(Object *instance, Request *request); + virtual void setup_routes(); virtual void setup_middleware(); @@ -57,6 +61,8 @@ public: MourneApplication(); ~MourneApplication(); + AdminPanel *_admin_panel; + static std::string menu_head; static std::string footer; };