diff --git a/app/assets/javascripts/app/frontend/controllers/notes.js b/app/assets/javascripts/app/frontend/controllers/notes.js index 5bb7fba5a..76ee180f0 100644 --- a/app/assets/javascripts/app/frontend/controllers/notes.js +++ b/app/assets/javascripts/app/frontend/controllers/notes.js @@ -26,6 +26,8 @@ angular.module('app.frontend') }) .controller('NotesCtrl', function (authManager, $timeout, $rootScope, modelManager) { + this.sortBy = localStorage.getItem("sortBy") || "created_at"; + $rootScope.$on("editorFocused", function(){ this.showMenu = false; }.bind(this)) @@ -110,4 +112,22 @@ angular.module('app.frontend') } }.bind(this), 100) } + + this.selectedMenuItem = function() { + this.showMenu = false; + } + + this.selectedSortByCreated = function() { + this.setSortBy("created_at"); + } + + this.selectedSortByUpdated = function() { + this.setSortBy("updated_at"); + } + + this.setSortBy = function(type) { + this.sortBy = type; + localStorage.setItem("sortBy", type); + } + }); diff --git a/app/assets/javascripts/app/services/modelManager.js b/app/assets/javascripts/app/services/modelManager.js index 9a26cfa14..37b24a832 100644 --- a/app/assets/javascripts/app/services/modelManager.js +++ b/app/assets/javascripts/app/services/modelManager.js @@ -147,9 +147,7 @@ class ModelManager { } } else if(item.content_type == "Note") { if(!_.find(this.notes, {uuid: item.uuid})) { - this.notes.splice(_.sortedLastIndexBy(this.notes, item, function(item){ - return -item.created_at; - }), 0, item); + this.notes.unshift(item); } } else if(item.content_type == "Extension") { if(!_.find(this._extensions, {uuid: item.uuid})) { diff --git a/app/assets/stylesheets/app/_standard.scss b/app/assets/stylesheets/app/_standard.scss index bf5e098b1..e9f7e8b04 100644 --- a/app/assets/stylesheets/app/_standard.scss +++ b/app/assets/stylesheets/app/_standard.scss @@ -157,7 +157,7 @@ } .inline { - display: inline-block; + display: inline-block !important; &.top { vertical-align: top; diff --git a/app/assets/templates/frontend/notes.html.haml b/app/assets/templates/frontend/notes.html.haml index 94b9e9dec..f259f62c8 100644 --- a/app/assets/templates/frontend/notes.html.haml +++ b/app/assets/templates/frontend/notes.html.haml @@ -17,10 +17,18 @@ %ul.dropdown-menu.dropdown-menu-left.nt-dropdown-menu.dark{"ng-if" => "ctrl.showMenu"} %li %a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.selectedTagDelete()"} Delete Tag + %li + %a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.selectedSortByCreated()"} + %span.top.mt-5.mr-5{"ng-if" => "ctrl.sortBy == 'created_at'"} ✓ + Sort by date created + %li + %a.text{"ng-click" => "ctrl.selectedMenuItem(); ctrl.selectedSortByUpdated()"} + %span.top.mt-5.mr-5{"ng-if" => "ctrl.sortBy == 'updated_at'"} ✓ + Sort by date updated .scrollable .infinite-scroll{"infinite-scroll" => "ctrl.paginate()", "can-load" => "true", "threshold" => "200"} - .note{"ng-repeat" => "note in ctrl.tag.notes | filter: ctrl.filterNotes | limitTo:ctrl.notesToDisplay", + .note{"ng-repeat" => "note in ctrl.tag.notes | filter: ctrl.filterNotes | orderBy: ctrl.sortBy:true | limitTo:ctrl.notesToDisplay", "ng-click" => "ctrl.selectNote(note)", "ng-class" => "{'selected' : ctrl.selectedNote == note}"} .name{"ng-if" => "note.title"} {{note.title}}