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

massive update to fix #20 and other small stuff

This commit is contained in:
fazo96 2014-09-26 12:59:23 +02:00
parent edf8ef22a6
commit a23b02d39d
6 changed files with 83 additions and 41 deletions

View File

@ -10,5 +10,4 @@ natestrauser:font-awesome@4.1.0
accounts-base accounts-base
accounts-password accounts-password
iron:router iron:router
rajit:bootstrap3-datepicker mrt:moment

View File

@ -39,11 +39,11 @@ minimongo@1.0.3
mobile-status-bar@1.0.0 mobile-status-bar@1.0.0
mongo@1.0.5 mongo@1.0.5
mrt:bootstrap-3@3.1.1-1 mrt:bootstrap-3@3.1.1-1
mrt:moment@2.8.1
natestrauser:font-awesome@4.2.0 natestrauser:font-awesome@4.2.0
npm-bcrypt@0.7.7 npm-bcrypt@0.7.7
observe-sequence@1.0.2 observe-sequence@1.0.2
ordered-dict@1.0.0 ordered-dict@1.0.0
rajit:bootstrap3-datepicker@1.3.1
random@1.0.0 random@1.0.0
reactive-dict@1.0.2 reactive-dict@1.0.2
reactive-var@1.0.1 reactive-var@1.0.1

View File

@ -2,16 +2,13 @@
homework_version = "1.0" homework_version = "1.0"
# Utilities # Utilities
notes = new Meteor.Collection "notes" notes = new Meteor.Collection "notes"
Meteor.subscribe 'user'
getUser = -> Meteor.user() getUser = -> Meteor.user()
deleteAccount = -> deleteAccount = ->
Meteor.call 'deleteMe', (r) -> if r is yes then Router.go 'home' Meteor.call 'deleteMe', (r) -> if r is yes then Router.go 'home'
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()
@ -103,8 +100,15 @@ Template.menu.events
'click .go-archive': -> Router.go 'archive' 'click .go-archive': -> Router.go 'archive'
# Account Page # Account Page
Template.account.dateformat = -> getUser().dateformat
Template.account.events Template.account.events
'click #btn-logout': (e,template) -> Meteor.logout logoutCallback 'click #reset-settings': (e,t) ->
t.find('#set-date-format').value = "MM/DD/YYYY"
'click #save-settings': (e,t) ->
Meteor.users.update getUser()._id,
$set: dateformat: t.find('#set-date-format').value
showError msg: 'Settings saved', type: 'success'
'click #btn-logout': -> Meteor.logout logoutCallback
'click #btn-delete-me': -> deleteAccount() 'click #btn-delete-me': -> deleteAccount()
# Notes list # Notes list
@ -113,22 +117,16 @@ Template.notelist.active = ->
return @_id is Router.current().data()._id return @_id is Router.current().data()._id
Template.notelist.empty = -> Template.notelist.notelist().length is 0 Template.notelist.empty = -> Template.notelist.notelist().length is 0
Template.notelist.getDate = -> Template.notelist.getDate = ->
return unless @date; diff = daysUntil @date return unless @date
if diff <= 0 then return msg:"You missed it!", color: "danger" #dif = moment(@date, getUser().dateformat).diff(moment(), 'days')
if diff is 1 then return msg:"Today", color: "warning" dif = moment.unix(@date).diff(moment(), 'days')
if diff is 2 then return msg:"Tomorrow", color: "info" color = "primary"
msg: "due in "+diff+" days", color: "primary" color = "info" if dif < 7
color = "warning" if dif is 1
color = "danger" if dif < 1
msg: moment.unix(@date).fromNow(), color: color
Template.notelist.notelist = -> Template.notelist.notelist = ->
notes.find({ archived: no },{ sort: date: 1}).fetch() notes.find({ archived: no },{ sort: date: 1}).fetch()
###
return [] unless getUser() and Router.current and Router.current().path
path = Router.current().path
if path.startsWith '/note'
return notes.find({ archived: no },{ sort: date: 1}).fetch()
else if path.startsWith '/archive'
return notes.find({ archived: yes },{ sort: date: 1}).fetch()
else return []
###
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'
@ -141,6 +139,7 @@ Template.notelist.events
# Archive # Archive
Template.archivedlist.empty = -> Template.archivedlist.archived().length is 0 Template.archivedlist.empty = -> Template.archivedlist.archived().length is 0
Template.archivedlist.getDate = Template.notelist.getDate
Template.archivedlist.archived = -> Template.archivedlist.archived = ->
notes.find({ archived: yes },{ sort: date: 1}).fetch() notes.find({ archived: yes },{ sort: date: 1}).fetch()
Template.archivedlist.events = Template.archivedlist.events =
@ -151,20 +150,29 @@ Template.archivedlist.events =
# Note Editor # Note Editor
Template.editor.note = -> Router.current().data() Template.editor.note = -> Router.current().data()
Template.editor.rendered = -> $('.date').datepicker Template.editor.formattedDate = ->
weekStart: 1 return unless @date
startDate: "today" moment.unix(@date).format(getUser().dateformat)
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
dat = no
if t.find('.date').value isnt ""
dat = moment(t.find('.date').value,getUser().dateformat)
if dat.isValid()
dat = dat.unix()
else
dat = no; showError msg: 'Invalid date'
t.find('.date').value = ""
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 date: dat
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
'click .set-date': (e,t) ->
t.find('.date').value = moment().add(1,'days').format(getUser().dateformat)
'keypress .title': (e,t) -> saveCurrentNote t, e 'keypress .title': (e,t) -> saveCurrentNote t, e
# Notifications (not used yet) # Notifications (not used yet)
@ -241,6 +249,7 @@ registerRequest = (e,template) ->
Accounts.createUser { Accounts.createUser {
email: mail, email: mail,
password: pass password: pass
dateformat: "MM/DD/YYYY"
}, (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

View File

@ -21,6 +21,15 @@ input {
margin-bottom: 22px; margin-bottom: 22px;
} }
#save-settings, #reset-settings {
margin-top: 20px;
margin-bottom: 20px;
}
#set-date-format {
max-width: 200px;
}
.date { .date {
max-width: 250px; max-width: 250px;
} }
@ -63,7 +72,6 @@ input {
.note-date{ .note-date{
float:right; float:right;
margin-top: -17px;
} }
.note-desc { .note-desc {
color: #999; color: #999;
@ -81,6 +89,13 @@ input {
.edit-note { .edit-note {
display: inline-block; display: inline-block;
margin-right: 10px; margin-right: 10px;
font-size: 18px;
font-weight: bold;
line-height: 1;
color: #000;
text-shadow: 0 1px 0 #fff;
filter: alpha(opacity=20);
opacity: .2;
} }
.editor-title { width: 70%; } .editor-title { width: 70%; }
@ -95,7 +110,7 @@ input {
margin-right: 5px; margin-right: 5px;
} }
.save-editor { .save-editor, .set-date {
margin-top: 10px; margin-top: 10px;
} }
@ -104,7 +119,7 @@ input {
} }
.btn-ver { .btn-ver {
width:150px; width:115px;
margin-top:20px; margin-top:20px;
} }

View File

@ -33,7 +33,7 @@
{{#each notelist}} {{#each notelist}}
<a href="{{pathFor 'notes'}}" class="note list-group-item"> <a href="{{pathFor 'notes'}}" class="note list-group-item">
<span class="note-content"> <span class="note-content">
{{#if active}}<a role="button" class="edit-note close"> {{#if active}}<a role="button" class="edit-note">
<i class="fa fa-pencil-square-o"></i> <i class="fa fa-pencil-square-o"></i>
</a>{{/if}} </a>{{/if}}
<b>{{title}}</b> <span class="note-desc">{{content}}</span> <b>{{title}}</b> <span class="note-desc">{{content}}</span>
@ -60,7 +60,7 @@
<a href="{{pathFor 'archive'}}" class="note list-group-item"> <a href="{{pathFor 'archive'}}" class="note list-group-item">
<span class="note-content"> <span class="note-content">
<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 class="note-date label label-{{getDate.color}}">{{getDate.msg}}</span>
</span> </span>
<button type="button" class="close-note close archive-close-note"> <button type="button" class="close-note close archive-close-note">
<i class="fa fa-trash-o"></i></button> <i class="fa fa-trash-o"></i></button>
@ -90,8 +90,11 @@
</div> </div>
<div align="center" class="panel-body"> <div align="center" class="panel-body">
<textarea id="area" class="area form-control in-bt" rows="3" placeholder="...">{{content}}</textarea> <textarea id="area" class="area form-control in-bt" rows="3" placeholder="...">{{content}}</textarea>
<!--<input class="form-control date" value="{{date}}" placeholder="Due Date">--> <input class="form-control date" value="{{formattedDate}}" placeholder="Due Date">
<button type="button" class="btn btn-info save-editor">Save</button> <button type="button" class="btn btn-warning set-date">
<i class="fa fa-clock-o"></i> Do Today</button>
<button type="button" class="btn btn-info save-editor">
<i class="fa fa-upload"></i> Save</button>
</div> </div>
</div> </div>
{{/if}} {{/if}}
@ -143,6 +146,16 @@
<template name="account"> <template name="account">
<div align="center"> <div align="center">
<h3 class="cool-header"><i class="fa fa-user fa-2x"></i><br>{{email}}</h3> <h3 class="cool-header"><i class="fa fa-user fa-2x"></i><br>{{email}}</h3>
{{> error}}
<p class="lead">Settings</p>
<p>You can choose the format used to write and read dates in the note list</p>
<input type="text" class="form-control" id="set-date-format" placeholder="Date Format" value="{{dateformat}}">
<div class="btn-group">
<button type="button" id="save-settings" class="btn btn-primary">
<i class="fa fa-upload"></i> Save</button>
<button type="button" id="reset-settings" class="btn btn-warning">
<i class="fa fa-cog"></i> Reset</button>
</div>
{{> menu}} {{> menu}}
<div class="btn-group btns-account"> <div class="btn-group btns-account">
<button type="button" id="btn-logout" class="btn btn-warning"> <button type="button" id="btn-logout" class="btn btn-warning">
@ -163,16 +176,16 @@
<p>Click the link inside the email we sent you or paste it here:</p> <p>Click the link inside the email we sent you or paste it here:</p>
{{> error}} {{> error}}
<input type="text" id="token-field" class="form-control" placeholder="Token" value="{{token}}"> <input type="text" id="token-field" class="form-control" placeholder="Token" value="{{token}}">
<div align="center" class="buttons"> <div align="center" class="btn-group">
<button type="button" class="btn btn-warning btn-ver" id="btn-resend"> <button type="button" class="btn btn-warning btn-ver" id="btn-resend">
<i class="fa fa-refresh"></i> Resend</button> <i class="fa fa-refresh"></i> Resend</button>
<button type="button" class="btn btn-success btn-ver" id="btn-verify"> <button type="button" class="btn btn-success btn-ver" id="btn-verify">
<i class="fa fa-check"></i> Verify Token</button> <i class="fa fa-check"></i> Verify</button>
<button type="button" class="btn btn-danger btn-ver" id="btn-delete"> <button type="button" class="btn btn-danger btn-ver" id="btn-delete">
<i class="fa fa-trash-o"></i> Delete Account</button> <i class="fa fa-trash-o"></i> Delete</button>
<br><button type="button" class="btn btn-primary btn-ver" id="btn-logout"> </div><br>
<i class="fa fa-sign-out"></i> Sign Out</button> <button type="button" class="btn btn-primary btn-ver" id="btn-logout">
</div> <i class="fa fa-sign-out"></i> Sign Out</button>
</div> </div>
</template> </template>

View File

@ -15,6 +15,7 @@ userValidated = (user) ->
return no unless user? return no unless user?
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
Meteor.publish 'user', -> Meteor.users.find @userId, fields: dateformat: 1
# 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)
@ -50,4 +51,9 @@ Meteor.methods
{$set : { "resume.loginTokens" : [] } }, { multi: yes } {$set : { "resume.loginTokens" : [] } }, { multi: yes }
return yes return yes
no no
version: -> "1.0" # Request server version number. Meteor.users.allow
update: (id,doc,fields,mod) ->
if fields[0] == 'dateformat' and fields.length == 1
console.log mod
return yes
return no