diff --git a/resources/views/dashboard.blade.php b/resources/views/dashboard.blade.php index 1d7f5a112170..cd3c6067858b 100644 --- a/resources/views/dashboard.blade.php +++ b/resources/views/dashboard.blade.php @@ -18,11 +18,10 @@ @if (Auth::user()->hasPermission('view_all')) function loadChart(data) { var ctx = document.getElementById('chart-canvas').getContext('2d'); - if (window.myChart) { window.myChart.config.data = data; - window.myChart.config.options.scales.xAxes[0].time.unit = chartGropuBy.toLowerCase(); - window.myChart.config.options.scales.xAxes[0].time.round = chartGropuBy.toLowerCase(); + window.myChart.config.options.scales.xAxes[0].time.unit = chartGroupBy.toLowerCase(); + window.myChart.config.options.scales.xAxes[0].time.round = chartGroupBy.toLowerCase(); window.myChart.update(); } else { $('#progress-div').hide(); @@ -63,8 +62,8 @@ xAxes: [{ type: 'time', time: { - unit: 'day', - round: 'day', + unit: chartGroupBy, + round: chartGroupBy, }, gridLines: { display: false, @@ -85,14 +84,38 @@ } var account = {!! $account !!}; - var chartStartDate = moment().subtract(29, 'days'); - var chartEndDate = moment(); - var chartGropuBy = 'day'; + var chartGroupBy = 'day'; var chartCurrencyId = {{ $account->getCurrencyId() }}; + var dateRanges = {!! $account->present()->dateRangeOptions !!}; + var chartStartDate; + var chartEndDate; $(function() { // Initialize date range selector + chartStartDate = moment().subtract(29, 'days'); + chartEndDate = moment(); + + if (isStorageSupported()) { + var lastRange = localStorage.getItem('last:dashboard_range'); + lastRange = dateRanges[lastRange]; + if (lastRange) { + chartStartDate = lastRange[0]; + chartEndDate = lastRange[1]; + } + + var currencyId = localStorage.getItem('last:dashboard_currency_id'); + if (currencyId) { + chartCurrencyId = currencyId; + $("#currency-btn-group [data-button=\"" + chartCurrencyId + "\"]").addClass("active").siblings().removeClass("active"); + } + + var groupBy = localStorage.getItem('last:dashboard_group_by'); + if (groupBy) { + chartGroupBy = groupBy; + $("#group-btn-group [data-button=\"" + groupBy + "\"]").addClass("active").siblings().removeClass("active"); + } + } function cb(start, end, label) { $('#reportrange span').html(start.format('{{ $account->getMomentDateFormat() }}') + ' - ' + end.format('{{ $account->getMomentDateFormat() }}')); @@ -100,6 +123,10 @@ chartEndDate = end; $('.range-label-div').text(label); loadData(); + + if (isStorageSupported() && label && label != "{{ trans('texts.custom_range') }}") { + localStorage.setItem('last:dashboard_range', label); + } } $('#reportrange').daterangepicker({ @@ -110,7 +137,7 @@ startDate: chartStartDate, endDate: chartEndDate, linkedCalendars: false, - ranges: {!! $account->present()->dateRangeOptions !!} + ranges: dateRanges, }, cb); cb(chartStartDate, chartEndDate); @@ -119,17 +146,23 @@ $(this).addClass("active").siblings().removeClass("active"); chartCurrencyId = currencyMap[$(this).text()].id; loadData(); + if (isStorageSupported()) { + localStorage.setItem('last:dashboard_currency_id', $(this).attr('data-button')); + } }); $("#group-btn-group > .btn").click(function(){ $(this).addClass("active").siblings().removeClass("active"); - chartGropuBy = $(this).attr('data-button'); + chartGroupBy = $(this).attr('data-button'); loadData(); + if (isStorageSupported()) { + localStorage.setItem('last:dashboard_group_by', chartGroupBy); + } }); function loadData() { var includeExpenses = "{{ count($expenses) ? 'true' : 'false' }}"; - var url = "{!! url('/dashboard_chart_data') !!}/" + chartGropuBy + '/' + chartStartDate.format('YYYY-MM-DD') + '/' + chartEndDate.format('YYYY-MM-DD') + '/' + chartCurrencyId + '/' + includeExpenses; + var url = "{!! url('/dashboard_chart_data') !!}/" + chartGroupBy + '/' + chartStartDate.format('YYYY-MM-DD') + '/' + chartEndDate.format('YYYY-MM-DD') + '/' + chartCurrencyId + '/' + includeExpenses; $.get(url, function(response) { response = JSON.parse(response); loadChart(response.data); @@ -183,7 +216,7 @@
@foreach ($currencies as $key => $val) + data-button="{{ $key }}" style="font-weight:normal !important;background-color:white">{{ $val }} @endforeach
@endif diff --git a/resources/views/reports/chart_builder.blade.php b/resources/views/reports/chart_builder.blade.php index 2a2b62f8d500..c8bb069f8994 100644 --- a/resources/views/reports/chart_builder.blade.php +++ b/resources/views/reports/chart_builder.blade.php @@ -31,16 +31,30 @@