Handlers: HandlerAllPages / HandlerCategory: Use PageListRenderer

This commit is contained in:
Albert S. 2022-04-03 11:14:09 +02:00
parent 1c1416934b
commit 634cb2d7ee
4 changed files with 25 additions and 14 deletions

View File

@ -19,6 +19,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include "handlerallpages.h" #include "handlerallpages.h"
#include "../grouper.h"
#include "../pagelistrenderer.h"
Response HandlerAllPages::handleRequest(const Request &r) Response HandlerAllPages::handleRequest(const Request &r)
{ {
@ -27,17 +29,21 @@ Response HandlerAllPages::handleRequest(const Request &r)
Response response; Response response;
auto pageDao = this->database->createPageDao(); auto pageDao = this->database->createPageDao();
QueryOption qo = queryOption(r); QueryOption qo = queryOption(r);
auto resultList = pageDao->getPageList(qo); std::vector<Page> pageList = pageDao->getPageList(qo);
if(resultList.size() == 0) if(pageList.size() == 0)
{ {
return errorResponse("No pages", "This wiki does not have any pages yet"); return errorResponse("No pages", "This wiki does not have any pages yet");
} }
TemplatePage searchPage = this->templ->getPage("allpages");
std::string body = this->templ->renderSearch(resultList); PageListRenderer pagelistrender(*this->templ, *this->urlProvider, *this->database);
searchPage.setVar("pagelist", body); TemplatePage allPages = this->templ->getPage("allpages");
searchPage.setVar("title", createPageTitle("All pages")); allPages.setVar("pagelistcontent", pagelistrender.render(pageList, r.get("rendertype")));
setGeneralVars(searchPage); allPages.setVar("pagelistletterlink", this->urlProvider->allPages(PageListRenderer::RENDER_GROUP_BY_LETTER));
response.setBody(searchPage.render()); allPages.setVar("pagelistcreationdatelink", this->urlProvider->allPages(PageListRenderer::RENDER_GROUP_BY_CREATIONDATE));
allPages.setVar("title", createPageTitle("All pages"));
setGeneralVars(allPages);
response.setBody(allPages.render());
response.setStatus(200); response.setStatus(200);
return response; return response;
} }

View File

@ -19,6 +19,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
*/ */
#include "handlercategory.h" #include "handlercategory.h"
#include "../pagelistrenderer.h"
Response HandlerCategory::handleRequest(const Request &r) Response HandlerCategory::handleRequest(const Request &r)
{ {
@ -34,8 +35,12 @@ Response HandlerCategory::handleRequest(const Request &r)
QueryOption qo = queryOption(r); QueryOption qo = queryOption(r);
auto resultList = categoryDao->fetchMembers(categoryname, qo); auto resultList = categoryDao->fetchMembers(categoryname, qo);
TemplatePage searchPage = this->templ->getPage("show_category"); TemplatePage searchPage = this->templ->getPage("show_category");
std::string body = this->templ->renderSearch(resultList); PageListRenderer pagelistrender(*this->templ, *this->urlProvider, *this->database);
searchPage.setVar("pagelist", body);
std::string body = pagelistrender.render(resultList, r.get("rendertype"));
searchPage.setVar("pagelistcontent", body);
searchPage.setVar("pagelistletterlink", this->urlProvider->category(categoryname, PageListRenderer::RENDER_GROUP_BY_LETTER));
searchPage.setVar("pagelistcreationdatelink", this->urlProvider->category(categoryname, PageListRenderer::RENDER_GROUP_BY_CREATIONDATE));
searchPage.setVar("categoryname", categoryname); searchPage.setVar("categoryname", categoryname);
setGeneralVars(searchPage); setGeneralVars(searchPage);
searchPage.setVar("title", createPageTitle("Category: " + categoryname)); searchPage.setVar("title", createPageTitle("Category: " + categoryname));

View File

@ -1,6 +1,6 @@
{qswiki:include:general_header} {qswiki:include:general_header}
<div id="content" style="margin-top: 10px;"> <div id="content" style="margin-top: 10px;">
<h2>All pages</h2> <h2>All pages</h2>
{qswiki:var:pagelist} {qswiki:include:pagelistrender}
</div> </div>
{qswiki:include:general_footer} {qswiki:include:general_footer}

View File

@ -1,6 +1,6 @@
{qswiki:include:general_header} {qswiki:include:general_header}
<main id="content"> <main id="content">
<h2>Category: {qswiki:var:categoryname}</h2> <h2>Category: {qswiki:var:categoryname}</h2>
{qswiki:var:pagelist} {qswiki:include:pagelistrender}
</main> </main>
{qswiki:include:general_footer} {qswiki:include:general_footer}