2013-05-19 22:48:51 +00:00
|
|
|
algos = require 'habitrpg-shared/script/algos'
|
2013-05-19 17:53:13 +00:00
|
|
|
helpers = require 'habitrpg-shared/script/helpers'
|
2013-05-19 22:48:51 +00:00
|
|
|
_ = require 'lodash'
|
2013-02-08 22:44:06 +00:00
|
|
|
moment = require 'moment'
|
2013-05-21 23:40:46 +00:00
|
|
|
misc = require './misc'
|
2013-02-08 22:44:06 +00:00
|
|
|
|
|
|
|
|
appExports.clearCompleted = (e, el) ->
|
2013-04-10 23:24:33 +00:00
|
|
|
completedIds = _.pluck( _.where(model.get('_todoList'), {completed:true}), 'id')
|
2013-02-09 01:48:31 +00:00
|
|
|
todoIds = user.get('todoIds')
|
2013-04-10 23:24:33 +00:00
|
|
|
|
2013-05-22 10:29:24 +00:00
|
|
|
_.each completedIds, (id) -> user.del "tasks.#{id}"; true
|
2013-04-10 23:24:33 +00:00
|
|
|
user.set 'todoIds', _.difference(todoIds, completedIds)
|
2013-02-08 22:44:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
appExports.toggleTaskEdit = (e, el) ->
|
2013-05-28 15:43:16 +00:00
|
|
|
id = e.get('id')
|
2013-06-15 16:35:55 +00:00
|
|
|
[editPath, chartPath] = ["_tasks.editing.#{id}", "_page.charts.#{id}"]
|
|
|
|
|
model.set editPath, !(model.get editPath)
|
|
|
|
|
model.set chartPath, false
|
2013-02-08 22:44:06 +00:00
|
|
|
|
|
|
|
|
appExports.toggleChart = (e, el) ->
|
2013-05-28 15:43:16 +00:00
|
|
|
id = $(el).attr('data-id')
|
2013-06-15 16:35:55 +00:00
|
|
|
[historyPath, togglePath] = ['','']
|
2013-05-28 15:43:16 +00:00
|
|
|
|
2013-06-15 16:35:55 +00:00
|
|
|
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)
|
2013-02-08 22:44:06 +00:00
|
|
|
|
|
|
|
|
matrix = [['Date', 'Score']]
|
2013-06-15 16:35:55 +00:00
|
|
|
_.each history, (obj) -> matrix.push([ moment(obj.date).format('MM/DD/YY'), obj.value ])
|
2013-02-08 22:44:06 +00:00
|
|
|
data = google.visualization.arrayToDataTable matrix
|
2013-05-28 15:43:16 +00:00
|
|
|
options =
|
2013-03-09 19:06:53 +00:00
|
|
|
title: 'History'
|
2013-03-21 22:31:23 +00:00
|
|
|
backgroundColor: { fill:'transparent' }
|
2013-05-28 15:43:16 +00:00
|
|
|
chart = new google.visualization.LineChart $(".#{id}-chart")[0]
|
2013-02-08 22:44:06 +00:00
|
|
|
chart.draw(data, options)
|
|
|
|
|
|
2013-05-12 09:52:32 +00:00
|
|
|
appExports.todosShowRemaining = -> model.set '_showCompleted', false
|
|
|
|
|
appExports.todosShowCompleted = -> model.set '_showCompleted', true
|
2013-02-09 15:45:00 +00:00
|
|
|
|
2013-03-18 00:30:54 +00:00
|
|
|
|
|
|
|
|
###
|
|
|
|
|
Undo
|
|
|
|
|
###
|
|
|
|
|
appExports.undo = () ->
|
|
|
|
|
undo = model.get '_undo'
|
2013-03-18 03:15:19 +00:00
|
|
|
clearTimeout(undo.timeoutId) if undo?.timeoutId
|
|
|
|
|
model.del '_undo'
|
2013-05-29 09:23:23 +00:00
|
|
|
_.each undo.stats, (val, key) -> user.set "stats.#{key}", val; true
|
2013-03-18 00:30:54 +00:00
|
|
|
taskPath = "tasks.#{undo.task.id}"
|
2013-03-18 01:43:03 +00:00
|
|
|
_.each undo.task, (val, key) ->
|
2013-05-22 10:29:24 +00:00
|
|
|
return true if key in ['id', 'type'] # strange bugs in this world: https://workflowy.com/shared/a53582ea-43d6-bcce-c719-e134f9bf71fd/
|
2013-03-18 01:43:03 +00:00
|
|
|
if key is 'completed'
|
|
|
|
|
user.pass({cron:true}).set("#{taskPath}.completed",val)
|
|
|
|
|
else
|
2013-05-29 09:23:23 +00:00
|
|
|
user.set "#{taskPath}.#{key}", val
|
2013-05-22 10:29:24 +00:00
|
|
|
true
|