mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Remember dashboard/report settings
This commit is contained in:
parent
2a4665dcff
commit
f2ce5d622b
@ -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 @@
|
||||
<div id="currency-btn-group" class="btn-group" role="group" style="border: 1px solid #ccc;">
|
||||
@foreach ($currencies as $key => $val)
|
||||
<button type="button" class="btn btn-normal {{ array_values($currencies)[0] == $val ? 'active' : '' }}"
|
||||
style="font-weight:normal !important;background-color:white">{{ $val }}</button>
|
||||
data-button="{{ $key }}" style="font-weight:normal !important;background-color:white">{{ $val }}</button>
|
||||
@endforeach
|
||||
</div>
|
||||
@endif
|
||||
|
@ -31,16 +31,30 @@
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
var chartStartDate = moment("{{ $startDate }}");
|
||||
var chartEndDate = moment("{{ $endDate }}");
|
||||
var dateRanges = {!! $account->present()->dateRangeOptions !!};
|
||||
|
||||
$(function() {
|
||||
|
||||
var chartStartDate = moment("{{ $startDate }}");
|
||||
var chartEndDate = moment("{{ $endDate }}");
|
||||
if (isStorageSupported()) {
|
||||
var lastRange = localStorage.getItem('last:report_range');
|
||||
lastRange = dateRanges[lastRange];
|
||||
if (lastRange) {
|
||||
chartStartDate = lastRange[0];
|
||||
chartEndDate = lastRange[1];
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize date range selector
|
||||
function cb(start, end) {
|
||||
function cb(start, end, label) {
|
||||
$('#reportrange span').html(start.format('{{ $account->getMomentDateFormat() }}') + ' - ' + end.format('{{ $account->getMomentDateFormat() }}'));
|
||||
$('#start_date').val(start.format('YYYY-MM-DD'));
|
||||
$('#end_date').val(end.format('YYYY-MM-DD'));
|
||||
|
||||
if (isStorageSupported() && label && label != "{{ trans('texts.custom_range') }}") {
|
||||
localStorage.setItem('last:report_range', label);
|
||||
}
|
||||
}
|
||||
|
||||
$('#reportrange').daterangepicker({
|
||||
@ -51,7 +65,7 @@
|
||||
startDate: chartStartDate,
|
||||
endDate: chartEndDate,
|
||||
linkedCalendars: false,
|
||||
ranges: {!! $account->present()->dateRangeOptions !!}
|
||||
ranges: dateRanges,
|
||||
}, cb);
|
||||
|
||||
cb(chartStartDate, chartEndDate);
|
||||
|
Loading…
x
Reference in New Issue
Block a user