mirror of
https://github.com/fazo96/homework.git
synced 2025-01-10 12:14:22 +01:00
code cleanup. fixed a few bugs
This commit is contained in:
parent
f39a2752df
commit
7ebd34163c
@ -1,6 +1,7 @@
|
||||
# Homework - Client Side
|
||||
notes = new Meteor.Collection "notes"
|
||||
Deps.autorun -> Meteor.subscribe "my-notes" unless not Meteor.userId()
|
||||
user = -> Meteor.user()
|
||||
# Loading (Spinning Cog)
|
||||
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
||||
|
||||
@ -15,18 +16,20 @@ Template.notes.truncateNoteDesc = (s) ->
|
||||
if s.length > 52 then s.slice(0,48)+"..." else s
|
||||
Template.notes.notes = ->
|
||||
d = notes.find().fetch()
|
||||
Template.notes.events {
|
||||
'click .close-note': -> notes.remove @_id
|
||||
Template.notes.events
|
||||
'click .close-note': ->
|
||||
if Session.get('note')._id is @_id
|
||||
Session.set 'note', undefined
|
||||
notes.remove @_id
|
||||
'click .edit-note': -> Session.set 'note', this
|
||||
'keypress #newNote': (e,template) ->
|
||||
if e.keyCode is 13
|
||||
if e.keyCode is 13 and template.find('#newNote').value isnt ""
|
||||
notes.insert {
|
||||
title: template.find('#newNote').value
|
||||
content: "..."
|
||||
content: ""
|
||||
userId: Meteor.userId()
|
||||
}
|
||||
template.find('#newNote').value = ""
|
||||
}
|
||||
|
||||
# Note Editor
|
||||
Template.editor.note = -> Session.get 'note'
|
||||
@ -39,7 +42,6 @@ saveCurrentNote = (t,e) ->
|
||||
Template.editor.events
|
||||
'click .close-editor': -> Session.set 'note', undefined
|
||||
'click .save-editor': (e,t) -> saveCurrentNote t
|
||||
#'keypress .edit-note': (e,t) -> saveCurrentNote t, e # Doesnt work??
|
||||
'keypress .title': (e,t) -> saveCurrentNote t, e
|
||||
|
||||
# Notifications
|
||||
@ -58,22 +60,21 @@ notify = (data) ->
|
||||
clearNotifications = -> alerts.clear(); alertDep.changed()
|
||||
# Get all the notifications
|
||||
Template.notifications.notification = -> alertDep.depend(); alerts
|
||||
Template.notifications.events {
|
||||
Template.notifications.events
|
||||
'click .close-notification': (e,template) ->
|
||||
alerts.splice alerts.indexOf(this), 1
|
||||
alertDep.changed()
|
||||
}
|
||||
|
||||
# "Loading" template
|
||||
Template.loading.status = -> Meteor.status()
|
||||
|
||||
# Login and Register
|
||||
pressLogin = (template) ->
|
||||
mail = template.find('#mail').value; pass = template.find('#pass').value
|
||||
Meteor.loginWithPassword mail, pass, (err) ->
|
||||
errCallback err
|
||||
|
||||
Template.auth.events {
|
||||
'keypress .login': (e,template) ->
|
||||
if e.keyCode is 13 then pressLogin template
|
||||
Meteor.loginWithPassword mail, pass, (err) -> errCallback err
|
||||
Template.auth.events
|
||||
# Login
|
||||
'keypress .login': (e,template) -> if e.keyCode is 13 then pressLogin template
|
||||
'click #login': (e,template) -> pressLogin template
|
||||
# Register
|
||||
'click #register': (e,template) ->
|
||||
@ -92,4 +93,3 @@ Template.auth.events {
|
||||
}, (e) -> errCallback e
|
||||
catch err
|
||||
notify { msg: err }
|
||||
}
|
||||
|
@ -75,7 +75,7 @@
|
||||
</h3>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
@ -91,15 +91,6 @@
|
||||
{{/each}}
|
||||
</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">
|
||||
<div class="github-fork-ribbon-wrapper right">
|
||||
<div class="github-fork-ribbon">
|
||||
@ -113,3 +104,12 @@
|
||||
<i class="fa fa-cog fa-spin fa-3x"></i>
|
||||
</div>
|
||||
</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
|
||||
}
|
||||
|
||||
# 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", ->
|
||||
# TODO: Don't publish unless user is validated
|
||||
notes.find( { userId: @userId } ) unless not @userId
|
||||
|
||||
# Authentication
|
||||
@ -19,3 +24,10 @@ Accounts.validateNewUser (user) ->
|
||||
if Match.test(mail,String) is no or validateEmail(mail) is no
|
||||
throw new Meteor.Error 403, "Invalid Email"
|
||||
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