Browse Source

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.
pull/2500/head
Kate von Roeder 12 years ago
parent
commit
185cb0196a
  1. 27
      couchpotato/static/scripts/page/manage.js

27
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()
}
});

Loading…
Cancel
Save