Skip to content
This repository was archived by the owner on Nov 17, 2018. It is now read-only.

Commit f8f5660

Browse files
committed
I partially add support for expenses_matching.
1 parent e6f37e3 commit f8f5660

17 files changed

Lines changed: 504 additions & 98 deletions

app/assets/javascripts/application.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
//
1313
//= require jquery
1414
//= require jquery_ujs
15-
//= require chart_helpers
15+
//= require oauth

app/assets/javascripts/oauth.js.coffee

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,40 @@
66
# All this logic will automatically be available in application.js.
77
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
88

9-
createCheckin = (n, callback) -> () ->
10-
n -= 1
11-
callback() if n is 0
12-
9+
this.activateMatchbox = () ->
10+
$('.side-menu-item.matching').append($("<div id='matchbox-container'>
11+
<div id='matchbox-nub'></div>
12+
<div id='matchbox'>
13+
<input type='text' placeholder='Use regular expressions!'>
14+
<button class='submit'>Search</button>
15+
</div>
16+
</div>"))
17+
$('.side-menu-item.matching').click(() ->
18+
$('.side-menu-item.matching #matchbox-container').css('visibility', 'visible')
19+
false
20+
)
21+
$(document).click(() ->
22+
$('.side-menu-item.matching #matchbox-container').css('visibility', 'hidden')
23+
)
24+
$('#matchbox button.submit').click(() ->
25+
console.debug($('#matchbox input'))
26+
console.debug($('#matchbox input')[0])
27+
console.debug($('#matchbox input').val())
28+
window.location.href = "/user/expenses_matching?query=#{$('#matchbox input').val()}"
29+
)
1330

14-
prettyTime = (t) -> "#{t.toLocaleTimeString()} #{t.getDate()}/#{t.getMonth()+1}"
31+
### Example arguments:
32+
chartType = 'AreaChart'
1533
16-
scrollLabelDate = (t) -> t.toLocaleDateString()
34+
url = '/user/get_balance_over_time?format=google-charts'
1735
18-
###
1936
cols = [{id: 'date', type: 'date'}, {id: 'balance', type: 'number'}]
20-
rows = undefined
37+
38+
processRow = ([dateStr, balance]) ->
39+
date = new Date(dateStr)
40+
{c: [{v: date, f: prettyTime(date)}, {v: Number(balance)}]}
41+
42+
2143
optionsMainChart =
2244
colors: ['#0088CC']
2345
legend:
@@ -40,13 +62,19 @@ optionsScrollChart =
4062
textPosition: 'none'
4163
vAxis:
4264
textPosition: 'none'
43-
44-
processRow = ([dateStr, balance]) ->
45-
date = new Date(dateStr)
46-
{c: [{v: date, f: prettyTime(date)}, {v: Number(balance)}]}
4765
###
4866

49-
createScrolledChart = (varChartType, varUrl, varCols, varProcessRow, varOptionsMainChart, varOptionsScrollChart) ->
67+
68+
this.createScrolledChart = (variable) ->
69+
70+
createCheckin = (n, callback) -> () ->
71+
n -= 1
72+
callback() if n is 0
73+
74+
prettyTime = (t) -> "#{t.toLocaleTimeString()} #{t.getMonth()+1}/#{t.getDate()}"
75+
76+
scrollLabelDate = (t) -> t.toLocaleDateString()
77+
5078
dates = {}
5179
spawnDates = () ->
5280
dates.all = rows.map((r) -> r.c[0].v)
@@ -57,23 +85,23 @@ createScrolledChart = (varChartType, varUrl, varCols, varProcessRow, varOptionsM
5785
return new Date(dates.first + dates.span * (x / elem.film.offsetParent().width()))
5886

5987
initScrollChart = () ->
60-
chart = new google.visualization[varChartType]($('#scroll-chart')[0])
61-
dataTable = new google.visualization.DataTable({cols: varCols, rows: rows})
88+
chart = new google.visualization[variable.chartType]($('#scroll-chart')[0])
89+
dataTable = new google.visualization.DataTable({cols: variable.cols, rows: rows})
6290
google.visualization.events.addListener(chart, 'ready', layerFilm)
63-
chart.draw(dataTable, varOptionsScrollChart)
91+
chart.draw(dataTable, variable.optionsScrollChart)
6492
return chart
6593

6694
initMainChart = () ->
67-
chart = new google.visualization[varChartType]($('#main-chart')[0])
68-
dataTable = new google.visualization.DataTable({cols: varCols, rows: rows})
69-
chart.draw(dataTable, varOptionsMainChart)
95+
chart = new google.visualization[variable.chartType]($('#main-chart')[0])
96+
dataTable = new google.visualization.DataTable({cols: variable.cols, rows: rows})
97+
chart.draw(dataTable, variable.optionsMainChart)
7098
return chart
7199

72100
redrawMainChart = (startDate, finishDate) ->
73101
start = Math.max(0, indexOfDateAfter(startDate) - 1)
74102
finish = indexOfDateAfter(finishDate) + 1
75-
dataTable = new google.visualization.DataTable({cols: varCols, rows: rows.slice(start, finish)})
76-
elem.mainChart.draw(dataTable, optionsMainChart)
103+
dataTable = new google.visualization.DataTable({cols: variable.cols, rows: rows.slice(start, finish)})
104+
elem.mainChart.draw(dataTable, variable.optionsMainChart)
77105

78106
indexOfDateAfter = (date) ->
79107
for d, i in dates.all #optimize this by using a binary search
@@ -157,9 +185,9 @@ createScrolledChart = (varChartType, varUrl, varCols, varProcessRow, varOptionsM
157185
google.load('visualization', '1', {packages: ['corechart']})
158186

159187
rows = undefined
160-
$.ajax({url: varUrl}).done((d) ->
188+
$.ajax({url: variable.url}).done((d) ->
161189

162-
rows = JSON.parse(d).map(processRow)
190+
rows = variable.processData(JSON.parse(d))
163191
drawCharts()
164192

165193
)

app/assets/javascripts/oauth_balance.js.coffee

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,95 @@
22
# All this logic will automatically be available in application.js.
33
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
44

5+
6+
prettyTime = (t) -> "#{t.toLocaleTimeString()} #{t.getMonth()+1}/#{t.getDate()}"
7+
8+
9+
options =
10+
chartType: 'AreaChart'
11+
12+
cols: [{id: 'date', type: 'date'}, {id: 'balance', type: 'number'}],
13+
14+
url: '/user/get_balance_over_time?format=google-charts'
15+
16+
processData: (d) -> d.map(([dateStr, balance]) ->
17+
date = new Date(dateStr)
18+
{c: [{v: date, f: prettyTime(date)}, {v: Number(balance)}]}
19+
)
20+
21+
optionsMainChart:
22+
colors: ['#0088CC']
23+
legend:
24+
position: 'none'
25+
hAxis:
26+
textStyle:
27+
fontName: 'Lucida Grande'
28+
vAxis:
29+
textStyle:
30+
fontName: 'Lucida Grande'
31+
32+
optionsScrollChart:
33+
colors: ['#0088CC']
34+
backgroundColor: '#F5F5F5'
35+
chartArea:
36+
width: '100%'
37+
height: '100%'
38+
legend:
39+
position: 'none'
40+
hAxis:
41+
textPosition: 'none'
42+
vAxis:
43+
textPosition: 'none'
44+
45+
createScrolledChart(options)
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
59+
60+
61+
62+
63+
64+
65+
66+
67+
68+
69+
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+
82+
83+
84+
85+
86+
87+
88+
89+
90+
91+
92+
93+
###
594
createCheckin = (n, callback) -> () ->
695
n -= 1
796
callback() if n is 0
@@ -160,4 +249,5 @@ $(document).ready(() ->
160249
$('.active a').click(() -> false)
161250
drawCharts()
162251
163-
)
252+
)
253+
###

app/assets/javascripts/oauth_expenses.js.coffee

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,53 @@
22
# All this logic will automatically be available in application.js.
33
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
44

5+
6+
prettyTime = (t) -> "#{t.toLocaleTimeString()} #{t.getMonth()+1}/#{t.getDate()}"
7+
8+
9+
options =
10+
chartType: 'AreaChart'
11+
12+
cols: [{id: 'date', type: 'date'}, {id: 'balance', type: 'number'}]
13+
14+
url: '/user/get_expenses_over_time_cumulative'
15+
16+
processData: (d) -> d.map((e) ->
17+
date = new Date(e.date)
18+
{c: [{v: date, f: prettyTime(date)}, {v: Number(e.expense)}]}
19+
)
20+
21+
optionsMainChart:
22+
colors: ['#0088CC']
23+
legend:
24+
position: 'none'
25+
hAxis:
26+
textStyle:
27+
fontName: 'Lucida Grande'
28+
vAxis:
29+
textStyle:
30+
fontName: 'Lucida Grande'
31+
32+
optionsScrollChart:
33+
colors: ['#0088CC']
34+
backgroundColor: '#F5F5F5'
35+
chartArea:
36+
width: '100%'
37+
height: '100%'
38+
legend:
39+
position: 'none'
40+
hAxis:
41+
textPosition: 'none'
42+
vAxis:
43+
textPosition: 'none'
44+
45+
$(activateMatchbox)
46+
createScrolledChart(options)
47+
48+
49+
50+
51+
###
552
createCheckin = (n, callback) -> () ->
653
n -= 1
754
callback() if n is 0
@@ -158,4 +205,5 @@ $(document).ready(() ->
158205
$('.top-menu-item.expenses').addClass('active')
159206
$('.active a').click(() -> false)
160207
drawCharts()
161-
)
208+
)
209+
###

app/assets/javascripts/oauth_expenses_by_category.js.coffee

Lines changed: 80 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,84 @@
22
# All this logic will automatically be available in application.js.
33
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
44

5+
6+
prettyTime = (t) -> "#{t.toLocaleTimeString()} #{t.getMonth()+1}/#{t.getDate()}"
7+
8+
createCheckin = (n, callback) -> () ->
9+
n -= 1
10+
callback() if n is 0
11+
12+
cols = [{id: 'Category', type: 'string'}, {id: 'Spending', type: 'number'}]
13+
rows = undefined
14+
options = {}
15+
16+
drawChart = createCheckin(2, () ->
17+
chart = new google.visualization.PieChart($('#main-chart')[0])
18+
dataTable = new google.visualization.DataTable({cols: cols, rows: rows})
19+
chart.draw(dataTable, options)
20+
)
21+
22+
google.setOnLoadCallback(drawChart)
23+
google.load('visualization', '1', {packages: ['corechart']})
24+
25+
26+
$.ajax({url: '/user/get_expenses_by_category'}).done((jsonData) ->
27+
categories = JSON.parse(jsonData)
28+
29+
rows = ({c: [{v: category}, {v: spending}]} for category, spending of categories)
30+
31+
console.debug(rows)
32+
console.debug(categories)
33+
34+
drawChart()
35+
)
36+
37+
$(activateMatchbox)
38+
39+
###
40+
options =
41+
chartType: 'ColumnChart'
42+
43+
cols: [{id: 'date', type: 'date'}]
44+
45+
url: '/user/get_expenses_by_category'
46+
47+
processData: (data) ->
48+
for category in data.categories
49+
options.cols.push({id: category, label: category, type: 'number'})
50+
51+
data.rows.map((r) ->
52+
date = new Date(r.date)
53+
return {c: [{v: date, f: prettyTime(date)}].concat(r.expenses.map((e) ->
54+
{v: Number(e)}
55+
))}
56+
)
57+
58+
optionsMainChart:
59+
hAxis:
60+
textStyle:
61+
fontName: 'Lucida Grande'
62+
vAxis:
63+
textStyle:
64+
fontName: 'Lucida Grande'
65+
66+
optionsScrollChart:
67+
backgroundColor: '#F5F5F5'
68+
chartArea:
69+
width: '100%'
70+
height: '100%'
71+
legend:
72+
position: 'none'
73+
hAxis:
74+
textPosition: 'none'
75+
vAxis:
76+
textPosition: 'none'
77+
78+
createScrolledChart(options)
79+
###
80+
81+
82+
###
583
createCheckin = (n, callback) -> () ->
684
n -= 1
785
callback() if n is 0
@@ -172,4 +250,5 @@ $(document).ready(() ->
172250
$('.active a').click(() -> false)
173251
drawCharts()
174252
175-
)
253+
)
254+
###

0 commit comments

Comments
 (0)