From 2700ed6a3e1092a064f28b07f8e2c4e5b9b830e7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 16 Nov 2015 20:02:06 +0200 Subject: Implement new URL path schema for the web interface --- brep/repository-details.cxx | 142 +++++++++++++++++++++++--------------------- 1 file changed, 75 insertions(+), 67 deletions(-) (limited to 'brep/repository-details.cxx') diff --git a/brep/repository-details.cxx b/brep/repository-details.cxx index 86a6099..eb2885c 100644 --- a/brep/repository-details.cxx +++ b/brep/repository-details.cxx @@ -4,9 +4,6 @@ #include -#include -#include // make_shared() - #include #include @@ -17,85 +14,96 @@ #include #include +#include +#include #include #include #include #include -using namespace std; using namespace odb::core; +using namespace brep::cli; -namespace brep +void brep::repository_details:: +init (scanner& s) { - using namespace cli; + MODULE_DIAG; - void repository_details:: - init (scanner& s) - { - MODULE_DIAG; + options_ = make_shared ( + s, unknown_mode::fail, unknown_mode::fail); - options_ = make_shared ( - s, unknown_mode::fail, unknown_mode::fail); + db_ = shared_database (options_->db_host (), options_->db_port ()); +} - db_ = shared_database (options_->db_host (), options_->db_port ()); - } +void brep::repository_details:: +handle (request& rq, response& rs) +{ + using namespace web::xhtml; - void repository_details:: - handle (request&, response& rs) + MODULE_DIAG; + + // The module options object is not changed after being created once per + // server process. + // + static const dir_path& root ( + options_->root ().empty () + ? dir_path ("/") + : options_->root ()); + + // Make sure no parameters passed. + // + try { - using namespace web::xhtml; + param_scanner s (rq.parameters ()); + params::repository_details (s, unknown_mode::fail, unknown_mode::fail); + } + catch (const unknown_argument& e) + { + throw invalid_request (400, e.what ()); + } - MODULE_DIAG; + static const string title ("About"); + xml::serializer s (rs.content (), title); - // The module options object is not changed after being created once per - // server process. + s << HTML + << HEAD + << TITLE << title << ~TITLE + << CSS_LINKS (path ("repository-details.css"), root) + << ~HEAD + << BODY + << DIV_HEADER (root) + << DIV(ID="content"); + + transaction t (db_->begin ()); + + using query = query; + + for (const auto& r: + db_->query ( + query::internal + "ORDER BY" + query::priority)) + { + //@@ Feels like a lot of trouble (e.g., id_attribute()) for very + // dubious value. A link to the package search page just for + // this repository would probably be more useful. // - static const dir_path& rt ( - options_->root ().empty () - ? dir_path ("/") - : options_->root ()); - - xml::serializer s (rs.content (), "About"); - const string& title (s.output_name ()); - static const path sp ("repository-details.css"); - - s << HTML - << HEAD - << TITLE << title << ~TITLE - << CSS_LINKS (sp, rt) - << ~HEAD - << BODY - << DIV_HEADER (rt) - << DIV(ID="content"); - - transaction t (db_->begin ()); - - using query = query; - auto rp (db_->query (query::internal + "ORDER BY name")); - - for (const auto& r: rp) - { - string id (id_attribute (r.name)); - s << H1(ID=id) - << A(HREF="#" + web::mime_url_encode (id)) << r.name << ~A - << ~H1; - - if (r.summary) - s << H2 << *r.summary << ~H2; - - if (r.description) - s << P_DESCRIPTION (*r.description, false); - - if (r.email) - s << P - << A << HREF << "mailto:" << *r.email << ~HREF << *r.email << ~A - << ~P; - } - - t.commit (); - - s << ~DIV - << ~BODY - << ~HTML; + string id (html_id (r.name)); + s << H1(ID=id) + << A(HREF="#" + web::mime_url_encode (id)) << r.display_name << ~A + << ~H1; + + if (r.summary) + s << H2 << *r.summary << ~H2; + + if (r.description) + s << P_DESCRIPTION (*r.description); + + if (r.email) + s << P << A(HREF="mailto:" + *r.email) << *r.email << ~A << ~P; } + + t.commit (); + + s << ~DIV + << ~BODY + << ~HTML; } -- cgit v1.1