Skip to content

Commit

Permalink
Merge pull request #140 from qedi-r/issue-134-all-time
Browse files Browse the repository at this point in the history
add all time button to charts
  • Loading branch information
simhnna authored Aug 27, 2022
2 parents b407790 + 519936c commit 15b179c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
30 changes: 30 additions & 0 deletions silverstrike/templates/silverstrike/charts.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ <h1>{% trans 'Charts' %}
<button id="6month" class="btn btn-s btn-default range-chooser">{% trans 'Last 6 Months' %}</button>
<button id="3month" class="btn btn-s btn-default range-chooser">{% trans 'Last 3 Months' %}</button>
<button id="currentMonth" class="btn btn-s btn-default range-chooser">{% trans 'Current Month' %}</button>
<button id="all-time" class="btn btn-s btn-default range-chooser">{% trans 'All Time' %}</button>
<!--button id="custom" class="btn btn-s btn-default range-chooser">Custom Range</button-->
</div>
</div>
Expand Down Expand Up @@ -202,6 +203,7 @@ <h3 class="box-title">{% trans 'Spending by category' %}</h3>
var three_months = 1;
var six_months = 2;
var twelve_months = 3;
var all_time = 10;
var accountChartData = new Array(4);
var balanceChartData = new Array(4);
var categoryChartData = new Array(4);
Expand All @@ -223,6 +225,34 @@ <h3 class="box-title">{% trans 'Spending by category' %}</h3>
});

// update charts
$('#all-time').click(function() {
if (accountChartData[twelve_months] == null) {
$.getJSON("{% url 'api_accounts_balance' all_time today %}", {}, function(res, status) {
updateAccountChart(res);
accountChartData[all_time] = res;
});
} else {
updateAccountChart(accountChartData[all_time]);
}
if (balanceChartData[all_time] == null) {
$.getJSON("{% url 'api_balance' all_time today %}", {}, function(res, status) {
updateBalanceChart(res);
balanceChartData[all_time] = res;
});
} else {
updateBalanceChart(balanceChartData[all_time]);
}
if (categoryChartData[all_time] == null) {
$.getJSON("{% url 'category_spending' all_time today %}", {}, function(res, status) {
updateCategoryChart(res);
categoryChartData[all_time] = res;
});
} else {
updateCategoryChart(categoryChartData[all_time]);
}
});


$('#12month').click(function() {
if (accountChartData[twelve_months] == null) {
$.getJSON("{% url 'api_accounts_balance' minus_12_months today %}", {}, function(res, status) {
Expand Down
5 changes: 5 additions & 0 deletions silverstrike/views/charts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.contrib.auth.mixins import LoginRequiredMixin
from django.views import generic

from silverstrike.models import Transaction
from silverstrike.lib import last_day_of_month


Expand All @@ -18,6 +19,10 @@ def get_context_data(self, **kwargs):
context['minus_3_months'] = date.today() - relativedelta(months=3)
context['minus_6_months'] = date.today() - relativedelta(months=6)
context['minus_12_months'] = date.today() - relativedelta(years=1)
context['all_time'] = date.today()
if Transaction.objects.first():
earliest_transaction = Transaction.objects.earliest('date')
context['all_time'] = earliest_transaction.date - relativedelta(days=1)

context['first_day_of_month'] = date.today().replace(day=1)
context['last_day_of_month'] = last_day_of_month(date.today())
Expand Down

0 comments on commit 15b179c

Please sign in to comment.