charts: fix exp & todos charts

This commit is contained in:
Tyler Renelle 2013-06-15 12:35:55 -04:00
parent 6b307cd52c
commit c797ea5999
4 changed files with 20 additions and 22 deletions

View file

@ -56,30 +56,28 @@ module.exports.app = (appExports, model) ->
appExports.toggleTaskEdit = (e, el) ->
id = e.get('id')
path = "_tasks.editing.#{id}"
model.set path, !model.get(path)
$(".#{id}-chart").hide()
[editPath, chartPath] = ["_tasks.editing.#{id}", "_page.charts.#{id}"]
model.set editPath, !(model.get editPath)
model.set chartPath, false
appExports.toggleChart = (e, el) ->
id = $(el).attr('data-id')
history = []
[historyPath, togglePath] = ['','']
if id is 'todos'
model.set "_tasks.charts.todos", !model.get("_tasks.charts.todos")
history = model.get("_user.history.todos")
$(".#{id}-chart").toggle()
else
[id, path] = [$(el).attr('data-id'), "_tasks.charts.#{id}"]
model.set path, !model.get(path)
model.set "_tasks.editing.#{id}", false
$(".#{id}-chart").toggle()
history = model.get("_user.tasks.#{id}.history")
switch id
when 'exp'
[togglePath, historyPath] = ['_page.charts.exp', '_user.history.exp']
when 'todos'
[togglePath, historyPath] = ['_page.charts.todos', '_user.history.todos']
else
[togglePath, historyPath] = ["_page.charts.#{id}", "_user.tasks.#{id}.history"]
model.set "_tasks.editing.#{id}", false
history = model.get(historyPath)
model.set togglePath, !(model.get togglePath)
matrix = [['Date', 'Score']]
for obj in history
date = +new Date(obj.date)
readableDate = moment(date).format('MM/DD')
matrix.push [ readableDate, obj.value ]
_.each history, (obj) -> matrix.push([ moment(obj.date).format('MM/DD/YY'), obj.value ])
data = google.visualization.arrayToDataTable matrix
options =
title: 'History'

View file

@ -16,7 +16,7 @@
<div class="bar" style="width: {percent(_user.stats.exp,tnl(_user.stats.lvl))}%;"></div>
<span class="meter-text">
{#if _user.history.exp}
<a x-bind=click:toggleChart data-toggle-id="exp-chart" data-history-path="_user.history.exp" rel=tooltip title="Progress"><i class=icon-signal></i></a>&nbsp;
<a x-bind=click:toggleChart data-id="exp" rel=tooltip title="Progress"><i class=icon-signal></i></a>&nbsp;
{/}
<i class=icon-star></i> {floor(_user.stats.exp)} / {tnl(_user.stats.lvl)}
</span>

View file

@ -40,7 +40,7 @@
<div id="wrap">
<app:alerts:flash />
{#if _user.preferences.hideHeader}<app:settings:menu />{/} <!-- if they hide the header, we still need user-menu visible -->
<div id="exp-chart" style="display:none;"></div>
<div class="exp-chart {#unless _page.charts.exp}hidden{/}"></div>
<div id=main class="grid">
<div class='{#if _gamePane}hidden{/}'>

View file

@ -132,7 +132,7 @@
<task-list: nonvoid>
<h2 class="task-column_title">{{t(@header)}}</h2>
{{#if equal(@type,'todo')}}<div class="todos-chart" style='display:none;'></div>{{/}}
{{#if equal(@type,'todo')}}<div class='todos-chart {#unless _page.charts.todos}hidden{/}'></div>{{/}}
{#if @editable}
@ -354,4 +354,4 @@
</form>
</div>
<div style="display:none;" class={{:task.id}}-chart></div>
<div class="{#unless _page.charts[:task.id]}hidden{/} {{:task.id}}-chart"></div>