Browse Source

Added format flags to determine header/footer inclusion

pull/3/head
Jessica James 9 years ago
parent
commit
49917b6bcc
  1. 104
      RenX.Ladder.Web/RenX_Ladder_Web.cpp
  2. 15
      RenX.Ladder.Web/RenX_Ladder_Web.h

104
RenX.Ladder.Web/RenX_Ladder_Web.cpp

@ -260,7 +260,7 @@ Jupiter::String generate_page_buttons(RenX::LadderDatabase *db)
/** Ladder page */ /** Ladder page */
Jupiter::String RenX_Ladder_WebPlugin::generate_entry_table(RenX::LadderDatabase *db, size_t index, size_t count) Jupiter::String RenX_Ladder_WebPlugin::generate_entry_table(RenX::LadderDatabase *db, uint8_t format, size_t index, size_t count)
{ {
if (db->getEntries() == 0) // No ladder data if (db->getEntries() == 0) // No ladder data
return Jupiter::String("Error: No ladder data"_jrs); return Jupiter::String("Error: No ladder data"_jrs);
@ -282,7 +282,9 @@ Jupiter::String RenX_Ladder_WebPlugin::generate_entry_table(RenX::LadderDatabase
// table header // table header
Jupiter::String result(2048); Jupiter::String result(2048);
result = RenX_Ladder_WebPlugin::ladder_table_header;
if ((format & this->FLAG_INCLUDE_DATA_HEADER) != 0) // Data Header
result = RenX_Ladder_WebPlugin::ladder_table_header;
// append rows // append rows
Jupiter::String row(256); Jupiter::String row(256);
@ -296,7 +298,7 @@ Jupiter::String RenX_Ladder_WebPlugin::generate_entry_table(RenX::LadderDatabase
--count; --count;
} }
// table footer if ((format & this->FLAG_INCLUDE_DATA_FOOTER) != 0) // Data footer
result += RenX_Ladder_WebPlugin::ladder_table_footer; result += RenX_Ladder_WebPlugin::ladder_table_footer;
// search buttons // search buttons
@ -305,31 +307,56 @@ Jupiter::String RenX_Ladder_WebPlugin::generate_entry_table(RenX::LadderDatabase
return result; return result;
} }
Jupiter::String *RenX_Ladder_WebPlugin::generate_ladder_page(RenX::LadderDatabase *db, size_t index, size_t count, const Jupiter::INIFile::Section &query_params) Jupiter::String *RenX_Ladder_WebPlugin::generate_ladder_page(RenX::LadderDatabase *db, uint8_t format, size_t index, size_t count, const Jupiter::INIFile::Section &query_params)
{ {
Jupiter::String *result = new Jupiter::String(RenX_Ladder_WebPlugin::header); Jupiter::String *result = new Jupiter::String(2048);
result->concat(generate_search(db));
result->concat(generate_database_selector(db, query_params)); if ((format & this->FLAG_INCLUDE_PAGE_HEADER) != 0) // Header
result->concat(this->generate_entry_table(db, index, count)); result->concat(RenX_Ladder_WebPlugin::header);
result->concat(RenX_Ladder_WebPlugin::footer);
if ((format & this->FLAG_INCLUDE_SEARCH) != 0) // Search
result->concat(generate_search(db));
if ((format & this->FLAG_INCLUDE_SELECTOR) != 0) // Selector
result->concat(generate_database_selector(db, query_params));
result->concat(this->generate_entry_table(db, format, index, count));
if ((format & this->FLAG_INCLUDE_PAGE_FOOTER) != 0) // Footer
result->concat(RenX_Ladder_WebPlugin::footer);
return result; return result;
} }
// format:
// include_header | include_footer | include_any_headers | include_any_footers
/** Search page */ /** Search page */
Jupiter::String *RenX_Ladder_WebPlugin::generate_search_page(RenX::LadderDatabase *db, const Jupiter::ReadableString &name, const Jupiter::INIFile::Section &query_params) Jupiter::String *RenX_Ladder_WebPlugin::generate_search_page(RenX::LadderDatabase *db, uint8_t format, size_t start_index, size_t count, const Jupiter::ReadableString &name, const Jupiter::INIFile::Section &query_params)
{ {
Jupiter::String *result = new Jupiter::String(RenX_Ladder_WebPlugin::header); Jupiter::String *result = new Jupiter::String(2048);
result->concat(generate_search(db));
result->concat(generate_database_selector(db, query_params)); if ((format & this->FLAG_INCLUDE_PAGE_HEADER) != 0) // Header
result->concat(RenX_Ladder_WebPlugin::header);
if ((format & this->FLAG_INCLUDE_SEARCH) != 0) // Search
result->concat(generate_search(db));
if ((format & this->FLAG_INCLUDE_SELECTOR) != 0) // Selector
result->concat(generate_database_selector(db, query_params));
if (db->getEntries() == 0) // No ladder data if (db->getEntries() == 0) // No ladder data
{ {
result->concat("Error: No ladder data"_jrs); result->concat("Error: No ladder data"_jrs);
result->concat(RenX_Ladder_WebPlugin::footer);
if ((format & this->FLAG_INCLUDE_PAGE_FOOTER) != 0) // Footer
result->concat(RenX_Ladder_WebPlugin::footer);
return result; return result;
} }
result->concat(RenX_Ladder_WebPlugin::ladder_table_header); if ((format & this->FLAG_INCLUDE_DATA_HEADER) != 0) // Data header
result->concat(RenX_Ladder_WebPlugin::ladder_table_header);
// append rows // append rows
Jupiter::String row(256); Jupiter::String row(256);
@ -346,22 +373,36 @@ Jupiter::String *RenX_Ladder_WebPlugin::generate_search_page(RenX::LadderDatabas
node = node->next; node = node->next;
} }
result->concat(RenX_Ladder_WebPlugin::ladder_table_footer); if ((format & this->FLAG_INCLUDE_DATA_FOOTER) != 0) // Data footer
result->concat(RenX_Ladder_WebPlugin::footer); result->concat(RenX_Ladder_WebPlugin::ladder_table_footer);
if ((format & this->FLAG_INCLUDE_PAGE_FOOTER) != 0) // Footer
result->concat(RenX_Ladder_WebPlugin::footer);
return result; return result;
} }
/** Profile page */ /** Profile page */
Jupiter::String *RenX_Ladder_WebPlugin::generate_profile_page(RenX::LadderDatabase *db, uint64_t steam_id, const Jupiter::INIFile::Section &query_params) Jupiter::String *RenX_Ladder_WebPlugin::generate_profile_page(RenX::LadderDatabase *db, uint8_t format, uint64_t steam_id, const Jupiter::INIFile::Section &query_params)
{ {
Jupiter::String *result = new Jupiter::String(RenX_Ladder_WebPlugin::header); Jupiter::String *result = new Jupiter::String(2048);
result->concat(generate_search(db));
result->concat(generate_database_selector(db, query_params)); if ((format & this->FLAG_INCLUDE_PAGE_HEADER) != 0)
result->concat(RenX_Ladder_WebPlugin::header);
if ((format & this->FLAG_INCLUDE_SEARCH) != 0) // Search
result->concat(generate_search(db));
if ((format & this->FLAG_INCLUDE_SELECTOR) != 0) // Selector
result->concat(generate_database_selector(db, query_params));
if (db->getEntries() == 0) // No ladder data if (db->getEntries() == 0) // No ladder data
{ {
result->concat("Error: No ladder data"_jrs); result->concat("Error: No ladder data"_jrs);
result->concat(RenX_Ladder_WebPlugin::footer);
if ((format & this->FLAG_INCLUDE_PAGE_FOOTER) != 0) // Footer
result->concat(RenX_Ladder_WebPlugin::footer);
return result; return result;
} }
@ -401,7 +442,9 @@ Jupiter::String *RenX_Ladder_WebPlugin::generate_profile_page(RenX::LadderDataba
result->concat("</div>"_jrs); result->concat("</div>"_jrs);
} }
result->concat(RenX_Ladder_WebPlugin::footer); if ((format & this->FLAG_INCLUDE_PAGE_FOOTER) != 0) // Footer
result->concat(RenX_Ladder_WebPlugin::footer);
return result; return result;
} }
@ -427,9 +470,11 @@ Jupiter::ReadableString *handle_ladder_page(const Jupiter::ReadableString &query
Jupiter::HTTP::HTMLFormResponse html_form_response(query_string); Jupiter::HTTP::HTMLFormResponse html_form_response(query_string);
RenX::LadderDatabase *db = RenX::default_ladder_database; RenX::LadderDatabase *db = RenX::default_ladder_database;
size_t start_index = 0, count = pluginInstance.getEntriesPerPage(); size_t start_index = 0, count = pluginInstance.getEntriesPerPage();
uint8_t format = 0xFF;
if (html_form_response.table.size() != 0) if (html_form_response.table.size() != 0)
{ {
format = static_cast<uint8_t>(html_form_response.table.getInt("format"_jrs, format));
start_index = static_cast<size_t>(html_form_response.table.getInt("start"_jrs, start_index)); start_index = static_cast<size_t>(html_form_response.table.getInt("start"_jrs, start_index));
count = static_cast<size_t>(html_form_response.table.getInt("count"_jrs, count)); count = static_cast<size_t>(html_form_response.table.getInt("count"_jrs, count));
@ -449,17 +494,22 @@ Jupiter::ReadableString *handle_ladder_page(const Jupiter::ReadableString &query
if (db == nullptr) if (db == nullptr)
return generate_no_db_page(html_form_response.table); return generate_no_db_page(html_form_response.table);
return pluginInstance.generate_ladder_page(db, start_index, count, html_form_response.table); return pluginInstance.generate_ladder_page(db, format, start_index, count, html_form_response.table);
} }
Jupiter::ReadableString *handle_search_page(const Jupiter::ReadableString &query_string) Jupiter::ReadableString *handle_search_page(const Jupiter::ReadableString &query_string)
{ {
Jupiter::HTTP::HTMLFormResponse html_form_response(query_string); Jupiter::HTTP::HTMLFormResponse html_form_response(query_string);
RenX::LadderDatabase *db = RenX::default_ladder_database; RenX::LadderDatabase *db = RenX::default_ladder_database;
uint8_t format = 0xFF;
size_t start_index = 0, count = pluginInstance.getEntriesPerPage();
Jupiter::ReferenceString name; Jupiter::ReferenceString name;
if (html_form_response.table.size() != 0) if (html_form_response.table.size() != 0)
{ {
format = static_cast<uint8_t>(html_form_response.table.getInt("format"_jrs, format));
start_index = static_cast<size_t>(html_form_response.table.getInt("start"_jrs, start_index));
count = static_cast<size_t>(html_form_response.table.getInt("count"_jrs, count));
name = html_form_response.table.get("name"_jrs); name = html_form_response.table.get("name"_jrs);
const Jupiter::ReadableString &db_name = html_form_response.table.get("database"_jrs); const Jupiter::ReadableString &db_name = html_form_response.table.get("database"_jrs);
@ -481,7 +531,7 @@ Jupiter::ReadableString *handle_search_page(const Jupiter::ReadableString &query
if (name.size() < pluginInstance.getMinSearchNameLength()) // Generate ladder page when no name specified if (name.size() < pluginInstance.getMinSearchNameLength()) // Generate ladder page when no name specified
return handle_ladder_page(query_string); return handle_ladder_page(query_string);
return pluginInstance.generate_search_page(db, name, html_form_response.table); return pluginInstance.generate_search_page(db, format, start_index, count, name, html_form_response.table);
} }
Jupiter::ReadableString *handle_profile_page(const Jupiter::ReadableString &query_string) Jupiter::ReadableString *handle_profile_page(const Jupiter::ReadableString &query_string)
@ -489,9 +539,11 @@ Jupiter::ReadableString *handle_profile_page(const Jupiter::ReadableString &quer
Jupiter::HTTP::HTMLFormResponse html_form_response(query_string); Jupiter::HTTP::HTMLFormResponse html_form_response(query_string);
RenX::LadderDatabase *db = RenX::default_ladder_database; RenX::LadderDatabase *db = RenX::default_ladder_database;
uint64_t steam_id = 0; uint64_t steam_id = 0;
uint8_t format = 0xFF;
if (html_form_response.table.size() != 0) if (html_form_response.table.size() != 0)
{ {
format = static_cast<uint8_t>(html_form_response.table.getInt("format"_jrs, format));
steam_id = html_form_response.table.getLongLong("id"_jrs); steam_id = html_form_response.table.getLongLong("id"_jrs);
const Jupiter::ReadableString &db_name = html_form_response.table.get("database"_jrs); const Jupiter::ReadableString &db_name = html_form_response.table.get("database"_jrs);
@ -510,7 +562,7 @@ Jupiter::ReadableString *handle_profile_page(const Jupiter::ReadableString &quer
if (db == nullptr) if (db == nullptr)
return generate_no_db_page(html_form_response.table); return generate_no_db_page(html_form_response.table);
return pluginInstance.generate_profile_page(db, steam_id, html_form_response.table); return pluginInstance.generate_profile_page(db, format, steam_id, html_form_response.table);
} }
extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin() extern "C" __declspec(dllexport) Jupiter::Plugin *getPlugin()

15
RenX.Ladder.Web/RenX_Ladder_Web.h

@ -28,14 +28,21 @@
class RenX_Ladder_WebPlugin : public RenX::Plugin class RenX_Ladder_WebPlugin : public RenX::Plugin
{ {
protected: protected:
Jupiter::String generate_entry_table(RenX::LadderDatabase *db, size_t index, size_t count); Jupiter::String generate_entry_table(RenX::LadderDatabase *db, uint8_t format, size_t index, size_t count);
public: public:
const uint8_t FLAG_INCLUDE_PAGE_HEADER = 0x01;
const uint8_t FLAG_INCLUDE_PAGE_FOOTER = 0x02;
const uint8_t FLAG_INCLUDE_DATA_HEADER = 0x04;
const uint8_t FLAG_INCLUDE_DATA_FOOTER = 0x08;
const uint8_t FLAG_INCLUDE_SEARCH = 0x10;
const uint8_t FLAG_INCLUDE_SELECTOR = 0x20;
Jupiter::StringS header; Jupiter::StringS header;
Jupiter::StringS footer; Jupiter::StringS footer;
Jupiter::String *generate_ladder_page(RenX::LadderDatabase *db, size_t start_index, size_t count, const Jupiter::INIFile::Section &query_params); Jupiter::String *generate_ladder_page(RenX::LadderDatabase *db, uint8_t format, size_t start_index, size_t count, const Jupiter::INIFile::Section &query_params);
Jupiter::String *generate_search_page(RenX::LadderDatabase *db, const Jupiter::ReadableString &name, const Jupiter::INIFile::Section &query_params); Jupiter::String *generate_search_page(RenX::LadderDatabase *db, uint8_t format, size_t start_index, size_t count, const Jupiter::ReadableString &name, const Jupiter::INIFile::Section &query_params);
Jupiter::String *generate_profile_page(RenX::LadderDatabase *db, uint64_t steam_id, const Jupiter::INIFile::Section &query_params); Jupiter::String *generate_profile_page(RenX::LadderDatabase *db, uint8_t format, uint64_t steam_id, const Jupiter::INIFile::Section &query_params);
inline size_t getEntriesPerPage() const { return this->entries_per_page; } inline size_t getEntriesPerPage() const { return this->entries_per_page; }
inline size_t getMinSearchNameLength() const { return this->min_search_name_length; }; inline size_t getMinSearchNameLength() const { return this->min_search_name_length; };

Loading…
Cancel
Save