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:
parent
6ed12e98d8
commit
f620bffcb3
@ -45,13 +45,22 @@ Router.map ->
|
|||||||
@route 'account',
|
@route 'account',
|
||||||
onBeforeAction: -> if not getUser() then Router.go 'home'
|
onBeforeAction: -> if not getUser() then Router.go 'home'
|
||||||
@route 'notes',
|
@route 'notes',
|
||||||
|
path: '/notes/:_id?'
|
||||||
waitOn: -> Meteor.subscribe "my-notes"
|
waitOn: -> Meteor.subscribe "my-notes"
|
||||||
|
data: -> notes.findOne _id: @params._id
|
||||||
onBeforeAction: -> if not getUser() then Router.go 'home'
|
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',
|
@route 'note',
|
||||||
path: '/note/:_id'
|
path: '/note/:_id'
|
||||||
waitOn: -> Meteor.subscribe "my-notes"
|
waitOn: -> Meteor.subscribe "my-notes"
|
||||||
data: -> notes.findOne _id: @params._id
|
data: -> notes.findOne _id: @params._id
|
||||||
onBeforeAction: -> if not @data()? then Router.go 'home'
|
onBeforeAction: -> if not @data()? then Router.go 'home'
|
||||||
|
###
|
||||||
@route 'verifyEmail',
|
@route 'verifyEmail',
|
||||||
path: '/verify/:token?'
|
path: '/verify/:token?'
|
||||||
template: 'verifyEmail'
|
template: 'verifyEmail'
|
||||||
@ -98,22 +107,26 @@ Template.account.events
|
|||||||
Template.notelist.active = ->
|
Template.notelist.active = ->
|
||||||
return no unless Router.current() and Router.current().data()
|
return no unless Router.current() and Router.current().data()
|
||||||
return @_id is Router.current().data()._id
|
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 = ->
|
Template.notelist.getDate = ->
|
||||||
return unless @date; diff = daysUntil @date
|
return unless @date; diff = daysUntil @date
|
||||||
if diff <= 0 then return msg:"You missed it!", color: "danger"
|
if diff <= 0 then return msg:"You missed it!", color: "danger"
|
||||||
if diff is 1 then return msg:"Today", color: "warning"
|
if diff is 1 then return msg:"Today", color: "warning"
|
||||||
if diff is 2 then return msg:"Tomorrow", color: "info"
|
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"
|
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 = ->
|
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
|
Template.notelist.events
|
||||||
'click .close-note': -> notes.remove @_id
|
'click .close-note': -> notes.update @_id, $set: archived: yes
|
||||||
'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
|
||||||
@ -121,6 +134,16 @@ Template.notelist.events
|
|||||||
content: "", date: no, archived: no, userId: Meteor.userId()
|
content: "", date: no, archived: no, userId: Meteor.userId()
|
||||||
template.find('#newNote').value = ""
|
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
|
# Note Editor
|
||||||
Template.editor.note = -> Router.current().data()
|
Template.editor.note = -> Router.current().data()
|
||||||
Template.editor.rendered = -> $('.date').datepicker
|
Template.editor.rendered = -> $('.date').datepicker
|
||||||
@ -135,7 +158,9 @@ saveCurrentNote = (t,e) ->
|
|||||||
content: t.find('.area').value
|
content: t.find('.area').value
|
||||||
date: t.find('.date').value
|
date: t.find('.date').value
|
||||||
Template.editor.events
|
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
|
'click .save-editor': (e,t) -> saveCurrentNote t
|
||||||
'keypress .title': (e,t) -> saveCurrentNote t, e
|
'keypress .title': (e,t) -> saveCurrentNote t, e
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
<template name="menu">
|
<template name="menu">
|
||||||
<div align="center" class="menu-container">
|
<div align="center" class="menu-container">
|
||||||
<div class="btn-group">
|
<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
|
<i class="fa fa-book fa-inverse"></i> Archive
|
||||||
</button>
|
</button>
|
||||||
<button type="button" class="btn btn-primary go-home">
|
<button type="button" class="btn btn-primary go-home">
|
||||||
@ -32,8 +32,8 @@
|
|||||||
</div></div>
|
</div></div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<template name="notes">{{> error }} {{> notelist }} {{> menu}}</template>
|
<template name="notes">{{> error }} {{> editor }} {{> notelist }} {{> menu}}</template>
|
||||||
<template name="note">{{> error }} {{> editor }} {{> notelist }} <hr> {{> menu}}</template>
|
<template name="archive">{{> error}} {{> archivedlist }} {{> menu }}</template>
|
||||||
|
|
||||||
<template name="noteadder">
|
<template name="noteadder">
|
||||||
<div align="center">
|
<div align="center">
|
||||||
@ -44,7 +44,7 @@
|
|||||||
<template name="notelist">
|
<template name="notelist">
|
||||||
<div class="list-group">
|
<div class="list-group">
|
||||||
{{#each notelist}}
|
{{#each notelist}}
|
||||||
<a href="{{pathFor 'note'}}" class="note list-group-item">
|
<a href="{{pathFor 'notes'}}" class="note list-group-item">
|
||||||
<span class="note-content">
|
<span class="note-content">
|
||||||
{{#if active}}<a role="button" href="{{pathFor 'notes'}}" class="edit-note close">
|
{{#if active}}<a role="button" href="{{pathFor 'notes'}}" class="edit-note close">
|
||||||
<i class="fa fa-pencil-square-o"></i>
|
<i class="fa fa-pencil-square-o"></i>
|
||||||
@ -57,11 +57,37 @@
|
|||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
{{#if empty}}
|
{{#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}}
|
{{/if}}
|
||||||
{{> noteadder }}
|
{{> noteadder }}
|
||||||
</template>
|
</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">
|
<template name="editor">
|
||||||
{{#if _id}}
|
{{#if _id}}
|
||||||
<div class="panel panel-info">
|
<div class="panel panel-info">
|
||||||
|
Loading…
Reference in New Issue
Block a user