Use dedicated show route for report templates

This commit is contained in:
Marcus Moore 2023-12-20 14:01:46 -08:00
parent c35179b098
commit 26cc4497eb
No known key found for this signature in database
4 changed files with 25 additions and 3 deletions

View file

@ -29,6 +29,27 @@ class ReportTemplatesController extends Controller
return redirect()->route('reports/custom', ['report' => $report->id]);
}
public function show(Request $request, $reportId)
{
$this->authorize('reports.view');
$reportTemplate = ReportTemplate::find($reportId);
if (!$reportTemplate) {
return redirect()->route('reports/custom')
->with('error', 'Template does not exist or you do not have permission to view it.');
}
$customfields = CustomField::get();
$report_templates = ReportTemplate::orderBy('name')->get();
return view('reports/custom', [
'customfields' => $customfields,
'report_templates' => $report_templates,
'reportTemplate' => $reportTemplate,
]);
}
public function edit(Request $request, $reportId)
{
$report = ReportTemplate::findOrFail($reportId);

View file

@ -397,7 +397,7 @@ class ReportsController extends Controller
return view('reports/custom', [
'customfields' => $customfields,
'report_templates' => $report_templates,
'reportTemplate' => $report_templates->find($request->input('report')) ?? new ReportTemplate,
'reportTemplate' => new ReportTemplate,
]);
}

View file

@ -429,7 +429,7 @@
>
<option></option>
@foreach($report_templates as $template)
<option value="{{ $template->id }}" @if (request()->input('report') == $template->id) selected @endif>
<option value="{{ $template->id }}" @if (request()->route()->parameter('reportId') == $template->id) selected @endif>
{{ $template->name }}
</option>
@endforeach
@ -439,7 +439,7 @@
<script>
$('#saved_report_select')
.on('select2:select', function (event) {
window.location.href = '{{ route('reports/custom') }}?report=' + event.params.data.id;
window.location.href = '/reports/saved-templates/' + event.params.data.id;
})
.on('select2:clearing', function (event) {
window.location.href = '{{ route('reports/custom') }}';

View file

@ -358,6 +358,7 @@ Route::group(['middleware' => ['auth']], function () {
Route::get('reports/custom', [ReportsController::class, 'getCustomReport'])->name('reports/custom');
Route::post('reports/custom', [ReportsController::class, 'postCustom']);
Route::post('reports/saved-templates', [ReportTemplatesController::class, 'store'])->name('report-templates.store');
Route::get('reports/saved-templates/{reportId}', [ReportTemplatesController::class, 'show'])->name('report-templates.show');
Route::get('reports/saved-templates/{reportId}/edit', [ReportTemplatesController::class, 'edit'])->name('report-templates.edit');
Route::post('report/saved-templates/{reportId}', [ReportTemplatesController::class, 'update'])->name('report-templates.update');