mirror of
https://github.com/fazo96/homework.git
synced 2025-03-28 23:38:38 +01:00
code cleanup. fixed a few bugs
This commit is contained in:
parent
f39a2752df
commit
7ebd34163c
@ -1,6 +1,7 @@
|
|||||||
# Homework - Client Side
|
# Homework - Client Side
|
||||||
notes = new Meteor.Collection "notes"
|
notes = new Meteor.Collection "notes"
|
||||||
Deps.autorun -> Meteor.subscribe "my-notes" unless not Meteor.userId()
|
Deps.autorun -> Meteor.subscribe "my-notes" unless not Meteor.userId()
|
||||||
|
user = -> Meteor.user()
|
||||||
# Loading (Spinning Cog)
|
# Loading (Spinning Cog)
|
||||||
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
||||||
|
|
||||||
@ -15,18 +16,20 @@ Template.notes.truncateNoteDesc = (s) ->
|
|||||||
if s.length > 52 then s.slice(0,48)+"..." else s
|
if s.length > 52 then s.slice(0,48)+"..." else s
|
||||||
Template.notes.notes = ->
|
Template.notes.notes = ->
|
||||||
d = notes.find().fetch()
|
d = notes.find().fetch()
|
||||||
Template.notes.events {
|
Template.notes.events
|
||||||
'click .close-note': -> notes.remove @_id
|
'click .close-note': ->
|
||||||
|
if Session.get('note')._id is @_id
|
||||||
|
Session.set 'note', undefined
|
||||||
|
notes.remove @_id
|
||||||
'click .edit-note': -> Session.set 'note', this
|
'click .edit-note': -> Session.set 'note', this
|
||||||
'keypress #newNote': (e,template) ->
|
'keypress #newNote': (e,template) ->
|
||||||
if e.keyCode is 13
|
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: ""
|
||||||
userId: Meteor.userId()
|
userId: Meteor.userId()
|
||||||
}
|
}
|
||||||
template.find('#newNote').value = ""
|
template.find('#newNote').value = ""
|
||||||
}
|
|
||||||
|
|
||||||
# Note Editor
|
# Note Editor
|
||||||
Template.editor.note = -> Session.get 'note'
|
Template.editor.note = -> Session.get 'note'
|
||||||
@ -39,7 +42,6 @@ saveCurrentNote = (t,e) ->
|
|||||||
Template.editor.events
|
Template.editor.events
|
||||||
'click .close-editor': -> Session.set 'note', undefined
|
'click .close-editor': -> Session.set 'note', undefined
|
||||||
'click .save-editor': (e,t) -> saveCurrentNote t
|
'click .save-editor': (e,t) -> saveCurrentNote t
|
||||||
#'keypress .edit-note': (e,t) -> saveCurrentNote t, e # Doesnt work??
|
|
||||||
'keypress .title': (e,t) -> saveCurrentNote t, e
|
'keypress .title': (e,t) -> saveCurrentNote t, e
|
||||||
|
|
||||||
# Notifications
|
# Notifications
|
||||||
@ -58,22 +60,21 @@ notify = (data) ->
|
|||||||
clearNotifications = -> alerts.clear(); alertDep.changed()
|
clearNotifications = -> alerts.clear(); alertDep.changed()
|
||||||
# Get all the notifications
|
# Get all the notifications
|
||||||
Template.notifications.notification = -> alertDep.depend(); alerts
|
Template.notifications.notification = -> alertDep.depend(); alerts
|
||||||
Template.notifications.events {
|
Template.notifications.events
|
||||||
'click .close-notification': (e,template) ->
|
'click .close-notification': (e,template) ->
|
||||||
alerts.splice alerts.indexOf(this), 1
|
alerts.splice alerts.indexOf(this), 1
|
||||||
alertDep.changed()
|
alertDep.changed()
|
||||||
}
|
|
||||||
|
# "Loading" template
|
||||||
|
Template.loading.status = -> Meteor.status()
|
||||||
|
|
||||||
# Login and Register
|
# Login and Register
|
||||||
pressLogin = (template) ->
|
pressLogin = (template) ->
|
||||||
mail = template.find('#mail').value; pass = template.find('#pass').value
|
mail = template.find('#mail').value; pass = template.find('#pass').value
|
||||||
Meteor.loginWithPassword mail, pass, (err) ->
|
Meteor.loginWithPassword mail, pass, (err) -> errCallback err
|
||||||
errCallback err
|
Template.auth.events
|
||||||
|
|
||||||
Template.auth.events {
|
|
||||||
'keypress .login': (e,template) ->
|
|
||||||
if e.keyCode is 13 then pressLogin template
|
|
||||||
# Login
|
# Login
|
||||||
|
'keypress .login': (e,template) -> if e.keyCode is 13 then pressLogin template
|
||||||
'click #login': (e,template) -> pressLogin template
|
'click #login': (e,template) -> pressLogin template
|
||||||
# Register
|
# Register
|
||||||
'click #register': (e,template) ->
|
'click #register': (e,template) ->
|
||||||
@ -92,4 +93,3 @@ Template.auth.events {
|
|||||||
}, (e) -> errCallback e
|
}, (e) -> errCallback e
|
||||||
catch err
|
catch err
|
||||||
notify { msg: err }
|
notify { msg: err }
|
||||||
}
|
|
||||||
|
@ -75,7 +75,7 @@
|
|||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
<div align="center" class="panel-body">
|
<div align="center" class="panel-body">
|
||||||
<textarea class="area form-control" rows="3" placeholder="">{{note.content}}</textarea>
|
<textarea class="area form-control" rows="3" placeholder="...">{{note.content}}</textarea>
|
||||||
<button type="button" class="btn btn-info save-editor">Save</button>
|
<button type="button" class="btn btn-info save-editor">Save</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -91,15 +91,6 @@
|
|||||||
{{/each}}
|
{{/each}}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="footer">
|
|
||||||
<hr>
|
|
||||||
<p>This app is <a href="https://en.wikipedia.org/wiki/Free_software">Free Software</a>, under the <a href="http://opensource.org/licenses/MIT">MIT License</a></p>
|
|
||||||
<p>Built by Enrico Fasoli as a prototype.<br><u>Not ready for daily usage yet!</u></p>
|
|
||||||
<a class="custom-link" href="http://www.linkedin.com/profile/view?id=292450419"><i class="fa fa-linkedin fa-2x"></i></a>
|
|
||||||
<a href="http://twitter.com/fazo96"><i class="fa fa-twitter fa-2x footer-center-icon"></i></a>
|
|
||||||
<a class="custom-link" href="http://github.com/fazo96"><i class="fa fa-github fa-2x"></i></a>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template name="ribbon">
|
<template name="ribbon">
|
||||||
<div class="github-fork-ribbon-wrapper right">
|
<div class="github-fork-ribbon-wrapper right">
|
||||||
<div class="github-fork-ribbon">
|
<div class="github-fork-ribbon">
|
||||||
@ -113,3 +104,12 @@
|
|||||||
<i class="fa fa-cog fa-spin fa-3x"></i>
|
<i class="fa fa-cog fa-spin fa-3x"></i>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template name="footer">
|
||||||
|
<hr>
|
||||||
|
<p>This app is <a href="https://en.wikipedia.org/wiki/Free_software">Free Software</a>, under the <a href="http://opensource.org/licenses/MIT">MIT License</a></p>
|
||||||
|
<p>Built by Enrico Fasoli as a prototype.<br><u>Not ready for daily usage yet!</u></p>
|
||||||
|
<a class="custom-link" href="http://www.linkedin.com/profile/view?id=292450419"><i class="fa fa-linkedin fa-2x"></i></a>
|
||||||
|
<a href="http://twitter.com/fazo96"><i class="fa fa-twitter fa-2x footer-center-icon"></i></a>
|
||||||
|
<a class="custom-link" href="http://github.com/fazo96"><i class="fa fa-github fa-2x"></i></a>
|
||||||
|
</template>
|
||||||
|
@ -10,7 +10,12 @@ Accounts.config {
|
|||||||
loginExpirationInDays: 1
|
loginExpirationInDays: 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Returns true if the user has verified at least one email address
|
||||||
|
userValidated = (user) ->
|
||||||
|
return yes for mail in user.emails when mail.verified is yes; no
|
||||||
|
|
||||||
Meteor.publish "my-notes", ->
|
Meteor.publish "my-notes", ->
|
||||||
|
# TODO: Don't publish unless user is validated
|
||||||
notes.find( { userId: @userId } ) unless not @userId
|
notes.find( { userId: @userId } ) unless not @userId
|
||||||
|
|
||||||
# Authentication
|
# Authentication
|
||||||
@ -19,3 +24,10 @@ Accounts.validateNewUser (user) ->
|
|||||||
if Match.test(mail,String) is no or validateEmail(mail) is no
|
if Match.test(mail,String) is no or validateEmail(mail) is no
|
||||||
throw new Meteor.Error 403, "Invalid Email"
|
throw new Meteor.Error 403, "Invalid Email"
|
||||||
return yes
|
return yes
|
||||||
|
|
||||||
|
# Methods that the clients can invoke
|
||||||
|
Meteor.methods
|
||||||
|
amIValidated: ->
|
||||||
|
user = Meteor.users.findOne { _id: @userId }
|
||||||
|
return no unless user?
|
||||||
|
userValidated user
|
||||||
|
Loading…
Reference in New Issue
Block a user