3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-08-18 03:06:23 +00:00

Fix some page headings

This commit is contained in:
Marcus Moore
2026-06-04 13:34:38 -07:00
parent 5f1c459318
commit 86ace3a1d5
4 changed files with 54 additions and 12 deletions

View File

@ -7,6 +7,7 @@ use App\Models\ReportTemplate;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use UnhandledMatchError;
class ReportTemplatesController extends Controller
{
@ -36,7 +37,15 @@ class ReportTemplatesController extends Controller
$customfields = CustomField::get();
$report_templates = ReportTemplate::orderBy('name')->get();
return view('reports.custom.asset', [
try {
$view = $reportTemplate->getViewPath();
} catch (UnhandledMatchError $e) {
return redirect()
->route('reports.index')
->with('error', 'Saved template type is not valid.');
}
return view($view, [
'customfields' => $customfields,
'report_templates' => $report_templates,
'template' => $reportTemplate,
@ -53,7 +62,15 @@ class ReportTemplatesController extends Controller
->withError(trans('general.report_not_editable'));
}
return view('reports.custom.asset', [
try {
$view = $reportTemplate->getViewPath();
} catch (UnhandledMatchError $e) {
return redirect()
->route('reports.index')
->with('error', 'Saved template type is not valid.');
}
return view($view, [
'customfields' => CustomField::get(),
'template' => $reportTemplate,
]);

View File

@ -8,6 +8,7 @@ use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use UnhandledMatchError;
use Watson\Validating\ValidatingTrait;
class ReportTemplate extends Model
@ -202,4 +203,15 @@ class ReportTemplate extends Model
{
return $this->name;
}
/**
* @throws UnhandledMatchError
*/
public function getViewPath(): string
{
return match ($this->type) {
'asset' => 'reports.custom.asset',
'component' => 'reports.custom.component',
};
}
}

View File

@ -627,10 +627,9 @@
form.attr('action', '{{ route('report-templates.store') }}').submit();
});
// $('#saved_report_select')
// .on('select2:select', function (event) {
// window.location.href = event.params.data.element.dataset.route;
// });
$('#saved_report_select').on('select2:select', function (event) {
window.location.href = event.params.data.element.dataset.route;
});
</script>
@stop

View File

@ -552,15 +552,29 @@ Route::group(['prefix' => 'reports', 'middleware' => ['auth']], function () {
// The breadcrumb on this is a little odd for now since we don't have a template index
Route::get('/{reportTemplate}', [ReportTemplatesController::class, 'show'])
->name('report-templates.show')
->breadcrumbs(fn (Trail $trail, ReportTemplate $reportTemplate) => $trail->parent('reports/custom')
->push($reportTemplate->name, null)
->push(trans('general.customize_report'), ''));
->breadcrumbs(function (Trail $trail, ReportTemplate $reportTemplate) {
$parent = match ($reportTemplate->type) {
'asset' => 'reports/custom',
'component' => 'reports.custom.component',
};
return $trail->parent($parent)
->push($reportTemplate->name, null)
->push(trans('general.customize_report'), '');
});
Route::get('/{reportTemplate}/edit', [ReportTemplatesController::class, 'edit'])
->name('report-templates.edit')
->breadcrumbs(fn (Trail $trail, ReportTemplate $reportTemplate) => $trail->parent('reports/custom')
->push($reportTemplate->name, route('report-templates.show', $reportTemplate))
->push(trans('general.customize_report'), ''));
->breadcrumbs(function (Trail $trail, ReportTemplate $reportTemplate) {
$parent = match ($reportTemplate->type) {
'asset' => 'reports/custom',
'component' => 'reports.custom.component',
};
return $trail->parent($parent)
->push($reportTemplate->name, route('report-templates.show', $reportTemplate))
->push(trans('general.customize_report'), '');
});
Route::post('/{reportTemplate}', [ReportTemplatesController::class, 'update'])
->name('report-templates.update');