Commit e8400068 authored by Max Rees's avatar Max Rees

Optionally show availability on each architecture on search page

parent 0acc5ae5
......@@ -94,6 +94,20 @@ def pkg_paginate(conf, query, db, sql):
sql += " LIMIT :limit OFFSET :offset"
return db.execute(sql, query).fetchall()
def pkg_versions(conf, db, pkgs):
versions = {}
repos = set()
arches = set()
for i, pkg in enumerate(pkgs):
repos.add(pkg.repo)
pkgs[i] = pkg._replace(updated=format_timestamp(pkg.updated))
versions[pkg.name] = pkg.get_versions(db)
for repo in repos:
arches.update(conf.getmaplist("repos")[repo])
return versions, sorted(repos), sorted(arches)
def page_branches(path, _query):
conf = apkvitrine.config()
branches = list(conf.sections())
......@@ -124,22 +138,14 @@ def page_branch(path, query):
ORDER BY updated DESC
""")
ok()
versions = {}
repos = set()
arches = set()
for i, pkg in enumerate(pkgs):
repos.add(pkg.repo)
arches.update(conf.getmaplist("repos")[pkg.repo])
pkgs[i] = pkg._replace(updated=format_timestamp(pkg.updated))
versions[pkg.name] = pkg.get_versions(db)
versions, repos, arches = pkg_versions(conf, db, pkgs)
response = ENV.get_template("branch.tmpl").render(
conf=conf,
branch=branch,
query=query,
repos=sorted(repos),
arches=sorted(arches),
repos=repos,
arches=arches,
pkgs=pkgs,
versions=versions,
)
......@@ -222,13 +228,23 @@ def page_search(path, query):
searched = False
pkgs = []
if query.get("availability"):
versions, repos, arches = pkg_versions(conf, db, pkgs)
else:
versions = {}
repos = []
arches = []
response = ENV.get_template("search.tmpl").render(
conf=conf,
branch=branch,
query=query,
maints=maints,
searched=searched,
repos=repos,
arches=arches,
pkgs=pkgs,
versions=versions,
)
print(response)
if not searched:
......
......@@ -4,6 +4,20 @@
## Copyright (c) 2020 A. Wilcox
## See LICENSE for more information.
# macro table_availability(arches, pkg, versions)
# for arch in arches
# set apk = versions[pkg.name]|selectattr("arch", "==", arch)|list
# if not apk or (apk|first).vrank is none
# set cell = ("is-danger", "✗")
# elif (apk|first).vrank
# set cell = ("is-warning", "~ " ~ apk.version)
# else
# set cell = ("is-success", "✓ " ~ apk.version)
# endif
<td class="version {{ cell[0] }}">{{ cell[1]|safe }}</td>
# endfor
# endmacro
# macro i_text(id, name)
<div class="field">
<div class="control">
......
......@@ -51,17 +51,7 @@
</a>
</td>
<td>{{ pkg.description }}</td>
# for arch in arches
# set apk = versions[pkg.name]|selectattr("arch", "==", arch)|list
# if not apk or (apk|first).vrank is none
# set cell = ("is-danger", "&cross;")
# elif (apk|first).vrank
# set cell = ("is-warning", "~ " ~ apk.version)
# else
# set cell = ("is-success", "&check; " ~ apk.version)
# endif
<td class="version {{ cell[0] }}">{{ cell[1]|safe }}</td>
# endfor
{{ table_availability(arches, pkg, versions) }}
</tr>
# endfor
</table>
......
......@@ -9,6 +9,7 @@
# set title = ["Search for packages in ", conf["distro"], branch]|join(" ")
# endif
# set n = pkgs|length
# set availability = query.get("availability")
# block breadcrumb
<nav class="breadcrumb is-medium">
......@@ -53,6 +54,7 @@
<div class="field">
{{ i_check("cs", "Case-sensitive match with exact globbing") }}
{{ i_check("subpkgs", "Include subpackages") }}
{{ i_check("availability", "Show availability on each architecture") }}
</div>
<article class="message">
<div class="message-header">
......@@ -105,11 +107,16 @@ Displaying the first {{ query["limit"] }}.
<tr>
<th>Name</th>
<th>Description</th>
# for arch in arches
<th align="center">{{ arch }}</th>
# endfor
</tr>
# for pkg in pkgs
<tr>
<td><a href="{{ branch }}/{{ pkg.name }}">{{ pkg.name }}</a></td>
<td>{{ pkg.description }}</td>
{{ table_availability(arches, pkg, versions) }}
</tr>
# endfor
</table>
......
......@@ -2,7 +2,7 @@ nav.breadcrumb a { color: #b5b5b5 }
nav.breadcrumb .is-active a { color: white }
.pagination-list li { list-style-type: none }
.version { text-align: center !important }
.version { text-align: center !important; vertical-align: middle !important }
.version.is-success, .version.is-warning, .version.is-danger {
border-color: inherit !important
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment