mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Optimize new JS code.
This commit is contained in:
parent
e67709e339
commit
9b4fd57f51
@ -30,12 +30,44 @@ class JavascriptController extends Controller
|
|||||||
*/
|
*/
|
||||||
public function variables()
|
public function variables()
|
||||||
{
|
{
|
||||||
|
$picker = $this->getDateRangePicker();
|
||||||
|
$start = Session::get('start');
|
||||||
|
$end = Session::get('end');
|
||||||
|
$linkTitle = sprintf('%s - %s', $start->formatLocalized($this->monthAndDayFormat), $end->formatLocalized($this->monthAndDayFormat));
|
||||||
|
$firstDate = session('first')->format('Y-m-d');
|
||||||
|
$localeconv = localeconv();
|
||||||
|
$accounting = Amount::getJsConfig($localeconv);
|
||||||
|
$localeconv = localeconv();
|
||||||
|
$defaultCurrency = Amount::getDefaultCurrency();
|
||||||
|
$localeconv['frac_digits'] = $defaultCurrency->decimal_places;
|
||||||
|
$pref = Preferences::get('language', config('firefly.default_language', 'en_US'));
|
||||||
|
$lang = $pref->data;
|
||||||
|
$data = [
|
||||||
|
'picker' => $picker,
|
||||||
|
'linkTitle' => $linkTitle,
|
||||||
|
'firstDate' => $firstDate,
|
||||||
|
'currencyCode' => Amount::getCurrencyCode(),
|
||||||
|
'currencySymbol' => Amount::getCurrencySymbol(),
|
||||||
|
'accounting' => $accounting,
|
||||||
|
'localeconv' => $localeconv,
|
||||||
|
'language' => $lang,
|
||||||
|
];
|
||||||
|
|
||||||
|
return response()
|
||||||
|
->view('javascript.variables', $data, 200)
|
||||||
|
->header('Content-Type', 'text/javascript');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
* @throws FireflyException
|
||||||
|
*/
|
||||||
|
private function getDateRangePicker(): array
|
||||||
|
{
|
||||||
$viewRange = Preferences::get('viewRange', '1M')->data;
|
$viewRange = Preferences::get('viewRange', '1M')->data;
|
||||||
$start = Session::get('start');
|
$start = Session::get('start');
|
||||||
$end = Session::get('end');
|
$end = Session::get('end');
|
||||||
$linkTitle = sprintf('%s - %s', $start->formatLocalized($this->monthAndDayFormat), $end->formatLocalized($this->monthAndDayFormat));
|
|
||||||
$firstDate = session('first')->format('Y-m-d');
|
|
||||||
$prevStart = clone $start;
|
$prevStart = clone $start;
|
||||||
$prevEnd = clone $start;
|
$prevEnd = clone $start;
|
||||||
$nextStart = clone $end;
|
$nextStart = clone $end;
|
||||||
@ -83,35 +115,18 @@ class JavascriptController extends Controller
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$current = $start->formatLocalized($format);
|
$current = $start->formatLocalized($format);
|
||||||
$next = $nextStart->formatLocalized($format);
|
$next = $nextStart->formatLocalized($format);
|
||||||
$prev = $prevStart->formatLocalized($format);
|
$prev = $prevStart->formatLocalized($format);
|
||||||
$localeconv = localeconv();
|
|
||||||
$accounting = Amount::getJsConfig($localeconv);
|
|
||||||
$localeconv = localeconv();
|
|
||||||
$defaultCurrency = Amount::getDefaultCurrency();
|
|
||||||
$localeconv['frac_digits'] = $defaultCurrency->decimal_places;
|
|
||||||
$pref = Preferences::get('language', config('firefly.default_language', 'en_US'));
|
|
||||||
$lang = $pref->data;
|
|
||||||
$data = [
|
|
||||||
'dpStart' => $start->format('Y-m-d'),
|
|
||||||
'dpEnd' => $end->format('Y-m-d'),
|
|
||||||
'dpCurrent' => $current,
|
|
||||||
'dpPrevious' => $prev,
|
|
||||||
'dpNext' => $next,
|
|
||||||
'dpRanges' => $ranges,
|
|
||||||
'linkTitle' => $linkTitle,
|
|
||||||
'firstDate' => $firstDate,
|
|
||||||
'currencyCode' => Amount::getCurrencyCode(),
|
|
||||||
'currencySymbol' => Amount::getCurrencySymbol(),
|
|
||||||
'accounting' => $accounting,
|
|
||||||
'localeconv' => $localeconv,
|
|
||||||
'language' => $lang,
|
|
||||||
];
|
|
||||||
|
|
||||||
return response()
|
return [
|
||||||
->view('javascript.variables', $data, 200)
|
'start' => $start->format('Y-m-d'),
|
||||||
->header('Content-Type', 'text/javascript');
|
'end' => $end->format('Y-m-d'),
|
||||||
|
'current' => $current,
|
||||||
|
'previous' => $prev,
|
||||||
|
'next' => $next,
|
||||||
|
'ranges' => $ranges,
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -1,20 +1,20 @@
|
|||||||
// date range picker configuration:
|
// date range picker configuration:
|
||||||
var dateRangeConfig = {
|
var dateRangeConfig = {
|
||||||
startDate: moment("{{ dpStart }}"),
|
startDate: moment("{{ picker.start }}"),
|
||||||
endDate: moment("{{ dpEnd }}"),
|
endDate: moment("{{ picker.end }}"),
|
||||||
linkTitle: "{{ linkTitle }}",
|
linkTitle: "{{ linkTitle }}",
|
||||||
URL: "{{ route('daterange') }}",
|
URL: "{{ route('daterange') }}",
|
||||||
firstDate: moment("{{ firstDate }}"),
|
firstDate: moment("{{ firstDate }}"),
|
||||||
currentPeriod: "{{ dpCurrent }}",
|
currentPeriod: "{{ picker.current }}",
|
||||||
previousPeriod: "{{ dpPrevious }}",
|
previousPeriod: "{{ picker.previous }}",
|
||||||
nextPeriod: "{{ dpNext }}",
|
nextPeriod: "{{ picker.next }}",
|
||||||
everything: '{{ 'everything'|_|escape }}',
|
everything: '{{ 'everything'|_|escape }}',
|
||||||
customRangeLabel: '{{ 'customRange'|_|escape }}',
|
customRangeLabel: '{{ 'customRange'|_|escape }}',
|
||||||
applyLabel: '{{ 'apply'|_|escape }}',
|
applyLabel: '{{ 'apply'|_|escape }}',
|
||||||
cancelLabel: '{{ 'cancel'|_|escape }}',
|
cancelLabel: '{{ 'cancel'|_|escape }}',
|
||||||
fromLabel: '{{ 'from'|_|escape }}',
|
fromLabel: '{{ 'from'|_|escape }}',
|
||||||
toLabel: '{{ 'to'|_|escape }}',
|
toLabel: '{{ 'to'|_|escape }}',
|
||||||
ranges: {{ dpRanges|json_encode|raw }}
|
ranges: {{ picker.ranges|json_encode|raw }}
|
||||||
};
|
};
|
||||||
|
|
||||||
var language = "{{ language|escape }}";
|
var language = "{{ language|escape }}";
|
||||||
|
Loading…
Reference in New Issue
Block a user