From 211340c8bd6ccd6b16f3115a71fce4abedcc4c06 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 23 Jul 2012 21:31:17 -0500 Subject: Ensure package files JS can support corner cases We should handle the cases dealing with no filelist available, outdated filelist, or a package without files, just as the HTML server-side page does. Add a bit more info to the JSON returned so we can do so. Signed-off-by: Dan McGee --- packages/views/display.py | 6 ++++++ sitestatic/archweb.js | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/views/display.py b/packages/views/display.py index d5aa2c20..02f5a5b2 100644 --- a/packages/views/display.py +++ b/packages/views/display.py @@ -160,10 +160,16 @@ def files_json(request, name, repo, arch): pkgname=name, repo__name__iexact=repo, arch__name=arch) # files are inserted in sorted order, so preserve that fileslist = PackageFile.objects.filter(pkg=pkg).order_by('id') + dir_count = sum(1 for f in fileslist if f.is_directory) + files_count = len(fileslist) - dir_count data = { 'pkgname': pkg.pkgname, 'repo': pkg.repo.name.lower(), 'arch': pkg.arch.name.lower(), + 'pkg_last_update': pkg.last_update, + 'files_last_update': pkg.files_last_update, + 'files_count': files_count, + 'dir_count': dir_count, 'files': fileslist, } to_json = json.dumps(data, ensure_ascii=False, cls=PackageJSONEncoder) diff --git a/sitestatic/archweb.js b/sitestatic/archweb.js index d17cc68f..b04b1d01 100644 --- a/sitestatic/archweb.js +++ b/sitestatic/archweb.js @@ -170,7 +170,17 @@ function ajaxifyFiles() { var cls = value.match(/\/$/) ? 'd' : 'f'; return ['
  • ', value, '
  • ']; }); - $('#pkgfilelist').html(''); + $('#pkgfilelist').empty(); + if (data.pkg_last_update > data.files_last_update) { + $('#pkgfilelist').append('

    Note: This file list was generated from a previous version of the package; it may be out of date.

    '); + } + if (list_items.length > 0) { + $('#pkgfilelist').append(''); + } else if (data.files_last_update == null) { + $('#pkgfilelist').append('

    No file list available.

    '); + } else { + $('#pkgfilelist').append('

    Package has no files.

    '); + } }); }); } -- cgit v1.2.3-55-g3dc8