Skip to content

Commit 2006a71

Browse files
committed
Added date fields in URL search
1 parent c402aee commit 2006a71

3 files changed

Lines changed: 35 additions & 15 deletions

File tree

src/Controllers/TicketsController.php

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -795,9 +795,13 @@ public function search_form($parameters = null)
795795
// Add param value pair into search_fields array
796796
$search_fields[$key] = $param;
797797

798-
}elseif(in_array($key, $a_text_params)){
798+
}elseif(in_array($key, $a_text_params) or in_array($key, $this->a_search_fields_date)){
799799
// Decode strings in URL
800800
$search_fields[$key] = urldecode($param);
801+
802+
}elseif(in_array(str_replace('_type', '', $key), $this->a_search_fields_date)){
803+
// Get date field related type
804+
$search_fields[$key] = $param;
801805
}
802806

803807
// key reset to look for a new parameter
@@ -812,7 +816,14 @@ public function search_form($parameters = null)
812816
}
813817
}
814818

815-
if (isset($search_fields)){
819+
foreach($this->a_search_fields_date as $field){
820+
if(isset($search_fields[$field]) and !isset($search_fields[$field . '_type'])){
821+
// Unset date field if it's type is not specified
822+
unset($search_fields[$field]);
823+
}
824+
}
825+
826+
if (isset($search_fields) and $search_fields){
816827
// Store search fields in session to use in datatable
817828
session(compact('search_fields'));
818829

@@ -840,6 +851,8 @@ public function search_form_defaults()
840851

841852
$priorities = $this->getCacheList('priorities');
842853

854+
$a_date_additional_types = ['until', 'exact_year', 'exact_month', 'exact_day'];
855+
843856
$a_categories = $this->member->findOrFail(auth()->user()->id)->getEditTicketCategories();
844857

845858
$c_visible_agents = Member::visible()->get();
@@ -856,7 +869,7 @@ public function search_form_defaults()
856869
])
857870
->select('id', 'name')->get();
858871

859-
$data = compact('c_members', 'c_status', 'priorities', 'a_categories', 'c_visible_agents', 'c_cat_tags');
872+
$data = compact('c_members', 'c_status', 'priorities', 'a_date_additional_types', 'a_categories', 'c_visible_agents', 'c_cat_tags');
860873

861874
if (Setting::grab('departments_feature')){
862875
$data['c_departments'] = Department::whereNull('department_id')->with('descendants.ancestor')->orderBy('name', 'asc')->get();

src/Views/tickets/partials/form_scripts.blade.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
format: '{{ trans('panichd::lang.datetimepicker-format') }}',
88
@if (isset($ticket) && $a_current['start_date'] != "")
99
defaultDate: "{{ $a_current['start_date'] }}",
10+
11+
@elseif(isset($search_fields['start_date']))
12+
defaultDate: "{{ $search_fields['start_date'] }}",
1013
@endif
1114
keyBinds: { 'delete':null, 'left':null, 'right':null }
1215
});
@@ -17,6 +20,9 @@
1720
format: '{{ trans('panichd::lang.datetimepicker-format') }}',
1821
@if (isset($ticket) && $a_current['limit_date'] != "")
1922
defaultDate: "{{ $a_current['limit_date'] }}",
23+
24+
@elseif(isset($search_fields['limit_date']))
25+
defaultDate: "{{ $search_fields['limit_date'] }}",
2026
@endif
2127
keyBinds: { 'delete':null, 'left':null, 'right':null },
2228
useCurrent: false

src/Views/tickets/search/form.blade.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,10 @@
132132
</span>
133133
</div>
134134
<div class="form-text">
135-
<label><input type="radio" name="start_date_type" value="from" checked="checked"> {{ trans('panichd::lang.searchform-date-type-from') }}</label>
136-
<label class="ml-2"><input type="radio" name="start_date_type" value="until"> {{ trans('panichd::lang.searchform-date-type-until') }}</label>
137-
<label class="ml-2"><input type="radio" name="start_date_type" value="exact_day"> {{ trans('panichd::lang.searchform-date-type-exact_day') }}</label>
135+
<label><input type="radio" name="start_date_type" value="from" @if(!isset($search_fields['start_date_type']) || $search_fields['start_date_type'] == 'from') checked="checked" @endif> {{ trans('panichd::lang.searchform-date-type-from') }}</label>
136+
@foreach($a_date_additional_types as $type)
137+
<label class="ml-2"><input type="radio" name="start_date_type" value="{{ $type }}" @if(isset($search_fields['start_date_type']) && $search_fields['start_date_type'] == $type) checked="checked" @endif> {{ trans('panichd::lang.searchform-date-type-' . $type) }}</label>
138+
@endforeach
138139
</div>
139140
</div>
140141
</div>
@@ -150,9 +151,10 @@
150151
</span>
151152
</div>
152153
<div class="form-text">
153-
<label><input type="radio" name="limit_date_type" value="from" checked="checked"> {{ trans('panichd::lang.searchform-date-type-from') }}</label>
154-
<label class="ml-2"><input type="radio" name="limit_date_type" value="until"> {{ trans('panichd::lang.searchform-date-type-until') }}</label>
155-
<label class="ml-2"><input type="radio" name="limit_date_type" value="exact_day"> {{ trans('panichd::lang.searchform-date-type-exact_day') }}</label>
154+
<label><input type="radio" name="limit_date_type" value="from" @if(!isset($search_fields['limit_date_type']) || $search_fields['limit_date_type'] == 'from') checked="checked" @endif> {{ trans('panichd::lang.searchform-date-type-from') }}</label>
155+
@foreach($a_date_additional_types as $type)
156+
<label class="ml-2"><input type="radio" name="limit_date_type" value="{{ $type }}" @if(isset($search_fields['limit_date_type']) && $search_fields['limit_date_type'] == $type) checked="checked" @endif> {{ trans('panichd::lang.searchform-date-type-' . $type) }}</label>
157+
@endforeach
156158
</div>
157159
</div>
158160
</div>
@@ -239,18 +241,17 @@
239241
{!! CollectiveForm::label($date_field, trans('panichd::lang.searchform-' . $date_field) . trans('panichd::lang.colon'), ['class' => 'col-lg-3 col-form-label']) !!}
240242
<div class="col-lg-9">
241243
<div class="input-group date" id="{{ $date_field }}">
242-
<input type="text" class="form-control" name="{{ $date_field }}" value=""/>
244+
<input type="text" class="form-control" name="{{ $date_field }}" value="{{ $search_fields[$date_field] ?? '' }}"/>
243245
<span class="input-group-addon" style="display: none"></span>
244246
<span class="input-group-append">
245247
<button class="btn btn-light btn-default"><span class="fa fa-calendar"></span></button>
246248
</span>
247249
</div>
248250
<div class="form-text">
249-
<label><input type="radio" name="{{ $date_field }}_type" value="from" checked="checked"> {{ trans('panichd::lang.searchform-date-type-from') }}</label>
250-
<label class="ml-2"><input type="radio" name="{{ $date_field }}_type" value="until"> {{ trans('panichd::lang.searchform-date-type-until') }}</label>
251-
<label class="ml-2"><input type="radio" name="{{ $date_field }}_type" value="exact_year"> {{ trans('panichd::lang.searchform-date-type-exact_year') }}</label>
252-
<label class="ml-2"><input type="radio" name="{{ $date_field }}_type" value="exact_month"> {{ trans('panichd::lang.searchform-date-type-exact_month') }}</label>
253-
<label class="ml-2"><input type="radio" name="{{ $date_field }}_type" value="exact_day"> {{ trans('panichd::lang.searchform-date-type-exact_day') }}</label>
251+
<label><input type="radio" name="{{ $date_field }}_type" value="from" @if(!isset($search_fields[$date_field . '_type']) || $search_fields[$date_field . '_type'] == 'from') checked="checked" @endif> {{ trans('panichd::lang.searchform-date-type-from') }}</label>
252+
@foreach($a_date_additional_types as $type)
253+
<label class="ml-2"><input type="radio" name="{{ $date_field }}_type" value="{{ $type }}" @if(isset($search_fields[$date_field . '_type']) && $search_fields[$date_field . '_type'] == $type) checked="checked" @endif> {{ trans('panichd::lang.searchform-date-type-' . $type) }}</label>
254+
@endforeach
254255
</div>
255256
</div>
256257
</div>

0 commit comments

Comments
 (0)