1
0
mirror of https://github.com/fazo96/homework.git synced 2025-01-10 12:14:22 +01:00

implemented archive, fixes #4

This commit is contained in:
fazo96 2014-06-03 15:40:59 +02:00
parent 6ed12e98d8
commit f620bffcb3
2 changed files with 65 additions and 14 deletions

View File

@ -45,13 +45,22 @@ Router.map ->
@route 'account',
onBeforeAction: -> if not getUser() then Router.go 'home'
@route 'notes',
path: '/notes/:_id?'
waitOn: -> Meteor.subscribe "my-notes"
data: -> notes.findOne _id: @params._id
onBeforeAction: -> if not getUser() then Router.go 'home'
onStop: -> console.log "UNLOAD"
@route 'archive',
path: '/archive/:_id?'
waitOn: -> Meteor.subscribe "archive"
onBeforeAction: -> if not getUser() then Router.go 'home'
###
@route 'note',
path: '/note/:_id'
waitOn: -> Meteor.subscribe "my-notes"
data: -> notes.findOne _id: @params._id
onBeforeAction: -> if not @data()? then Router.go 'home'
###
@route 'verifyEmail',
path: '/verify/:token?'
template: 'verifyEmail'
@ -98,22 +107,26 @@ Template.account.events
Template.notelist.active = ->
return no unless Router.current() and Router.current().data()
return @_id is Router.current().data()._id
Template.notelist.empty = -> notes.find().count() is 0
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"
#if new Date(@date).getMonth() > Date.now().getMonth()
#return msg:"Next Month", color:"success" unless diff < 7
msg: "due in "+diff+" days", color: "primary"
#day = new Date(@date).toLocaleString().split(' ')[0]
Template.notelist.notes = ->
d = notes.find({},{ sort: date: 1}).fetch()
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.remove @_id
'click .close-note': -> notes.update @_id, $set: archived: yes
'keypress #newNote': (e,template) ->
if e.keyCode is 13 and template.find('#newNote').value isnt ""
notes.insert
@ -121,6 +134,16 @@ Template.notelist.events
content: "", date: no, archived: no, userId: Meteor.userId()
template.find('#newNote').value = ""
# Archive
Template.archivedlist.empty = -> Template.archivedlist.archived().length is 0
Template.archivedlist.archived = ->
notes.find({ archived: yes },{ sort: date: 1}).fetch()
Template.archivedlist.events =
'click .close-note': -> notes.remove @_id
'click .note': -> notes.update @_id, $set: archived: no
'click .clear': ->
notes.remove item._id for item in Template.archivedlist.archived()
# Note Editor
Template.editor.note = -> Router.current().data()
Template.editor.rendered = -> $('.date').datepicker
@ -135,7 +158,9 @@ saveCurrentNote = (t,e) ->
content: t.find('.area').value
date: t.find('.date').value
Template.editor.events
'click .close-editor': -> Router.go 'notes'
'click .close-editor': ->
Router.go 'notes'
#if Router.current().path.startsWith '/note' then Router.go 'notes'
'click .save-editor': (e,t) -> saveCurrentNote t
'keypress .title': (e,t) -> saveCurrentNote t, e

View File

@ -20,7 +20,7 @@
<template name="menu">
<div align="center" class="menu-container">
<div class="btn-group">
<button type="button" disabled="disabled" class="btn btn-success go-archive">
<button type="button" class="btn btn-success go-archive">
<i class="fa fa-book fa-inverse"></i> Archive
</button>
<button type="button" class="btn btn-primary go-home">
@ -32,8 +32,8 @@
</div></div>
</template>
<template name="notes">{{> error }} {{> notelist }} {{> menu}}</template>
<template name="note">{{> error }} {{> editor }} {{> notelist }} <hr> {{> menu}}</template>
<template name="notes">{{> error }} {{> editor }} {{> notelist }} {{> menu}}</template>
<template name="archive">{{> error}} {{> archivedlist }} {{> menu }}</template>
<template name="noteadder">
<div align="center">
@ -44,7 +44,7 @@
<template name="notelist">
<div class="list-group">
{{#each notelist}}
<a href="{{pathFor 'note'}}" class="note list-group-item">
<a href="{{pathFor 'notes'}}" class="note list-group-item">
<span class="note-content">
{{#if active}}<a role="button" href="{{pathFor 'notes'}}" class="edit-note close">
<i class="fa fa-pencil-square-o"></i>
@ -57,11 +57,37 @@
{{/each}}
</div>
{{#if empty}}
<p align="center">You don't have any notes, try adding a new one</p>
<p class="lead" align="center">You don't have any notes, try adding a new one!</p>
{{/if}}
{{> noteadder }}
</template>
<template name="archivedlist">
{{#unless empty}}
<p align="center" class="lead">This is your archive.</p>
<p align="center">Click on a note to bring it back to the homepage.</p>
{{/unless}}
<div class="list-group">
{{#each archived}}
<a href="{{pathFor 'archive'}}" class="note list-group-item">
<span class="note-content">
<b>{{title}}</b> <span class="note-desc">{{content}}</span>
<!--<span class="note-date label label-{{getDate.color}}">{{getDate.msg}}</span>-->
</span>
<button type="button" class="close-note close">
<i class="fa fa-trash-o"></i></button>
</a>
{{/each}}
</div>
{{#if empty}}
<p class="lead" align="center">Your archive is empty</p>
{{else}}
<div align="center" class="in-bt"><button class="btn btn-danger clear">
<i class="fa fa-trash-o"></i> Clear</button>
</div>
{{/if}}
</template>
<template name="editor">
{{#if _id}}
<div class="panel panel-info">