diff options
author | Joas Schilling <coding@schilljs.com> | 2016-10-27 13:40:57 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2016-11-07 16:56:31 +0300 |
commit | 538b2e097c9dfc04963a9f886d733165b1696d15 (patch) | |
tree | 69a6cf65058df0f5ff118b797b768799806ae800 /apps/systemtags/js | |
parent | 52b4606d08281da06f2f7d37ca4da009c94f7793 (diff) |
Also sort the tags in the filter
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'apps/systemtags/js')
-rw-r--r-- | apps/systemtags/js/systemtagsfilelist.js | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/apps/systemtags/js/systemtagsfilelist.js b/apps/systemtags/js/systemtagsfilelist.js index 56838018a2c..5f282c319cf 100644 --- a/apps/systemtags/js/systemtagsfilelist.js +++ b/apps/systemtags/js/systemtagsfilelist.js @@ -35,6 +35,7 @@ * @type Array.<string> */ _systemTagIds: [], + _lastUsedTags: [], _clientSideSort: true, _allowSelection: false, @@ -58,6 +59,7 @@ var $controls = this.$el.find('#controls').empty(); + _.defer(_.bind(this._getLastUsedTags, this)); this._initFilterField($controls); }, @@ -67,7 +69,19 @@ OCA.Files.FileList.prototype.destroy.apply(this, arguments); }, + _getLastUsedTags: function() { + var self = this; + $.ajax({ + type: 'GET', + url: OC.generateUrl('/apps/systemtags/lastused'), + success: function (response) { + self._lastUsedTags = response; + } + }); + }, + _initFilterField: function($container) { + var self = this; this.$filterField = $('<input type="hidden" name="tags"/>'); $container.append(this.$filterField); this.$filterField.select2({ @@ -112,6 +126,27 @@ return OC.SystemTags.getDescriptiveTag(tag)[0].outerHTML; }, + sortResults: function(results) { + results.sort(function(a, b) { + var aLastUsed = self._lastUsedTags.indexOf(a.id); + var bLastUsed = self._lastUsedTags.indexOf(b.id); + + if (aLastUsed !== bLastUsed) { + if (bLastUsed === -1) { + return -1; + } + if (aLastUsed === -1) { + return 1; + } + return aLastUsed < bLastUsed ? -1 : 1; + } + + // Both not found + return OC.Util.naturalSortCompare(a.name, b.name); + }); + return results; + }, + escapeMarkup: function(m) { // prevent double markup escape return m; |