mirror of
https://github.com/fazo96/homework.git
synced 2025-01-25 14:34:20 +01:00
added dates to the notes
This commit is contained in:
parent
398eca2a41
commit
736d695a68
@ -11,3 +11,4 @@ font-awesome
|
|||||||
accounts-base
|
accounts-base
|
||||||
accounts-password
|
accounts-password
|
||||||
iron-router
|
iron-router
|
||||||
|
bootstrap3-datepicker
|
||||||
|
@ -8,6 +8,10 @@ deleteAccount = ->
|
|||||||
amIValid = ->
|
amIValid = ->
|
||||||
return no unless getUser()
|
return no unless getUser()
|
||||||
return yes for mail in getUser().emails when mail.verified is yes; no
|
return yes for mail in getUser().emails when mail.verified is yes; no
|
||||||
|
daysUntil = (time) ->
|
||||||
|
date = new Date time; now = new Date() #console.log date+" "+now
|
||||||
|
now.setHours(0); now.setMinutes(0); now.setSeconds(0)
|
||||||
|
(Math.floor ((date.getTime() - now.getTime()) / 1000 / 60 / 60) + 1) / 24
|
||||||
|
|
||||||
# Common Helpers for the Templates
|
# Common Helpers for the Templates
|
||||||
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
||||||
@ -17,12 +21,10 @@ UI.registerHelper "verified", -> amIValid()
|
|||||||
|
|
||||||
# Router
|
# Router
|
||||||
###
|
###
|
||||||
Important: before rendering and routing, always "dispatch" the user to 'home'
|
Important: 'home' dispatches the user to the correct landing page.
|
||||||
if he doesn't have the permission to access the current route. 'home' then
|
|
||||||
dispatches the user to the correct landing page.
|
|
||||||
Routes are client side, but even if by hacking the client you can access pages
|
Routes are client side, but even if by hacking the client you can access pages
|
||||||
without being logged in, it's impossible to inteact with data because
|
without being logged in, it's impossible to inteact with data because
|
||||||
the server checks all the things before providing the data. It's safe.
|
the server doesn't let the user if he doesn't have permission. It's still safe.
|
||||||
###
|
###
|
||||||
Router.configure
|
Router.configure
|
||||||
layoutTemplate: 'layout'
|
layoutTemplate: 'layout'
|
||||||
@ -41,12 +43,10 @@ Router.map ->
|
|||||||
@route 'register',
|
@route 'register',
|
||||||
onBeforeAction: -> Router.go 'home' if getUser()
|
onBeforeAction: -> Router.go 'home' if getUser()
|
||||||
@route 'account',
|
@route 'account',
|
||||||
onBeforeAction: ->
|
onBeforeAction: -> if not getUser() then Router.go 'home'
|
||||||
if not getUser() then Router.go 'home'
|
|
||||||
@route 'notes',
|
@route 'notes',
|
||||||
waitOn: -> Meteor.subscribe "my-notes"
|
waitOn: -> Meteor.subscribe "my-notes"
|
||||||
onBeforeAction: ->
|
onBeforeAction: -> if not getUser() then Router.go 'home'
|
||||||
if not getUser() then Router.go 'home'
|
|
||||||
@route 'note',
|
@route 'note',
|
||||||
path: '/note/:_id'
|
path: '/note/:_id'
|
||||||
waitOn: -> Meteor.subscribe "my-notes"
|
waitOn: -> Meteor.subscribe "my-notes"
|
||||||
@ -72,7 +72,9 @@ Deps.autorun ->
|
|||||||
# Client Templates
|
# Client Templates
|
||||||
|
|
||||||
# Some utilities
|
# Some utilities
|
||||||
logoutCallback = (err) -> if err then errCallback err else Router.go 'home'
|
logoutCallback = (err) ->
|
||||||
|
if err then errCallback err
|
||||||
|
else Router.go 'home'; Meteor.unsubscribe "my-notes"
|
||||||
errCallback = (err) ->
|
errCallback = (err) ->
|
||||||
if err.reason
|
if err.reason
|
||||||
showError msg: err.reason
|
showError msg: err.reason
|
||||||
@ -90,28 +92,43 @@ Template.account.events
|
|||||||
'click #btn-delete-me': -> deleteAccount()
|
'click #btn-delete-me': -> deleteAccount()
|
||||||
|
|
||||||
# Notes template
|
# Notes template
|
||||||
|
Template.notelist.active = ->
|
||||||
|
return no unless Router.current() and Router.current().data()
|
||||||
|
return @_id is Router.current().data()._id
|
||||||
Template.notelist.empty = -> notes.find().count() is 0
|
Template.notelist.empty = -> notes.find().count() is 0
|
||||||
|
Template.notelist.getDate = ->
|
||||||
|
return unless @date; diff = daysUntil @date
|
||||||
|
if diff <= 0 then return msg:"You missed it!", color: "danger"
|
||||||
|
if diff is 1 then return msg:"Today", color: "warning"
|
||||||
|
if diff is 2 then return msg:"Tomorrow", color: "info"
|
||||||
|
#if new Date(@date).getMonth() > Date.now().getMonth()
|
||||||
|
#return msg:"Next Month", color:"success" unless diff < 7
|
||||||
|
msg: "due in "+diff+" days", color: "primary"
|
||||||
|
#day = new Date(@date).toLocaleString().split(' ')[0]
|
||||||
Template.notelist.notes = ->
|
Template.notelist.notes = ->
|
||||||
d = notes.find().fetch()
|
d = notes.find({},{ sort: date: 1}).fetch()
|
||||||
Template.notelist.events
|
Template.notelist.events
|
||||||
'click .close-note': -> notes.remove @_id
|
'click .close-note': -> notes.remove @_id
|
||||||
'click .edit-note': -> Router.go 'note', {_id: @_id}
|
|
||||||
'keypress #newNote': (e,template) ->
|
'keypress #newNote': (e,template) ->
|
||||||
if e.keyCode is 13 and template.find('#newNote').value isnt ""
|
if e.keyCode is 13 and template.find('#newNote').value isnt ""
|
||||||
notes.insert
|
notes.insert
|
||||||
title: template.find('#newNote').value
|
title: template.find('#newNote').value
|
||||||
content: ""
|
content: "", date: no, archived: no, userId: Meteor.userId()
|
||||||
userId: Meteor.userId()
|
|
||||||
template.find('#newNote').value = ""
|
template.find('#newNote').value = ""
|
||||||
|
|
||||||
# Note Editor
|
# Note Editor
|
||||||
Template.editor.note = -> Router.current.data() # Only when we're in /note/:_id
|
Template.editor.note = -> Router.current().data()
|
||||||
|
Template.editor.rendered = -> $('.date').datepicker
|
||||||
|
weekStart: 1
|
||||||
|
startDate: "today"
|
||||||
|
todayBtn: "linked"
|
||||||
saveCurrentNote = (t,e) ->
|
saveCurrentNote = (t,e) ->
|
||||||
if e and e.keyCode isnt 13 then return
|
if e and e.keyCode isnt 13 then return
|
||||||
notes.update Router.current().data()._id,
|
notes.update Router.current().data()._id,
|
||||||
$set:
|
$set:
|
||||||
title: t.find('.editor-title').value
|
title: t.find('.editor-title').value
|
||||||
content: t.find('.area').value
|
content: t.find('.area').value
|
||||||
|
date: t.find('.date').value
|
||||||
Template.editor.events
|
Template.editor.events
|
||||||
'click .close-editor': -> Router.go 'notes'
|
'click .close-editor': -> Router.go 'notes'
|
||||||
'click .save-editor': (e,t) -> saveCurrentNote t
|
'click .save-editor': (e,t) -> saveCurrentNote t
|
||||||
|
@ -20,6 +20,10 @@ input {
|
|||||||
margin-bottom: 22px;
|
margin-bottom: 22px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.date {
|
||||||
|
max-width: 250px;
|
||||||
|
}
|
||||||
|
|
||||||
.btns-account {
|
.btns-account {
|
||||||
margin-top: 20px;
|
margin-top: 20px;
|
||||||
}
|
}
|
||||||
@ -47,8 +51,12 @@ input {
|
|||||||
.close-note {
|
.close-note {
|
||||||
float: right;
|
float: right;
|
||||||
margin-top: -2px;
|
margin-top: -2px;
|
||||||
|
clear:both;
|
||||||
|
}
|
||||||
|
.note-date{
|
||||||
|
float:right;
|
||||||
|
margin-top: -17px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.note-desc {
|
.note-desc {
|
||||||
color: #999;
|
color: #999;
|
||||||
}
|
}
|
||||||
|
@ -45,10 +45,11 @@
|
|||||||
{{#each notes}}
|
{{#each notes}}
|
||||||
<a href="{{pathFor 'note'}}" class="note list-group-item">
|
<a href="{{pathFor 'note'}}" class="note list-group-item">
|
||||||
<span class="note-content">
|
<span class="note-content">
|
||||||
<button type="button" class="edit-note close">
|
{{#if active}}<a role="button" href="{{pathFor 'notes'}}" class="edit-note close">
|
||||||
<i class="fa fa-pencil-square-o"></i>
|
<i class="fa fa-pencil-square-o"></i>
|
||||||
</button>
|
</a>{{/if}}
|
||||||
<b>{{title}}</b> <span class="note-desc">{{content}}</span>
|
<b>{{title}}</b> <span class="note-desc">{{content}}</span>
|
||||||
|
<span class="note-date label label-{{getDate.color}}">{{getDate.msg}}</span>
|
||||||
</span>
|
</span>
|
||||||
<button type="button" class="close-note close">×</button>
|
<button type="button" class="close-note close">×</button>
|
||||||
</a>
|
</a>
|
||||||
@ -60,6 +61,26 @@
|
|||||||
{{> noteadder }}
|
{{> noteadder }}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template name="editor">
|
||||||
|
{{#if _id}}
|
||||||
|
<div class="panel panel-info">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">
|
||||||
|
<div align="center">
|
||||||
|
<input type="text" class="form-control editor-title" value="{{title}}" placeholder="Title">
|
||||||
|
<button type="button" class="close close-editor">×</button>
|
||||||
|
</div>
|
||||||
|
</h3>
|
||||||
|
</div>
|
||||||
|
<div align="center" class="panel-body">
|
||||||
|
<textarea id="area" class="area form-control in-bt" rows="3" placeholder="...">{{content}}</textarea>
|
||||||
|
<input class="form-control date" value="{{date}}" placeholder="Due Date">
|
||||||
|
<button type="button" class="btn btn-info save-editor">Save</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{/if}}
|
||||||
|
</template>
|
||||||
|
|
||||||
<template name="login">
|
<template name="login">
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<h3 class="cool-header"><i class="fa fa-sign-in fa-2x"></i><br>Login</h3>
|
<h3 class="cool-header"><i class="fa fa-sign-in fa-2x"></i><br>Login</h3>
|
||||||
@ -125,25 +146,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="editor">
|
|
||||||
{{#if _id}}
|
|
||||||
<div class="panel panel-info">
|
|
||||||
<div class="panel-heading">
|
|
||||||
<h3 class="panel-title">
|
|
||||||
<div align="center">
|
|
||||||
<input type="text" class="form-control editor-title" value="{{title}}" placeholder="Title">
|
|
||||||
<button type="button" class="close close-editor">×</button>
|
|
||||||
</div>
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
<div align="center" class="panel-body">
|
|
||||||
<textarea id="area" class="area form-control" rows="3" placeholder="...">{{content}}</textarea>
|
|
||||||
<button type="button" class="btn btn-info save-editor">Save</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{{/if}}
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template name="notifications">
|
<template name="notifications">
|
||||||
{{#each notification}}
|
{{#each notification}}
|
||||||
<div class="alert alert-{{type}} notification">
|
<div class="alert alert-{{type}} notification">
|
||||||
|
1
packages/.gitignore
vendored
1
packages/.gitignore
vendored
@ -2,3 +2,4 @@
|
|||||||
/font-awesome
|
/font-awesome
|
||||||
/iron-router
|
/iron-router
|
||||||
/blaze-layout
|
/blaze-layout
|
||||||
|
/bootstrap3-datepicker
|
||||||
|
@ -12,15 +12,16 @@ getUser = (id) -> Meteor.users.findOne { _id: id }
|
|||||||
|
|
||||||
# Returns true if the user has verified at least one email address
|
# Returns true if the user has verified at least one email address
|
||||||
userValidated = (user) ->
|
userValidated = (user) ->
|
||||||
if not user?
|
return no unless user?
|
||||||
console.log "Impossible! Trying to validate null user"
|
|
||||||
return no
|
|
||||||
return yes for mail in user.emails when mail.verified is yes; no
|
return yes for mail in user.emails when mail.verified is yes; no
|
||||||
|
|
||||||
# Publish user's notes to each user.
|
# Publish user's notes to each user.
|
||||||
Meteor.publish "my-notes", ->
|
Meteor.publish "my-notes", ->
|
||||||
if userValidated getUser(@userId)
|
if userValidated getUser(@userId)
|
||||||
notes.find userId: @userId
|
notes.find userId: @userId, archived: no
|
||||||
|
Meteor.publish "archive", ->
|
||||||
|
if userValidated getUser(@userId)
|
||||||
|
notes.find userId: @userId, archived: yes
|
||||||
|
|
||||||
# Methods that the clients can invoke
|
# Methods that the clients can invoke
|
||||||
Meteor.methods
|
Meteor.methods
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
"packages": {
|
"packages": {
|
||||||
"bootstrap-3": {},
|
"bootstrap-3": {},
|
||||||
"font-awesome": {},
|
"font-awesome": {},
|
||||||
"iron-router": {}
|
"iron-router": {},
|
||||||
|
"bootstrap3-datepicker": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,8 @@
|
|||||||
"basePackages": {
|
"basePackages": {
|
||||||
"bootstrap-3": {},
|
"bootstrap-3": {},
|
||||||
"font-awesome": {},
|
"font-awesome": {},
|
||||||
"iron-router": {}
|
"iron-router": {},
|
||||||
|
"bootstrap3-datepicker": {}
|
||||||
},
|
},
|
||||||
"packages": {
|
"packages": {
|
||||||
"bootstrap-3": {
|
"bootstrap-3": {
|
||||||
@ -22,6 +23,11 @@
|
|||||||
"tag": "v0.7.1",
|
"tag": "v0.7.1",
|
||||||
"commit": "d1ffb3f06ea4c112132b030f2eb1a70b81675ecb"
|
"commit": "d1ffb3f06ea4c112132b030f2eb1a70b81675ecb"
|
||||||
},
|
},
|
||||||
|
"bootstrap3-datepicker": {
|
||||||
|
"git": "https://github.com/rajit/bootstrap3-datepicker.git",
|
||||||
|
"tag": "v0.2.1",
|
||||||
|
"commit": "442484eb1c8eb00c6b9e0e9c88accc934cf8f04a"
|
||||||
|
},
|
||||||
"blaze-layout": {
|
"blaze-layout": {
|
||||||
"git": "https://github.com/EventedMind/blaze-layout.git",
|
"git": "https://github.com/EventedMind/blaze-layout.git",
|
||||||
"tag": "v0.2.4",
|
"tag": "v0.2.4",
|
||||||
|
Loading…
Reference in New Issue
Block a user