diff options
Diffstat (limited to 'media/archweb.js')
-rw-r--r-- | media/archweb.js | 193 |
1 files changed, 151 insertions, 42 deletions
diff --git a/media/archweb.js b/media/archweb.js index 49f2a319..151d0f81 100644 --- a/media/archweb.js +++ b/media/archweb.js @@ -6,7 +6,7 @@ if (typeof $.tablesorter !== 'undefined') { is: function(s) { return false; }, format: function(s) { var m = s.match(/\d+/); - return m ? parseInt(m[0]) : 0; + return m ? parseInt(m[0], 10) : 0; }, type: 'numeric' }); @@ -27,7 +27,9 @@ if (typeof $.tablesorter !== 'undefined') { return ($.inArray(s, this.special) > -1) || $.tablesorter.isDigit(s, c); }, format: function(s) { - if ($.inArray(s, this.special) > -1) return Number.MAX_VALUE; + if ($.inArray(s, this.special) > -1) { + return Number.MAX_VALUE; + } return $.tablesorter.formatFloat(s); }, type: 'numeric' @@ -41,14 +43,31 @@ if (typeof $.tablesorter !== 'undefined') { return ($.inArray(s, this.special) > -1) || this.re.test(s); }, format: function(s) { - if ($.inArray(s, this.special) > -1) return Number.MAX_VALUE; + if ($.inArray(s, this.special) > -1) { + return Number.MAX_VALUE; + } var matches = this.re.exec(s); - if (!matches) return Number.MAX_VALUE; + if (!matches) { + return Number.MAX_VALUE; + } return matches[1] * 60 + matches[2]; }, type: 'numeric' }); $.tablesorter.addParser({ + id: 'epochdate', + is: function(s) { return false; }, + format: function(s, t, c) { + /* TODO: this assumes our magic class is the only one */ + var epoch = $(c).attr('class'); + if (!epoch.indexOf('epoch-') == 0) { + return 0; + } + return epoch.slice(6); + }, + type: 'numeric' + }); + $.tablesorter.addParser({ id: 'longDateTime', re: /^(\d{4})-(\d{2})-(\d{2}) ([012]\d):([0-5]\d)(:([0-5]\d))?( (\w+))?$/, is: function(s) { @@ -56,9 +75,13 @@ if (typeof $.tablesorter !== 'undefined') { }, format: function(s) { var matches = this.re.exec(s); - if (!matches) return 0; + if (!matches) { + return 0; + } /* skip group 6, group 7 is optional seconds */ - if (matches[7] == undefined) matches[7] = 0; + if (matches[7] === undefined) { + matches[7] = 0; + } /* The awesomeness of the JS date constructor. Month needs to be * between 0-11, because things have to be difficult. */ var date = new Date(matches[1], matches[2] - 1, matches[3], @@ -75,25 +98,26 @@ if (typeof $.tablesorter !== 'undefined') { }, format: function(s) { var matches = this.re.exec(s); - if (!matches) return 0; + if (!matches) { + return 0; + } var size = parseFloat(matches[1]); var suffix = matches[2]; switch(suffix) { - case 'byte': - case 'bytes': - return size; - case 'KB': - return size * 1024; - case 'MB': - return size * 1024 * 1024; - case 'GB': - return size * 1024 * 1024 * 1024; - case 'TB': - return size * 1024 * 1024 * 1024 * 1024; + /* intentional fall-through at each level */ case 'PB': - return size * 1024 * 1024 * 1024 * 1024 * 1024; + size *= 1024; + case 'TB': + size *= 1024; + case 'GB': + size *= 1024; + case 'MB': + size *= 1024; + case 'KB': + size *= 1024; } + return size; }, type: 'numeric' }); @@ -128,7 +152,7 @@ function ajaxifyFiles() { /* packages/differences.html */ function filter_packages() { - // start with all rows, and then remove ones we shouldn't show + /* start with all rows, and then remove ones we shouldn't show */ var rows = $('#tbody_differences').children(); var all_rows = rows; if (!$('#id_multilib').is(':checked')) { @@ -139,34 +163,42 @@ function filter_packages() { rows = rows.filter('.' + arch); } if (!$('#id_minor').is(':checked')) { - // this check is done last because it is the most expensive + /* this check is done last because it is the most expensive */ var pat = /(.*)-(.+)/; rows = rows.filter(function(index) { var cells = $(this).children('td'); - // all this just to get the split version out of the table cell + /* all this just to get the split version out of the table cell */ var ver_a = cells.eq(2).find('span').text().match(pat); - if (!ver_a) return true; + if (!ver_a) { + return true; + } var ver_b = cells.eq(3).find('span').text().match(pat); - if (!ver_b) return true; + if (!ver_b) { + return true; + } - // first check pkgver - if (ver_a[1] !== ver_b[1]) return true; - // pkgver matched, so see if rounded pkgrel matches - if (Math.floor(parseFloat(ver_a[2])) == - Math.floor(parseFloat(ver_b[2]))) return false; - // pkgrel didn't match, so keep the row + /* first check pkgver */ + if (ver_a[1] !== ver_b[1]) { + return true; + } + /* pkgver matched, so see if rounded pkgrel matches */ + if (Math.floor(parseFloat(ver_a[2])) === + Math.floor(parseFloat(ver_b[2]))) { + return false; + } + /* pkgrel didn't match, so keep the row */ return true; }); } - // hide all rows, then show the set we care about + /* hide all rows, then show the set we care about */ all_rows.hide(); rows.show(); - // make sure we update the odd/even styling from sorting + /* make sure we update the odd/even styling from sorting */ $('.results').trigger('applyWidgets'); } -function filter_reset() { +function filter_packages_reset() { $('#id_archonly').val('both'); $('#id_multilib').removeAttr('checked'); $('#id_minor').removeAttr('checked'); @@ -194,21 +226,98 @@ function todolist_flag() { function signoff_package() { var link = this; $.getJSON(link.href, function(data) { + link = $(link); + var signoff = null; + var cell = link.closest('td'); if (data.created) { - var signoff = $('<li>').addClass('signed-username').text(data.user); - $(link).append(signoff); + signoff = $('<li>').addClass('signed-username').text(data.user); + var list = cell.children('ul.signoff-list'); + if (list.size() == 0) { + list = $('<ul class="signoff-list">').prependTo(cell); + } + list.append(signoff); + } else if(data.user) { + signoff = link.closest('td').find('li').filter(function(index) { + return $(this).text() == data.user; + }); + } + if (signoff && data.revoked) { + signoff.text(signoff.text() + ' (revoked)'); } /* update the approved column to reflect reality */ - if (data.approved) { - var approved = $(link).closest('tr').children('.signoff-no'); - approved.text('Yes').addClass( - 'signoff-yes').removeClass('signoff-no'); + var approved = link.closest('tr').children('.approval'); + approved.attr('class', ''); + if (data.known_bad) { + approved.text('Bad').addClass('signoff-bad'); + } else if (!data.enabled) { + approved.text('Disabled').addClass('signoff-disabled'); + } else if (data.approved) { + approved.text('Yes').addClass('signoff-yes'); + } else { + approved.text('No').addClass('signoff-no'); + } + link.removeAttr('title'); + /* Form our new link. The current will be something like + * '/packages/repo/arch/package/...' */ + var base_href = link.attr('href').split('/').slice(0, 5).join('/'); + if (data.revoked) { + link.text('Signoff'); + link.attr('href', base_href + '/signoff/'); + /* should we be hiding the link? */ + if (data.known_bad || !data.enabled) { + link.remove(); + } } else { - var approved = $(link).closest('tr').children('.signoff-yes'); - approved.text('No').addClass( - 'signoff-no').removeClass('signoff-yes'); + link.text('Revoke Signoff'); + link.attr('href', base_href + '/signoff/revoke/'); } $('.results').trigger('updateCell', approved); }); return false; } + +function filter_signoffs() { + /* start with all rows, and then remove ones we shouldn't show */ + var rows = $('#tbody_signoffs').children(); + var all_rows = rows; + /* apply arch and repo filters */ + $('#signoffs_filter .arch_filter').add( + '#signoffs_filter .repo_filter').each(function() { + if (!$(this).is(':checked')) { + rows = rows.not('.' + $(this).val()); + } + }); + /* and then the slightly more expensive pending check */ + if ($('#id_pending').is(':checked')) { + rows = rows.has('td.signoff-no'); + } + /* hide all rows, then show the set we care about */ + all_rows.hide(); + rows.show(); + $('#filter-count').text(rows.length); + /* make sure we update the odd/even styling from sorting */ + $('.results').trigger('applyWidgets'); +} +function filter_signoffs_reset() { + $('#signoffs_filter .arch_filter').attr('checked', 'checked'); + $('#signoffs_filter .repo_filter').attr('checked', 'checked'); + $('#id_pending').removeAttr('checked'); + filter_signoffs(); +} + +/* visualizations */ +function format_filesize(size, decimals) { + /*var labels = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'];*/ + var labels = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']; + var label = 0; + + while (size > 2048.0 && label < labels.length - 1) { + label++; + size /= 1024.0; + } + if (decimals === undefined) { + decimals = 2; + } + + return size.toFixed(decimals) + ' ' + labels[label]; +} |