diff --git a/couchpotato/core/_base/clientscript/main.py b/couchpotato/core/_base/clientscript/main.py index 1b7f163..a0be0d0 100644 --- a/couchpotato/core/_base/clientscript/main.py +++ b/couchpotato/core/_base/clientscript/main.py @@ -34,6 +34,7 @@ class ClientScript(Plugin): 'scripts/library/question.js', 'scripts/library/scrollspy.js', 'scripts/library/spin.js', + 'scripts/library/Array.stableSort.js', 'scripts/couchpotato.js', 'scripts/api.js', 'scripts/library/history.js', diff --git a/couchpotato/core/media/movie/_base/static/movie.css b/couchpotato/core/media/movie/_base/static/movie.css index c013bd8..a88a207 100644 --- a/couchpotato/core/media/movie/_base/static/movie.css +++ b/couchpotato/core/media/movie/_base/static/movie.css @@ -1036,7 +1036,7 @@ text-overflow: ellipsis; overflow: hidden; width: 85%; - direction: rtl; + direction: ltr; vertical-align: middle; } diff --git a/couchpotato/core/plugins/manage/main.py b/couchpotato/core/plugins/manage/main.py index e8ccaf7..8720761 100644 --- a/couchpotato/core/plugins/manage/main.py +++ b/couchpotato/core/plugins/manage/main.py @@ -79,6 +79,7 @@ class Manage(Plugin): try: directories = self.directories() + directories.sort() added_identifiers = [] # Add some progress diff --git a/couchpotato/static/scripts/couchpotato.js b/couchpotato/static/scripts/couchpotato.js index 59fac34..d8d2655 100644 --- a/couchpotato/static/scripts/couchpotato.js +++ b/couchpotato/static/scripts/couchpotato.js @@ -503,7 +503,7 @@ function randomString(length, extra) { case "string": saveKeyPath(argument.match(/[+-]|[^.]+/g)); break; } }); - return this.sort(comparer); + return this.stableSort(comparer); } }); diff --git a/couchpotato/static/scripts/library/Array.stableSort.js b/couchpotato/static/scripts/library/Array.stableSort.js new file mode 100644 index 0000000..062c756 --- /dev/null +++ b/couchpotato/static/scripts/library/Array.stableSort.js @@ -0,0 +1,56 @@ +/* +--- + +script: Array.stableSort.js + +description: Add a stable sort algorithm for all browsers + +license: MIT-style license. + +authors: + - Yorick Sijsling + +requires: + core/1.3: '*' + +provides: + - [Array.stableSort, Array.mergeSort] + +... +*/ + +(function() { + + var defaultSortFunction = function(a, b) { + return a > b ? 1 : (a < b ? -1 : 0); + } + + Array.implement({ + + stableSort: function(compare) { + // I would love some real feature recognition. Problem is that an unstable algorithm sometimes/often gives the same result as an unstable algorithm. + return (Browser.chrome || Browser.firefox2 || Browser.opera9) ? this.mergeSort(compare) : this.sort(compare); + }, + + mergeSort: function(compare, token) { + compare = compare || defaultSortFunction; + if (this.length > 1) { + // Split and sort both parts + var right = this.splice(Math.floor(this.length / 2)).mergeSort(compare); + var left = this.splice(0).mergeSort(compare); // 'this' is now empty. + + // Merge parts together + while (left.length > 0 || right.length > 0) { + this.push( + right.length === 0 ? left.shift() + : left.length === 0 ? right.shift() + : compare(left[0], right[0]) > 0 ? right.shift() + : left.shift()); + } + } + return this; + } + + }); +})(); + diff --git a/couchpotato/static/scripts/page/manage.js b/couchpotato/static/scripts/page/manage.js index 4827f51..6955cf2 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() + } }); diff --git a/couchpotato/static/scripts/page/settings.js b/couchpotato/static/scripts/page/settings.js index 68b41d0..213c0d9 100644 --- a/couchpotato/static/scripts/page/settings.js +++ b/couchpotato/static/scripts/page/settings.js @@ -111,6 +111,10 @@ Page.Settings = new Class({ Cookie.write('advanced_toggle_checked', +self.advanced_toggle.checked, {'duration': 365}); }, + sortByOrder: function(a, b){ + return (a.order || 100) - (b.order || 100) + }, + create: function(json){ var self = this; @@ -141,13 +145,11 @@ Page.Settings = new Class({ options.include(section); }); - options.sort(function(a, b){ - return (a.order || 100) - (b.order || 100) - }).each(function(section){ + options.stableSort(self.sortByOrder).each(function(section){ var section_name = section.section_name; // Add groups to content - section.groups.sortBy('order').each(function(group){ + section.groups.stableSort(self.sortByOrder).each(function(group){ if(group.hidden) return; if(self.wizard_only && !group.wizard) @@ -184,9 +186,7 @@ Page.Settings = new Class({ } // Add options to group - group.options.sort(function(a, b){ - return (a.order || 100) - (b.order || 100) - }).each(function(option){ + group.options.stableSort(self.sortByOrder).each(function(option){ if(option.hidden) return; var class_name = (option.type || 'string').capitalize(); var input = new Option[class_name](section_name, option.name, self.getValue(section_name, option.name), option);