mirror of
https://github.com/fazo96/homework.git
synced 2025-01-09 12:10:08 +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
|
||||
notes = new Meteor.Collection "notes"
|
||||
Deps.autorun -> Meteor.subscribe "my-notes" unless not Meteor.userId()
|
||||
|
||||
getUser = -> Meteor.user()
|
||||
myNotes = -> Meteor.subscribe "my-notes"
|
||||
amIValid = ->
|
||||
return no unless getUser()
|
||||
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
|
||||
UI.registerHelper "loggingIn", -> Meteor.loggingIn()
|
||||
@ -18,22 +15,23 @@ UI.registerHelper "verified", -> amIValid()
|
||||
Router.configure
|
||||
layoutTemplate: 'layout'
|
||||
loadingTemplate: 'loading'
|
||||
notFoundTemplate: '404'
|
||||
Router.map ->
|
||||
@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: '/'
|
||||
template: 'auth'
|
||||
@route 'notes',
|
||||
waitOn: -> Meteor.subscribe "my-notes"
|
||||
onBeforeAction: ->
|
||||
if not getUser() then Router.go 'home'
|
||||
if amIValid() is no then Router.go 'verifyEmail'
|
||||
@route 'note',
|
||||
path: '/note/:_id'
|
||||
waitOn: -> Meteor.subscribe "my-notes"
|
||||
data: -> notes.findOne _id: @params._id
|
||||
onBeforeAction: ->
|
||||
if not getUser() then Router.go 'home'
|
||||
if amIValid() is no then Router.go 'verifyEmail'
|
||||
if not @data() then Router.go 'notes'
|
||||
onBeforeAction: -> if not @data()? then Router.go 'home'
|
||||
@route 'verifyEmail',
|
||||
path: '/verify/:token?'
|
||||
template: 'verifyEmail'
|
||||
@ -47,23 +45,26 @@ Router.map ->
|
||||
else if not getUser()
|
||||
Router.go 'home'
|
||||
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
|
||||
# Menu
|
||||
Template.menu.at_home = ->
|
||||
if Router.current() then return "active" if Router.current().path is "/notes"
|
||||
|
||||
# User Interface
|
||||
Template.account.events
|
||||
'click #logout': (e,template) -> Meteor.logout logoutCallback
|
||||
'click #btn-logout': (e,template) -> Meteor.logout logoutCallback
|
||||
|
||||
# Notes template
|
||||
Template.notelist.empty = -> notes.find().count() is 0
|
||||
Template.notelist.notes = ->
|
||||
d = notes.find().fetch()
|
||||
Template.notelist.events
|
||||
'click .close-note': ->
|
||||
notes.remove @_id
|
||||
'click .edit-note': ->
|
||||
Router.go 'note', {_id: @_id}
|
||||
'click .close-note': -> notes.remove @_id
|
||||
'click .edit-note': -> Router.go 'note', {_id: @_id}
|
||||
'keypress #newNote': (e,template) ->
|
||||
if e.keyCode is 13 and template.find('#newNote').value isnt ""
|
||||
notes.insert
|
||||
@ -134,7 +135,7 @@ Template.verifyEmail.events
|
||||
# Login and Register
|
||||
pressLogin = (template) ->
|
||||
mail = template.find('#mail').value; pass = template.find('#pass').value
|
||||
Meteor.loginWithPassword mail, pass, loginCallback
|
||||
Meteor.loginWithPassword mail, pass, errCallback
|
||||
|
||||
Template.auth.events
|
||||
# Login
|
||||
|
@ -15,6 +15,10 @@ input {
|
||||
.custom-link { color: #999; }
|
||||
.custom-link:hover { color: #101010;}
|
||||
|
||||
.menu-item {
|
||||
margin-right: 100px; margin-left:100px;
|
||||
}
|
||||
|
||||
.note {
|
||||
padding-bottom: 5px;
|
||||
}
|
||||
|
@ -3,21 +3,31 @@
|
||||
<div class="container">
|
||||
<div class="page-header">
|
||||
<h1 id="title">Homework<br>
|
||||
<small id="small">management for students</small>
|
||||
<small>management for students</small>
|
||||
</h1>
|
||||
</div>
|
||||
<div class="center-block" id="ui-container">
|
||||
{{> error}}
|
||||
{{> yield}}
|
||||
</div>
|
||||
<hr>
|
||||
<div class="center-block" align="center">{{> footer}}</div>
|
||||
</div>
|
||||
{{> ribbon}}
|
||||
</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">
|
||||
{{> notelist }} <hr> {{> account }}
|
||||
</template>
|
||||
|
||||
<template name="note">
|
||||
{{> editor }} {{> notelist }} <hr> {{> account }}
|
||||
</template>
|
||||
@ -70,7 +80,7 @@
|
||||
{{#if loggingIn}} {{> loading}} {{/if}}
|
||||
<div align="center">
|
||||
<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>
|
||||
</template>
|
||||
|
||||
@ -140,10 +150,15 @@
|
||||
</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="404">
|
||||
<div align="center">
|
||||
<h2>Acciderbolina!<br><small>Page not found</small></h2>
|
||||
</div>
|
||||
</template>
|
||||
|
Loading…
Reference in New Issue
Block a user