From e1f6316e0100aa32ba2874f4124cfc265c6f4e6b Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Tue, 22 Aug 2017 16:06:47 -0500 Subject: [PATCH] Sort by title option --- app/assets/javascripts/app/frontend/controllers/notes.js | 8 ++++++++ app/assets/templates/frontend/notes.html.haml | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/app/frontend/controllers/notes.js b/app/assets/javascripts/app/frontend/controllers/notes.js index 7fe779a6a..62277be9c 100644 --- a/app/assets/javascripts/app/frontend/controllers/notes.js +++ b/app/assets/javascripts/app/frontend/controllers/notes.js @@ -34,6 +34,7 @@ angular.module('app.frontend') .controller('NotesCtrl', function (authManager, $timeout, $rootScope, modelManager) { this.sortBy = localStorage.getItem("sortBy") || "created_at"; + this.sortDescending = this.sortBy != "title"; $rootScope.$on("editorFocused", function(){ this.showMenu = false; @@ -120,10 +121,17 @@ angular.module('app.frontend') this.selectedSortByCreated = function() { this.setSortBy("created_at"); + this.sortDescending = true; } this.selectedSortByUpdated = function() { this.setSortBy("updated_at"); + this.sortDescending = true; + } + + this.selectedSortByTitle = function() { + this.setSortBy("title"); + this.sortDescending = false; } this.setSortBy = function(type) { diff --git a/app/assets/templates/frontend/notes.html.haml b/app/assets/templates/frontend/notes.html.haml index 3ee469702..5f23c29db 100644 --- a/app/assets/templates/frontend/notes.html.haml +++ b/app/assets/templates/frontend/notes.html.haml @@ -19,10 +19,14 @@ %label{"ng-click" => "ctrl.selectedMenuItem($event); ctrl.selectedSortByUpdated()"} %span.top.mt-5.mr-5{"ng-if" => "ctrl.sortBy == 'updated_at'"} ✓ By date modified + %li + %label{"ng-click" => "ctrl.selectedMenuItem($event); ctrl.selectedSortByTitle()"} + %span.top.mt-5.mr-5{"ng-if" => "ctrl.sortBy == 'title'"} ✓ + By title .scrollable .infinite-scroll{"infinite-scroll" => "ctrl.paginate()", "can-load" => "true", "threshold" => "200"} - .note{"ng-repeat" => "note in (ctrl.sortedNotes = (ctrl.tag.notes | filter: ctrl.filterNotes | orderBy: ctrl.sortBy:true | limitTo:ctrl.notesToDisplay))", + .note{"ng-repeat" => "note in (ctrl.sortedNotes = (ctrl.tag.notes | filter: ctrl.filterNotes | orderBy: ctrl.sortBy:ctrl.sortDescending | limitTo:ctrl.notesToDisplay))", "ng-click" => "ctrl.selectNote(note)", "ng-class" => "{'selected' : ctrl.selectedNote == note}"} %strong.red.medium{"ng-if" => "note.conflict_of"} Conflicted copy %strong.red.medium{"ng-if" => "note.errorDecrypting"} Error decrypting