Merge branch 'tags' into develop

Conflicts:
	src/app/index.coffee
	src/app/tasks.coffee
	styles/app/index.styl
	views/app/index.html
	views/app/settings.html
	views/app/tasks.html
This commit is contained in:
Tyler Renelle 2013-05-06 14:01:43 +01:00
commit a3003a758d
11 changed files with 138 additions and 13 deletions

View file

@ -89,6 +89,7 @@ userSchema =
flags:
partyEnabled: false
itemsEnabled: false
tags: []
# ads: 'show' # added on registration
module.exports.newUserObject = ->
@ -112,6 +113,12 @@ module.exports.newUserObject = ->
{type: 'reward', text: 'Cake', notes: 'But only buy if you have enough gold - you lose HP otherwise.', value: 10 }
]
defaultTags = [
{name: 'morning'}
{name: 'afternoon'}
{name: 'evening'}
]
for task in defaultTasks
guid = task.id = derby.uuid()
newUser.tasks[guid] = task
@ -120,6 +127,11 @@ module.exports.newUserObject = ->
when 'daily' then newUser.dailyIds.push guid
when 'todo' then newUser.todoIds.push guid
when 'reward' then newUser.rewardIds.push guid
for tag in defaultTags
tag.id = derby.uuid()
newUser.tags.push tag
return newUser
module.exports.BatchUpdate = BatchUpdate = (model) ->

30
src/app/filters.coffee Normal file
View file

@ -0,0 +1,30 @@
_ = require 'underscore'
module.exports.app = (appExports, model) ->
user = model.at('_user')
appExports.toggleFilterByTag = (e, el) ->
tagId = $(el).attr('data-tag-id')
path = 'filters.' + tagId
user.set path, !(user.get path)
appExports.filtersNewTag = ->
user.push "tags",
id: model.id()
name: model.get("_newTag")
, (-> location.reload())
appExports.toggleEditingTags = ->
model.set '_editingTags', !model.get('_editingTags')
appExports.filtersDeleteTag = (e, el) ->
tags = user.get('tags')
tagId = $(el).attr('data-tag-id')
model.del "_user.filters.#{tagId}"
#TODO remove tag from each task
_.each tags, (tag, i) ->
if tag.id is tagId
tags.splice(i,1)
model.del "_user.filters.#{tag.id}"
model.set "_user.tags", tags, -> location.reload()

View file

@ -116,10 +116,15 @@ viewHelpers = (view) ->
###
Tasks
###
view.fn 'taskClasses', (task, dayStart, lastCron) ->
view.fn 'taskClasses', (task, filters, dayStart, lastCron) ->
return unless task
{type, completed, value, repeat} = task
for filter, enabled of filters
if enabled and not task.tags?[filter]
# All the other classes don't matter
return 'hide'
classes = type
now = moment().day()

View file

@ -100,4 +100,4 @@ ready (model) ->
require('./debug').app(exports, model) if model.flags.nodeEnv != 'production'
require('./browser').app(exports, model, app)
require('./unlock').app(exports, model)
require('./filters').app(exports, model)

View file

@ -121,6 +121,13 @@ module.exports.app = (appExports, model) ->
target.removeClass(oldContext)
target.addClass(newContext)
appExports.addTag = (e, el) ->
tagId = $(el).attr('data-tag-id')
taskId = $(el).attr('data-task-id')
console.log taskId
path = "_user.tasks.#{taskId}.tags.#{tagId}"
model.set path, !(model.get path)
setUndo = (stats, task) ->
previousUndo = model.get('_undo')
@ -187,4 +194,4 @@ module.exports.app = (appExports, model) ->
appExports.tasksSetPriority = (e, el) ->
dataId = $(el).parent('[data-id]').attr('data-id')
#"_user.tasks.#{dataId}"
model.at(e.target).set 'priority', $(el).attr('data-priority')
model.at(e.target).set 'priority', $(el).attr('data-priority')

15
styles/app/filters.styl Normal file
View file

@ -0,0 +1,15 @@
/* Filters */
.filters
padding-left: 19px
padding-right: 19px
.filters .nav
margin-bottom: 0
.filter-description
margin-top: 7px
margin-right: 7px
/* Filters applied to tasks */
.task.filtered-out
display: none

View file

@ -20,6 +20,7 @@
@import "./helpers.styl";
@import "./responsive.styl";
@import "./header.styl";
@import "./filters.styl";
@import "./scrollbars.styl";
@import "./achievements.styl";
@import "./game-pane.styl";
@ -45,8 +46,6 @@ hr
border-color: rgba(0,0,0,0.1)
/* Footer
-------------------------------------------------- */
@ -149,4 +148,4 @@ hr
z-index: 1001;
.modal-body
margin: 10px
margin: 10px

View file

@ -379,7 +379,7 @@ form
// context switching
.context-enabled
.display-context-dependant,
.task-list li
.task-list > li
display: none
&.context-completed
@ -405,4 +405,4 @@ form
color: #333
&:hover
border-top: 0
margin-top: 2px
margin-top: 2px

29
views/app/filters.html Normal file
View file

@ -0,0 +1,29 @@
<filters:>
<div class="well well-small filters">
<div class="pull-left filter-description">
Filter:
</div>
<ul class="nav nav-pills">
{#each _user.tags as :tag}
<li class="{#if _user.filters[:tag.id]}active{/}" style='position:relative;'>
{#if _editingTags}
<a style='float:left;' x-bind=click:filtersDeleteTag data-tag-id={:tag.id}><i class='icon-trash'></i></a>&nbsp
<input type='text' value='{:tag.name}' />
{else}
<a data-tag-id="{:tag.id}" x-bind="click:toggleFilterByTag">{:tag.name}</a>
{/}
</li>
{/}
<li>
{#if _editingTags}
<form x-bind="submit:filtersNewTag">
<input type="text" value="{_newTag}" placeholder="New Tag"/>
</form>
<a x-bind=click:toggleEditingTags>[done]</a>
{else}
<a x-bind=click:toggleEditingTags>[edit]</a>
{/}
</li>
</ul>
</div>

View file

@ -9,6 +9,7 @@
<import: src="party">
<import: src="pets">
<import: src="game-pane">
<import: src="filters">
<Title:>
HabitRPG | Gamify Your Life
@ -37,6 +38,7 @@
<div id="notification-area"></div>
<div id="wrap">
<app:alerts:flash />
<app:filters:filters />
<div id="exp-chart" style="display:none;"></div>
<div id=main class="grid">
@ -44,4 +46,4 @@
<div class='{#unless _gamePane}hidden{/}'><app:game-pane:main /></div>
</div>
</div>
<app:footer:footer />
<app:footer:footer />

View file

@ -93,7 +93,6 @@
<!-- Rewards Column -->
<app:rewards:rewardsColumn />
<!-- Templates -->
<newTask:>
<form class="addtask-form form-inline new-task-form" id="new-{@type}" data-task-type="{@type}" x-bind="submit:addTask">
@ -104,8 +103,8 @@
<!-- all the parts of a single task -->
<task:>
<li data-id={{:task.id}} class="task {taskClasses(:task, _user.preferences.dayStart, _user.lastCron)} {#if :task.down}{#if :task.up}habit-wide{/}{/}">
<li data-id={{:task.id}} class="task {taskClasses(:task, _user.filters, _user.preferences.dayStart, _user.lastCron)} {#if :task.down}{#if :task.up}habit-wide{/}{/}">
<!-- right-hand side control buttons -->
<div class="task-meta-controls">
<!-- Streak -->
@ -151,7 +150,18 @@
</div>
<!-- main content -->
<p class="task-text">{:task.text}</p>
<p class="task-text">
{:task.text}
<!-- There's a very strange bug where live-bound #each here loses model.at reference on _{type}List alter -->
{{#each _user.tags as :tag}}
<span>
{#if :task.tags[:tag.id]}
<span class="label {#if _user.filters[:tag.id]}label-info{/}">{:tag.name}</span>
{/}
</span>
{{/}}
</p>
<!-- edit/options dialog -->
<app:tasks:taskMeta />
@ -226,6 +236,22 @@
</div>
</fieldset>
{/}
<div class="control-group">
<div class="btn-group">
<button class="btn dropdown-toggle" data-toggle="dropdown">
Tags <span class="caret"></span>
</button>
<ul class="dropdown-menu">
{{#each _user.tags as :tag}}
<li class="{#if :task.tags[:tag.id]}active{/}">
<a data-task-id="{{:task.id}}" data-tag-id="{:tag.id}" x-bind=click:addTag>{:tag.name}</a>
</li>
{{/}}
</ul>
</div>
</div>
<button type=submit class="task-action-btn tile spacious" x-bind="click:tasksSaveAndClose">Save & Close</button>
</form>
</div>