From 1367aa09951e0aa7491bc2a5bf7209b0b47be65e Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 13 Sep 2018 19:27:00 +0300 Subject: Add support for packages and builds global views --- mod/mod-packages.cxx | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'mod/mod-packages.cxx') diff --git a/mod/mod-packages.cxx b/mod/mod-packages.cxx index 1515a53..27e1270 100644 --- a/mod/mod-packages.cxx +++ b/mod/mod-packages.cxx @@ -67,7 +67,7 @@ init (scanner& s) template static inline query -search_param (const brep::string& q, const brep::string& t) +search_param (const brep::string& q, const brep::optional& t) { using query = query; return "(" + @@ -75,7 +75,7 @@ search_param (const brep::string& q, const brep::string& t) ? query ("NULL") : "plainto_tsquery (" + query::_val (q) + ")") + "," + - query::_val (t) + + (!t ? query ("NULL") : query (query::_val (*t))) + ")"; } @@ -89,6 +89,7 @@ handle (request& rq, response& rs) const size_t res_page (options_->search_results ()); const dir_path& root (options_->root ()); const string& title (options_->search_title ()); + const string& tenant_name (options_->tenant_name ()); params::packages params; @@ -135,25 +136,30 @@ handle (request& rq, response& rs) << DIV_HEADER (options_->logo (), options_->menu (), root, tenant) << DIV(ID="content"); + // If the tenant is empty then we are in the global view and will display + // packages from all the tenants. + // + optional tn; + if (!tenant.empty ()) + tn = tenant; + session sn; transaction t (package_db_->begin ()); auto pkg_count ( package_db_->query_value ( - search_param (squery, tenant))); + search_param (squery, tn))); s << FORM_SEARCH (squery, "packages") << DIV_COUNTER (pkg_count, "Package", "Packages"); // Enclose the subsequent tables to be able to use nth-child CSS selector. // - // @@ TENANT: use tenant for sorting when add support for global view. - // s << DIV; for (const auto& pr: package_db_->query ( - search_param (squery, tenant) + - "ORDER BY rank DESC, name" + + search_param (squery, tn) + + "ORDER BY rank DESC, name, tenant" + "OFFSET" + to_string (page * res_page) + "LIMIT" + to_string (res_page))) { @@ -161,13 +167,20 @@ handle (request& rq, response& rs) s << TABLE(CLASS="proplist package") << TBODY - << TR_NAME (p->name, equery, root, tenant) + << TR_NAME (p->name, equery, root, p->tenant) << TR_SUMMARY (p->summary) << TR_LICENSE (p->license_alternatives) << TR_TAGS (p->project, p->tags, root, tenant) - << TR_DEPENDS (p->dependencies, root, tenant) - << TR_REQUIRES (p->requirements) - << ~TBODY + << TR_DEPENDS (p->dependencies, root, p->tenant) + << TR_REQUIRES (p->requirements); + + // In the global view mode add the tenant packages link. Note that the + // global view (and the link) makes sense only in the multi-tenant mode. + // + if (!tn && !p->tenant.empty ()) + s << TR_TENANT (tenant_name, "packages", root, p->tenant); + + s << ~TBODY << ~TABLE; } s << ~DIV; -- cgit v1.1