diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-09-15 17:48:57 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-09-24 11:23:34 +0200 |
commit | b192a3fcc7875210b3e1f6bd2292022a78c9f0e1 (patch) | |
tree | fb56f7c60405a91483d31ba934b5752ec854dd19 | |
parent | d09f17fbd7ffd5ea92feeb8aded6c66b1bfa2333 (diff) |
Partial package version detals page implementation
-rw-r--r-- | brep/buildfile | 2 | ||||
-rw-r--r-- | brep/options.cli | 8 | ||||
-rw-r--r-- | brep/package-search.cxx | 5 | ||||
-rw-r--r-- | brep/package-version-details | 32 | ||||
-rw-r--r-- | brep/package-version-details.cxx | 103 | ||||
-rw-r--r-- | brep/package-version-search.cxx | 10 | ||||
-rw-r--r-- | brep/services.cxx | 7 | ||||
-rwxr-xr-x | build.sh | 5 | ||||
-rw-r--r-- | etc/httpd.conf | 13 | ||||
-rw-r--r-- | etc/package-version-details.conf | 7 |
10 files changed, 181 insertions, 11 deletions
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 <brep/package-search> #include <string> -#include <memory> // make_shared() +#include <memory> // make_shared() +#include <cstddef> // size_t #include <xml/serializer> @@ -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 <memory> // shared_ptr + +#include <odb/forward.hxx> // database + +#include <brep/module> +#include <brep/options> + +namespace brep +{ + class package_version_details: public module + { + private: + virtual void + handle (request&, response&); + + virtual void + init (cli::scanner&); + + private: + std::shared_ptr<options::package_version_details> options_; + std::shared_ptr<odb::core::database> 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 <brep/package-version-details> + +#include <string> +#include <memory> // make_shared() +#include <cassert> +#include <stdexcept> // invalid_argument + + +#include <xml/serializer> + +#include <odb/database.hxx> +#include <odb/transaction.hxx> + +#include <web/xhtml> +#include <web/module> +#include <web/mime-url-encoding> + +#include <brep/package> +#include <brep/package-odb> +#include <brep/shared-database> + +using namespace std; +using namespace cli; +using namespace odb::core; + +namespace brep +{ + void package_version_details:: + init (scanner& s) + { + MODULE_DIAG; + + options_ = make_shared<options::package_version_details> ( + 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 <brep/package-version-search> #include <string> -#include <memory> // make_shared() +#include <memory> // make_shared(), shared_ptr +#include <cstddef> // size_t +#include <cassert> #include <xml/serializer> @@ -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 <brep/package-search> #include <brep/package-version-search> +#include <brep/package-version-details> 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"}); @@ -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" </IfModule> +LoadModule package_version_details_srv ${AP_MODULE_DIR}/libbrep-apache.so + +<IfModule package_version_details_srv> + 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" +</IfModule> + <LocationMatch ^/$> SetHandler package-search </LocationMatch> @@ -64,8 +72,9 @@ LoadModule package_version_search_srv ${AP_MODULE_DIR}/libbrep-apache.so SetHandler package-version-search </LocationMatch> -# Location for package version details url -#<LocationMatch ^/go/[^/]+/[^/]+$> +<LocationMatch ^/go/[^/]+/[^/]+$> + SetHandler package-version-details +</LocationMatch> 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 |