minor refactoring in config
implement pagination
This commit is contained in:
24
src/main.cpp
24
src/main.cpp
@ -1,6 +1,7 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
|
||||
#include <pqxx/pqxx>
|
||||
|
||||
@ -36,9 +37,28 @@ int main(int argc, char *argv[]) {
|
||||
* Freelancer Profile listing for customers
|
||||
*/
|
||||
CROW_ROUTE(app, "/").methods("POST"_method, "GET"_method)
|
||||
([configuration]() {
|
||||
([configuration](const crow::request& request) {
|
||||
int selectedPage = 1;
|
||||
if (!request.url_params.keys().empty()) {
|
||||
string selectedPageString = request.url_params.get("page");
|
||||
if (!selectedPageString.empty())
|
||||
selectedPage = stoi(selectedPageString);
|
||||
}
|
||||
auto page = crow::mustache::load(TEMPLATE_CUSTOMER_INDEX_FREELANCER_LISTING);
|
||||
crow::mustache::context ctx(Utilities::getFreelancerListing(configuration));
|
||||
crow::mustache::context ctx(Utilities::getFreelancerListing(configuration, selectedPage));
|
||||
if (configuration.itemsPerPage > 0) {
|
||||
ctx[MUSTACHE_PAGINATION] = true;
|
||||
vector<int> pages = Utilities::getFreelancerIndexPagination(configuration);
|
||||
ctx[MUSTACHE_PAGINATION_NUMBERS] = pages;
|
||||
if (selectedPage <= 1)
|
||||
ctx[MUSTACHE_PAGINATION_PREVIOUS] = 1;
|
||||
else
|
||||
ctx[MUSTACHE_PAGINATION_PREVIOUS] = selectedPage - 1;
|
||||
if (selectedPage >= pages.size())
|
||||
ctx[MUSTACHE_PAGINATION_NEXT] = pages.size();
|
||||
else
|
||||
ctx[MUSTACHE_PAGINATION_NEXT] = selectedPage + 1;
|
||||
}
|
||||
return page.render(ctx);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user