From 85f093e356717b74dfbbed29f6d55e4bb9279935 Mon Sep 17 00:00:00 2001 From: Ilya Kreymer Date: Mon, 15 Jan 2018 19:54:15 -0800 Subject: [PATCH] Fix Query UI (#278) * query fix: setup: ensure all static files included in package_data recursively to add new query assets test: add test for nested static asset query: correctly display 0 captures, 'capture' and 'captures' text moved to Text block --- pywb/static/query.js | 27 +++++++++++++++++++++------ pywb/templates/query.html | 2 +- setup.py | 15 ++++++++++++++- tests/test_integration.py | 5 +++++ 4 files changed, 41 insertions(+), 8 deletions(-) diff --git a/pywb/static/query.js b/pywb/static/query.js index 9de8d728..f6e90877 100644 --- a/pywb/static/query.js +++ b/pywb/static/query.js @@ -12,7 +12,9 @@ var Text = { '10': "October", '11': "November", '12': "December", - } + }, + version: "capture", + versions: "captures", }; function RenderCalendar(prefix, url) { @@ -81,13 +83,20 @@ function RenderCalendar(prefix, url) { data: {"url": url, "output": "json"}, dataType: "text", success: function(data) { - processAll(data.trim().split("\n")); + processAll(data.trim()); } }); } - function processAll(cdxLines) { - $("#count").text(cdxLines.length); + function processAll(data) { + var cdxLines = []; + + if (data) { + cdxLines = data.split("\n"); + } + + $("#count").text(numVersionsText(cdxLines.length)); + for (var i = 0; i < cdxLines.length; i++) { var obj = JSON.parse(cdxLines[i]); processUrl(prefix, obj.timestamp, obj.url); @@ -96,6 +105,13 @@ function RenderCalendar(prefix, url) { handleClicks(); } + function numVersionsText(count) { + var text = count + " "; + text += count == 1 ? Text.version : Text.versions; + return text; + } + + function processUrl(prefix, ts, url) { var currentYear = getYearTs(ts); years.push(currentYear); @@ -124,8 +140,7 @@ function RenderCalendar(prefix, url) { for (var i = 0; i < years.length; i++) { numberofVersions = $('#year_' + years[i].toString()).parent().next().find(".day").length; - numberofVersionsString = numberofVersions == 1 ? numberofVersions + " version " : numberofVersions + " versions "; - $('#' + years[i] + '_right').prepend(numberofVersionsString); + $('#' + years[i] + '_right').prepend(numVersionsText(numberofVersions)); } } diff --git a/pywb/templates/query.html b/pywb/templates/query.html index d45081f5..71d3deec 100644 --- a/pywb/templates/query.html +++ b/pywb/templates/query.html @@ -10,7 +10,7 @@

pywb Query Results

-

captures of {{ url }}

+

of {{ url }}

diff --git a/setup.py b/setup.py index 0ca31ec2..98c4f100 100755 --- a/setup.py +++ b/setup.py @@ -60,6 +60,19 @@ def load_requirements(filename): return fh.read().rstrip().split('\n') +def get_package_data(): + pkgs = ['static/*.*', + 'templates/*', + '*.yaml'] + + for root, dirs, files in os.walk(os.path.join('pywb', 'static')): + for dir_ in dirs: + pkgs.append(os.path.relpath(os.path.join(root, dir_, '*'), 'pywb')) + + return pkgs + + + generate_git_hash_py('pywb') @@ -87,7 +100,7 @@ setup( 'pywb.apps', ], package_data={ - 'pywb': ['static/flowplayer/*', 'static/*.*', 'templates/*', '*.yaml'], + 'pywb': get_package_data(), }, data_files=[ ('sample_archive/cdx', glob.glob('sample_archive/cdx/*')), diff --git a/tests/test_integration.py b/tests/test_integration.py index 4a9de768..afdabcb9 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -397,6 +397,11 @@ class TestWbIntegration(BaseConfigTest): assert resp.content_type == 'text/css' assert resp.content_length > 0 + def test_static_nested_dir(self): + resp = self.testapp.get('/static/fonts/font-awesome/fontawesome-webfont.woff') + assert resp.status_int == 200 + assert resp.content_length > 0 + def test_static_not_found(self): resp = self.testapp.get('/static/notfound.css', status = 404) assert resp.status_int == 404