diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-16 20:02:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-11-25 20:35:10 +0200 |
commit | 2700ed6a3e1092a064f28b07f8e2c4e5b9b830e7 (patch) | |
tree | a54ffc979dde42e609bc9877120fa010887c6b66 /brep/repository-details.cxx | |
parent | 48a3c47d34c2acc0a39e2db5acfd437dace499c1 (diff) |
Implement new URL path schema for the web interface
Diffstat (limited to 'brep/repository-details.cxx')
-rw-r--r-- | brep/repository-details.cxx | 142 |
1 files changed, 75 insertions, 67 deletions
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 <brep/repository-details> -#include <string> -#include <memory> // make_shared() - #include <xml/serializer> #include <odb/database.hxx> @@ -17,85 +14,96 @@ #include <web/mime-url-encoding> #include <brep/page> +#include <brep/types> +#include <brep/utility> #include <brep/options> #include <brep/package> #include <brep/package-odb> #include <brep/shared-database> -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<options::repository_details> ( + s, unknown_mode::fail, unknown_mode::fail); - options_ = make_shared<options::repository_details> ( - 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<repository>; + + for (const auto& r: + db_->query<repository> ( + 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<repository>; - auto rp (db_->query<repository> (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; } |