From 8462482f461b1a3c810fe8ef26c9802042767dc9 Mon Sep 17 00:00:00 2001 From: Mo Bitar Date: Mon, 27 Feb 2017 12:31:32 -0600 Subject: [PATCH] note selection adjustment --- .../javascripts/app/frontend/controllers/home.js | 7 ++++--- .../javascripts/app/frontend/controllers/notes.js | 15 +++------------ app/assets/templates/frontend/notes.html.haml | 2 +- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/app/frontend/controllers/home.js b/app/assets/javascripts/app/frontend/controllers/home.js index e59ece731..9ee571cb2 100644 --- a/app/assets/javascripts/app/frontend/controllers/home.js +++ b/app/assets/javascripts/app/frontend/controllers/home.js @@ -34,10 +34,11 @@ angular.module('app.frontend') }, 30000); }); - $scope.allTag = new Tag({all: true}); - $scope.allTag.title = "All"; + var allTag = new Tag({all: true}); + allTag.title = "All"; $scope.tags = modelManager.tags; - $scope.allTag.notes = modelManager.notes; + allTag.notes = modelManager.notes; + $scope.allTag = allTag; /* Editor Callbacks diff --git a/app/assets/javascripts/app/frontend/controllers/notes.js b/app/assets/javascripts/app/frontend/controllers/notes.js index 76ee180f0..9f7b13fa4 100644 --- a/app/assets/javascripts/app/frontend/controllers/notes.js +++ b/app/assets/javascripts/app/frontend/controllers/notes.js @@ -32,8 +32,6 @@ angular.module('app.frontend') this.showMenu = false; }.bind(this)) - var isFirstLoad = true; - this.notesToDisplay = 20; this.paginate = function() { this.notesToDisplay += 20 @@ -51,16 +49,9 @@ angular.module('app.frontend') tag.notes.forEach(function(note){ note.visible = true; }) - this.selectFirstNote(false); - if(isFirstLoad) { - $timeout(function(){ - this.createNewNote(); - isFirstLoad = false; - }.bind(this)) - } else if(tag.notes.length == 0) { - this.createNewNote(); - } + var createNew = tag.notes.length == 0; + this.selectFirstNote(createNew); } this.selectedTagDelete = function() { @@ -69,7 +60,7 @@ angular.module('app.frontend') } this.selectFirstNote = function(createNew) { - var visibleNotes = this.tag.notes.filter(function(note){ + var visibleNotes = this.sortedNotes.filter(function(note){ return note.visible; }); diff --git a/app/assets/templates/frontend/notes.html.haml b/app/assets/templates/frontend/notes.html.haml index f259f62c8..e7b1aa5c2 100644 --- a/app/assets/templates/frontend/notes.html.haml +++ b/app/assets/templates/frontend/notes.html.haml @@ -28,7 +28,7 @@ .scrollable .infinite-scroll{"infinite-scroll" => "ctrl.paginate()", "can-load" => "true", "threshold" => "200"} - .note{"ng-repeat" => "note in 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:true | limitTo:ctrl.notesToDisplay))", "ng-click" => "ctrl.selectNote(note)", "ng-class" => "{'selected' : ctrl.selectedNote == note}"} .name{"ng-if" => "note.title"} {{note.title}}