From b192a3fcc7875210b3e1f6bd2292022a78c9f0e1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 15 Sep 2015 17:48:57 +0200 Subject: Partial package version detals page implementation --- brep/buildfile | 2 +- brep/options.cli | 8 +++ brep/package-search.cxx | 5 +- brep/package-version-details | 32 ++++++++++++ brep/package-version-details.cxx | 103 +++++++++++++++++++++++++++++++++++++++ brep/package-version-search.cxx | 10 ++-- brep/services.cxx | 7 +++ build.sh | 5 +- etc/httpd.conf | 13 ++++- etc/package-version-details.conf | 7 +++ 10 files changed, 181 insertions(+), 11 deletions(-) create mode 100644 brep/package-version-details create mode 100644 brep/package-version-details.cxx create mode 100644 etc/package-version-details.conf diff --git a/brep/buildfile b/brep/buildfile index 7e73d2b..c903b37 100644 --- a/brep/buildfile +++ b/brep/buildfile @@ -22,7 +22,7 @@ libso{brep}: cxx.export.poptions = -I$out_root -I$src_root import libs += libstudxml%lib{studxml} brep = cxx{diagnostics module services package-search package-version-search \ - shared-database page} cli.cxx{options} + package-version-details shared-database page} cli.cxx{options} web = ../web/apache/cxx{request service} ../web/cxx{mime-url-encoding} libso{brep-apache}: $brep $web libso{brep} $libs diff --git a/brep/options.cli b/brep/options.cli index 3dc5553..90063c1 100644 --- a/brep/options.cli +++ b/brep/options.cli @@ -33,6 +33,10 @@ namespace brep std::uint16_t results-on-page = 10; std::uint16_t pages-in-pager = 10; }; + + class package_version_details: module, db + { + }; } // Web module HTTP request parameters. @@ -62,5 +66,9 @@ namespace brep // std::string query | q = ""; }; + + class package_version_details + { + }; } } diff --git a/brep/package-search.cxx b/brep/package-search.cxx index f51dade..02a8547 100644 --- a/brep/package-search.cxx +++ b/brep/package-search.cxx @@ -5,7 +5,8 @@ #include #include -#include // make_shared() +#include // make_shared() +#include // size_t #include @@ -77,7 +78,7 @@ namespace brep << ".package {margin: 0.5em 0 0;}" << ident << ".name {font-size: x-large;}" << ident << ".tags {margin: 0.1em 0 0;}" << ident - << ".tag {padding: 0 0.3em 0 0;}" << ident + << ".tag {padding: 0 0.3em 0 0;}" << ~CSS_STYLE << ~HEAD << BODY; diff --git a/brep/package-version-details b/brep/package-version-details new file mode 100644 index 0000000..7917de3 --- /dev/null +++ b/brep/package-version-details @@ -0,0 +1,32 @@ +// file : brep/package-version-details -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#ifndef BREP_PACKAGE_VERSION_DETAILS +#define BREP_PACKAGE_VERSION_DETAILS + +#include // shared_ptr + +#include // database + +#include +#include + +namespace brep +{ + class package_version_details: public module + { + private: + virtual void + handle (request&, response&); + + virtual void + init (cli::scanner&); + + private: + std::shared_ptr options_; + std::shared_ptr db_; + }; +} + +#endif // BREP_PACKAGE_VERSION_DETAILS diff --git a/brep/package-version-details.cxx b/brep/package-version-details.cxx new file mode 100644 index 0000000..094c3a3 --- /dev/null +++ b/brep/package-version-details.cxx @@ -0,0 +1,103 @@ +// file : brep/package-version-details.cxx -*- C++ -*- +// copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +// license : MIT; see accompanying LICENSE file + +#include + +#include +#include // make_shared() +#include +#include // invalid_argument + + +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include + +using namespace std; +using namespace cli; +using namespace odb::core; + +namespace brep +{ + void package_version_details:: + init (scanner& s) + { + MODULE_DIAG; + + options_ = make_shared ( + s, unknown_mode::fail, unknown_mode::fail); + + db_ = shared_database (options_->db_host (), options_->db_port ()); + } + + void package_version_details:: + handle (request& rq, response& rs) + { + using namespace xml; + using namespace web; + using namespace web::xhtml; + + MODULE_DIAG; + + path::reverse_iterator i (rq.path ().rbegin ()); + version ver; + + try + { + ver = version (*i++); + } + catch (const invalid_argument& ) + { + throw invalid_request (400, "invalid package version format"); + } + + assert (i != rq.path ().rend ()); + const string& package (*i); + + params::package_version_details pr; + + try + { + param_scanner s (rq.parameters ()); + pr = params::package_version_details ( + s, unknown_mode::fail, unknown_mode::fail); + } + catch (const unknown_argument& e) + { + throw invalid_request (400, e.what ()); + } + + const char* ident ("\n "); + const string name (package + "-" + ver.string ()); + const string title ("Package Version " + name); + serializer s (rs.content (), title); + + s << HTML + << HEAD + << TITLE << title << ~TITLE + << CSS_STYLE << ident + << "a {text-decoration: none;}" << ident + << "a:hover {text-decoration: underline;}" << ident + << ".name {font-size: xx-large; font-weight: bold;}" + << ~CSS_STYLE + << ~HEAD + << BODY; + + s << DIV(CLASS="name") + << name + << ~DIV; + + s << ~BODY + << ~HTML; + } +} diff --git a/brep/package-version-search.cxx b/brep/package-version-search.cxx index df0ba81..d7fea2d 100644 --- a/brep/package-version-search.cxx +++ b/brep/package-version-search.cxx @@ -5,7 +5,9 @@ #include #include -#include // make_shared() +#include // make_shared(), shared_ptr +#include // size_t +#include #include @@ -81,7 +83,7 @@ namespace brep << ".tag {padding: 0 0.3em 0 0;}" << ident << ".versions {font-size: x-large; margin: 0.5em 0 0;}" << ident << ".package_version {margin: 0.5em 0 0;}" << ident - << ".version {font-size: x-large;}" << ident + << ".version {font-size: x-large;}" << ~CSS_STYLE << ~HEAD << BODY; @@ -224,8 +226,8 @@ namespace brep return url; }); - s << pager (pr.page (), pvc, rop, options_->pages_in_pager (), u) - << ~BODY + s << pager (pr.page (), pvc, rop, options_->pages_in_pager (), u) + << ~BODY << ~HTML; } } diff --git a/brep/services.cxx b/brep/services.cxx index 510a231..c022a7d 100644 --- a/brep/services.cxx +++ b/brep/services.cxx @@ -8,6 +8,7 @@ #include #include +#include using namespace brep; using web::apache::service; @@ -23,3 +24,9 @@ service AP_MODULE_DECLARE_DATA package_version_search_srv ( "package-version-search", package_version_search_mod, {"db-host", "db-port", "conf"}); + +static package_version_details package_version_details_mod; +service AP_MODULE_DECLARE_DATA package_version_details_srv ( + "package-version-details", + package_version_details_mod, + {"db-host", "db-port", "conf"}); diff --git a/build.sh b/build.sh index 78d68e9..9517223 100755 --- a/build.sh +++ b/build.sh @@ -30,8 +30,9 @@ cli --include-with-brackets --include-prefix brep --hxx-suffix "" \ echo "g++ libbrep-apache.so" -s="package-search.cxx package-version-search.cxx module.cxx diagnostics.cxx \ -page.cxx services.cxx options.cxx shared-database.cxx \ +s="package-search.cxx package-version-search.cxx package-version-details.cxx \ +module.cxx diagnostics.cxx page.cxx services.cxx options.cxx \ +shared-database.cxx \ ../web/apache/request.cxx ../web/apache/service.cxx \ ../web/mime-url-encoding.cxx" diff --git a/etc/httpd.conf b/etc/httpd.conf index ef8cb50..bf1d9e2 100644 --- a/etc/httpd.conf +++ b/etc/httpd.conf @@ -56,6 +56,14 @@ LoadModule package_version_search_srv ${AP_MODULE_DIR}/libbrep-apache.so package-version-search-conf "${AP_CONFIG_DIR}/package-version-search.conf" +LoadModule package_version_details_srv ${AP_MODULE_DIR}/libbrep-apache.so + + + package-version-details-db-host ${AP_DB_HOST} + package-version-details-db-port ${AP_DB_PORT} + package-version-details-conf "${AP_CONFIG_DIR}/package-version-details.conf" + + SetHandler package-search @@ -64,8 +72,9 @@ LoadModule package_version_search_srv ${AP_MODULE_DIR}/libbrep-apache.so SetHandler package-version-search -# Location for package version details url -# + + SetHandler package-version-details + ExtendedStatus On diff --git a/etc/package-version-details.conf b/etc/package-version-details.conf new file mode 100644 index 0000000..61a6fb9 --- /dev/null +++ b/etc/package-version-details.conf @@ -0,0 +1,7 @@ +# file : etc/package-version-details.conf +# copyright : Copyright (c) 2014-2015 Code Synthesis Ltd +# license : MIT; see accompanying LICENSE file +# +# brep::module options +# +verb 1 -- cgit v1.1