- {{ 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()}}
@@ -35,147 +40,147 @@
@@ -185,32 +190,32 @@
{{ trans('general.checked_out_to') }} {{ trans('general.fields') }}:
@@ -223,7 +228,7 @@
@foreach ($customfields as $customfield)
@@ -239,21 +244,21 @@
- @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')])
@@ -261,9 +266,9 @@
@@ -271,9 +276,9 @@
@@ -281,9 +286,9 @@
@@ -291,9 +296,9 @@
@@ -301,9 +306,9 @@
@@ -311,37 +316,36 @@
-
@@ -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();
});
diff --git a/tests/Unit/SavedReportTest.php b/tests/Unit/SavedReportTest.php
new file mode 100644
index 0000000000..b447b0d452
--- /dev/null
+++ b/tests/Unit/SavedReportTest.php
@@ -0,0 +1,129 @@
+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.
+ }
+}