mirror of
https://github.com/fazo96/homework.git
synced 2025-01-10 12:14:22 +01:00
fixed a few bugs... getting familiar with iron-router
This commit is contained in:
parent
ee38f824ea
commit
a841e3d9b2
@ -1,13 +1,10 @@
|
|||||||
# 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()
|
|
||||||
|
|
||||||
getUser = -> Meteor.user()
|
getUser = -> Meteor.user()
|
||||||
|
myNotes = -> Meteor.subscribe "my-notes"
|
||||||
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
|
||||||
logoutCallback = (err) -> if err then errCallback err else Router.go 'home'
|
|
||||||
loginCallback = (err) -> if err then errCallback err else Router.go 'notes'
|
|
||||||
|
|
||||||
# Common Helpers
|
# Common Helpers
|
||||||
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
||||||
@ -18,22 +15,23 @@ UI.registerHelper "verified", -> amIValid()
|
|||||||
Router.configure
|
Router.configure
|
||||||
layoutTemplate: 'layout'
|
layoutTemplate: 'layout'
|
||||||
loadingTemplate: 'loading'
|
loadingTemplate: 'loading'
|
||||||
|
notFoundTemplate: '404'
|
||||||
Router.map ->
|
Router.map ->
|
||||||
@route 'home',
|
@route 'home',
|
||||||
onBeforeAction: -> if getUser() then Router.go 'notes'
|
onBeforeAction: (pause)->
|
||||||
|
if getUser()
|
||||||
|
if amIValid() is yes then Router.go 'notes' else Router.go 'verifyEmail'
|
||||||
path: '/'
|
path: '/'
|
||||||
template: 'auth'
|
template: 'auth'
|
||||||
@route 'notes',
|
@route 'notes',
|
||||||
|
waitOn: -> Meteor.subscribe "my-notes"
|
||||||
onBeforeAction: ->
|
onBeforeAction: ->
|
||||||
if not getUser() then Router.go 'home'
|
if not getUser() then Router.go 'home'
|
||||||
if amIValid() is no then Router.go 'verifyEmail'
|
|
||||||
@route 'note',
|
@route 'note',
|
||||||
path: '/note/:_id'
|
path: '/note/:_id'
|
||||||
|
waitOn: -> Meteor.subscribe "my-notes"
|
||||||
data: -> notes.findOne _id: @params._id
|
data: -> notes.findOne _id: @params._id
|
||||||
onBeforeAction: ->
|
onBeforeAction: -> if not @data()? then Router.go 'home'
|
||||||
if not getUser() then Router.go 'home'
|
|
||||||
if amIValid() is no then Router.go 'verifyEmail'
|
|
||||||
if not @data() then Router.go 'notes'
|
|
||||||
@route 'verifyEmail',
|
@route 'verifyEmail',
|
||||||
path: '/verify/:token?'
|
path: '/verify/:token?'
|
||||||
template: 'verifyEmail'
|
template: 'verifyEmail'
|
||||||
@ -47,23 +45,26 @@ Router.map ->
|
|||||||
else if not getUser()
|
else if not getUser()
|
||||||
Router.go 'home'
|
Router.go 'home'
|
||||||
else if amIValid() is yes then Router.go 'notes'
|
else if amIValid() is yes then Router.go 'notes'
|
||||||
|
@route '404', path: '*'
|
||||||
|
|
||||||
|
logoutCallback = (err) -> if err then errCallback err else Router.go 'home'
|
||||||
|
|
||||||
# Client Templates
|
# Client Templates
|
||||||
|
# Menu
|
||||||
|
Template.menu.at_home = ->
|
||||||
|
if Router.current() then return "active" if Router.current().path is "/notes"
|
||||||
|
|
||||||
# User Interface
|
# User Interface
|
||||||
Template.account.events
|
Template.account.events
|
||||||
'click #logout': (e,template) -> Meteor.logout logoutCallback
|
'click #btn-logout': (e,template) -> Meteor.logout logoutCallback
|
||||||
|
|
||||||
# Notes template
|
# Notes template
|
||||||
Template.notelist.empty = -> notes.find().count() is 0
|
Template.notelist.empty = -> notes.find().count() is 0
|
||||||
Template.notelist.notes = ->
|
Template.notelist.notes = ->
|
||||||
d = notes.find().fetch()
|
d = notes.find().fetch()
|
||||||
Template.notelist.events
|
Template.notelist.events
|
||||||
'click .close-note': ->
|
'click .close-note': -> notes.remove @_id
|
||||||
notes.remove @_id
|
'click .edit-note': -> Router.go 'note', {_id: @_id}
|
||||||
'click .edit-note': ->
|
|
||||||
Router.go 'note', {_id: @_id}
|
|
||||||
'keypress #newNote': (e,template) ->
|
'keypress #newNote': (e,template) ->
|
||||||
if e.keyCode is 13 and template.find('#newNote').value isnt ""
|
if e.keyCode is 13 and template.find('#newNote').value isnt ""
|
||||||
notes.insert
|
notes.insert
|
||||||
@ -134,7 +135,7 @@ Template.verifyEmail.events
|
|||||||
# 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, loginCallback
|
Meteor.loginWithPassword mail, pass, errCallback
|
||||||
|
|
||||||
Template.auth.events
|
Template.auth.events
|
||||||
# Login
|
# Login
|
||||||
|
@ -15,6 +15,10 @@ input {
|
|||||||
.custom-link { color: #999; }
|
.custom-link { color: #999; }
|
||||||
.custom-link:hover { color: #101010;}
|
.custom-link:hover { color: #101010;}
|
||||||
|
|
||||||
|
.menu-item {
|
||||||
|
margin-right: 100px; margin-left:100px;
|
||||||
|
}
|
||||||
|
|
||||||
.note {
|
.note {
|
||||||
padding-bottom: 5px;
|
padding-bottom: 5px;
|
||||||
}
|
}
|
||||||
|
@ -3,21 +3,31 @@
|
|||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="page-header">
|
<div class="page-header">
|
||||||
<h1 id="title">Homework<br>
|
<h1 id="title">Homework<br>
|
||||||
<small id="small">management for students</small>
|
<small>management for students</small>
|
||||||
</h1>
|
</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="center-block" id="ui-container">
|
<div class="center-block" id="ui-container">
|
||||||
{{> error}}
|
{{> error}}
|
||||||
{{> yield}}
|
{{> yield}}
|
||||||
</div>
|
</div>
|
||||||
|
<hr>
|
||||||
<div class="center-block" align="center">{{> footer}}</div>
|
<div class="center-block" align="center">{{> footer}}</div>
|
||||||
</div>
|
</div>
|
||||||
{{> ribbon}}
|
{{> ribbon}}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template name="menu">
|
||||||
|
<ul class="nav nav-pills nav-justified">
|
||||||
|
<li class="menu-item {{at_archive}}"><a href="/archive">Archive</a></li>
|
||||||
|
<li class="menu-item {{at_home}}"><a href="/notes">Home</a></li>
|
||||||
|
<li class="menu-item {{at_account}}"><a href="/account">Account</a></li>
|
||||||
|
</ul>
|
||||||
|
</template>
|
||||||
|
|
||||||
<template name="notes">
|
<template name="notes">
|
||||||
{{> notelist }} <hr> {{> account }}
|
{{> notelist }} <hr> {{> account }}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="note">
|
<template name="note">
|
||||||
{{> editor }} {{> notelist }} <hr> {{> account }}
|
{{> editor }} {{> notelist }} <hr> {{> account }}
|
||||||
</template>
|
</template>
|
||||||
@ -70,7 +80,7 @@
|
|||||||
{{#if loggingIn}} {{> loading}} {{/if}}
|
{{#if loggingIn}} {{> loading}} {{/if}}
|
||||||
<div align="center">
|
<div align="center">
|
||||||
<p>{{email}}</p>
|
<p>{{email}}</p>
|
||||||
<button type="button" id="logout" class="btn btn-danger">Logout</button>
|
<button type="button" id="btn-logout" class="btn btn-danger">Logout</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -140,10 +150,15 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="footer">
|
<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>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>
|
<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 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 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>
|
<a class="custom-link" href="http://github.com/fazo96"><i class="fa fa-github fa-2x"></i></a>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<template name="404">
|
||||||
|
<div align="center">
|
||||||
|
<h2>Acciderbolina!<br><small>Page not found</small></h2>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user