From 185cb0196a29f5f7326b56bed6b5f84ee0e57d1d Mon Sep 17 00:00:00 2001 From: Kate von Roeder Date: Wed, 20 Nov 2013 13:36:08 -0800 Subject: [PATCH] Fix for #1578 - Depends on stableSort, so added to PR#2500. Object.each is not necessarily alphabetic when iterating an object's properties, so we pull the folders out of the object, add them to an array, and sort that. --- couchpotato/static/scripts/page/manage.js | 25 ++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/couchpotato/static/scripts/page/manage.js b/couchpotato/static/scripts/page/manage.js index 4827f51d..6955cf21 100644 --- a/couchpotato/static/scripts/page/manage.js +++ b/couchpotato/static/scripts/page/manage.js @@ -102,6 +102,8 @@ Page.Manage = new Class({ } } else { + // Capture progress so we can use it in our *each* closure + var progress = json.progress // Don't add loader when page is loading still if(!self.list.navigation) @@ -112,10 +114,13 @@ Page.Manage = new Class({ self.progress_container.empty(); - Object.each(json.progress, function(progress, folder){ + var sorted_table = self.parseProgress(json.progress) + + sorted_table.each(function(folder){ + var folder_progress = progress[folder] new Element('div').adopt( new Element('span.folder', {'text': folder}), - new Element('span.percentage', {'text': progress.total ? (((progress.total-progress.to_go)/progress.total)*100).round() + '%' : '0%'}) + new Element('span.percentage', {'text': folder_progress.total ? (((folder_progress.total-folder_progress.to_go)/folder_progress.total)*100).round() + '%' : '0%'}) ).inject(self.progress_container) }); @@ -124,7 +129,21 @@ Page.Manage = new Class({ }) }, 1000); + }, - } + parseProgress: function (progress_object) { + var folder, temp_array = []; + + /* Sort the properties on the progress object into an alphabetic array, ensuring that our folders display in appropriate alphabetic order. + + Bugfix for https://github.com/RuudBurger/CouchPotatoServer/issues/1578 + */ + for (folder in progress_object) { + if (progress_object.hasOwnProperty(folder)) { + temp_array.push(folder) + } + } + return temp_array.stableSort() + } });