1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
// file : mod/mod-build-configs.cxx -*- C++ -*-
// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
#include <mod/mod-build-configs.hxx>
#include <libstudxml/serializer.hxx>
#include <web/xhtml.hxx>
#include <web/module.hxx>
#include <mod/page.hxx>
#include <mod/options.hxx>
using namespace std;
using namespace bbot;
using namespace brep::cli;
// While currently the user-defined copy constructor is not required (we don't
// need to deep copy nullptr's), it is a good idea to keep the placeholder
// ready for less trivial cases.
//
brep::build_configs::
build_configs (const build_configs& r)
: handler (r),
build_config_module (r),
options_ (r.initialized_ ? r.options_ : nullptr)
{
}
void brep::build_configs::
init (scanner& s)
{
HANDLER_DIAG;
options_ = make_shared<options::build_configs> (
s, unknown_mode::fail, unknown_mode::fail);
if (options_->build_config_specified ())
build_config_module::init (static_cast<options::build> (*options_));
}
bool brep::build_configs::
handle (request& rq, response& rs)
{
using namespace web::xhtml;
HANDLER_DIAG;
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 ());
params::build_configs params;
try
{
name_value_scanner s (rq.parameters (1024));
params = params::build_configs (s, unknown_mode::fail, unknown_mode::fail);
}
catch (const cli::exception& e)
{
throw invalid_request (400, e.what ());
}
size_t page (params.page ());
const char* title ("Build Configurations");
xml::serializer s (rs.content (), title);
s << HTML
<< HEAD
<< TITLE << title << ~TITLE
<< CSS_LINKS (path ("build-configs.css"), root)
<< ~HEAD
<< BODY
<< DIV_HEADER (options_->logo (), options_->menu (), root, tenant)
<< 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<const build_config*> 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"))
{
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;
// Append the base class, if present.
//
auto i (build_conf_->class_inheritance_map.find (cls));
if (i != build_conf_->class_inheritance_map.end ())
{
classes += ':';
classes += i->second;
}
}
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 << DIV_PAGER (page,
count,
page_configs,
options_->build_config_pages (),
root.string () + "?build-configs")
<< ~DIV
<< ~BODY
<< ~HTML;
return true;
}
|