From cef8431af03260d8f24664d4b6b1580667d6ca55 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Sat, 19 Oct 2013 16:15:48 -0700 Subject: [PATCH] charts: port toggleChart back in (functional, but it's not getting the right width) --- archive/derby_controllers/tasks.coffee | 25 -------------------- public/js/controllers/rootCtrl.js | 32 ++++++++++++++++++++++++++ public/js/controllers/tasksCtrl.js | 2 +- views/index.jade | 2 +- views/shared/header/header.jade | 2 +- views/tasks/index.jade | 6 ++--- views/tasks/task.jade | 6 ++--- 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/archive/derby_controllers/tasks.coffee b/archive/derby_controllers/tasks.coffee index 6452e72ac0..1a01c095e0 100644 --- a/archive/derby_controllers/tasks.coffee +++ b/archive/derby_controllers/tasks.coffee @@ -10,31 +10,6 @@ misc = require './misc' _.each completedIds, (id) -> user.del "tasks.#{id}"; true user.set 'todoIds', _.difference(todoIds, completedIds) - appExports.toggleChart = (e, el) -> - id = $(el).attr('data-id') - [historyPath, togglePath] = ['',''] - - 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']] - _.each history, (obj) -> matrix.push([ moment(obj.date).format('MM/DD/YY'), obj.value ]) - data = google.visualization.arrayToDataTable matrix - options = - title: 'History' - backgroundColor: { fill:'transparent' } - chart = new google.visualization.LineChart $(".#{id}-chart")[0] - chart.draw(data, options) - ### Undo diff --git a/public/js/controllers/rootCtrl.js b/public/js/controllers/rootCtrl.js index a298188db3..0ea848316c 100644 --- a/public/js/controllers/rootCtrl.js +++ b/public/js/controllers/rootCtrl.js @@ -61,5 +61,37 @@ habitrpg.controller("RootCtrl", ['$scope', '$rootScope', '$location', 'User', '$ } }); } + + $rootScope.charts = {}; + $rootScope.toggleChart = function(id, task) { + var history = [], matrix, data, chart, options; + switch (id) { + case 'exp': + $rootScope.charts.exp = !$rootScope.charts.exp; + history = User.user.history.exp; + break; + case 'todos': + $rootScope.charts.todos = !$rootScope.charts.todos; + history = User.user.history.todos; + break; + default: + $rootScope.charts[id] = !$rootScope.charts[id]; + history = task.history; + if (task) task._editing = false; + } + matrix = [['Date', 'Score']]; + _.each(history, function(obj) { + matrix.push([moment(obj.date).format('MM/DD/YY'), obj.value]); + }); + data = google.visualization.arrayToDataTable(matrix); + options = { + title: 'History', + backgroundColor: { + fill: 'transparent' + } + }; + chart = new google.visualization.LineChart($("." + id + "-chart")[0]); + chart.draw(data, options); + }; } ]); diff --git a/public/js/controllers/tasksCtrl.js b/public/js/controllers/tasksCtrl.js index 9e9c3af7d8..0bb798ccdc 100644 --- a/public/js/controllers/tasksCtrl.js +++ b/public/js/controllers/tasksCtrl.js @@ -116,4 +116,4 @@ habitrpg.controller("TasksCtrl", ['$scope', '$rootScope', '$location', 'User', ' User.log({op: 'clear-completed'}); } -}]); + }]); diff --git a/views/index.jade b/views/index.jade index d174b42099..1b6e26fab9 100644 --- a/views/index.jade +++ b/views/index.jade @@ -102,7 +102,7 @@ html div(ng-if='user.preferences.hideHeader') include ./shared/header/menu - .exp-chart(ng-show='page.charts.exp') + .exp-chart(ng-show='charts.exp') #main(ng-view) diff --git a/views/shared/header/header.jade b/views/shared/header/header.jade index 2a93254e55..0570507780 100644 --- a/views/shared/header/header.jade +++ b/views/shared/header/header.jade @@ -23,7 +23,7 @@ | {{user.stats.exp | number:0}} / {{tnl(user.stats.lvl)}} // FIXME doesn't look great here, but the "Experience" CSS title rollover covers it where it was before span(ng-show='user.history.exp') - a(x-bind='click:toggleChart', ng-click='notPorted()', data-id='exp', tooltip='Progress') + a(ng-click='toggleChart("exp")', tooltip='Progress') i.icon-signal // party span(ng-controller='PartyCtrl') diff --git a/views/tasks/index.jade b/views/tasks/index.jade index d56da854a2..a50a17b0cb 100644 --- a/views/tasks/index.jade +++ b/views/tasks/index.jade @@ -6,10 +6,10 @@ div(ng-controller='TasksCtrl') // Todos export/graph options span.option-box.pull-right(ng-if='list.main && list.type=="todo"') - a.option-action(ng-show='user.history.todos', x-bind='click:toggleChart', ng-click='notPorted()', data-id='todos', tooltip='Progress') + a.option-action(ng-show='user.history.todos', ng-click='toggleChart("todos")', tooltip='Progress') i.icon-signal //-a.option-action(ng-href='/v1/users/{{user.id}}/calendar.ics?apiToken={{user.apiToken}}', tooltip='iCal') - a.option-action(ng-click='notPorted()', tooltip='iCal') + a.option-action(ng-click='notPorted()', tooltip='iCal', ng-show='false') i.icon-calendar // @@ -26,7 +26,7 @@ div(ng-controller='TasksCtrl') h2.task-column_title {{list.header}} // Todo Chart - .todos-chart(ng-if='list.type == "todo"', ng-show='_page.charts.todos') + .todos-chart(ng-if='list.type == "todo"', ng-show='charts.todos') // Add New form.addtask-form.form-inline.new-task-form(name='new{{list.type}}form', ng-show='list.editable', ng-hide='list.showCompleted && list.type=="todo"', data-task-type='{{list.type}}', ng-submit='addTask(list)') diff --git a/views/tasks/task.jade b/views/tasks/task.jade index 05dc0605f6..68f31e4244 100644 --- a/views/tasks/task.jade +++ b/views/tasks/task.jade @@ -27,10 +27,10 @@ li(ng-repeat='task in user[list.type + "s"]', class='task {{taskClasses(task,use a(ng-click='remove(task)', tooltip='Delete') i.icon-trash // chart - a(ng-show='task.history', x-bind='click:toggleChart', ng-click='notPorted()', data-id='{{task.id}}', tooltip='Progress') + a(ng-show='task.history', ng-click='toggleChart(task.id, task)', tooltip='Progress') i.icon-signal // notes - span.task-notes(ng-hide='task._editing', ng-show='task.notes', popover-trigger='mouseenter', popover-placement='left', popover='{{task.notes}}', popover-title='{{task.text}}') + span.task-notes(ng-show='task.notes && !task._editing', popover-trigger='mouseenter', popover-placement='left', popover='{{task.notes}}', popover-title='{{task.text}}') i.icon-comment // left-hand side checkbox @@ -157,4 +157,4 @@ li(ng-repeat='task in user[list.type + "s"]', class='task {{taskClasses(task,use input.option-content(type='number', ng-model='task.streak') button.task-action-btn.tile.spacious(type='submit') Save & Close - div(class='{{task.id}}-chart', ng-show='_page.charts[task.id]') + div(class='{{task.id}}-chart', ng-show='charts[task.id]')