Sort reverse option
This commit is contained in:
@@ -44,6 +44,7 @@ angular.module('app')
|
||||
let prevSortValue = this.sortBy;
|
||||
|
||||
this.sortBy = authManager.getUserPrefValue("sortBy", "created_at");
|
||||
this.sortReverse = authManager.getUserPrefValue("sortReverse", false);
|
||||
|
||||
if(this.sortBy == "updated_at") {
|
||||
// use client_updated_at instead
|
||||
@@ -55,7 +56,6 @@ angular.module('app')
|
||||
this.selectFirstNote();
|
||||
})
|
||||
}
|
||||
this.sortDescending = this.sortBy != "title";
|
||||
|
||||
this.showArchived = authManager.getUserPrefValue("showArchived", false);
|
||||
this.hidePinned = authManager.getUserPrefValue("hidePinned", false);
|
||||
@@ -301,17 +301,21 @@ angular.module('app')
|
||||
|
||||
this.selectedSortByCreated = function() {
|
||||
this.setSortBy("created_at");
|
||||
this.sortDescending = true;
|
||||
}
|
||||
|
||||
this.selectedSortByUpdated = function() {
|
||||
this.setSortBy("client_updated_at");
|
||||
this.sortDescending = true;
|
||||
}
|
||||
|
||||
this.selectedSortByTitle = function() {
|
||||
this.setSortBy("title");
|
||||
this.sortDescending = false;
|
||||
}
|
||||
|
||||
this.toggleReverseSort = function() {
|
||||
this.selectedMenuItem();
|
||||
this.sortReverse = !this.sortReverse;
|
||||
authManager.setUserPrefValue("sortReverse", this.sortReverse);
|
||||
authManager.syncUserPreferences();
|
||||
}
|
||||
|
||||
this.setSortBy = function(type) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
angular.module('app')
|
||||
.filter('sortBy', function ($filter) {
|
||||
return function(items, sortBy) {
|
||||
return function(items, sortBy, reverse) {
|
||||
let sortValueFn = (a, b, pinCheck = false) => {
|
||||
if(!pinCheck) {
|
||||
if(a.pinned && b.pinned) {
|
||||
@@ -14,6 +14,11 @@ angular.module('app')
|
||||
var bValue = b[sortBy] || "";
|
||||
|
||||
let vector = 1;
|
||||
|
||||
if(reverse) {
|
||||
vector *= -1;
|
||||
}
|
||||
|
||||
if(sortBy == "title") {
|
||||
aValue = aValue.toLowerCase();
|
||||
bValue = bValue.toLowerCase();
|
||||
@@ -21,11 +26,11 @@ angular.module('app')
|
||||
if(aValue.length == 0 && bValue.length == 0) {
|
||||
return 0;
|
||||
} else if(aValue.length == 0 && bValue.length != 0) {
|
||||
return 1;
|
||||
return 1 * vector;
|
||||
} else if(aValue.length != 0 && bValue.length == 0) {
|
||||
return -1;
|
||||
return -1 * vector;
|
||||
} else {
|
||||
vector = -1;
|
||||
vector *= -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user