From 3e96f33995c522106b645908b4537b25536b8a7d Mon Sep 17 00:00:00 2001 From: ryanwr Date: Sat, 22 Oct 2016 21:26:21 +0100 Subject: [PATCH] Sort favorite files first Issue #1802 Signed-off-by: Ryan Welch --- apps/files/js/filelist.js | 14 ++++++++------ core/js/files/client.js | 7 +++++++ core/js/files/fileinfo.js | 7 ++++++- 3 files changed, 21 insertions(+), 7 deletions(-) diff --git a/apps/files/js/filelist.js b/apps/files/js/filelist.js index 159d008e6e6..53ad8eafeef 100644 --- a/apps/files/js/filelist.js +++ b/apps/files/js/filelist.js @@ -1500,13 +1500,15 @@ var comparator = FileList.Comparators[sort] || FileList.Comparators.name; this._sort = sort; this._sortDirection = (direction === 'desc')?'desc':'asc'; - this._sortComparator = comparator; + this._sortComparator = function(fileInfo1, fileInfo2) { + if(fileInfo1.isFavorite && !fileInfo2.isFavorite) { + return -1; + } else if(!fileInfo1.isFavorite && fileInfo2.isFavorite) { + return 1; + } + return direction === 'asc' ? comparator(fileInfo1, fileInfo2) : -comparator(fileInfo1, fileInfo2); + }; - if (direction === 'desc') { - this._sortComparator = function(fileInfo1, fileInfo2) { - return -comparator(fileInfo1, fileInfo2); - }; - } this.$el.find('thead th .sort-indicator') .removeClass(this.SORT_INDICATOR_ASC_CLASS) .removeClass(this.SORT_INDICATOR_DESC_CLASS) diff --git a/core/js/files/client.js b/core/js/files/client.js index 572f7879e17..ee3efbd5517 100644 --- a/core/js/files/client.js +++ b/core/js/files/client.js @@ -287,6 +287,13 @@ data.hasPreview = true; } + var isFavorite = props['{' + Client.NS_OWNCLOUD + '}favorite']; + if (!_.isUndefined(isFavorite)) { + data.isFavorite = isFavorite === '1'; + } else { + data.isFavorite = false; + } + var contentType = props['{' + Client.NS_DAV + '}getcontenttype']; if (!_.isUndefined(contentType)) { data.mimetype = contentType; diff --git a/core/js/files/fileinfo.js b/core/js/files/fileinfo.js index 1fc239da47a..7c8e4586448 100644 --- a/core/js/files/fileinfo.js +++ b/core/js/files/fileinfo.js @@ -132,7 +132,12 @@ /** * @type boolean */ - hasPreview: true + hasPreview: true, + + /** + * @type boolean + */ + isFavorite: false }; if (!OC.Files) { -- 2.39.5