mirror of
https://github.com/snipe/snipe-it.git
synced 2025-03-05 20:52:15 -08:00
Allow saving custom reports
This commit is contained in:
parent
e636d7b9d5
commit
c3b53b28e3
|
@ -397,9 +397,7 @@ class ReportsController extends Controller
|
|||
return view('reports/custom', [
|
||||
'customfields' => $customfields,
|
||||
'saved_reports' => $saved_reports,
|
||||
// @todo: temporary
|
||||
'savedReport' => $saved_reports->find($request->input('report')),
|
||||
// 'savedReport' => new SavedReport,
|
||||
'savedReport' => $saved_reports->find($request->input('report')) ?? new SavedReport,
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,21 +2,17 @@
|
|||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\SavedReport;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SavedReportsController extends Controller
|
||||
{
|
||||
public function store(Request $request)
|
||||
{
|
||||
// @todo: make this dynamic
|
||||
$savedReport = SavedReport::first();
|
||||
$report = $request->user()->savedReports()->create([
|
||||
'name' => $request->get('report_name'),
|
||||
'options' => $request->except(['_token', 'report_name']),
|
||||
]);
|
||||
|
||||
$savedReport->options = $request->except('_token');
|
||||
|
||||
$savedReport->save();
|
||||
|
||||
// @todo: redirect back with the saved report pre-populated?
|
||||
return redirect()->back();
|
||||
return redirect()->route('reports/custom', ['report' => $report->id]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,8 @@ class SavedReport extends Model
|
|||
'options',
|
||||
];
|
||||
|
||||
// @todo: add $rules
|
||||
|
||||
//we will need a bit to catch and store the name of the report.
|
||||
//for now the blip above is creating the name, but can be confusing if multiple are made at once
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
|
|||
use Illuminate\Contracts\Translation\HasLocalePreference;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\Access\Authorizable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
@ -329,6 +330,11 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
|||
return $this->belongsToMany(\App\Models\License::class, 'license_seats', 'assigned_to', 'license_id')->withPivot('id');
|
||||
}
|
||||
|
||||
public function savedReports(): HasMany
|
||||
{
|
||||
return $this->hasMany(SavedReport::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes a count of all items assigned
|
||||
*
|
||||
|
|
|
@ -371,14 +371,11 @@
|
|||
{{ trans('general.generate') }}
|
||||
</button>
|
||||
</div>
|
||||
<div style=padding-bottom:5px>
|
||||
<a href="#" class="btn btn-primary" style="width: 100%">
|
||||
{{ trans('admin/reports/general.apply_and_generate') }}</a>
|
||||
</div>
|
||||
<div style=padding-bottom:5px>
|
||||
<form method="post" id="savetemplateform" action="{{ route("savedreports/store") }}">
|
||||
@csrf
|
||||
<input type="hidden" id="savetemplateform" name="options">
|
||||
<input type="text" id="report_name" name="report_name">
|
||||
{{-- this will be a box to name the report? --}}
|
||||
<button class = "btn btn-primary" style="width: 100%">
|
||||
{{ trans('admin/reports/general.save_template') }}
|
||||
|
@ -391,13 +388,30 @@
|
|||
{{-- <strong class="caret"></strong>--}}
|
||||
{{-- </a>--}}
|
||||
{{-- {!! Form::select('brand', array('1'=>'Text','2'=>'Logo','3'=>'Logo + Text'), old('brand', $setting->brand), array('class' => 'form-control select2', 'style'=>'width: 150px ;')) !!}--}}
|
||||
<select class="form-control select2">
|
||||
<select
|
||||
id="saved_report_select"
|
||||
class="form-control select2"
|
||||
data-placeholder="Load Saved Report"
|
||||
data-allow-clear="true"
|
||||
>
|
||||
<option></option>
|
||||
@foreach($saved_reports as $report)
|
||||
<option>
|
||||
<option value="{{ $report->id }}" @if (request()->input('report') == $report->id) selected @endif>
|
||||
{{ $report->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
@push('js')
|
||||
<script>
|
||||
$('#saved_report_select')
|
||||
.on('select2:select', function (event) {
|
||||
window.location.href = '{{ route('reports/custom') }}?report=' + event.params.data.id;
|
||||
})
|
||||
.on('select2:clearing', function (event) {
|
||||
window.location.href = '{{ route('reports/custom') }}';
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -445,7 +459,17 @@
|
|||
|
||||
$("#savetemplateform").submit(function(e) {
|
||||
e.preventDefault(e);
|
||||
$('#custom-report-form').attr('action', '/reports/savedtemplate').submit()
|
||||
|
||||
let form = $('#custom-report-form');
|
||||
|
||||
$('<input>').attr({
|
||||
type: 'hidden',
|
||||
name: 'report_name',
|
||||
value: $('#report_name').val(),
|
||||
}).appendTo(form);
|
||||
|
||||
form.attr('action', '/reports/savedtemplate').submit();
|
||||
|
||||
// let elements = Array.from(document.getElementById("custom-report-form").elements).map(item=>item.name);
|
||||
// console.log(elements);
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue