mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-09 23:15:45 -06:00
Allow report options to be pulled using AJAX. Ajax is cool.
This commit is contained in:
parent
f0e0cdb49b
commit
fe57648349
@ -23,6 +23,7 @@ use FireflyIII\Models\Transaction;
|
||||
use FireflyIII\Repositories\Account\AccountRepositoryInterface;
|
||||
use Illuminate\Support\Collection;
|
||||
use Preferences;
|
||||
use Response;
|
||||
use Session;
|
||||
use Steam;
|
||||
use View;
|
||||
@ -85,6 +86,23 @@ class ReportController extends Controller
|
||||
return view('reports.index', compact('months', 'accounts', 'start', 'accountList', 'customFiscalYear'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $reportType
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function options(string $reportType)
|
||||
{
|
||||
$result = false;
|
||||
switch ($reportType) {
|
||||
default:
|
||||
$result = $this->noReportOptions();
|
||||
break;
|
||||
}
|
||||
|
||||
return Response::json($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $reportType
|
||||
* @param Carbon $start
|
||||
@ -292,4 +310,12 @@ class ReportController extends Controller
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
private function noReportOptions(): array
|
||||
{
|
||||
return ['html' => view('reports.options.no-options')->render()];
|
||||
}
|
||||
}
|
||||
|
@ -44,9 +44,24 @@ $(function () {
|
||||
|
||||
$('.date-select').on('click', preSelectDate);
|
||||
$('#report-form').on('submit', catchSubmit);
|
||||
$('select[name="report_type"]').on('change', getReportOptions);
|
||||
getReportOptions();
|
||||
|
||||
});
|
||||
|
||||
function getReportOptions() {
|
||||
"use strict";
|
||||
var reportType = $('select[name="report_type"]').val();
|
||||
$('#extra-options').empty();
|
||||
$('#extra-options').addClass('loading');
|
||||
console.log('Changed report type to ' + reportType);
|
||||
$.getJSON('reports/options/' + reportType, function(data) {
|
||||
$('#extra-options').removeClass('loading').html(data.html);
|
||||
}).fail(function(){
|
||||
$('#extra-options').removeClass('loading').addClass('error');
|
||||
});
|
||||
}
|
||||
|
||||
function catchSubmit() {
|
||||
"use strict";
|
||||
// default;20141201;20141231;4;5
|
||||
|
@ -26,6 +26,7 @@
|
||||
<select name="report_type" class="form-control" id="inputReportType">
|
||||
<option selected label="{{ 'report_type_default'|_ }}" value="default">{{ 'report_type_default'|_ }}</option>
|
||||
<option label="{{ 'report_type_audit'|_ }}" value="audit">{{ 'report_type_audit'|_ }}</option>
|
||||
<option label="{{ 'report_type_category'|_ }}" value="category">{{ 'report_type_category'|_ }}</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@ -86,10 +87,7 @@
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'reports_extra_options'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<p id="no_extra_options">
|
||||
<em>{{ 'report_has_no_extra_options'|_ }}</em>
|
||||
</p>
|
||||
<div class="box-body loading" id="extra-options">
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
3
resources/views/reports/options/no-options.twig
Normal file
3
resources/views/reports/options/no-options.twig
Normal file
@ -0,0 +1,3 @@
|
||||
<p id="no_extra_options">
|
||||
<em>{{ 'report_has_no_extra_options'|_ }}</em>
|
||||
</p>
|
@ -308,6 +308,7 @@ Route::group(
|
||||
*/
|
||||
Route::get('/reports', ['uses' => 'ReportController@index', 'as' => 'reports.index']);
|
||||
Route::get('/reports/report/{reportType}/{start_date}/{end_date}/{accountList}', ['uses' => 'ReportController@report', 'as' => 'reports.report']);
|
||||
Route::get('/reports/options/{reportType}', ['uses' => 'ReportController@options', 'as' => 'reports.options']);
|
||||
|
||||
/**
|
||||
* Report AJAX data Controller:
|
||||
|
Loading…
Reference in New Issue
Block a user