Skip to content

A free open source IT asset/license management system

Merge save/update flow

snipe910092a24505
diff --git a/app/Http/Controllers/ReportTemplatesController.php b/app/Http/Controllers/ReportTemplatesController.php
index a0f393e80d..ba59e5a9cc 100644
--- a/app/Http/Controllers/ReportTemplatesController.php
+++ b/app/Http/Controllers/ReportTemplatesController.php
@@ -56,26 +56,7 @@ class ReportTemplatesController extends Controller
public function edit(ReportTemplate $reportTemplate)
{
- $this->authorize('reports.view');
-
- if ($reportTemplate->created_by != auth()->id()) {
- return redirect()
- ->route('report-templates.show', $reportTemplate)
- ->withError(trans('general.report_not_editable'));
- }
-
- 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,
- ]);
+ return redirect()->route('report-templates.show', $reportTemplate);
}
public function update(Request $request, ReportTemplate $reportTemplate): RedirectResponse
diff --git a/resources/views/reports/custom/asset.blade.php b/resources/views/reports/custom/asset.blade.php
index e5548c6c4a..f382db72a5 100644
--- a/resources/views/reports/custom/asset.blade.php
+++ b/resources/views/reports/custom/asset.blade.php
@@ -2,9 +2,7 @@
{{-- Page Title --}}
@section('title')
- @if (request()->routeIs('report-templates.edit'))
- {{ trans('general.update') }} {{ $template->name }}
- @elseif(request()->routeIs('report-templates.show'))
+ @if ($template->exists)
{{ trans('general.custom_report') }}: {{ $template->name }}
@else
{{ trans('general.custom_report') }}
@@ -13,11 +11,7 @@
@stop
@section('header_right')
- @if (request()->routeIs('report-templates.edit'))
- <a href="{{ route('report-templates.show', $template) }}" class="btn btn-primary pull-right">
- {{ trans('general.back') }}
- </a>
- @elseif (request()->routeIs('report-templates.show'))
+ @if ($template->exists)
<a href="{{ route('reports/custom') }}" class="btn btn-primary pull-right">
{{ trans('general.back') }}
</a>
@@ -35,9 +29,13 @@
<div class="row">
<div class="col-md-9">
+ {{-- Form action is always post-custom (download the report). The
+ sidebar Save button overrides this via formaction so it POSTs
+ to report-templates.update instead, letting the user save
+ config changes without downloading. --}}
<form
method="POST"
- action="{{ request()->routeIs('report-templates.edit') ? route('report-templates.update', $template) : route('reports.post-custom') }}"
+ action="{{ route('reports.post-custom') }}"
accept-charset="UTF-8"
class="form-horizontal"
id="custom-report-form"
@@ -48,7 +46,7 @@
<div class="box box-default">
<div class="box-header with-border">
<h2 class="box-title" style="padding-top: 7px;">
- @if (request()->routeIs('report-templates.edit'))
+ @if ($template->exists)
{{ trans('general.customize_report') }}: {{ $template->name }}
@else
{{ trans('general.customize_report') }}
@@ -327,71 +325,69 @@
<br>
- @include ('partials.forms.edit.company-select', [
- 'translated_name' => trans('general.company'),
- 'fieldname' =>
- 'by_company_id[]',
- 'multiple' => 'true',
- 'hide_new' => 'true',
- 'selected' => $template->selectValues('by_company_id', \App\Models\Company::class),
- ])
- @include ('partials.forms.edit.location-select', [
- 'translated_name' => trans('general.location'),
- 'fieldname' => 'by_location_id[]',
- 'multiple' => 'true',
- 'hide_new' => 'true',
- 'selected' => $template->selectValues('by_location_id', \App\Models\Location::class),
- ])
- @include ('partials.forms.edit.location-select', [
- 'translated_name' => trans('admin/hardware/form.default_location'),
- 'fieldname' => 'by_rtd_location_id[]',
- 'multiple' => 'true',
- 'hide_new' => 'true',
- 'selected' => $template->selectValues('by_rtd_location_id', \App\Models\Location::class),
- ])
- @include ('partials.forms.edit.department-select',[
- 'translated_name' => trans('general.department'),
- 'fieldname' => 'by_dept_id[]',
- 'multiple' => 'true',
- 'hide_new' => 'true',
- 'selected' => $template->selectValues('by_dept_id', \App\Models\Department::class),
- ])
- @include ('partials.forms.edit.supplier-select', [
- 'translated_name' => trans('general.supplier'),
- 'fieldname' => 'by_supplier_id[]',
- 'multiple' => 'true',
- 'hide_new' => 'true',
- 'selected' => $template->selectValues('by_supplier_id', \App\Models\Supplier::class),
- ])
- @include ('partials.forms.edit.model-select', [
- 'translated_name' => trans('general.asset_model'),
- 'fieldname' => 'by_model_id[]',
- 'multiple' => 'true',
- 'hide_new' => 'true',
- 'selected' => $template->selectValues('by_model_id', \App\Models\AssetModel::class),
- ])
- @include ('partials.forms.edit.manufacturer-select', [
- 'translated_name' => trans('general.manufacturer'),
- 'fieldname' => 'by_manufacturer_id[]',
- 'multiple' => 'true',
- 'hide_new' => 'true',
- 'selected' => $template->selectValues('by_manufacturer_id', \App\Models\Manufacturer::class),
- ])
- @include ('partials.forms.edit.category-select', [
- 'translated_name' => trans('general.category'),
- 'fieldname' => 'by_category_id[]',
- 'multiple' => 'true',
- 'hide_new' => 'true',
- 'category_type' => 'asset',
- 'selected' => $template->selectValues('by_category_id', \App\Models\Category::class),
- ])
- @include ('partials.forms.edit.status-select', [
- 'translated_name' => trans('admin/hardware/form.status'),
- 'fieldname' => 'by_status_id[]',
- 'multiple' => 'true',
- 'hide_new' => 'true',
- 'selected' => $template->selectValues('by_status_id', \App\Models\Statuslabel::class),
- ])
+ <x-input.select2-checkboxes
+ name="by_company_id"
+ :label="trans('general.company')"
+ endpoint="companies"
+ :selected="$template->selectValues('by_company_id', \App\Models\Company::class)"
+ :modelClass="\App\Models\Company::class"
+ />
+ <x-input.select2-checkboxes
+ name="by_location_id"
+ :label="trans('general.location')"
+ endpoint="locations"
+ :selected="$template->selectValues('by_location_id', \App\Models\Location::class)"
+ :modelClass="\App\Models\Location::class"
+ />
+ <x-input.select2-checkboxes
+ name="by_rtd_location_id"
+ :label="trans('admin/hardware/form.default_location')"
+ endpoint="locations"
+ :selected="$template->selectValues('by_rtd_location_id', \App\Models\Location::class)"
+ :modelClass="\App\Models\Location::class"
+ />
+ <x-input.select2-checkboxes
+ name="by_dept_id"
+ :label="trans('general.department')"
+ endpoint="departments"
+ :selected="$template->selectValues('by_dept_id', \App\Models\Department::class)"
+ :modelClass="\App\Models\Department::class"
+ />
+ <x-input.select2-checkboxes
+ name="by_supplier_id"
+ :label="trans('general.supplier')"
+ endpoint="suppliers"
+ :selected="$template->selectValues('by_supplier_id', \App\Models\Supplier::class)"
+ :modelClass="\App\Models\Supplier::class"
+ />
+ <x-input.select2-checkboxes
+ name="by_model_id"
+ :label="trans('general.asset_model')"
+ endpoint="models"
+ :selected="$template->selectValues('by_model_id', \App\Models\AssetModel::class)"
+ :modelClass="\App\Models\AssetModel::class"
+ />
+ <x-input.select2-checkboxes
+ name="by_manufacturer_id"
+ :label="trans('general.manufacturer')"
+ endpoint="manufacturers"
+ :selected="$template->selectValues('by_manufacturer_id', \App\Models\Manufacturer::class)"
+ :modelClass="\App\Models\Manufacturer::class"
+ />
+ <x-input.select2-checkboxes
+ name="by_category_id"
+ :label="trans('general.category')"
+ endpoint="categories/asset"
+ :selected="$template->selectValues('by_category_id', \App\Models\Category::class)"
+ :modelClass="\App\Models\Category::class"
+ />
+ <x-input.select2-checkboxes
+ name="by_status_id"
+ :label="trans('admin/hardware/form.status')"
+ endpoint="statuslabels"
+ :selected="$template->selectValues('by_status_id', \App\Models\Statuslabel::class)"
+ :modelClass="\App\Models\Statuslabel::class"
+ />
<!-- Order Number -->
<div class="form-group">
@@ -712,17 +708,12 @@
</div>
</div> <!-- /.box-body-->
- @unless (request()->routeIs('report-templates.edit'))
- {{-- See consumable blade for the edit-mode footer rationale
- (sidebar Save is the affordance there; download button
- belongs to preview). --}}
- <div class="box-footer text-right">
- <button type="submit" class="btn btn-success">
- <i class="fas fa-download icon-white" aria-hidden="true"></i>
- {{ trans('general.download') }}
- </button>
- </div>
- @endunless
+ <div class="box-footer text-right">
+ <button type="submit" class="btn btn-success">
+ <i class="fas fa-download icon-white" aria-hidden="true"></i>
+ {{ trans('general.download') }}
+ </button>
+ </div>
</div> <!--/.box.box-default-->
</form>
</div>
diff --git a/resources/views/reports/custom/component.blade.php b/resources/views/reports/custom/component.blade.php
index c0bad6252f..df97bc5598 100644
--- a/resources/views/reports/custom/component.blade.php
+++ b/resources/views/reports/custom/component.blade.php
@@ -2,9 +2,7 @@
{{-- Page Title --}}
@section('title')
- @if (request()->routeIs('report-templates.edit'))
- {{ trans('general.update') }} {{ $template->name }}
- @elseif(request()->routeIs('report-templates.show'))
+ @if ($template->exists)
{{ trans('general.custom_component_report') }}: {{ $template->name }}
@else
{{ trans('general.custom_component_report') }}
@@ -13,11 +11,7 @@
@stop
@section('header_right')
- @if (request()->routeIs('report-templates.edit'))
- <a href="{{ route('report-templates.show', $template) }}" class="btn btn-primary pull-right">
- {{ trans('general.back') }}
- </a>
- @elseif (request()->routeIs('report-templates.show'))
+ @if ($template->exists)
<a href="{{ route('reports/custom') }}" class="btn btn-primary pull-right">
{{ trans('general.back') }}
</a>
@@ -35,9 +29,12 @@
<div class="row">
<div class="col-md-9">
+ {{-- Form action is always custom.component.run (download). The
+ sidebar Save button overrides this via formaction so it
+ POSTs to report-templates.update instead. --}}
<form
method="POST"
- action="{{ request()->routeIs('report-templates.edit') ? route('report-templates.update', $template) : route('reports.custom.component.run') }}"
+ action="{{ route('reports.custom.component.run') }}"
accept-charset="UTF-8"
class="form-horizontal"
id="custom-report-form"
@@ -48,7 +45,7 @@
<div class="box box-default">
<div class="box-header with-border">
<h2 class="box-title" style="padding-top: 7px;">
- @if (request()->routeIs('report-templates.edit'))
+ @if ($template->exists)
{{ trans('general.customize_report') }}: {{ $template->name }}
@else
{{ trans('general.customize_report') }}
@@ -417,17 +414,12 @@
</div>
</div> <!-- /.box-body-->
- @unless (request()->routeIs('report-templates.edit'))
- {{-- See consumable blade for the edit-mode footer
- rationale (sidebar Save is the affordance
- there; download button belongs to preview). --}}
- <div class="box-footer text-right">
- <button type="submit" class="btn btn-success">
- <i class="fas fa-download icon-white" aria-hidden="true"></i>
- {{ trans('general.download') }}
- </button>
- </div>
- @endunless
+ <div class="box-footer text-right">
+ <button type="submit" class="btn btn-success">
+ <i class="fas fa-download icon-white" aria-hidden="true"></i>
+ {{ trans('general.download') }}
+ </button>
+ </div>
</div> <!--/.box.box-default-->
</form>
</div>
diff --git a/resources/views/reports/custom/consumable.blade.php b/resources/views/reports/custom/consumable.blade.php
index 3673fcbac1..850f9b5ecd 100644
--- a/resources/views/reports/custom/consumable.blade.php
+++ b/resources/views/reports/custom/consumable.blade.php
@@ -2,9 +2,7 @@
{{-- Page Title --}}
@section('title')
- @if (request()->routeIs('report-templates.edit'))
- {{ trans('general.update') }} {{ $template->name }}
- @elseif(request()->routeIs('report-templates.show'))
+ @if ($template->exists)
{{ trans('general.custom_consumable_report') }}: {{ $template->name }}
@else
{{ trans('general.custom_consumable_report') }}
@@ -13,11 +11,7 @@
@stop
@section('header_right')
- @if (request()->routeIs('report-templates.edit'))
- <a href="{{ route('report-templates.show', $template) }}" class="btn btn-primary pull-right">
- {{ trans('general.back') }}
- </a>
- @elseif (request()->routeIs('report-templates.show'))
+ @if ($template->exists)
<a href="{{ route('reports/custom') }}" class="btn btn-primary pull-right">
{{ trans('general.back') }}
</a>
@@ -35,9 +29,12 @@
<x-container columns="2">
<x-page-column class="col-md-9">
+ {{-- Form action is always custom.consumable.run (download). The
+ sidebar Save button overrides this via formaction so it
+ POSTs to report-templates.update instead. --}}
<form
method="POST"
- action="{{ request()->routeIs('report-templates.edit') ? route('report-templates.update', $template) : route('reports.custom.consumable.run') }}"
+ action="{{ route('reports.custom.consumable.run') }}"
accept-charset="UTF-8"
class="form-horizontal"
id="custom-report-form"
@@ -47,7 +44,7 @@
<div class="box box-default">
<div class="box-header with-border">
<h2 class="box-title" style="padding-top: 7px;">
- @if (request()->routeIs('report-templates.edit'))
+ @if ($template->exists)
{{ trans('general.customize_report') }}: {{ $template->name }}
@else
{{ trans('general.customize_report') }}
@@ -413,18 +410,12 @@
</div>
</div> <!-- /.box-body-->
- @unless (request()->routeIs('report-templates.edit'))
- {{-- In edit mode the sidebar Save button is the
- affordance for persisting template changes;
- the "Generate" download button here only
- makes sense on the config / preview page. --}}
- <div class="box-footer text-right">
- <button type="submit" class="btn btn-success">
- <i class="fas fa-download icon-white" aria-hidden="true"></i>
- {{ trans('general.download') }}
- </button>
- </div>
- @endunless
+ <div class="box-footer text-right">
+ <button type="submit" class="btn btn-success">
+ <i class="fas fa-download icon-white" aria-hidden="true"></i>
+ {{ trans('general.download') }}
+ </button>
+ </div>
</div> <!--/.box.box-default-->
</form>
</x-page-column>