diff --git a/app/assignments/assignment_controller.cpp b/app/assignments/assignment_controller.cpp deleted file mode 100644 index 45ba2ac..0000000 --- a/app/assignments/assignment_controller.cpp +++ /dev/null @@ -1,199 +0,0 @@ -#include "assignment_controller.h" - -#include "web/html/form_validator.h" -#include "web/html/html_builder.h" -#include "web/http/cookie.h" -#include "web/http/http_enums.h" -#include "web/http/http_session.h" -#include "web/http/request.h" -#include "web/http/session_manager.h" - -#include "assignment_model.h" - -#include "../html_macros.h" - -void AssignmentController::handle_request_default(Request *request) { -} - -void AssignmentController::admin_handle_request_main(Request *request) { - String seg = request->get_current_path_segment(); - - if (seg == "") { - admin_render_assignment_list(request); - return; - } else if (seg == "new") { - request->push_path(); - Ref b; - b.instance(); - - admin_render_assignment(request, b); - return; - } else if (seg == "edit") { - request->push_path(); - - String seg_assignment_id = request->get_current_path_segment(); - - if (!seg_assignment_id.is_int()) { - request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND); - return; - } - - int bid = seg_assignment_id.to_int(); - - Ref b = AssignmentModel::get_singleton()->get_assignment(bid); - - if (!b.is_valid()) { - request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND); - return; - } - - admin_render_assignment(request, b); - return; - } - - request->send_error(404); -} -String AssignmentController::admin_get_section_name() { - return "Assignments"; -} -void AssignmentController::admin_add_section_links(Vector *links) { - links->push_back(AdminSectionLinkInfo("- Assignment Editor", "")); -} -bool AssignmentController::admin_full_render() { - return false; -} - -void AssignmentController::admin_render_assignment_list(Request *request) { - Vector > assignments = AssignmentModel::get_singleton()->get_all(); - - HTMLBuilder b; - - b.div("back")->fa(request->get_url_root_parent(), "<--- Back")->cdiv(); - b.br(); - b.fdiv("Assignment Editor", "top_menu"); - b.br(); - b.div("top_menu")->fa(request->get_url_root("new"), "Create New")->cdiv(); - b.br(); - - b.div("list_container"); - - for (int i = 0; i < assignments.size(); ++i) { - Ref assignment = assignments[i]; - - if (!assignment.is_valid()) { - continue; - } - - if (i % 2 == 0) { - b.div("row"); - } else { - b.div("row second"); - } - { - b.fdiv(String::num(assignment->id), "attr_box"); - b.fdiv(assignment->description, "name"); - - b.div("actionbox")->fa(request->get_url_root("edit/" + String::num(assignment->id)), "Edit")->cdiv(); - } - b.cdiv(); - } - - b.cdiv(); - - request->body += b.result; -} - -void AssignmentController::admin_render_assignment(Request *request, Ref assignment) { - if (!assignment.is_valid()) { - RLOG_ERR("admin_render_assignment: !assignment.is_valid()\n"); - request->send_error(HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR); - return; - } - - Vector > assignments = AssignmentModel::get_singleton()->get_all(); - - HTMLBuilder b; - - b.div("back")->fa(request->get_url_root_parent(), "<--- Back")->cdiv(); - b.br(); - b.fdiv("Assignment Editor", "top_menu"); - b.br(); - - b.form_post(request->get_url_root()); - - bool show_post = false; //request->get_method() == HTTP_METHOD_POST && validation errors; - - //Todo make it a dropdown - ADMIN_EDIT_INPUT_TEXT("Unitid:", "unitid", show_post, String::num(assignment->unitid), request->get_parameter("unitid")); - ADMIN_EDIT_INPUT_TEXT("max:", "max", show_post, String::num(assignment->max), request->get_parameter("max")); - ADMIN_EDIT_INPUT_TEXT("bonus_per_assigned:", "bonus_per_assigned", show_post, String::num(assignment->bonus_per_assigned), request->get_parameter("bonus_per_assigned")); - ADMIN_EDIT_INPUT_TEXT("spellid:", "spellid", show_post, String::num(assignment->spellid), request->get_parameter("spellid")); - //Todo make it a dropdown - ADMIN_EDIT_INPUT_TEXT("req_tech:", "req_tech", show_post, String::num(assignment->req_tech), request->get_parameter("req_tech")); - - ADMIN_EDIT_LINE_SPACER(); - - ADMIN_EDIT_INPUT_TEXT("Mod Max Food:", "mod_max_food", show_post, String::num(assignment->mod_max_food), request->get_parameter("mod_max_food")); - ADMIN_EDIT_INPUT_TEXT("Mod Max Wood:", "mod_max_wood", show_post, String::num(assignment->mod_max_wood), request->get_parameter("mod_max_wood")); - ADMIN_EDIT_INPUT_TEXT("Mod Max Stone:", "mod_max_stone", show_post, String::num(assignment->mod_max_stone), request->get_parameter("mod_max_stone")); - ADMIN_EDIT_INPUT_TEXT("Mod Max Iron:", "mod_max_iron", show_post, String::num(assignment->mod_max_iron), request->get_parameter("mod_max_iron")); - ADMIN_EDIT_INPUT_TEXT("Mod Max Mana:", "mod_max_mana", show_post, String::num(assignment->mod_max_mana), request->get_parameter("mod_max_mana")); - - ADMIN_EDIT_LINE_SPACER(); - - ADMIN_EDIT_INPUT_TEXT("Mod Rate Food:", "mod_rate_food", show_post, String::num(assignment->mod_rate_food), request->get_parameter("mod_rate_food")); - ADMIN_EDIT_INPUT_TEXT("Mod Rate Wood:", "mod_rate_wood", show_post, String::num(assignment->mod_rate_wood), request->get_parameter("mod_rate_wood")); - ADMIN_EDIT_INPUT_TEXT("Mod Rate Stone:", "mod_rate_stone", show_post, String::num(assignment->mod_rate_stone), request->get_parameter("mod_rate_stone")); - ADMIN_EDIT_INPUT_TEXT("Mod Rate Iron:", "mod_rate_iron", show_post, String::num(assignment->mod_rate_iron), request->get_parameter("mod_rate_iron")); - ADMIN_EDIT_INPUT_TEXT("Mod Rate Mana:", "mod_rate_mana", show_post, String::num(assignment->mod_rate_mana), request->get_parameter("mod_rate_mana")); - - ADMIN_EDIT_LINE_SPACER(); - - ADMIN_EDIT_INPUT_TEXT("Mod Percent Food:", "mod_percent_food", show_post, String::num(assignment->mod_percent_food), request->get_parameter("mod_percent_food")); - ADMIN_EDIT_INPUT_TEXT("Mod Percent Wood:", "mod_percent_wood", show_post, String::num(assignment->mod_percent_wood), request->get_parameter("mod_percent_wood")); - ADMIN_EDIT_INPUT_TEXT("Mod Percent Stone:", "mod_percent_stone", show_post, String::num(assignment->mod_percent_stone), request->get_parameter("mod_percent_stone")); - ADMIN_EDIT_INPUT_TEXT("Mod Percent Iron:", "mod_percent_iron", show_post, String::num(assignment->mod_percent_iron), request->get_parameter("mod_percent_iron")); - ADMIN_EDIT_INPUT_TEXT("Mod Percent Mana:", "mod_percent_mana", show_post, String::num(assignment->mod_percent_mana), request->get_parameter("mod_percent_mana")); - - ADMIN_EDIT_LINE_SPACER(); - - ADMIN_EDIT_INPUT_TEXTAREA("Description:", "description", show_post, assignment->description, request->get_parameter("description")); - - b.div("edit_submit")->input_submit("Save", "submit")->cdiv(); - - b.cform(); - - request->body += b.result; -} - -void AssignmentController::create_table() { - AssignmentModel::get_singleton()->create_table(); -} -void AssignmentController::drop_table() { - AssignmentModel::get_singleton()->drop_table(); -} -void AssignmentController::create_default_entries() { - AssignmentModel::get_singleton()->create_default_entries(); -} - -AssignmentController *AssignmentController::get_singleton() { - return _self; -} - -AssignmentController::AssignmentController() : - AdminNode() { - - if (_self) { - printf("AssignmentController::AssignmentController(): Error! self is not null!/n"); - } - - _self = this; -} - -AssignmentController::~AssignmentController() { - if (_self == this) { - _self = nullptr; - } -} - -AssignmentController *AssignmentController::_self = nullptr; diff --git a/app/assignments/assignment_initializer.cpp b/app/assignments/assignment_initializer.cpp deleted file mode 100644 index 81142c0..0000000 --- a/app/assignments/assignment_initializer.cpp +++ /dev/null @@ -1,37 +0,0 @@ -#include "assignment_initializer.h" - -void AssignmentInitializer::allocate_controller() { - ERR_FAIL_COND(_controller); - - _controller = new AssignmentController(); -} -void AssignmentInitializer::free_controller() { - if (_controller) { - delete _controller; - _controller = nullptr; - } -} - -void AssignmentInitializer::allocate_model() { - ERR_FAIL_COND(_model); - - _model = new AssignmentModel(); -} -void AssignmentInitializer::free_model() { - if (_model) { - delete _model; - _model = nullptr; - } -} - -void AssignmentInitializer::allocate_all() { - allocate_model(); - allocate_controller(); -} -void AssignmentInitializer::free_all() { - free_controller(); - free_model(); -} - -AssignmentController *AssignmentInitializer::_controller = nullptr; -AssignmentModel *AssignmentInitializer::_model = nullptr; \ No newline at end of file diff --git a/app/assignments/assignment_initializer.h b/app/assignments/assignment_initializer.h deleted file mode 100644 index 60e7207..0000000 --- a/app/assignments/assignment_initializer.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ASSIGNMENT_INITIALIZER_H -#define ASSIGNMENT_INITIALIZER_H - -#include "assignment_model.h" -#include "assignment_controller.h" - -class AssignmentInitializer { -public: - static void allocate_controller(); - static void free_controller(); - - static void allocate_model(); - static void free_model(); - - static void allocate_all(); - static void free_all(); - -protected: - static AssignmentController *_controller; - static AssignmentModel *_model; -}; - -#endif \ No newline at end of file diff --git a/app/assignments/assignment_model.h b/app/assignments/assignment_model.h deleted file mode 100644 index 308b609..0000000 --- a/app/assignments/assignment_model.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef ASSIGNMENT_MODEL_H -#define ASSIGNMENT_MODEL_H - -#include "core/string.h" -#include "core/containers/vector.h" - -#include "core/object.h" -#include "core/reference.h" - -class Assignment; -class QueryResult; - -class AssignmentModel : public Object { - RCPP_OBJECT(AssignmentModel, Object); - -public: - virtual Ref get_assignment(const int id); - virtual Vector > get_all(); - virtual void save_assignment(Ref &assignment); - - virtual void parse_row(Ref &result, Ref &assignment); - - void create_table(); - void drop_table(); - void create_default_entries(); - - static AssignmentModel *get_singleton(); - - AssignmentModel(); - ~AssignmentModel(); - -protected: - static AssignmentModel *_self; -}; - -#endif \ No newline at end of file diff --git a/app/assignments/assignment_model.cpp b/app/assignments/assignment_node.cpp similarity index 53% rename from app/assignments/assignment_model.cpp rename to app/assignments/assignment_node.cpp index 11d9845..770450f 100644 --- a/app/assignments/assignment_model.cpp +++ b/app/assignments/assignment_node.cpp @@ -1,4 +1,12 @@ -#include "assignment_model.h" +#include "assignment_node.h" + +#include "web/html/form_validator.h" +#include "web/html/html_builder.h" +#include "web/http/cookie.h" +#include "web/http/http_enums.h" +#include "web/http/http_session.h" +#include "web/http/request.h" +#include "web/http/session_manager.h" #include "database/database.h" #include "database/database_manager.h" @@ -8,19 +16,176 @@ #include "crypto/hash/sha256.h" -#include "assignment.h" +#include "../html_macros.h" + #define ASSIGNMENT_TABLE_NAME "assignments" #define ASSIGNMENT_TABLE_COLUMNS "id, unitid, max, bonus_per_assigned, spellid, req_tech, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, description" #define ASSIGNMENT_TABLE_COLUMNS_NOID "unitid, max, bonus_per_assigned, spellid, req_tech, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, description" -Ref AssignmentModel::get_assignment(const int id) { + +void AssignmentNode::handle_request_default(Request *request) { +} + +void AssignmentNode::admin_handle_request_main(Request *request) { + String seg = request->get_current_path_segment(); + + if (seg == "") { + admin_render_assignment_list(request); + return; + } else if (seg == "new") { + request->push_path(); + Ref b; + b.instance(); + + admin_render_assignment(request, b); + return; + } else if (seg == "edit") { + request->push_path(); + + String seg_assignment_id = request->get_current_path_segment(); + + if (!seg_assignment_id.is_int()) { + request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND); + return; + } + + int bid = seg_assignment_id.to_int(); + + Ref b = db_get_assignment(bid); + + if (!b.is_valid()) { + request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND); + return; + } + + admin_render_assignment(request, b); + return; + } + + request->send_error(404); +} +String AssignmentNode::admin_get_section_name() { + return "Assignments"; +} +void AssignmentNode::admin_add_section_links(Vector *links) { + links->push_back(AdminSectionLinkInfo("- Assignment Editor", "")); +} +bool AssignmentNode::admin_full_render() { + return false; +} + +void AssignmentNode::admin_render_assignment_list(Request *request) { + Vector > assignments = db_get_all(); + + HTMLBuilder b; + + b.div("back")->fa(request->get_url_root_parent(), "<--- Back")->cdiv(); + b.br(); + b.fdiv("Assignment Editor", "top_menu"); + b.br(); + b.div("top_menu")->fa(request->get_url_root("new"), "Create New")->cdiv(); + b.br(); + + b.div("list_container"); + + for (int i = 0; i < assignments.size(); ++i) { + Ref assignment = assignments[i]; + + if (!assignment.is_valid()) { + continue; + } + + if (i % 2 == 0) { + b.div("row"); + } else { + b.div("row second"); + } + { + b.fdiv(String::num(assignment->id), "attr_box"); + b.fdiv(assignment->description, "name"); + + b.div("actionbox")->fa(request->get_url_root("edit/" + String::num(assignment->id)), "Edit")->cdiv(); + } + b.cdiv(); + } + + b.cdiv(); + + request->body += b.result; +} + +void AssignmentNode::admin_render_assignment(Request *request, Ref assignment) { + if (!assignment.is_valid()) { + RLOG_ERR("admin_render_assignment: !assignment.is_valid()\n"); + request->send_error(HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR); + return; + } + + Vector > assignments = db_get_all(); + + HTMLBuilder b; + + b.div("back")->fa(request->get_url_root_parent(), "<--- Back")->cdiv(); + b.br(); + b.fdiv("Assignment Editor", "top_menu"); + b.br(); + + b.form_post(request->get_url_root()); + + bool show_post = false; //request->get_method() == HTTP_METHOD_POST && validation errors; + + //Todo make it a dropdown + ADMIN_EDIT_INPUT_TEXT("Unitid:", "unitid", show_post, String::num(assignment->unitid), request->get_parameter("unitid")); + ADMIN_EDIT_INPUT_TEXT("max:", "max", show_post, String::num(assignment->max), request->get_parameter("max")); + ADMIN_EDIT_INPUT_TEXT("bonus_per_assigned:", "bonus_per_assigned", show_post, String::num(assignment->bonus_per_assigned), request->get_parameter("bonus_per_assigned")); + ADMIN_EDIT_INPUT_TEXT("spellid:", "spellid", show_post, String::num(assignment->spellid), request->get_parameter("spellid")); + //Todo make it a dropdown + ADMIN_EDIT_INPUT_TEXT("req_tech:", "req_tech", show_post, String::num(assignment->req_tech), request->get_parameter("req_tech")); + + ADMIN_EDIT_LINE_SPACER(); + + ADMIN_EDIT_INPUT_TEXT("Mod Max Food:", "mod_max_food", show_post, String::num(assignment->mod_max_food), request->get_parameter("mod_max_food")); + ADMIN_EDIT_INPUT_TEXT("Mod Max Wood:", "mod_max_wood", show_post, String::num(assignment->mod_max_wood), request->get_parameter("mod_max_wood")); + ADMIN_EDIT_INPUT_TEXT("Mod Max Stone:", "mod_max_stone", show_post, String::num(assignment->mod_max_stone), request->get_parameter("mod_max_stone")); + ADMIN_EDIT_INPUT_TEXT("Mod Max Iron:", "mod_max_iron", show_post, String::num(assignment->mod_max_iron), request->get_parameter("mod_max_iron")); + ADMIN_EDIT_INPUT_TEXT("Mod Max Mana:", "mod_max_mana", show_post, String::num(assignment->mod_max_mana), request->get_parameter("mod_max_mana")); + + ADMIN_EDIT_LINE_SPACER(); + + ADMIN_EDIT_INPUT_TEXT("Mod Rate Food:", "mod_rate_food", show_post, String::num(assignment->mod_rate_food), request->get_parameter("mod_rate_food")); + ADMIN_EDIT_INPUT_TEXT("Mod Rate Wood:", "mod_rate_wood", show_post, String::num(assignment->mod_rate_wood), request->get_parameter("mod_rate_wood")); + ADMIN_EDIT_INPUT_TEXT("Mod Rate Stone:", "mod_rate_stone", show_post, String::num(assignment->mod_rate_stone), request->get_parameter("mod_rate_stone")); + ADMIN_EDIT_INPUT_TEXT("Mod Rate Iron:", "mod_rate_iron", show_post, String::num(assignment->mod_rate_iron), request->get_parameter("mod_rate_iron")); + ADMIN_EDIT_INPUT_TEXT("Mod Rate Mana:", "mod_rate_mana", show_post, String::num(assignment->mod_rate_mana), request->get_parameter("mod_rate_mana")); + + ADMIN_EDIT_LINE_SPACER(); + + ADMIN_EDIT_INPUT_TEXT("Mod Percent Food:", "mod_percent_food", show_post, String::num(assignment->mod_percent_food), request->get_parameter("mod_percent_food")); + ADMIN_EDIT_INPUT_TEXT("Mod Percent Wood:", "mod_percent_wood", show_post, String::num(assignment->mod_percent_wood), request->get_parameter("mod_percent_wood")); + ADMIN_EDIT_INPUT_TEXT("Mod Percent Stone:", "mod_percent_stone", show_post, String::num(assignment->mod_percent_stone), request->get_parameter("mod_percent_stone")); + ADMIN_EDIT_INPUT_TEXT("Mod Percent Iron:", "mod_percent_iron", show_post, String::num(assignment->mod_percent_iron), request->get_parameter("mod_percent_iron")); + ADMIN_EDIT_INPUT_TEXT("Mod Percent Mana:", "mod_percent_mana", show_post, String::num(assignment->mod_percent_mana), request->get_parameter("mod_percent_mana")); + + ADMIN_EDIT_LINE_SPACER(); + + ADMIN_EDIT_INPUT_TEXTAREA("Description:", "description", show_post, assignment->description, request->get_parameter("description")); + + b.div("edit_submit")->input_submit("Save", "submit")->cdiv(); + + b.cform(); + + request->body += b.result; +} + + +Ref AssignmentNode::db_get_assignment(const int id) { if (id == 0) { return Ref(); } - Ref b = DatabaseManager::get_singleton()->ddb->get_query_builder(); + Ref b = get_query_builder(); b->select(ASSIGNMENT_TABLE_COLUMNS); b->from(ASSIGNMENT_TABLE_NAME); @@ -38,13 +203,13 @@ Ref AssignmentModel::get_assignment(const int id) { Ref assignment; assignment.instance(); - parse_row(r, assignment); + db_parse_row(r, assignment); return assignment; } -Vector > AssignmentModel::get_all() { - Ref b = DatabaseManager::get_singleton()->ddb->get_query_builder(); +Vector > AssignmentNode::db_get_all() { + Ref b = get_query_builder(); b->select(ASSIGNMENT_TABLE_COLUMNS); b->from(ASSIGNMENT_TABLE_NAME); @@ -59,7 +224,7 @@ Vector > AssignmentModel::get_all() { Ref assignment; assignment.instance(); - parse_row(r, assignment); + db_parse_row(r, assignment); assignments.push_back(assignment); } @@ -67,8 +232,8 @@ Vector > AssignmentModel::get_all() { return assignments; } -void AssignmentModel::save_assignment(Ref &assignment) { - Ref b = DatabaseManager::get_singleton()->ddb->get_query_builder(); +void AssignmentNode::db_save_assignment(Ref &assignment) { + Ref b = get_query_builder(); if (assignment->id == 0) { b->insert(ASSIGNMENT_TABLE_NAME, ASSIGNMENT_TABLE_COLUMNS_NOID); @@ -149,7 +314,7 @@ void AssignmentModel::save_assignment(Ref &assignment) { } } -void AssignmentModel::parse_row(Ref &result, Ref &assignment) { +void AssignmentNode::db_parse_row(Ref &result, Ref &assignment) { assignment->id = result->get_cell_int(0); @@ -180,8 +345,8 @@ void AssignmentModel::parse_row(Ref &result, Ref &assig assignment->description = result->get_cell(21); } -void AssignmentModel::create_table() { - Ref tb = DatabaseManager::get_singleton()->ddb->get_table_builder(); +void AssignmentNode::create_table() { + Ref tb = get_table_builder(); tb->create_table(ASSIGNMENT_TABLE_NAME); @@ -217,18 +382,18 @@ void AssignmentModel::create_table() { tb->run_query(); //tb->print(); } -void AssignmentModel::drop_table() { - Ref tb = DatabaseManager::get_singleton()->ddb->get_table_builder(); +void AssignmentNode::drop_table() { + Ref tb = get_table_builder(); tb->drop_table_if_exists(ASSIGNMENT_TABLE_NAME)->cdrop_table(); tb->run_query(); } -void AssignmentModel::create_default_entries() { +void AssignmentNode::create_default_entries() { String table_columns = "id, unitid, max, bonus_per_assigned, spellid, req_tech, mod_max_food, mod_max_wood, mod_max_stone, mod_max_iron, mod_max_mana, mod_rate_food, mod_rate_wood, mod_rate_stone, mod_rate_iron, mod_rate_mana, mod_percent_food, mod_percent_wood, mod_percent_stone, mod_percent_iron, mod_percent_mana, description"; - Ref qb = DatabaseManager::get_singleton()->ddb->get_query_builder(); + Ref qb = get_query_builder(); qb->begin_transaction()->nl(); qb->insert(ASSIGNMENT_TABLE_NAME, table_columns)->nl()->w("VALUES(1, 1, 10, 2, 0, 0, 0, 0, 0, 0, 0, 0.001, 0, 0, 0, 0, 0, 0, 0, 0, 0, 'This building will produce more food, every 2 villager you assign.')")->end_command()->nl(); @@ -241,24 +406,25 @@ void AssignmentModel::create_default_entries() { //qb->print(); } -AssignmentModel *AssignmentModel::get_singleton() { + +AssignmentNode *AssignmentNode::get_singleton() { return _self; } -AssignmentModel::AssignmentModel() : - Object() { +AssignmentNode::AssignmentNode() : + AdminNode() { if (_self) { - printf("AssignmentModel::AssignmentModel(): Error! self is not null!/n"); + printf("AssignmentNode::AssignmentNode(): Error! self is not null!/n"); } _self = this; } -AssignmentModel::~AssignmentModel() { +AssignmentNode::~AssignmentNode() { if (_self == this) { _self = nullptr; } } -AssignmentModel *AssignmentModel::_self = nullptr; +AssignmentNode *AssignmentNode::_self = nullptr; diff --git a/app/assignments/assignment_controller.h b/app/assignments/assignment_node.h similarity index 60% rename from app/assignments/assignment_controller.h rename to app/assignments/assignment_node.h index 887b979..13d9619 100644 --- a/app/assignments/assignment_controller.h +++ b/app/assignments/assignment_node.h @@ -1,8 +1,8 @@ #ifndef ASSIGNMENT_CONTROLLER_H #define ASSIGNMENT_CONTROLLER_H -#include "core/string.h" #include "core/containers/vector.h" +#include "core/string.h" #include "web_modules/admin_panel/admin_node.h" @@ -10,10 +10,11 @@ class Request; class FormValidator; +class QueryResult; + +class AssignmentNode : public AdminNode { + RCPP_OBJECT(AssignmentNode, AdminNode); -class AssignmentController : public AdminNode { - RCPP_OBJECT(AssignmentController, AdminNode); - public: void handle_request_default(Request *request); @@ -25,17 +26,23 @@ public: void admin_render_assignment_list(Request *request); void admin_render_assignment(Request *request, Ref assignment); + virtual Ref db_get_assignment(const int id); + virtual Vector > db_get_all(); + virtual void db_save_assignment(Ref &assignment); + + virtual void db_parse_row(Ref &result, Ref &assignment); + void create_table(); void drop_table(); void create_default_entries(); - static AssignmentController *get_singleton(); + static AssignmentNode *get_singleton(); - AssignmentController(); - ~AssignmentController(); + AssignmentNode(); + ~AssignmentNode(); protected: - static AssignmentController *_self; + static AssignmentNode *_self; }; #endif \ No newline at end of file diff --git a/app/mourne_root.cpp b/app/mourne_root.cpp index ff46db3..ec61ed6 100644 --- a/app/mourne_root.cpp +++ b/app/mourne_root.cpp @@ -21,11 +21,11 @@ #include "mourne_user_controller.h" -#include "assignments/assignment_initializer.h" #include "weather/weather_initializer.h" -#include "village/village_node.h" +#include "assignments/assignment_node.h" #include "buildings/building_node.h" +#include "village/village_node.h" void MourneRoot::handle_request_main(Request *request) { if (process_middlewares(request)) { @@ -256,21 +256,17 @@ void MourneRoot::setup_middleware() { void MourneRoot::create_table() { // TODO move these to the node system and remove from here - AssignmentController::get_singleton()->create_table(); WeatherController::get_singleton()->create_table(); } void MourneRoot::drop_table() { - AssignmentController::get_singleton()->drop_table(); WeatherController::get_singleton()->drop_table(); } void MourneRoot::udpate_table() { // TODO move these to the node system and remove from here - AssignmentController::get_singleton()->udpate_table(); WeatherController::get_singleton()->udpate_table(); } void MourneRoot::create_default_entries() { // TODO move these to the node system and remove from here - AssignmentController::get_singleton()->create_default_entries(); WeatherController::get_singleton()->create_default_entries(); } @@ -307,7 +303,6 @@ void MourneRoot::compile_menu() { MourneRoot::MourneRoot() : WebRoot() { - AssignmentInitializer::allocate_all(); WeatherInitializer::allocate_all(); _village = new VillageNode(); @@ -318,10 +313,14 @@ MourneRoot::MourneRoot() : _building->set_uri_segment("building"); add_child(_building); + _assignments = new AssignmentNode(); + _assignments->set_uri_segment("assignments"); + add_child(_assignments); + _admin_panel = new AdminPanel(); _admin_panel->set_uri_segment("admin"); _admin_panel->register_admin_controller("buildings", _building); - _admin_panel->register_admin_controller("assignments", AssignmentController::get_singleton()); + _admin_panel->register_admin_controller("assignments", _assignments); _admin_panel->register_admin_controller("weather", WeatherController::get_singleton()); _user_controller = new MourneUserController(); @@ -348,7 +347,6 @@ MourneRoot::MourneRoot() : } MourneRoot::~MourneRoot() { - AssignmentInitializer::free_all(); WeatherInitializer::free_all(); } diff --git a/app/mourne_root.h b/app/mourne_root.h index d03ea58..08f17a9 100644 --- a/app/mourne_root.h +++ b/app/mourne_root.h @@ -14,6 +14,7 @@ class MenuNode; class MourneUserController; class VillageNode; class BuildingNode; +class AssignmentNode; #define ENSURE_LOGIN(request) \ if (!is_logged_in(request)) { \ @@ -68,6 +69,7 @@ public: VillageNode *_village; BuildingNode *_building; + AssignmentNode *_assignments; static String menu_head; static String admin_headers;