mirror of
https://github.com/Relintai/mourne_rcpp_fw.git
synced 2024-12-23 21:16:50 +01:00
Same change to assignments.
This commit is contained in:
parent
ced07f3bb7
commit
d174286f1a
@ -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<Assignment> 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<Assignment> 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<AdminSectionLinkInfo> *links) {
|
|
||||||
links->push_back(AdminSectionLinkInfo("- Assignment Editor", ""));
|
|
||||||
}
|
|
||||||
bool AssignmentController::admin_full_render() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void AssignmentController::admin_render_assignment_list(Request *request) {
|
|
||||||
Vector<Ref<Assignment> > 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> 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> 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<Ref<Assignment> > 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;
|
|
@ -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;
|
|
@ -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
|
|
@ -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<Assignment> get_assignment(const int id);
|
|
||||||
virtual Vector<Ref<Assignment> > get_all();
|
|
||||||
virtual void save_assignment(Ref<Assignment> &assignment);
|
|
||||||
|
|
||||||
virtual void parse_row(Ref<QueryResult> &result, Ref<Assignment> &assignment);
|
|
||||||
|
|
||||||
void create_table();
|
|
||||||
void drop_table();
|
|
||||||
void create_default_entries();
|
|
||||||
|
|
||||||
static AssignmentModel *get_singleton();
|
|
||||||
|
|
||||||
AssignmentModel();
|
|
||||||
~AssignmentModel();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
static AssignmentModel *_self;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
@ -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.h"
|
||||||
#include "database/database_manager.h"
|
#include "database/database_manager.h"
|
||||||
@ -8,19 +16,176 @@
|
|||||||
|
|
||||||
#include "crypto/hash/sha256.h"
|
#include "crypto/hash/sha256.h"
|
||||||
|
|
||||||
#include "assignment.h"
|
#include "../html_macros.h"
|
||||||
|
|
||||||
|
|
||||||
#define ASSIGNMENT_TABLE_NAME "assignments"
|
#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 "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"
|
#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<Assignment> 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<Assignment> 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<Assignment> 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<AdminSectionLinkInfo> *links) {
|
||||||
|
links->push_back(AdminSectionLinkInfo("- Assignment Editor", ""));
|
||||||
|
}
|
||||||
|
bool AssignmentNode::admin_full_render() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssignmentNode::admin_render_assignment_list(Request *request) {
|
||||||
|
Vector<Ref<Assignment> > 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> 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> 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<Ref<Assignment> > 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<Assignment> AssignmentNode::db_get_assignment(const int id) {
|
||||||
if (id == 0) {
|
if (id == 0) {
|
||||||
return Ref<Assignment>();
|
return Ref<Assignment>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Ref<QueryBuilder> b = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
Ref<QueryBuilder> b = get_query_builder();
|
||||||
|
|
||||||
b->select(ASSIGNMENT_TABLE_COLUMNS);
|
b->select(ASSIGNMENT_TABLE_COLUMNS);
|
||||||
b->from(ASSIGNMENT_TABLE_NAME);
|
b->from(ASSIGNMENT_TABLE_NAME);
|
||||||
@ -38,13 +203,13 @@ Ref<Assignment> AssignmentModel::get_assignment(const int id) {
|
|||||||
Ref<Assignment> assignment;
|
Ref<Assignment> assignment;
|
||||||
assignment.instance();
|
assignment.instance();
|
||||||
|
|
||||||
parse_row(r, assignment);
|
db_parse_row(r, assignment);
|
||||||
|
|
||||||
return assignment;
|
return assignment;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<Ref<Assignment> > AssignmentModel::get_all() {
|
Vector<Ref<Assignment> > AssignmentNode::db_get_all() {
|
||||||
Ref<QueryBuilder> b = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
Ref<QueryBuilder> b = get_query_builder();
|
||||||
|
|
||||||
b->select(ASSIGNMENT_TABLE_COLUMNS);
|
b->select(ASSIGNMENT_TABLE_COLUMNS);
|
||||||
b->from(ASSIGNMENT_TABLE_NAME);
|
b->from(ASSIGNMENT_TABLE_NAME);
|
||||||
@ -59,7 +224,7 @@ Vector<Ref<Assignment> > AssignmentModel::get_all() {
|
|||||||
Ref<Assignment> assignment;
|
Ref<Assignment> assignment;
|
||||||
assignment.instance();
|
assignment.instance();
|
||||||
|
|
||||||
parse_row(r, assignment);
|
db_parse_row(r, assignment);
|
||||||
|
|
||||||
assignments.push_back(assignment);
|
assignments.push_back(assignment);
|
||||||
}
|
}
|
||||||
@ -67,8 +232,8 @@ Vector<Ref<Assignment> > AssignmentModel::get_all() {
|
|||||||
return assignments;
|
return assignments;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignmentModel::save_assignment(Ref<Assignment> &assignment) {
|
void AssignmentNode::db_save_assignment(Ref<Assignment> &assignment) {
|
||||||
Ref<QueryBuilder> b = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
Ref<QueryBuilder> b = get_query_builder();
|
||||||
|
|
||||||
if (assignment->id == 0) {
|
if (assignment->id == 0) {
|
||||||
b->insert(ASSIGNMENT_TABLE_NAME, ASSIGNMENT_TABLE_COLUMNS_NOID);
|
b->insert(ASSIGNMENT_TABLE_NAME, ASSIGNMENT_TABLE_COLUMNS_NOID);
|
||||||
@ -149,7 +314,7 @@ void AssignmentModel::save_assignment(Ref<Assignment> &assignment) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignmentModel::parse_row(Ref<QueryResult> &result, Ref<Assignment> &assignment) {
|
void AssignmentNode::db_parse_row(Ref<QueryResult> &result, Ref<Assignment> &assignment) {
|
||||||
|
|
||||||
assignment->id = result->get_cell_int(0);
|
assignment->id = result->get_cell_int(0);
|
||||||
|
|
||||||
@ -180,8 +345,8 @@ void AssignmentModel::parse_row(Ref<QueryResult> &result, Ref<Assignment> &assig
|
|||||||
assignment->description = result->get_cell(21);
|
assignment->description = result->get_cell(21);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AssignmentModel::create_table() {
|
void AssignmentNode::create_table() {
|
||||||
Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder();
|
Ref<TableBuilder> tb = get_table_builder();
|
||||||
|
|
||||||
tb->create_table(ASSIGNMENT_TABLE_NAME);
|
tb->create_table(ASSIGNMENT_TABLE_NAME);
|
||||||
|
|
||||||
@ -217,18 +382,18 @@ void AssignmentModel::create_table() {
|
|||||||
tb->run_query();
|
tb->run_query();
|
||||||
//tb->print();
|
//tb->print();
|
||||||
}
|
}
|
||||||
void AssignmentModel::drop_table() {
|
void AssignmentNode::drop_table() {
|
||||||
Ref<TableBuilder> tb = DatabaseManager::get_singleton()->ddb->get_table_builder();
|
Ref<TableBuilder> tb = get_table_builder();
|
||||||
|
|
||||||
tb->drop_table_if_exists(ASSIGNMENT_TABLE_NAME)->cdrop_table();
|
tb->drop_table_if_exists(ASSIGNMENT_TABLE_NAME)->cdrop_table();
|
||||||
|
|
||||||
tb->run_query();
|
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";
|
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<QueryBuilder> qb = DatabaseManager::get_singleton()->ddb->get_query_builder();
|
Ref<QueryBuilder> qb = get_query_builder();
|
||||||
|
|
||||||
qb->begin_transaction()->nl();
|
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();
|
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();
|
//qb->print();
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignmentModel *AssignmentModel::get_singleton() {
|
|
||||||
|
AssignmentNode *AssignmentNode::get_singleton() {
|
||||||
return _self;
|
return _self;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignmentModel::AssignmentModel() :
|
AssignmentNode::AssignmentNode() :
|
||||||
Object() {
|
AdminNode() {
|
||||||
|
|
||||||
if (_self) {
|
if (_self) {
|
||||||
printf("AssignmentModel::AssignmentModel(): Error! self is not null!/n");
|
printf("AssignmentNode::AssignmentNode(): Error! self is not null!/n");
|
||||||
}
|
}
|
||||||
|
|
||||||
_self = this;
|
_self = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignmentModel::~AssignmentModel() {
|
AssignmentNode::~AssignmentNode() {
|
||||||
if (_self == this) {
|
if (_self == this) {
|
||||||
_self = nullptr;
|
_self = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AssignmentModel *AssignmentModel::_self = nullptr;
|
AssignmentNode *AssignmentNode::_self = nullptr;
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef ASSIGNMENT_CONTROLLER_H
|
#ifndef ASSIGNMENT_CONTROLLER_H
|
||||||
#define ASSIGNMENT_CONTROLLER_H
|
#define ASSIGNMENT_CONTROLLER_H
|
||||||
|
|
||||||
#include "core/string.h"
|
|
||||||
#include "core/containers/vector.h"
|
#include "core/containers/vector.h"
|
||||||
|
#include "core/string.h"
|
||||||
|
|
||||||
#include "web_modules/admin_panel/admin_node.h"
|
#include "web_modules/admin_panel/admin_node.h"
|
||||||
|
|
||||||
@ -10,10 +10,11 @@
|
|||||||
|
|
||||||
class Request;
|
class Request;
|
||||||
class FormValidator;
|
class FormValidator;
|
||||||
|
class QueryResult;
|
||||||
|
|
||||||
|
class AssignmentNode : public AdminNode {
|
||||||
|
RCPP_OBJECT(AssignmentNode, AdminNode);
|
||||||
|
|
||||||
class AssignmentController : public AdminNode {
|
|
||||||
RCPP_OBJECT(AssignmentController, AdminNode);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void handle_request_default(Request *request);
|
void handle_request_default(Request *request);
|
||||||
|
|
||||||
@ -25,17 +26,23 @@ public:
|
|||||||
void admin_render_assignment_list(Request *request);
|
void admin_render_assignment_list(Request *request);
|
||||||
void admin_render_assignment(Request *request, Ref<Assignment> assignment);
|
void admin_render_assignment(Request *request, Ref<Assignment> assignment);
|
||||||
|
|
||||||
|
virtual Ref<Assignment> db_get_assignment(const int id);
|
||||||
|
virtual Vector<Ref<Assignment> > db_get_all();
|
||||||
|
virtual void db_save_assignment(Ref<Assignment> &assignment);
|
||||||
|
|
||||||
|
virtual void db_parse_row(Ref<QueryResult> &result, Ref<Assignment> &assignment);
|
||||||
|
|
||||||
void create_table();
|
void create_table();
|
||||||
void drop_table();
|
void drop_table();
|
||||||
void create_default_entries();
|
void create_default_entries();
|
||||||
|
|
||||||
static AssignmentController *get_singleton();
|
static AssignmentNode *get_singleton();
|
||||||
|
|
||||||
AssignmentController();
|
AssignmentNode();
|
||||||
~AssignmentController();
|
~AssignmentNode();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static AssignmentController *_self;
|
static AssignmentNode *_self;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -21,11 +21,11 @@
|
|||||||
|
|
||||||
#include "mourne_user_controller.h"
|
#include "mourne_user_controller.h"
|
||||||
|
|
||||||
#include "assignments/assignment_initializer.h"
|
|
||||||
#include "weather/weather_initializer.h"
|
#include "weather/weather_initializer.h"
|
||||||
|
|
||||||
#include "village/village_node.h"
|
#include "assignments/assignment_node.h"
|
||||||
#include "buildings/building_node.h"
|
#include "buildings/building_node.h"
|
||||||
|
#include "village/village_node.h"
|
||||||
|
|
||||||
void MourneRoot::handle_request_main(Request *request) {
|
void MourneRoot::handle_request_main(Request *request) {
|
||||||
if (process_middlewares(request)) {
|
if (process_middlewares(request)) {
|
||||||
@ -256,21 +256,17 @@ void MourneRoot::setup_middleware() {
|
|||||||
|
|
||||||
void MourneRoot::create_table() {
|
void MourneRoot::create_table() {
|
||||||
// TODO move these to the node system and remove from here
|
// TODO move these to the node system and remove from here
|
||||||
AssignmentController::get_singleton()->create_table();
|
|
||||||
WeatherController::get_singleton()->create_table();
|
WeatherController::get_singleton()->create_table();
|
||||||
}
|
}
|
||||||
void MourneRoot::drop_table() {
|
void MourneRoot::drop_table() {
|
||||||
AssignmentController::get_singleton()->drop_table();
|
|
||||||
WeatherController::get_singleton()->drop_table();
|
WeatherController::get_singleton()->drop_table();
|
||||||
}
|
}
|
||||||
void MourneRoot::udpate_table() {
|
void MourneRoot::udpate_table() {
|
||||||
// TODO move these to the node system and remove from here
|
// TODO move these to the node system and remove from here
|
||||||
AssignmentController::get_singleton()->udpate_table();
|
|
||||||
WeatherController::get_singleton()->udpate_table();
|
WeatherController::get_singleton()->udpate_table();
|
||||||
}
|
}
|
||||||
void MourneRoot::create_default_entries() {
|
void MourneRoot::create_default_entries() {
|
||||||
// TODO move these to the node system and remove from here
|
// TODO move these to the node system and remove from here
|
||||||
AssignmentController::get_singleton()->create_default_entries();
|
|
||||||
WeatherController::get_singleton()->create_default_entries();
|
WeatherController::get_singleton()->create_default_entries();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -307,7 +303,6 @@ void MourneRoot::compile_menu() {
|
|||||||
MourneRoot::MourneRoot() :
|
MourneRoot::MourneRoot() :
|
||||||
WebRoot() {
|
WebRoot() {
|
||||||
|
|
||||||
AssignmentInitializer::allocate_all();
|
|
||||||
WeatherInitializer::allocate_all();
|
WeatherInitializer::allocate_all();
|
||||||
|
|
||||||
_village = new VillageNode();
|
_village = new VillageNode();
|
||||||
@ -318,10 +313,14 @@ MourneRoot::MourneRoot() :
|
|||||||
_building->set_uri_segment("building");
|
_building->set_uri_segment("building");
|
||||||
add_child(_building);
|
add_child(_building);
|
||||||
|
|
||||||
|
_assignments = new AssignmentNode();
|
||||||
|
_assignments->set_uri_segment("assignments");
|
||||||
|
add_child(_assignments);
|
||||||
|
|
||||||
_admin_panel = new AdminPanel();
|
_admin_panel = new AdminPanel();
|
||||||
_admin_panel->set_uri_segment("admin");
|
_admin_panel->set_uri_segment("admin");
|
||||||
_admin_panel->register_admin_controller("buildings", _building);
|
_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());
|
_admin_panel->register_admin_controller("weather", WeatherController::get_singleton());
|
||||||
|
|
||||||
_user_controller = new MourneUserController();
|
_user_controller = new MourneUserController();
|
||||||
@ -348,7 +347,6 @@ MourneRoot::MourneRoot() :
|
|||||||
}
|
}
|
||||||
|
|
||||||
MourneRoot::~MourneRoot() {
|
MourneRoot::~MourneRoot() {
|
||||||
AssignmentInitializer::free_all();
|
|
||||||
WeatherInitializer::free_all();
|
WeatherInitializer::free_all();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@ class MenuNode;
|
|||||||
class MourneUserController;
|
class MourneUserController;
|
||||||
class VillageNode;
|
class VillageNode;
|
||||||
class BuildingNode;
|
class BuildingNode;
|
||||||
|
class AssignmentNode;
|
||||||
|
|
||||||
#define ENSURE_LOGIN(request) \
|
#define ENSURE_LOGIN(request) \
|
||||||
if (!is_logged_in(request)) { \
|
if (!is_logged_in(request)) { \
|
||||||
@ -68,6 +69,7 @@ public:
|
|||||||
|
|
||||||
VillageNode *_village;
|
VillageNode *_village;
|
||||||
BuildingNode *_building;
|
BuildingNode *_building;
|
||||||
|
AssignmentNode *_assignments;
|
||||||
|
|
||||||
static String menu_head;
|
static String menu_head;
|
||||||
static String admin_headers;
|
static String admin_headers;
|
||||||
|
Loading…
Reference in New Issue
Block a user