diff --git a/.meteor/packages b/.meteor/packages index cb790e7..2d67610 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -14,4 +14,5 @@ mizzao:bootstrap-3 spiderable kevohagan:sweetalert accounts-twitter +fazo96:paginator diff --git a/.meteor/versions b/.meteor/versions index edfc135..3f3d6fc 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -19,6 +19,7 @@ deps@1.0.5 ejson@1.0.4 email@1.0.4 fastclick@1.0.1 +fazo96:paginator@0.1.0 follower-livedata@1.0.2 geojson-utils@1.0.1 html-tools@1.0.2 diff --git a/client/client.coffee b/client/client.coffee index 0cfd7f1..9faacaf 100644 --- a/client/client.coffee +++ b/client/client.coffee @@ -1,10 +1,10 @@ # Homework - Client Side -version = "1.1.7" +version = "1.1.8" # Utilities tick = new Tracker.Dependency() Meteor.setInterval (-> tick.changed();), 15000 -notes = new Meteor.Collection "notes" +notes = new Meteor.Collection 'notes' userSub = Meteor.subscribe 'user' getUser = -> Meteor.user() deleteAccount = -> @@ -76,8 +76,7 @@ guestController = RouteController.extend if amIValid() is no then Router.go 'verifyEmail' else Router.go 'notes' @next() - - +# Page Routing Router.route '/', name: 'home' template: 'homepage' @@ -92,14 +91,9 @@ Router.route '/register', controller: guestController Router.route '/account', controller: loggedInController Router.route '/notes/:_id?', name: 'notes' - waitOn: -> Meteor.subscribe 'my-notes' + waitOn: -> Meteor.subscribe 'notes', no data: -> notes.findOne _id: @params._id controller: loggedInController -Router.route '/archive/:_id?', - name: 'archive' - waitOn: -> @notes = Meteor.subscribe 'archive' - onStop: -> @notes.stop() - controller: loggedInController Router.route '/verify/:token?', name: 'verifyEmail' template: 'verifyEmail' @@ -109,20 +103,26 @@ Router.route '/verify/:token?', else @render() onBeforeAction: -> if getUser() - if amIValid() then Router.go 'home' - else Router.go 'home' - # Automatic verification - if @params.token? and @params.token isnt "" - @render 'loading' - Accounts.verifyEmail @params.token, (err) => - if err - errCallback err; Router.go 'verifyEmail', token: @params.token - else - showErr type:'success', msg:'Verification complete' - Router.go 'home' - @next() - else @next() -Router.route '/(.*)', -> @render '404' + if amIValid() + Router.go 'home'; @next() + else if @params.token? and @params.token isnt "" + # Automatic verification + @render 'loading' + Accounts.verifyEmail @params.token, (err) => + if err + errCallback err; Router.go 'verifyEmail', token: @params.token + else + showErr type:'success', msg:'Verification complete' + Router.go 'home' + @next() + else + Router.go 'home'; @next() +Router.route '/archive/:_id?', + name: 'archive' + waitOn: -> @notes = Meteor.subscribe 'notes', yes + onStop: -> @notes.stop() + controller: loggedInController +Router.route '/(.*)', -> @render '404' # Catch-all route # Client Templates @@ -176,7 +176,13 @@ formattedDate = -> color = "warning" if dif is 1 color = "danger" if dif < 1 msg: moment.unix(@date).fromNow(), color: color -notelist = -> notes.find({ archived: no },{ sort: date: 1}) +notePaginator = new Paginator(10) +notelist = -> + notePaginator.calibrate(notes.find(archived: no).count()) + opt = notePaginator.queryOptions() + notes.find({ archived: no },{ + sort: {date: 1}, skip: opt.skip, limit: opt.limit + }) Template.notelist.helpers notelist: -> notelist().fetch() active: -> @@ -184,6 +190,8 @@ Template.notelist.helpers return @_id is Router.current().data()._id empty: -> notelist().count() is 0 getDate: formattedDate + paginator: -> notePaginator + pageActive: -> if @active then "btn-primary" else "btn-default" Template.notelist.events 'click .close-note': -> notes.update @_id, $set: archived: yes @@ -194,18 +202,28 @@ Template.notelist.events title: template.find('#newNote').value content: "", date: no, archived: no, userId: Meteor.userId() template.find('#newNote').value = "" + 'click .btn': -> notePaginator.page @index # Archive -archived = -> notes.find({ archived: yes },{ sort: date: 1}) +archivePaginator = new Paginator(10) +archived = -> + archivePaginator.calibrate(notes.find(archived: yes).count()) + opt = archivePaginator.queryOptions() + notes.find({archived: yes},{ + sort: {date: 1}, limit: opt.limit, skip: opt.skip + }) Template.archivedlist.helpers empty: -> archived().count() is 0 getDate: formattedDate archived: -> archived().fetch() + paginator: -> archivePaginator + pageActive: -> if @active then "btn-primary" else "btn-default" Template.archivedlist.events 'click .close-note': -> notes.remove @_id 'click .note': -> notes.update @_id, $set: archived: no 'click .clear': -> notes.remove item._id for item in Template.archivedlist.archived() + 'click .btn': (e) -> archivePaginator.page @index # Note Editor Template.editor.helpers diff --git a/client/view/style.css b/client/view/style.css index 3507219..1f7c683 100644 --- a/client/view/style.css +++ b/client/view/style.css @@ -153,6 +153,10 @@ input { margin-right: 10px } +.paginator { + margin-bottom: 1em; +} + /* IDs */ #ui-container { diff --git a/client/view/templates.html b/client/view/templates.html index 04dd294..6caba6e 100644 --- a/client/view/templates.html +++ b/client/view/templates.html @@ -43,6 +43,13 @@ {{/each}} + {{#if paginator.show}} +
You don't have any notes, try adding a new one!
{{/if}} @@ -67,6 +74,13 @@ {{/each}} + {{#if paginator.show}} +Your archive is empty
{{else}} diff --git a/server/server.coffee b/server/server.coffee index 64abbae..4abca28 100644 --- a/server/server.coffee +++ b/server/server.coffee @@ -19,12 +19,9 @@ userValidated = (user) -> Meteor.publish 'user', -> Meteor.users.find @userId, fields: {dateformat: 1, username: 1} # Publish user's notes to each user. -Meteor.publish "my-notes", -> +Meteor.publish "notes", (archived) -> if userValidated getUser(@userId) - notes.find userId: @userId, archived: no -Meteor.publish "archive", -> - if userValidated getUser(@userId) - notes.find userId: @userId, archived: yes + notes.find userId: @userId, archived: archived # Custom new account default settings Accounts.onCreateUser (options, user) ->