From a23b02d39dbbbf8437f6d59135d92613fe72e5bb Mon Sep 17 00:00:00 2001 From: fazo96 Date: Fri, 26 Sep 2014 12:59:23 +0200 Subject: [PATCH] massive update to fix #20 and other small stuff --- .meteor/packages | 3 +- .meteor/versions | 2 +- client/client.coffee | 57 ++++++++++++++++++++++---------------- client/view/style.css | 21 ++++++++++++-- client/view/templates.html | 33 +++++++++++++++------- server/server.coffee | 8 +++++- 6 files changed, 83 insertions(+), 41 deletions(-) diff --git a/.meteor/packages b/.meteor/packages index 541887b..f5901e1 100644 --- a/.meteor/packages +++ b/.meteor/packages @@ -10,5 +10,4 @@ natestrauser:font-awesome@4.1.0 accounts-base accounts-password iron:router -rajit:bootstrap3-datepicker - +mrt:moment diff --git a/.meteor/versions b/.meteor/versions index 43de3f6..f69fa23 100644 --- a/.meteor/versions +++ b/.meteor/versions @@ -39,11 +39,11 @@ minimongo@1.0.3 mobile-status-bar@1.0.0 mongo@1.0.5 mrt:bootstrap-3@3.1.1-1 +mrt:moment@2.8.1 natestrauser:font-awesome@4.2.0 npm-bcrypt@0.7.7 observe-sequence@1.0.2 ordered-dict@1.0.0 -rajit:bootstrap3-datepicker@1.3.1 random@1.0.0 reactive-dict@1.0.2 reactive-var@1.0.1 diff --git a/client/client.coffee b/client/client.coffee index 7112808..f9fd7f8 100644 --- a/client/client.coffee +++ b/client/client.coffee @@ -2,16 +2,13 @@ homework_version = "1.0" # Utilities notes = new Meteor.Collection "notes" +Meteor.subscribe 'user' getUser = -> Meteor.user() deleteAccount = -> Meteor.call 'deleteMe', (r) -> if r is yes then Router.go 'home' 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() @@ -103,8 +100,15 @@ Template.menu.events 'click .go-archive': -> Router.go 'archive' # Account Page +Template.account.dateformat = -> getUser().dateformat 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() # Notes list @@ -113,22 +117,16 @@ Template.notelist.active = -> return @_id is Router.current().data()._id Template.notelist.empty = -> Template.notelist.notelist().length 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" - msg: "due in "+diff+" days", color: "primary" + return unless @date + #dif = moment(@date, getUser().dateformat).diff(moment(), 'days') + dif = moment.unix(@date).diff(moment(), '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 = -> 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 'click .close-note': -> notes.update @_id, $set: archived: yes 'click .edit-note': -> Router.go 'notes' @@ -141,6 +139,7 @@ Template.notelist.events # Archive Template.archivedlist.empty = -> Template.archivedlist.archived().length is 0 +Template.archivedlist.getDate = Template.notelist.getDate Template.archivedlist.archived = -> notes.find({ archived: yes },{ sort: date: 1}).fetch() Template.archivedlist.events = @@ -151,20 +150,29 @@ Template.archivedlist.events = # Note Editor Template.editor.note = -> Router.current().data() -Template.editor.rendered = -> $('.date').datepicker - weekStart: 1 - startDate: "today" - todayBtn: "linked" +Template.editor.formattedDate = -> + return unless @date + moment.unix(@date).format(getUser().dateformat) saveCurrentNote = (t,e) -> 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, $set: title: t.find('.editor-title').value content: t.find('.area').value - date: t.find('.date').value + date: dat Template.editor.events 'click .close-editor': -> Router.go 'notes' '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 # Notifications (not used yet) @@ -241,6 +249,7 @@ registerRequest = (e,template) -> Accounts.createUser { email: mail, password: pass + dateformat: "MM/DD/YYYY" }, (err) -> if err then errCallback err else Router.go 'confirmEmail' catch err showError msg: err diff --git a/client/view/style.css b/client/view/style.css index fb14007..acd44b5 100644 --- a/client/view/style.css +++ b/client/view/style.css @@ -21,6 +21,15 @@ input { margin-bottom: 22px; } +#save-settings, #reset-settings { + margin-top: 20px; + margin-bottom: 20px; +} + +#set-date-format { + max-width: 200px; +} + .date { max-width: 250px; } @@ -63,7 +72,6 @@ input { .note-date{ float:right; - margin-top: -17px; } .note-desc { color: #999; @@ -81,6 +89,13 @@ input { .edit-note { display: inline-block; 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%; } @@ -95,7 +110,7 @@ input { margin-right: 5px; } -.save-editor { +.save-editor, .set-date { margin-top: 10px; } @@ -104,7 +119,7 @@ input { } .btn-ver { - width:150px; + width:115px; margin-top:20px; } diff --git a/client/view/templates.html b/client/view/templates.html index 36a34ef..d06d70e 100644 --- a/client/view/templates.html +++ b/client/view/templates.html @@ -33,7 +33,7 @@ {{#each notelist}} - {{#if active}} + {{#if active}} {{/if}} {{title}} {{content}} @@ -60,7 +60,7 @@ {{title}} {{content}} - + {{getDate.msg}} @@ -90,8 +90,11 @@
- - + + +
{{/if}} @@ -143,6 +146,16 @@ diff --git a/server/server.coffee b/server/server.coffee index e9c5bab..9f2f154 100644 --- a/server/server.coffee +++ b/server/server.coffee @@ -15,6 +15,7 @@ userValidated = (user) -> return no unless user? 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. Meteor.publish "my-notes", -> if userValidated getUser(@userId) @@ -50,4 +51,9 @@ Meteor.methods {$set : { "resume.loginTokens" : [] } }, { multi: yes } return yes 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