From 1ce84922e3008cad6cf1b9056b705f2642bd3772 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 28 Oct 2015 17:56:30 +0200 Subject: WEB pages re-styling --- brep/package-search.cxx | 86 +++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 49 deletions(-) (limited to 'brep/package-search.cxx') diff --git a/brep/package-search.cxx b/brep/package-search.cxx index ffe5cb9..64e43f1 100644 --- a/brep/package-search.cxx +++ b/brep/package-search.cxx @@ -73,80 +73,68 @@ namespace brep throw invalid_request (400, e.what ()); } - // @@ Would be nice to have a manipulator indenting string properly - // according to the most nested element identation. - // - const char* ident ("\n "); - const char* title ("Package Search"); - serializer s (rs.content (), title); + const string& sq (pr.query ()); // Search query. + size_t pg (pr.page ()); + string qp (sq.empty () ? "" : "q=" + mime_url_encode (sq)); + size_t rp (options_->results_on_page ()); + + serializer s (rs.content (), "Packages"); + + const string& title ( + sq.empty () ? s.output_name () : s.output_name () + " " + sq); s << HTML << HEAD << TITLE << title << ~TITLE - << CSS_STYLE << ident - << A_STYLE () << ident - << DIV_PAGER_STYLE () << ident - << "#packages {font-size: x-large;}" << ident - << ".package {margin: 0.5em 0 0;}" << ident - << ".name {font-size: x-large;}" << ident - << ".tags {margin: 0.3em 0 0;}" << ident - << "form {margin: 0.5em 0 0 0;}" - << ~CSS_STYLE + << CSS_LINKS ("/package-search.css") << ~HEAD - << BODY; - - const string& sq (pr.query ()); // Search query. - string qp (sq.empty () ? "" : "q=" + mime_url_encode (sq)); - size_t rop (options_->results_on_page ()); + << BODY + << DIV_HEADER () + << DIV(ID="content"); transaction t (db_->begin ()); - size_t pc ( + auto pc ( db_->query_value ( search_param (sq))); - s << DIV(ID="packages") << "Packages (" << pc << ")" << ~DIV - << FORM_SEARCH (sq); - auto r ( db_->query ( search_param (sq) + "ORDER BY rank DESC, name" + - "OFFSET" + to_string (pr.page () * rop) + - "LIMIT" + to_string (rop))); + "OFFSET" + to_string (pg * rp) + + "LIMIT" + to_string (rp))); + + s << FORM_SEARCH (sq.c_str ()) + << DIV_COUNTER (pc, "Package", "Packages") + + // Enclose the subsequent tables to be able to use nth-child CSS selector. + // + << DIV; for (const auto& pr: r) { shared_ptr p (db_->load (pr.id)); - s << DIV(CLASS="package") - << DIV(CLASS="name") - << A - << HREF << "/go/" << mime_url_encode (p->id.name); - - // Propagate search criteria to the package version search url. - // - if (!qp.empty ()) - s << "?" << qp; - - s << ~HREF - << p->id.name - << ~A - << ~DIV - << DIV(CLASS="summary") << p->summary << ~DIV - << DIV_TAGS (p->tags) - << DIV_LICENSES (p->license_alternatives) - << DIV(CLASS="dependencies") - << "Dependencies: " << p->dependencies.size () - << ~DIV - << ~DIV; + s << TABLE(CLASS="proplist package") + << TBODY + << TR_NAME (p->id.name, qp) + << TR_SUMMARY (p->summary) + << TR_LICENSE (p->license_alternatives) + << TR_TAGS (p->tags) + << TR_DEPENDS (p->dependencies) + << TR_REQUIRES (p->requirements) + << ~TBODY + << ~TABLE; } t.commit (); - string u (qp.empty () ? "/" : ("/?" + qp)); + string url (qp.empty () ? "/" : ("/?" + qp)); - s << DIV_PAGER (pr.page (), pc, rop, options_->pages_in_pager (), u) + s << ~DIV + << DIV_PAGER (pg, pc, rp, options_->pages_in_pager (), url) + << ~DIV << ~BODY << ~HTML; } -- cgit v1.1