Merge branch 'saved-custom-reports' into saving_custom_report_template

This commit is contained in:
Marcus Moore 2023-11-30 18:15:35 -08:00
commit 327d27591f
No known key found for this signature in database
14 changed files with 388 additions and 91 deletions

View file

@ -394,7 +394,13 @@ class ReportsController extends Controller
$customfields = CustomField::get();
$saved_reports = SavedReport::get();
return view('reports/custom')->with('customfields', $customfields)->with('saved_reports', $saved_reports);
return view('reports/custom', [
'customfields' => $customfields,
'saved_reports' => $saved_reports,
// @todo: temporary
'savedReport' => $saved_reports->first(),
// 'savedReport' => new SavedReport,
]);
}
/**
@ -407,6 +413,7 @@ class ReportsController extends Controller
*/
public function postCustom(Request $request)
{
dd('postCustom', $request->all());
ini_set('max_execution_time', env('REPORT_TIME_LIMIT', 12000)); //12000 seconds = 200 minutes
$this->authorize('reports.view');

View file

@ -2,17 +2,21 @@
namespace App\Http\Controllers;
use App\Models\SavedReport;
use Illuminate\Http\Request;
class SavedReportsController extends Controller
{
//a method to the madness
public function store(Request $request)
{
// @todo: make this dynamic
$savedReport = SavedReport::first();
$savedReport->options = $request->except('_token');
dd($request->all());
$savedReport->save();
// @todo: redirect back with the saved report pre-populated?
return redirect()->back();
}
}

View file

@ -23,4 +23,59 @@ class SavedReport extends Model
'name',
'options',
];
public function checkmarkValue($property): string
{
// Assuming we're using the null object pattern,
// return the default value if the object is not saved yet.
if (is_null($this->id)) {
return '1';
}
// Return the property's value if it exists
// and return the default value if not.
return $this->options[$property] ?? '0';
}
public function radioValue($property, $value, $return)
{
// @todo: this method feels more like "radioShouldBeChecked" or something...
if (array_has($this->options, $property) && $this->options[$property] === $value) {
return $return;
}
return null;
}
public function selectValue($property)
{
return $this->options[$property] ?? null;
}
public function selectValues($property)
{
if (!isset($this->options[$property])) {
return null;
}
if ($this->options[$property] === [null]) {
return null;
}
return $this->options[$property];
}
public function textValue($property): string
{
// Assuming we're using the null object pattern,
// return the default value if the object is not saved yet.
if (is_null($this->id)) {
return '';
}
// Return the property's value if it exists
// and return the default value if not.
return $this->options[$property] ?? '';
}
}

View file

@ -0,0 +1,21 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
class SavedReportFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->word(),
'options' => json_encode([]),
];
}
}

View file

@ -5,6 +5,18 @@
<div class="col-md-7{{ (isset($item) && (Helper::checkIfRequired($item, $fieldname))) ? ' required' : '' }}">
<select class="js-data-ajax" data-endpoint="categories/{{ (isset($category_type)) ? $category_type : 'assets' }}" data-placeholder="{{ trans('general.select_category') }}" name="{{ $fieldname }}" style="width: 100%" id="category_select_id" aria-label="{{ $fieldname }}" {!! ((isset($item)) && (Helper::checkIfRequired($item, $fieldname))) ? ' data-validation="required" required' : '' !!}{{ (isset($multiple) && ($multiple=='true')) ? " multiple='multiple'" : '' }}>
@isset ($selected)
@if (!is_array($selected))
@php
$selected = [$selected];
@endphp
@endif
@foreach ($selected as $category_id)
<option value="{{ $category_id }}" selected="selected" role="option" aria-selected="true" role="option">
{{ \App\Models\Category::find($category_id)->name }}
</option>
@endforeach
@endisset
@if ($category_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $category_id }}" selected="selected" role="option" aria-selected="true" role="option">
{{ (\App\Models\Category::find($category_id)) ? \App\Models\Category::find($category_id)->name : '' }}

View file

@ -22,6 +22,13 @@
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
<div class="col-md-6">
<select class="js-data-ajax" data-endpoint="companies" data-placeholder="{{ trans('general.select_company') }}" name="{{ $fieldname }}" style="width: 100%" id="company_select"{{ (isset($multiple) && ($multiple=='true')) ? " multiple='multiple'" : '' }}>
@isset ($selected)
@foreach ($selected as $company_id)
<option value="{{ $company_id }}" selected="selected" role="option" aria-selected="true">
{{ \App\Models\Company::find($company_id)->name }}
</option>
@endforeach
@endisset
@if ($company_id = Request::old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $company_id }}" selected="selected">
{{ (\App\Models\Company::find($company_id)) ? \App\Models\Company::find($company_id)->name : '' }}

View file

@ -4,6 +4,18 @@
<div class="col-md-6">
<select class="js-data-ajax" data-endpoint="departments" data-placeholder="{{ trans('general.select_department') }}" name="{{ $fieldname }}" style="width: 100%" id="department_select" aria-label="{{ $fieldname }}"{{ (isset($multiple) && ($multiple=='true')) ? " multiple='multiple'" : '' }}>
@isset ($selected)
@if (!is_array($selected))
@php
$selected = [$selected];
@endphp
@endif
@foreach ($selected as $department_id)
<option value="{{ $department_id }}" selected="selected" role="option" aria-selected="true">
{{ \App\Models\Department::find($department_id)->name }}
</option>
@endforeach
@endisset
@if ($department_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $department_id }}" selected="selected" role="option" aria-selected="true" role="option">
{{ (\App\Models\Department::find($department_id)) ? \App\Models\Department::find($department_id)->name : '' }}

View file

@ -4,6 +4,13 @@
{{ Form::label($fieldname, $translated_name, array('class' => 'col-md-3 control-label')) }}
<div class="col-md-7{{ ((isset($required) && ($required =='true'))) ? ' required' : '' }}">
<select class="js-data-ajax" data-endpoint="locations" data-placeholder="{{ trans('general.select_location') }}" name="{{ $fieldname }}" style="width: 100%" id="{{ $fieldname }}_location_select" aria-label="{{ $fieldname }}" {!! ((isset($item)) && (Helper::checkIfRequired($item, $fieldname))) ? ' data-validation="required" required' : '' !!}{{ (isset($multiple) && ($multiple=='true')) ? " multiple='multiple'" : '' }}>
@isset($selected)
@foreach($selected as $location_id)
<option value="{{ $location_id }}" selected="selected" role="option" aria-selected="true" role="option">
{{ (\App\Models\Location::find($location_id))->name }}
</option>
@endforeach
@endisset
@if ($location_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $location_id }}" selected="selected" role="option" aria-selected="true" role="option">
{{ (\App\Models\Location::find($location_id)) ? \App\Models\Location::find($location_id)->name : '' }}

View file

@ -5,6 +5,18 @@
<div class="col-md-7{{ ((isset($required)) && ($required=='true')) ? ' required' : '' }}">
<select class="js-data-ajax" data-endpoint="manufacturers" data-placeholder="{{ trans('general.select_manufacturer') }}" name="{{ $fieldname }}" style="width: 100%" id="manufacturer_select_id" aria-label="{{ $fieldname }}" {!! ((isset($item)) && (Helper::checkIfRequired($item, $fieldname))) ? ' data-validation="required" required' : '' !!}{{ (isset($multiple) && ($multiple=='true')) ? " multiple='multiple'" : '' }}>
@isset ($selected)
@if (!is_array($selected))
@php
$selected = [$selected];
@endphp
@endif
@foreach ($selected as $manufacturer_id)
<option value="{{ $manufacturer_id }}" selected="selected" role="option" aria-selected="true" role="option">
{{ \App\Models\Manufacturer::find($manufacturer_id)->name }}
</option>
@endforeach
@endisset
@if ($manufacturer_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $manufacturer_id }}" selected="selected" role="option" aria-selected="true" role="option">
{{ (\App\Models\Manufacturer::find($manufacturer_id)) ? \App\Models\Manufacturer::find($manufacturer_id)->name : '' }}

View file

@ -5,6 +5,18 @@
<div class="col-md-7{{ ((isset($field_req)) || ((isset($required) && ($required =='true')))) ? ' required' : '' }}">
<select class="js-data-ajax" data-endpoint="models" data-placeholder="{{ trans('general.select_model') }}" name="{{ $fieldname }}" style="width: 100%" id="model_select_id" aria-label="{{ $fieldname }}"{!! (isset($field_req) ? ' data-validation="required" required' : '') !!}{{ (isset($multiple) && ($multiple=='true')) ? " multiple='multiple'" : '' }}>
@isset ($selected)
@if (!is_array($selected))
@php
$selected = [$selected];
@endphp
@endif
@foreach ($selected as $model_id)
<option value="{{ $model_id }}" selected="selected" role="option" aria-selected="true">
{{ \App\Models\AssetModel::find($model_id)->name }}
</option>
@endforeach
@endisset
@if ($model_id = old($fieldname, ($item->{$fieldname} ?? request($fieldname) ?? '')))
<option value="{{ $model_id }}" selected="selected">
{{ (\App\Models\AssetModel::find($model_id)) ? \App\Models\AssetModel::find($model_id)->name : '' }}

View file

@ -5,6 +5,13 @@
<div class="col-md-7{{ ((isset($required)) && ($required=='true')) ? ' required' : '' }}">
<select class="js-data-ajax" data-endpoint="statuslabels" data-placeholder="{{ trans('general.select_statuslabel') }}" name="{{ $fieldname }}" style="width: 100%" id="status_select_id" aria-label="{{ $fieldname }}" {!! ((isset($item)) && (Helper::checkIfRequired($item, $fieldname))) ? ' data-validation="required" required' : '' !!}{{ (isset($multiple) && ($multiple=='true')) ? " multiple='multiple'" : '' }}>
@isset ($selected)
@foreach ($selected as $status_id)
<option value="{{ $status_id }}" selected="selected" role="option" aria-selected="true">
{{ \App\Models\Statuslabel::find($status_id)->name }}
</option>
@endforeach
@endisset
@if ($status_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $status_id }}" selected="selected" role="option" aria-selected="true" role="option">
{{ (\App\Models\Statuslabel::find($status_id)) ? \App\Models\Statuslabel::find($status_id)->name : '' }}

View file

@ -4,6 +4,13 @@
<div class="col-md-7{{ (isset($item) && (Helper::checkIfRequired($item, $fieldname))) ? ' required' : '' }}">
<select class="js-data-ajax" data-endpoint="suppliers" data-placeholder="{{ trans('general.select_supplier') }}" name="{{ $fieldname }}" style="width: 100%" id="supplier_select" aria-label="{{ $fieldname }}"{{ (isset($multiple) && ($multiple=='true')) ? " multiple='multiple'" : '' }}>
@isset ($selected)
@foreach ($selected as $supplier_id)
<option value="{{ $supplier_id }}" selected="selected" role="option" aria-selected="true">
{{ \App\Models\Supplier::find($supplier_id)->name }}
</option>
@endforeach
@endisset
@if ($supplier_id = old($fieldname, (isset($item)) ? $item->{$fieldname} : ''))
<option value="{{ $supplier_id }}" selected="selected" role="option" aria-selected="true" role="option">
{{ (\App\Models\Supplier::find($supplier_id)) ? \App\Models\Supplier::find($supplier_id)->name : '' }}

View file

@ -14,9 +14,14 @@
@section('content')
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="col-md-8 col-md-offset-1">
{{ Form::open(['method' => 'post', 'class' => 'form-horizontal', 'id' => 'custom-report-form']) }}
{{ Form::open([
'method' => 'post',
'class' => 'form-horizontal',
'id' => 'custom-report-form',
'url' => '/reports/custom',
]) }}
{{csrf_field()}}
<!-- Horizontal Form -->
@ -35,147 +40,147 @@
</label>
<label class="form-control">
{{ Form::checkbox('id', '1', '1') }}
{{ Form::checkbox('id', '1', $savedReport->checkmarkValue('id')) }}
{{ trans('general.id') }}
</label>
<label class="form-control">
{{ Form::checkbox('company', '1', '1') }}
{{ Form::checkbox('company', '1', $savedReport->checkmarkValue('company')) }}
{{ trans('general.company') }}
</label>
<label class="form-control">
{{ Form::checkbox('asset_tag', '1', '1') }}
{{ Form::checkbox('asset_tag', '1', $savedReport->checkmarkValue('asset_tag')) }}
{{ trans('general.asset_tag') }}
</label>
<label class="form-control">
{{ Form::checkbox('asset_name', '1', '1') }}
{{ Form::checkbox('asset_name', '1', $savedReport->checkmarkValue('asset_name')) }}
{{ trans('admin/hardware/form.name') }}
</label>
<label class="form-control">
{{ Form::checkbox('manufacturer', '1', '1') }}
{{ Form::checkbox('manufacturer', '1', $savedReport->checkmarkValue('manufacturer')) }}
{{ trans('general.manufacturer') }}
</label>
<label class="form-control">
{{ Form::checkbox('model', '1', '1') }}
{{ Form::checkbox('model', '1', $savedReport->checkmarkValue('model')) }}
{{ trans('general.asset_models') }}
</label>
<label class="form-control">
{{ Form::checkbox('category', '1', '1') }}
{{ Form::checkbox('category', '1', $savedReport->checkmarkValue('category')) }}
{{ trans('general.category') }}
</label>
<label class="form-control">
{{ Form::checkbox('serial', '1', '1') }}
{{ Form::checkbox('serial', '1', $savedReport->checkmarkValue('serial')) }}
{{ trans('admin/hardware/table.serial') }}
</label>
<label class="form-control">
{{ Form::checkbox('purchase_date', '1', '1') }}
{{ Form::checkbox('purchase_date', '1', $savedReport->checkmarkValue('purchase_date')) }}
{{ trans('admin/licenses/table.purchase_date') }}
</label>
<label class="form-control">
{{ Form::checkbox('purchase_cost', '1', '1') }}
{{ Form::checkbox('purchase_cost', '1', $savedReport->checkmarkValue('purchase_cost')) }}
{{ trans('admin/hardware/form.cost') }}
</label>
<label class="form-control">
{{ Form::checkbox('eol', '1', '1') }}
{{ Form::checkbox('eol', '1', $savedReport->checkmarkValue('eol')) }}
{{ trans('admin/hardware/table.eol') }}
</label>
<label class="form-control">
{{ Form::checkbox('order', '1', '1') }}
{{ Form::checkbox('order', '1', $savedReport->checkmarkValue('order')) }}
{{ trans('admin/hardware/form.order') }}
</label>
<label class="form-control">
{{ Form::checkbox('supplier', '1', '1') }}
{{ Form::checkbox('supplier', '1', $savedReport->checkmarkValue('supplier')) }}
{{ trans('general.suppliers') }}
</label>
<label class="form-control">
{{ Form::checkbox('location', '1', '1') }}
{{ Form::checkbox('location', '1', $savedReport->checkmarkValue('location')) }}
{{ trans('general.location') }}
</label>
<label class="form-control">
{{ Form::checkbox('location_address', '1', '1') }}
{{ Form::checkbox('location_address', '1', $savedReport->checkmarkValue('location_address')) }}
- {{ trans('general.address') }}
</label>
<label class="form-control">
{{ Form::checkbox('rtd_location', '1', '1') }}
{{ Form::checkbox('rtd_location', '1', $savedReport->checkmarkValue('rtd_location')) }}
{{ trans('admin/hardware/form.default_location') }}
</label>
<label class="form-control">
{{ Form::checkbox('rtd_location_address', '1', '1') }}
{{ Form::checkbox('rtd_location_address', '1', $savedReport->checkmarkValue('rtd_location_address')) }}
- {{ trans('general.address') }}
</label>
<label class="form-control">
{{ Form::checkbox('status', '1', '1') }}
{{ Form::checkbox('status', '1', $savedReport->checkmarkValue('status')) }}
{{ trans('general.status') }}
</label>
<label class="form-control">
{{ Form::checkbox('warranty', '1', '1') }}
{{ Form::checkbox('warranty', '1', $savedReport->checkmarkValue('warranty')) }}
{{ trans('admin/hardware/form.warranty') }}
</label>
<label class="form-control">
{{ Form::checkbox('depreciation', '1', '1') }}
{{ Form::checkbox('depreciation', '1', $savedReport->checkmarkValue('depreciation')) }}
{{ trans('general.depreciation') }}
</label>
<label class="form-control">
{{ Form::checkbox('checkout_date', '1', '1') }}
{{ Form::checkbox('checkout_date', '1', $savedReport->checkmarkValue('checkout_date')) }}
{{ trans('admin/hardware/table.checkout_date') }}
</label>
<label class="form-control">
{{ Form::checkbox('expected_checkin', '1', '1') }}
{{ Form::checkbox('expected_checkin', '1', $savedReport->checkmarkValue('expected_checkin')) }}
{{ trans('admin/hardware/form.expected_checkin') }}
</label>
<label class="form-control">
{{ Form::checkbox('created_at', '1', '1') }}
{{ Form::checkbox('created_at', '1', $savedReport->checkmarkValue('created_at')) }}
{{ trans('general.created_at') }}
</label>
<label class="form-control">
{{ Form::checkbox('updated_at', '1', '1') }}
{{ Form::checkbox('updated_at', '1', $savedReport->checkmarkValue('updated_at')) }}
{{ trans('general.updated_at') }}
</label>
<label class="form-control">
{{ Form::checkbox('deleted_at', '1', '1') }}
{{ Form::checkbox('deleted_at', '1', $savedReport->checkmarkValue('deleted_at')) }}
{{ trans('general.deleted') }}
</label>
<label class="form-control">
{{ Form::checkbox('last_audit_date', '1', '1') }}
{{ Form::checkbox('last_audit_date', '1', $savedReport->checkmarkValue('last_audit_date')) }}
{{ trans('general.last_audit') }}
</label>
<label class="form-control">
{{ Form::checkbox('next_audit_date', '1', '1') }}
{{ Form::checkbox('next_audit_date', '1', $savedReport->checkmarkValue('next_audit_date')) }}
{{ trans('general.next_audit_date') }}
</label>
<label class="form-control">
{{ Form::checkbox('notes', '1', '1') }}
{{ Form::checkbox('notes', '1', $savedReport->checkmarkValue('notes')) }}
{{ trans('general.notes') }}
</label>
<label class="form-control">
{{ Form::checkbox('url', '1', '1') }}
{{ Form::checkbox('url', '1', $savedReport->checkmarkValue('url')) }}
- {{ trans('admin/manufacturers/table.url') }}
</label>
@ -185,32 +190,32 @@
<h2>{{ trans('general.checked_out_to') }} {{ trans('general.fields') }}:</h2>
<label class="form-control">
{{ Form::checkbox('assigned_to', '1', '1') }}
{{ Form::checkbox('assigned_to', '1', $savedReport->checkmarkValue('assigned_to')) }}
{{ trans('admin/licenses/table.assigned_to') }}
</label>
<label class="form-control">
{{ Form::checkbox('username', '1', '1') }}
{{ Form::checkbox('username', '1', $savedReport->checkmarkValue('username')) }}
{{ trans('admin/users/table.username') }}
</label>
<label class="form-control">
{{ Form::checkbox('employee_num', '1', '1') }}
{{ Form::checkbox('employee_num', '1', $savedReport->checkmarkValue('employee_num')) }}
{{ trans('general.employee_number') }}
</label>
<label class="form-control">
{{ Form::checkbox('manager', '1', '1') }}
{{ Form::checkbox('manager', '1', $savedReport->checkmarkValue('manager')) }}
{{ trans('admin/users/table.manager') }}
</label>
<label class="form-control">
{{ Form::checkbox('department', '1', '1') }}
{{ Form::checkbox('department', '1', $savedReport->checkmarkValue('department')) }}
{{ trans('general.department') }}
</label>
<label class="form-control">
{{ Form::checkbox('title', '1', '1') }}
{{ Form::checkbox('title', '1', $savedReport->checkmarkValue('title')) }}
{{ trans('admin/users/table.title') }}
</label>
@ -223,7 +228,7 @@
@foreach ($customfields as $customfield)
<label class="form-control">
{{ Form::checkbox($customfield->db_column_name(), '1', '1') }}
{{ Form::checkbox($customfield->db_column_name(), '1', $savedReport->checkmarkValue($customfield->db_column_name())) }}
{{ $customfield->name }}
</label>
@ -239,21 +244,21 @@
<br>
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'),'multiple' => 'true', 'fieldname' => 'by_company_id[]', 'hide_new' => 'true'])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'multiple' => 'true', 'fieldname' => 'by_location_id[]', 'hide_new' => 'true'])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.default_location'), 'multiple' => 'true', 'fieldname' => 'by_rtd_location_id[]', 'hide_new' => 'true'])
@include ('partials.forms.edit.department-select', ['translated_name' => trans('general.department'), 'fieldname' => 'by_dept_id', 'hide_new' => 'true'])
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'by_supplier_id[]', 'multiple' => 'true', 'hide_new' => 'true'])
@include ('partials.forms.edit.model-select', ['translated_name' => trans('general.asset_model'), 'fieldname' => 'by_model_id[]', 'multiple' => 'true', 'hide_new' => 'true'])
@include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'by_manufacturer_id', 'hide_new' => 'true'])
@include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'by_category_id', 'hide_new' => 'true', 'category_type' => 'asset'])
@include ('partials.forms.edit.status-select', ['translated_name' => trans('admin/hardware/form.status'), 'fieldname' => 'by_status_id[]', 'multiple' => 'true', 'hide_new' => 'true'])
@include ('partials.forms.edit.company-select', ['translated_name' => trans('general.company'),'multiple' => 'true', 'fieldname' => 'by_company_id[]', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_company_id')])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('general.location'), 'multiple' => 'true', 'fieldname' => 'by_location_id[]', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_location_id')])
@include ('partials.forms.edit.location-select', ['translated_name' => trans('admin/hardware/form.default_location'), 'multiple' => 'true', 'fieldname' => 'by_rtd_location_id[]', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_rtd_location_id')])
@include ('partials.forms.edit.department-select', ['translated_name' => trans('general.department'), 'fieldname' => 'by_dept_id', 'hide_new' => 'true', 'selected' => $savedReport->selectValue('by_dept_id')])
@include ('partials.forms.edit.supplier-select', ['translated_name' => trans('general.supplier'), 'fieldname' => 'by_supplier_id[]', 'multiple' => 'true', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_supplier_id')])
@include ('partials.forms.edit.model-select', ['translated_name' => trans('general.asset_model'), 'fieldname' => 'by_model_id[]', 'multiple' => 'true', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_model_id')])
@include ('partials.forms.edit.manufacturer-select', ['translated_name' => trans('general.manufacturer'), 'fieldname' => 'by_manufacturer_id', 'hide_new' => 'true', 'selected' => $savedReport->selectValue('by_manufacturer_id')])
@include ('partials.forms.edit.category-select', ['translated_name' => trans('general.category'), 'fieldname' => 'by_category_id', 'hide_new' => 'true', 'category_type' => 'asset', 'selected' => $savedReport->selectValue('by_category_id')])
@include ('partials.forms.edit.status-select', ['translated_name' => trans('admin/hardware/form.status'), 'fieldname' => 'by_status_id[]', 'multiple' => 'true', 'hide_new' => 'true', 'selected' => $savedReport->selectValues('by_status_id')])
<!-- Order Number -->
<div class="form-group">
<label for="by_order_number" class="col-md-3 control-label">{{ trans('general.order_number') }}</label>
<div class="col-md-5 col-sm-8">
<input class="form-control" type="text" name="by_order_number" value="" aria-label="by_order_number">
<input class="form-control" type="text" name="by_order_number" value="{{ $savedReport->textValue('by_order_number') }}" aria-label="by_order_number">
</div>
</div>
@ -261,9 +266,9 @@
<div class="form-group purchase-range">
<label for="purchase_start" class="col-md-3 control-label">{{ trans('general.purchase_date') }} {{ trans('general.range') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="purchase_start" aria-label="purchase_start">
<input type="text" class="form-control" name="purchase_start" aria-label="purchase_start" value="{{ $savedReport->textValue('purchase_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="purchase_end" aria-label="purchase_end">
<input type="text" class="form-control" name="purchase_end" aria-label="purchase_end" value="{{ $savedReport->textValue('purchase_end') }}">
</div>
</div>
@ -271,9 +276,9 @@
<div class="form-group purchase-range">
<label for="created_start" class="col-md-3 control-label">{{ trans('general.created_at') }} {{ trans('general.range') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="created_start" aria-label="created_start">
<input type="text" class="form-control" name="created_start" aria-label="created_start" value="{{ $savedReport->textValue('created_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="created_end" aria-label="created_end">
<input type="text" class="form-control" name="created_end" aria-label="created_end" value="{{ $savedReport->textValue('created_end') }}">
</div>
</div>
@ -281,9 +286,9 @@
<div class="form-group checkout-range">
<label for="checkout_date" class="col-md-3 control-label">{{ trans('general.checkout') }} {{ trans('general.range') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="checkout_date_start" aria-label="checkout_date_start">
<input type="text" class="form-control" name="checkout_date_start" aria-label="checkout_date_start" value="{{ $savedReport->textValue('checkout_date_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="checkout_date_end" aria-label="checkout_date_end">
<input type="text" class="form-control" name="checkout_date_end" aria-label="checkout_date_end" value="{{ $savedReport->textValue('checkout_date_end') }}">
</div>
</div>
@ -291,9 +296,9 @@
<div class="form-group expected_checkin-range">
<label for="expected_checkin_start" class="col-md-3 control-label">{{ trans('admin/hardware/form.expected_checkin') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="expected_checkin_start" aria-label="expected_checkin_start">
<input type="text" class="form-control" name="expected_checkin_start" aria-label="expected_checkin_start" value="{{ $savedReport->textValue('expected_checkin_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="expected_checkin_end" aria-label="expected_checkin_end">
<input type="text" class="form-control" name="expected_checkin_end" aria-label="expected_checkin_end" value="{{ $savedReport->textValue('expected_checkin_end') }}">
</div>
</div>
@ -301,9 +306,9 @@
<div class="form-group last_audit-range">
<label for="last_audit_start" class="col-md-3 control-label">{{ trans('general.last_audit') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="last_audit_start" aria-label="last_audit_start">
<input type="text" class="form-control" name="last_audit_start" aria-label="last_audit_start" value="{{ $savedReport->textValue('last_audit_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="last_audit_end" aria-label="last_audit_end">
<input type="text" class="form-control" name="last_audit_end" aria-label="last_audit_end" value="{{ $savedReport->textValue('last_audit_end') }}">
</div>
</div>
@ -311,37 +316,36 @@
<div class="form-group next_audit-range">
<label for="next_audit_start" class="col-md-3 control-label">{{ trans('general.next_audit_date') }}</label>
<div class="input-daterange input-group col-md-6" id="datepicker">
<input type="text" class="form-control" name="next_audit_start" aria-label="nex_audit_start">
<input type="text" class="form-control" name="next_audit_start" aria-label="nex_audit_start" value="{{ $savedReport->textValue('next_audit_start') }}">
<span class="input-group-addon">to</span>
<input type="text" class="form-control" name="next_audit_end" aria-label="next_audit_end">
<input type="text" class="form-control" name="next_audit_end" aria-label="next_audit_end" value="{{ $savedReport->textValue('next_audit_end') }}">
</div>
</div>
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
{{ Form::checkbox('exclude_archived', '1', old('exclude_archived')) }}
{{ Form::checkbox('exclude_archived', '1', $savedReport->checkmarkValue('exclude_archived')) }}
{{ trans('general.exclude_archived') }}
</label>
</div>
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
{{ Form::checkbox('use_bom', '1', old('use_bom')) }}
{{ Form::checkbox('use_bom', '1', $savedReport->checkmarkValue('use_bom')) }}
{{ trans('general.bom_remark') }}
</label>
</div>
<div class="col-md-9 col-md-offset-3">
<label class="form-control">
{{ Form::radio('deleted_assets', '', true, ['aria-label'=>'deleted_assets', 'id'=>'deleted_assets_exclude_deleted'])}}
{{ Form::radio('deleted_assets', '', $savedReport->radioValue('deleted_assets', null, true), ['aria-label'=>'deleted_assets', 'id'=>'deleted_assets_exclude_deleted'])}}
{{ trans('general.exclude_deleted') }}
</label>
<label class="form-control">
{{ Form::radio('deleted_assets', '1', old('deleted_assets'), ['aria-label'=>'deleted_assets', 'id'=>'deleted_assets_include_deleted']) }}
{{ Form::radio('deleted_assets', '1', $savedReport->radioValue('deleted_assets', '1', '1'), ['aria-label'=>'deleted_assets', 'id'=>'deleted_assets_include_deleted']) }}
{{ trans('general.include_deleted') }}
</label>
<label class="form-control">
{{ Form::radio('deleted_assets', '0', old('deleted_assets'), ['aria-label'=>'deleted_assets','id'=>'deleted_assets_only_deleted']) }}
{{ Form::radio('deleted_assets', '0', $savedReport->radioValue('deleted_assets', '0', '1'), ['aria-label'=>'deleted_assets','id'=>'deleted_assets_only_deleted']) }}
{{ trans('general.only_deleted') }}
</label>
</div>
@ -449,27 +453,28 @@
$("#savetemplateform").submit(function(e) {
e.preventDefault(e);
let elements = Array.from(document.getElementById("custom-report-form").elements).map(item=>item.name);
console.log(elements);
$("#savetemplateoptions").val(elements)
let formElement = document.getElementById('custom-report-form')
let inputsAsArray = Array.from(formElement.elements)
inputsAsArray.map(function(item){
// not a real method
if (item.isACheckbox()){
return {name: item.name, type: checkbox, checked: item.checked};
}
if (item.isASelect){
return {name:item.name, type: select, selected: [item.elements]}
}
})
// set hidden input to variable
e.currentTarget.submit();
$('#custom-report-form').attr('action', '/reports/savedtemplate').submit()
// let elements = Array.from(document.getElementById("custom-report-form").elements).map(item=>item.name);
// console.log(elements);
//
// $("#savetemplateoptions").val(elements)
//
// let formElement = document.getElementById('custom-report-form')
//
// let inputsAsArray = Array.from(formElement.elements)
//
// inputsAsArray.map(function(item){
// // not a real method
// if (item.isACheckbox()){
// return {name: item.name, type: checkbox, checked: item.checked};
// }
//
// if (item.isASelect){
// return {name:item.name, type: select, selected: [item.elements]}
// }
// })
// // set hidden input to variable
// e.currentTarget.submit();
});
</script>

View file

@ -0,0 +1,129 @@
<?php
namespace Tests\Unit;
use App\Models\SavedReport;
use Tests\TestCase;
class SavedReportTest extends TestCase
{
public function testParsingCheckmarkValue()
{
$savedReport = SavedReport::factory()->create([
'options' => [
'is_a_checkbox_field' => '1',
],
]);
$this->assertEquals('1', $savedReport->checkmarkValue('is_a_checkbox_field'));
$this->assertEquals('0', $savedReport->checkmarkValue('non_existent_key'));
$this->assertEquals('1', (new SavedReport)->checkmarkValue('is_a_checkbox_field'));
}
public function testParsingTextValue()
{
$savedReport = SavedReport::factory()->create([
'options' => [
'is_a_text_field' => 'some text',
],
]);
$this->assertEquals('some text', $savedReport->textValue('is_a_text_field'));
$this->assertEquals('', $savedReport->textValue('non_existent_key'));
$this->assertEquals('', (new SavedReport)->textValue('is_a_text_field'));
}
public function testParsingRadioValue()
{
$savedReport = SavedReport::factory()->create([
'options' => [
'is_a_radio_field' => null,
],
]);
$this->assertEquals('return_value', $savedReport->radioValue('is_a_radio_field', null, 'return_value'));
$this->assertEquals(null, $savedReport->radioValue('is_a_radio_field', 'another_value', 'return_value'));
$this->assertNull($savedReport->radioValue('non_existent_key', '1', true));
}
public function testParsingSelectValue()
{
$savedReport = SavedReport::factory()->create([
'options' => [
'is_a_text_field_as_well' => '4',
'contains_a_null_value' => null,
],
]);
$this->assertEquals('4', $savedReport->selectValue('is_a_text_field_as_well'));
$this->assertEquals('', $savedReport->selectValue('non_existent_key'));
$this->assertNull($savedReport->selectValue('contains_a_null_value'));
}
public function testParsingSelectValues()
{
$savedReport = SavedReport::factory()->create([
'options' => [
'is_an_array' => ['2', '3', '4'],
'is_an_array_containing_null' => [null],
],
]);
$this->assertEquals(['2', '3', '4'], $savedReport->selectValues('is_an_array'));
$this->assertEquals(null, $savedReport->selectValues('non_existent_key'));
$this->assertNull($savedReport->selectValues('is_an_array_containing_null'));
}
public function testSelectValueDoesNotIncludeDeletedOrNonExistentModels()
{
$this->markTestIncomplete();
// @todo: maybe it should optionally include deleted values?
}
public function testSelectValuesDoNotIncludeDeletedOrNonExistentModels()
{
$this->markTestIncomplete();
// report saved with select option for a company (or whatever)
// company is deleted
// ensure company's id is not returned
}
public function testDeletedCustomFieldsDoNotCauseAnIssue()
{
$this->markTestIncomplete();
}
public function testDateRangesAreNotStored()
{
$this->markTestIncomplete();
// This might not be a test we implement, but it's a place to ask a question:
// Should we be saving and restoring date ranges?
// A use-case I can see is running a report at the end of the month for the date ranges for that month.
// Maybe it's better to leave those off so users are gently prompted to enter the ranges for each run?
// Another option would be to have checkbox that asks the user if they would like to save the dates?
// I'm not sure how helpful that is, and it would probably be a future feature if implemented.
}
public function testSavedReportHasDefaultValuesSet()
{
$this->markTestIncomplete();
// Quick thought: I think deleted_assets should be set to null so that
// "Exclude Deleted Assets" is selected when using a new'd up SavedReport.
}
public function testOldValuesStillWorkAfterTheseChanges()
{
$this->markTestIncomplete();
// Another marker that won't actually be a test case:
// We need to make sure that any behavior involving using "old" input.
// I explicitly removed the old()s from the "deleted_assets" radio buttons.
// The "x-selects" partials still include them, but I haven't tested them yet.
}
}