1
0
mirror of https://github.com/fazo96/homework.git synced 2025-01-10 12:14:22 +01:00

upgraded to meteor 1.0

This commit is contained in:
fazo96 2014-11-12 17:27:20 +01:00
parent 32dd07d50e
commit 5a4ada291f
2 changed files with 80 additions and 76 deletions

View File

@ -1,7 +1,7 @@
# Homework - Client Side # Homework - Client Side
version = "1.1.6" version = "1.1.7"
# Utilities # Utilities
tick = new Deps.Dependency() tick = new Tracker.Dependency()
Meteor.setInterval (-> tick.changed();), 15000 Meteor.setInterval (-> tick.changed();), 15000
notes = new Meteor.Collection "notes" notes = new Meteor.Collection "notes"
@ -62,7 +62,6 @@ loggedInController = RouteController.extend
@render 'loading' @render 'loading'
else @render() else @render()
onBeforeAction: -> onBeforeAction: ->
showError()
if not getUser() then Router.go 'home' if not getUser() then Router.go 'home'
else if not amIValid() then Router.go 'verifyEmail' else if not amIValid() then Router.go 'verifyEmail'
@next() @next()
@ -73,56 +72,57 @@ guestController = RouteController.extend
@render 'reconnect' @render 'reconnect'
else @render() else @render()
onBeforeAction: -> onBeforeAction: ->
showError()
if getUser() if getUser()
if amIValid() is no then Router.go 'verifyEmail' else Router.go 'notes' if amIValid() is no then Router.go 'verifyEmail' else Router.go 'notes'
@next() @next()
Router.map ->
@route 'home', Router.route '/',
path: '/' name: 'home'
template: 'homepage' template: 'homepage'
action: -> @render 'homepage', to: 'outside' action: -> @render 'homepage', to: 'outside'
onBeforeAction: -> onBeforeAction: ->
# Dispatch user to the right landing page based on his account status # Dispatch user to the right landing page based on his account status
if getUser() if getUser()
if amIValid() is yes then Router.go 'notes' else Router.go 'verifyEmail' if amIValid() is yes then Router.go 'notes' else Router.go 'verifyEmail'
@next() @next()
@route 'login', controller: guestController Router.route '/login', controller: guestController
@route 'register', controller: guestController Router.route '/register', controller: guestController
@route 'account', controller: loggedInController Router.route '/account', controller: loggedInController
@route 'notes', Router.route '/notes/:_id?',
path: '/notes/:_id?' name: 'notes'
waitOn: -> Meteor.subscribe 'my-notes' waitOn: -> Meteor.subscribe 'my-notes'
data: -> notes.findOne _id: @params._id data: -> notes.findOne _id: @params._id
controller: loggedInController controller: loggedInController
@route 'archive', Router.route '/archive/:_id?',
path: '/archive/:_id?' name: 'archive'
waitOn: -> @notes = Meteor.subscribe 'archive' waitOn: -> @notes = Meteor.subscribe 'archive'
onStop: -> @notes.stop() onStop: -> @notes.stop()
controller: loggedInController controller: loggedInController
@route 'verifyEmail', Router.route '/verify/:token?',
path: '/verify/:token?' name: 'verifyEmail'
template: 'verifyEmail' template: 'verifyEmail'
action: -> action: ->
if Meteor.status().connected is no if Meteor.status().connected is no
@render 'reconnect' @render 'reconnect'
else @render() else @render()
onBeforeAction: -> onBeforeAction: ->
if getUser() if getUser()
if amIValid() then Router.go 'home' if amIValid() then Router.go 'home'
else Router.go 'home' else Router.go 'home'
# Automatic verification # Automatic verification
if @params.token? and @params.token isnt "" if @params.token? and @params.token isnt ""
@render 'loading' @render 'loading'
Accounts.verifyEmail @params.token, (err) -> Accounts.verifyEmail @params.token, (err) =>
if err if err
errCallback err; Router.go 'verifyEmail', token: @params.token errCallback err; Router.go 'verifyEmail', token: @params.token
else else
showErr type:'success', msg:'Verification complete' showErr type:'success', msg:'Verification complete'
Router.go 'home' Router.go 'home'
@route '404', path: '*' @next()
else @next()
Router.route '/(.*)', -> @render '404'
# Client Templates # Client Templates
@ -140,10 +140,11 @@ Template.homepage.events
else else
Router.go 'notes' Router.go 'notes'
swal 'Ok', 'Logged In', 'success' swal 'Ok', 'Logged In', 'success'
Template.reconnect.time = -> Template.reconnect.helpers
tick.depend() time : ->
if Meteor.status().retryTime tick.depend()
'(retrying '+moment(Meteor.status().retryTime).fromNow()+')' if Meteor.status().retryTime
'(retrying '+moment(Meteor.status().retryTime).fromNow()+')'
# 3 Buttons navigation Menu # 3 Buttons navigation Menu
Template.menu.events Template.menu.events
@ -152,7 +153,8 @@ Template.menu.events
'click .go-archive': -> Router.go 'archive' 'click .go-archive': -> Router.go 'archive'
# Account Page # Account Page
Template.account.dateformat = -> if getUser() then return getUser().dateformat Template.account.helpers
dateformat: -> if getUser() then return getUser().dateformat
Template.account.events Template.account.events
'click #reset-settings': (e,t) -> 'click #reset-settings': (e,t) ->
t.find('#set-date-format').value = "MM/DD/YYYY" t.find('#set-date-format').value = "MM/DD/YYYY"
@ -164,11 +166,7 @@ Template.account.events
'click #btn-delete-me': -> deleteAccount() 'click #btn-delete-me': -> deleteAccount()
# Notes list # Notes list
Template.notelist.active = -> formattedDate = ->
return no unless Router.current() and Router.current().data()
return @_id is Router.current().data()._id
Template.notelist.empty = -> Template.notelist.notelist().length is 0
Template.notelist.getDate = ->
return unless @date return unless @date
tick.depend() tick.depend()
#dif = moment(@date, getUser().dateformat).diff(moment(), 'days') #dif = moment(@date, getUser().dateformat).diff(moment(), 'days')
@ -178,8 +176,15 @@ Template.notelist.getDate = ->
color = "warning" if dif is 1 color = "warning" if dif is 1
color = "danger" if dif < 1 color = "danger" if dif < 1
msg: moment.unix(@date).fromNow(), color: color msg: moment.unix(@date).fromNow(), color: color
Template.notelist.notelist = -> notelist = -> notes.find({ archived: no },{ sort: date: 1})
notes.find({ archived: no },{ sort: date: 1}).fetch() Template.notelist.helpers
notelist: -> notelist().fetch()
active: ->
return no unless Router.current() and Router.current().data()
return @_id is Router.current().data()._id
empty: -> notelist().count() is 0
getDate: formattedDate
Template.notelist.events Template.notelist.events
'click .close-note': -> notes.update @_id, $set: archived: yes 'click .close-note': -> notes.update @_id, $set: archived: yes
'click .edit-note': -> Router.go 'notes' 'click .edit-note': -> Router.go 'notes'
@ -191,22 +196,24 @@ Template.notelist.events
template.find('#newNote').value = "" template.find('#newNote').value = ""
# Archive # Archive
Template.archivedlist.empty = -> Template.archivedlist.archived().length is 0 archived = -> notes.find({ archived: yes },{ sort: date: 1})
Template.archivedlist.getDate = Template.notelist.getDate Template.archivedlist.helpers
Template.archivedlist.archived = -> empty: -> archived().count() is 0
notes.find({ archived: yes },{ sort: date: 1}).fetch() getDate: formattedDate
Template.archivedlist.events = archived: -> archived().fetch()
Template.archivedlist.events
'click .close-note': -> notes.remove @_id 'click .close-note': -> notes.remove @_id
'click .note': -> notes.update @_id, $set: archived: no 'click .note': -> notes.update @_id, $set: archived: no
'click .clear': -> 'click .clear': ->
notes.remove item._id for item in Template.archivedlist.archived() notes.remove item._id for item in Template.archivedlist.archived()
# Note Editor # Note Editor
Template.editor.note = -> Router.current().data() Template.editor.helpers
Template.editor.dateformat = -> getUser().dateformat note: -> Router.current().data()
Template.editor.formattedDate = -> dateformat: -> getUser().dateformat
return unless @date formattedDate: ->
moment.unix(@date).format(getUser().dateformat) return unless @date
moment.unix(@date).format(getUser().dateformat)
saveCurrentNote = (t,e) -> saveCurrentNote = (t,e) ->
if e and e.keyCode isnt 13 then return if e and e.keyCode isnt 13 then return
dat = no dat = no
@ -239,7 +246,8 @@ showError = (err) ->
swal title, err.msg, type swal title, err.msg, type
# Verify Email page # Verify Email page
Template.verifyEmail.token = -> Router.current().params.token Template.verifyEmail.helpers
token: -> Router.current().params.token
Template.verifyEmail.events Template.verifyEmail.events
'click #btn-verify': (e,template) -> 'click #btn-verify': (e,template) ->
t = template.find('#token-field').value; t = t.split("/") t = template.find('#token-field').value; t = t.split("/")
@ -286,6 +294,7 @@ registerRequest = (e,template) ->
}, (err) -> if err then errCallback err else Router.go 'confirmEmail' }, (err) -> if err then errCallback err else Router.go 'confirmEmail'
catch err catch err
showError msg: err showError msg: err
Template.register.events Template.register.events
'click #register-btn': (e,t) -> registerRequest null,t 'click #register-btn': (e,t) -> registerRequest null,t
'keypress .register': (e,t) -> registerRequest e,t 'keypress .register': (e,t) -> registerRequest e,t

5
packages/.gitignore vendored
View File

@ -1,5 +0,0 @@
/bootstrap-3
/font-awesome
/iron-router
/blaze-layout
/bootstrap3-datepicker