BuildingController is now inherited from AdminController, and set up the admin panel module.

This commit is contained in:
Relintai 2021-11-14 21:37:04 +01:00
parent a9080e05c3
commit 629ab517aa
4 changed files with 125 additions and 6 deletions

View File

@ -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<AdminSectionLinkInfo> *links) {
links->push_back(AdminSectionLinkInfo("Editor", ""));
}
bool BuildingController::admin_full_render() {
return false;
}
void BuildingController::admin_render_building_list(Request *request) {
Vector<Ref<Building> > 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> 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();
/*
<div class="back">
<a href="<?=site_url($link_back); ?>"><--- Back</a>
</div>
<div class="top_menu">
<a href="<?=site_url($link_new); ?>">Create New</a>
</div>
<div class="list_container">
<?php $i = 1; ?>
<?php foreach ($buildings as $row): ?>
<?php $link = $link_edit . $row['id']; ?>
<?php if (!($i % 2)): ?>
<div class="row">
<?php else: ?>
<div class="row second">
<?php endif; ?>
<div class="attr_box">
[<?=$row['id']; ?>]
</div>
<div class="attr_box">
[Rank: <?=$row['rank']; ?>]
</div>
<div class="attr_box">
[N Rank: <?=$row['next_rank']; ?>]
</div>
<div class="name">
<?=$row['name']; ?>
</div>
<div class="actionbox">
<a href="<?=site_url($link); ?>">Edit</a>
</div>
</div>
<?php $i++; ?>
<?php endforeach; ?>
</div>
*/
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");

View File

@ -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<AdminSectionLinkInfo> *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();

View File

@ -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();

View File

@ -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;
};