Skip to content

Commit

Permalink
Merge pull request #1860 from ryanwr/feature-sort-favorite
Browse files Browse the repository at this point in the history
Sort favorite files first
  • Loading branch information
rullzer authored Oct 25, 2016
2 parents 44e9f5d + 3e96f33 commit 60fa82d
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
14 changes: 8 additions & 6 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions core/js/files/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 6 additions & 1 deletion core/js/files/fileinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,12 @@
/**
* @type boolean
*/
hasPreview: true
hasPreview: true,

/**
* @type boolean
*/
isFavorite: false
};

if (!OC.Files) {
Expand Down

0 comments on commit 60fa82d

Please sign in to comment.