aboutsummaryrefslogtreecommitdiff
path: root/mod
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-05-28 19:48:01 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-05-29 15:33:03 +0300
commitd0e23f3ff61e9fe1f790dac0c6fc0873777d0f86 (patch)
tree6573c1d96989d966aaf8472efbfeac94666fd07b /mod
parent3ff2e95c6bd0a6692d5631acd8db66f6c604fdda (diff)
Add some page style improvements
Diffstat (limited to 'mod')
-rw-r--r--mod/mod-package-details.cxx3
-rw-r--r--mod/mod-package-version-details.cxx8
-rw-r--r--mod/page.cxx52
-rw-r--r--mod/page.hxx11
4 files changed, 55 insertions, 19 deletions
diff --git a/mod/mod-package-details.cxx b/mod/mod-package-details.cxx
index 7b75e62..74b3840 100644
--- a/mod/mod-package-details.cxx
+++ b/mod/mod-package-details.cxx
@@ -255,9 +255,6 @@ handle (request& rq, response& rs)
s << TABLE(CLASS="proplist version")
<< TBODY
<< TR_VERSION (name, p->version, root, tenant, p->upstream_version)
-
- // @@ Shouldn't we skip low priority row ? Don't think so, why?
- //
<< TR_PRIORITY (p->priority);
// Comparing objects of the license_alternatives class as being of the
diff --git a/mod/mod-package-version-details.cxx b/mod/mod-package-version-details.cxx
index 437bff4..d147449 100644
--- a/mod/mod-package-version-details.cxx
+++ b/mod/mod-package-version-details.cxx
@@ -221,7 +221,9 @@ handle (request& rq, response& rs)
{
assert (pkg->location);
- s << TR_DOWNLOAD (rl.url ().string () + "/" + pkg->location->string ());
+ s << TR_LINK (rl.url ().string () + "/" + pkg->location->string (),
+ pkg->location->leaf ().string (),
+ "download");
}
if (pkg->fragment)
@@ -268,7 +270,7 @@ handle (request& rq, response& rs)
const auto& ds (pkg->dependencies);
if (!ds.empty ())
{
- s << H3 << "Depends" << ~H3
+ s << H3 << "Depends (" << ds.size () << ")" << ~H3
<< TABLE(CLASS="proplist", ID="depends")
<< TBODY;
@@ -361,7 +363,7 @@ handle (request& rq, response& rs)
const auto& rm (pkg->requirements);
if (!rm.empty ())
{
- s << H3 << "Requires" << ~H3
+ s << H3 << "Requires (" << rm.size () << ")" << ~H3
<< TABLE(CLASS="proplist", ID="requires")
<< TBODY;
diff --git a/mod/page.cxx b/mod/page.cxx
index 0c4c257..e03ee4b 100644
--- a/mod/page.cxx
+++ b/mod/page.cxx
@@ -15,6 +15,8 @@
#include <libstudxml/serializer.hxx>
+#include <libbutl/url.mxx>
+
#include <web/xhtml.hxx>
#include <web/xhtml-fragment.hxx>
#include <web/mime-url-encoding.hxx>
@@ -575,10 +577,32 @@ namespace brep
void TR_URL::
operator() (serializer& s) const
{
+ // Strip the URL prefix for the link text.
+ //
+ // Note that it may not be a valid URL (see bpkg::url).
+ //
+ // @@ We should probably inherit bpkg::url from butl::url and make sure
+ // that it is "rootfull" and the authority is present. Should we also
+ // white-list the schema for security reasons? Then the offset will
+ // always be: url_.string ().find ("://") + 3.
+ //
+ size_t p (string::npos);
+
+ if (butl::url::traits::find (url_) == 0) // Is it a "rootfull" URL ?
+ {
+ size_t n (url_.find (":/") + 2);
+ if (url_[n] == '/' && url_[n + 1] != '\0') // Has authority?
+ p = n + 1;
+ }
+
s << TR(CLASS=label_)
<< TH << label_ << ~TH
<< TD
- << SPAN(CLASS="value") << A(HREF=url_) << url_ << ~A << ~SPAN
+ << SPAN(CLASS="value")
+ << A(HREF=url_)
+ << (p != string::npos ? url_.c_str () + p : url_.c_str ())
+ << ~A
+ << ~SPAN
<< SPAN_COMMENT (url_.comment)
<< ~TD
<< ~TR;
@@ -602,16 +626,26 @@ namespace brep
// TR_PRIORITY
//
+ static const strings priority_names ({"medium", "high", "security"});
+
void TR_PRIORITY::
operator() (serializer& s) const
{
- static const strings priority_names ({"low", "medium", "high", "security"});
- assert (priority_ < priority_names.size ());
+ // Omit the element for low priority.
+ //
+ if (priority_ == priority::low)
+ return;
+
+ size_t p (priority_ - 1);
+
+ assert (p < priority_names.size ());
+
+ const string& pn (priority_names[p]);
s << TR(CLASS="priority")
<< TH << "priority" << ~TH
<< TD
- << SPAN(CLASS="value") << priority_names[priority_] << ~SPAN
+ << SPAN(CLASS="value " + pn) << pn << ~SPAN
<< SPAN_COMMENT (priority_.comment)
<< ~TD
<< ~TR;
@@ -649,15 +683,15 @@ namespace brep
<< ~TR;
}
- // TR_DOWNLOAD
+ // TR_LINK
//
- void TR_DOWNLOAD::
+ void TR_LINK::
operator() (serializer& s) const
{
- s << TR(CLASS="download")
- << TH << "download" << ~TH
+ s << TR(CLASS=label_)
+ << TH << label_ << ~TH
<< TD
- << SPAN(CLASS="value") << A(HREF=url_) << url_ << ~A << ~SPAN
+ << SPAN(CLASS="value") << A(HREF=url_) << text_ << ~A << ~SPAN
<< ~TD
<< ~TR;
}
diff --git a/mod/page.hxx b/mod/page.hxx
index 28257c1..cd2048e 100644
--- a/mod/page.hxx
+++ b/mod/page.hxx
@@ -384,7 +384,7 @@ namespace brep
const requirements& requirements_;
};
- // Generate url element.
+ // Generate url element. Strip the `<scheme>://` prefix from the link text.
//
class TR_URL
{
@@ -460,18 +460,21 @@ namespace brep
const repository_location& location_;
};
- // Generate package download URL element.
+ // Generate link element.
//
- class TR_DOWNLOAD
+ class TR_LINK
{
public:
- TR_DOWNLOAD (const string& u): url_ (u) {}
+ TR_LINK (const string& u, const string& t, const char* l)
+ : url_ (u), text_ (t), label_ (l) {}
void
operator() (xml::serializer&) const;
private:
const string& url_;
+ const string& text_;
+ const char* label_;
};
// Generate sha256sum element.