From 7dabb6e931740b2777be5dca53c3cec0b984f0fb Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 3 Dec 2018 21:25:27 +0300 Subject: Print configuration target and classes on build configurations page --- mod/mod-build-configs.cxx | 78 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 12 deletions(-) (limited to 'mod/mod-build-configs.cxx') diff --git a/mod/mod-build-configs.cxx b/mod/mod-build-configs.cxx index d3d5191..99a092d 100644 --- a/mod/mod-build-configs.cxx +++ b/mod/mod-build-configs.cxx @@ -59,21 +59,24 @@ handle (request& rq, response& rs) if (build_conf_ == nullptr) throw invalid_request (501, "not implemented"); + const size_t page_configs (options_->build_config_page_entries ()); const dir_path& root (options_->root ()); - // Make sure no parameters passed. - // + params::build_configs params; + try { name_value_scanner s (rq.parameters (1024)); - params::build_configs (s, unknown_mode::fail, unknown_mode::fail); + params = params::build_configs (s, unknown_mode::fail, unknown_mode::fail); } catch (const cli::exception& e) { throw invalid_request (400, e.what ()); } - static const string title ("Build Configurations"); + size_t page (params.page ()); + + const char* title ("Build Configurations"); xml::serializer s (rs.content (), title); s << HTML @@ -83,20 +86,71 @@ handle (request& rq, response& rs) << ~HEAD << BODY << DIV_HEADER (options_->logo (), options_->menu (), root, tenant) - << DIV(ID="content") - << TABLE(CLASS="proplist") - << TBODY; + << DIV(ID="content"); + // Print build configurations that belong to the 'all' class. + // + // We will calculate the total configuration count and cache configurations + // for printing (skipping an appropriate number of them for page number + // greater than one) on the same pass. Note that we need to print the count + // before printing the configurations. + // + size_t count (0); + vector configs; + configs.reserve (page_configs); + + size_t skip (page * page_configs); + size_t print (page_configs); for (const build_config& c: *build_conf_) { if (belongs (c, "all")) - s << TR(CLASS="config") - << TD << SPAN(CLASS="value") << c.name << ~SPAN << ~TD - << ~TR; + { + if (skip != 0) + --skip; + else if (print != 0) + { + configs.emplace_back (&c); + --print; + } + + ++count; + } + } + + // Print configuration count. + // + s << DIV_COUNTER (count, "Build Configuration", title); + + // Finally, print the cached build configurations. + // + // Enclose the subsequent tables to be able to use nth-child CSS selector. + // + s << DIV; + for (const build_config* c: configs) + { + string classes; + for (const string& cls: c->classes) + { + if (!classes.empty ()) + classes += ' '; + classes += cls; + } + + s << TABLE(CLASS="proplist config") + << TBODY + << TR_VALUE ("name", c->name) + << TR_VALUE ("target", c->target.string ()) + << TR_VALUE ("classes", classes) + << ~TBODY + << ~TABLE; } + s << ~DIV; - s << ~TBODY - << ~TABLE + s << DIV_PAGER (page, + count, + page_configs, + options_->build_config_pages (), + root.string () + "?build-configs") << ~DIV << ~BODY << ~HTML; -- cgit v1.1