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

added dates to the notes

This commit is contained in:
fazo96 2014-06-01 11:47:27 +02:00
parent 398eca2a41
commit 736d695a68
8 changed files with 79 additions and 42 deletions

View File

@ -11,3 +11,4 @@ font-awesome
accounts-base
accounts-password
iron-router
bootstrap3-datepicker

View File

@ -8,6 +8,10 @@ deleteAccount = ->
amIValid = ->
return no unless getUser()
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
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
@ -17,12 +21,10 @@ UI.registerHelper "verified", -> amIValid()
# Router
###
Important: before rendering and routing, always "dispatch" the user to 'home'
if he doesn't have the permission to access the current route. 'home' then
dispatches the user to the correct landing page.
Important: 'home' dispatches the user to the correct landing page.
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
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
layoutTemplate: 'layout'
@ -41,12 +43,10 @@ Router.map ->
@route 'register',
onBeforeAction: -> Router.go 'home' if getUser()
@route 'account',
onBeforeAction: ->
if not getUser() then Router.go 'home'
onBeforeAction: -> if not getUser() then Router.go 'home'
@route 'notes',
waitOn: -> Meteor.subscribe "my-notes"
onBeforeAction: ->
if not getUser() then Router.go 'home'
onBeforeAction: -> if not getUser() then Router.go 'home'
@route 'note',
path: '/note/:_id'
waitOn: -> Meteor.subscribe "my-notes"
@ -72,7 +72,9 @@ Deps.autorun ->
# Client Templates
# 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) ->
if err.reason
showError msg: err.reason
@ -90,28 +92,43 @@ Template.account.events
'click #btn-delete-me': -> deleteAccount()
# 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.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 = ->
d = notes.find().fetch()
d = notes.find({},{ sort: date: 1}).fetch()
Template.notelist.events
'click .close-note': -> notes.remove @_id
'click .edit-note': -> Router.go 'note', {_id: @_id}
'keypress #newNote': (e,template) ->
if e.keyCode is 13 and template.find('#newNote').value isnt ""
notes.insert
title: template.find('#newNote').value
content: ""
userId: Meteor.userId()
content: "", date: no, archived: no, userId: Meteor.userId()
template.find('#newNote').value = ""
# 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) ->
if e and e.keyCode isnt 13 then return
notes.update Router.current().data()._id,
$set:
title: t.find('.editor-title').value
content: t.find('.area').value
date: t.find('.date').value
Template.editor.events
'click .close-editor': -> Router.go 'notes'
'click .save-editor': (e,t) -> saveCurrentNote t

View File

@ -20,6 +20,10 @@ input {
margin-bottom: 22px;
}
.date {
max-width: 250px;
}
.btns-account {
margin-top: 20px;
}
@ -47,8 +51,12 @@ input {
.close-note {
float: right;
margin-top: -2px;
clear:both;
}
.note-date{
float:right;
margin-top: -17px;
}
.note-desc {
color: #999;
}

View File

@ -45,10 +45,11 @@
{{#each notes}}
<a href="{{pathFor 'note'}}" class="note list-group-item">
<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>
</button>
</a>{{/if}}
<b>{{title}}</b> <span class="note-desc">{{content}}</span>
<span class="note-date label label-{{getDate.color}}">{{getDate.msg}}</span>
</span>
<button type="button" class="close-note close">&times;</button>
</a>
@ -60,6 +61,26 @@
{{> noteadder }}
</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">&times;</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">
<div align="center">
<h3 class="cool-header"><i class="fa fa-sign-in fa-2x"></i><br>Login</h3>
@ -125,25 +146,6 @@
</div>
</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">&times;</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">
{{#each notification}}
<div class="alert alert-{{type}} notification">

1
packages/.gitignore vendored
View File

@ -2,3 +2,4 @@
/font-awesome
/iron-router
/blaze-layout
/bootstrap3-datepicker

View File

@ -12,15 +12,16 @@ getUser = (id) -> Meteor.users.findOne { _id: id }
# Returns true if the user has verified at least one email address
userValidated = (user) ->
if not user?
console.log "Impossible! Trying to validate null user"
return no
return no unless user?
return yes for mail in user.emails when mail.verified is yes; no
# Publish user's notes to each user.
Meteor.publish "my-notes", ->
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
Meteor.methods

View File

@ -2,6 +2,7 @@
"packages": {
"bootstrap-3": {},
"font-awesome": {},
"iron-router": {}
"iron-router": {},
"bootstrap3-datepicker": {}
}
}

View File

@ -4,7 +4,8 @@
"basePackages": {
"bootstrap-3": {},
"font-awesome": {},
"iron-router": {}
"iron-router": {},
"bootstrap3-datepicker": {}
},
"packages": {
"bootstrap-3": {
@ -22,6 +23,11 @@
"tag": "v0.7.1",
"commit": "d1ffb3f06ea4c112132b030f2eb1a70b81675ecb"
},
"bootstrap3-datepicker": {
"git": "https://github.com/rajit/bootstrap3-datepicker.git",
"tag": "v0.2.1",
"commit": "442484eb1c8eb00c6b9e0e9c88accc934cf8f04a"
},
"blaze-layout": {
"git": "https://github.com/EventedMind/blaze-layout.git",
"tag": "v0.2.4",