Also sort the tags in the filter

Signed-off-by: Joas Schilling <coding@schilljs.com>
This commit is contained in:
Joas Schilling 2016-10-27 12:40:57 +02:00
parent 52b4606d08
commit 538b2e097c
No known key found for this signature in database
GPG Key ID: E166FD8976B3BAC8
1 changed files with 35 additions and 0 deletions

View File

@ -35,6 +35,7 @@
* @type Array.<string> * @type Array.<string>
*/ */
_systemTagIds: [], _systemTagIds: [],
_lastUsedTags: [],
_clientSideSort: true, _clientSideSort: true,
_allowSelection: false, _allowSelection: false,
@ -58,6 +59,7 @@
var $controls = this.$el.find('#controls').empty(); var $controls = this.$el.find('#controls').empty();
_.defer(_.bind(this._getLastUsedTags, this));
this._initFilterField($controls); this._initFilterField($controls);
}, },
@ -67,7 +69,19 @@
OCA.Files.FileList.prototype.destroy.apply(this, arguments); 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) { _initFilterField: function($container) {
var self = this;
this.$filterField = $('<input type="hidden" name="tags"/>'); this.$filterField = $('<input type="hidden" name="tags"/>');
$container.append(this.$filterField); $container.append(this.$filterField);
this.$filterField.select2({ this.$filterField.select2({
@ -112,6 +126,27 @@
return OC.SystemTags.getDescriptiveTag(tag)[0].outerHTML; 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) { escapeMarkup: function(m) {
// prevent double markup escape // prevent double markup escape
return m; return m;