From a9ab2e61a0f6a6a86ac001cc5bde8265e380c492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Fri, 6 Nov 2020 22:34:53 +0300 Subject: [PATCH] refs search filter files.. --- app/View/Components/SearchString.php | 86 ++++++++++++- .../assets/js/components/AkauntingSearch.vue | 117 +++++++++++++++--- resources/lang/en-GB/general.php | 10 +- .../views/components/search-string.blade.php | 9 +- 4 files changed, 195 insertions(+), 27 deletions(-) diff --git a/app/View/Components/SearchString.php b/app/View/Components/SearchString.php index d7969ad06..cfedd9190 100644 --- a/app/View/Components/SearchString.php +++ b/app/View/Components/SearchString.php @@ -30,12 +30,13 @@ class SearchString extends Component { $searc_string = config('search-string'); - $this->filters = false; + $this->filters = []; if (!empty($searc_string[$this->model])) { $columns = $searc_string[$this->model]['columns']; foreach ($columns as $column => $options) { + // This column skip for filter if (!empty($options['searchable'])) { continue; } @@ -43,13 +44,13 @@ class SearchString extends Component if (!is_array($options)) { $column = $options; } - - $name = $this->getFilterName($column); $this->filters[] = [ - 'key' => $column, - 'value' => $name, - 'url' => !empty($options['route']) ? route($options['route'][0], $options['route'][1]) : '' + 'key' => $this->getFilterKey($column, $options), + 'value' => $this->getFilterName($column), + 'type' => $this->getFilterType($options), + 'url' => $this->getFilterUrl($column, $options), + 'values' => $this->getFilterValues($options), ]; } } @@ -57,6 +58,15 @@ class SearchString extends Component return view('components.search-string'); } + protected function getFilterKey($column, $options) + { + if (isset($options['relationship'])) { + $column .= '.id'; + } + + return $column; + } + protected function getFilterName($column) { if (strpos($column, '_id') !== false) { @@ -79,4 +89,68 @@ class SearchString extends Component return $name; } + + protected function getFilterType($options) + { + $type = 'select'; + + if (isset($options['boolean'])) { + $type = 'boolean'; + } + + return $type; + } + + protected function getFilterUrl($column, $options) + { + $url = ''; + + if (isset($options['boolean'])) { + return $url; + } + + if (!empty($options['route'])) { + if (is_array($options['route'])) { + $url = route($options['route'][0], $options['route'][1]); + } else { + $url = route($options['route']); + } + } else { + if (strpos($this->model, 'Modules') !== false) { + $module_class = explode('\\', $this->model); + + $url .= Str::slug($module_class[1], '-') . '::'; + } + + if (strpos($column, '_id') !== false) { + $column = str_replace('_id', '', $column); + } + + $plural = Str::plural($column, 2); + + $url = route($url . $plural . '.index'); + } + + return $url; + } + + protected function getFilterValues($options) + { + $values = []; + + if (isset($options['boolean'])) { + $values = [ + [ + 'key' => 0, + 'value' => trans('general.no'), + ], + [ + 'key' => 1, + 'value' => trans('general.yes'), + ], + ]; + } + + return $values; + } } diff --git a/resources/assets/js/components/AkauntingSearch.vue b/resources/assets/js/components/AkauntingSearch.vue index 238c34490..ed3f893d6 100644 --- a/resources/assets/js/components/AkauntingSearch.vue +++ b/resources/assets/js/components/AkauntingSearch.vue @@ -36,16 +36,16 @@ @@ -53,6 +53,9 @@ + @@ -68,11 +71,31 @@ export default { default: 'Search or filter results...', description: 'Input placeholder' }, - textSearch: { + searchText: { type: String, default: 'Search for this text', description: 'Input placeholder' }, + operatorIsText: { + type: String, + default: 'is', + description: 'Operator is "="' + }, + operatorIsNotText: { + type: String, + default: 'is not', + description: 'Operator is not "!="' + }, + noDataText: { + type: String, + default: 'No Data', + description: "Selectbox empty options message" + }, + noMatchingDataText: { + type: String, + default: 'No Matchign Data', + description: "Selectbox search option not found item message" + }, value: { type: String, default: null, @@ -113,6 +136,10 @@ export default { methods: { onInputFocus() { + if (!this.filters.length) { + return; + } + this.visible[this.filter_last_step] = true; this.$nextTick(() => { @@ -122,6 +149,31 @@ export default { onInput(evt) { this.search = evt.target.value; + + let option_url = this.selected_options[this.filter_index].url; + + if (this.search) { + option_url += '?search=' + this.search; + } + + window.axios.get(option_url) + .then(response => { + this.values = []; + + let data = response.data.data; + + data.forEach(function (item) { + this.values.push({ + key: item.id, + value: item.name + }); + }, this); + + this.option_values[value] = this.values; + }) + .catch(error => { + + }); this.$emit('input', evt.target.value); }, @@ -138,17 +190,17 @@ export default { args += '?search='; } - args += this.selected_options[index].key + ':' + this.selected_values[index].key; + args += this.selected_options[index].key + ':' + this.selected_values[index].key + ' '; }, this); - window.location = url + '/common/items' + args; + window.location = window.location.href.replace(window.location.search, '') + args; }, onOptionSelected(value) { this.current_value = value; let option = false; - let option_url = url + ''; + let option_url = url; for (let i = 0; i < this.filter_list.length; i++) { if (this.filter_list[i].key == value) { @@ -158,6 +210,10 @@ export default { option_url = this.filter_list[i].url; } + if (typeof this.filter_list[i].type !== 'undefined' && this.filter_list[i].type == 'boolean') { + this.option_values[value] = this.filter_list[i].values; + } + this.selected_options.push(this.filter_list[i]); this.filter_list.splice(i, 1); break; @@ -190,11 +246,7 @@ export default { this.option_values[value] = this.values; }) .catch(error => { - this.form.loading = false; - this.form.onFail(error); - - this.method_show_html = error.message; }); } else { this.values = this.option_values[value]; @@ -277,13 +329,15 @@ export default { onSearchAndFilterClear() { this.filtered = []; this.search = ''; + + this.onInputConfirm(); }, closeIfClickedOutside(event) { if (!document.getElementById('search-field-' + this._uid).contains(event.target)) { - this.visible.options = false; - this.visible.operator = false; - this.visible.values = false; + //this.visible.options = false; + //this.visible.operator = false; + //this.visible.values = false; document.removeEventListener('click', this.closeIfClickedOutside); } @@ -299,12 +353,41 @@ export default { this.search = string; } else { let filter = string.split(':'); + let option = ''; + let value = ''; + + this.filter_list.forEach(function (_filter, i) { + if (_filter.key == filter[0]) { + option = _filter.value; + + _filter.values.forEach(function (_value) { + if (_value.key == filter[1]) { + value = _value.value; + } + }, this); + + this.selected_options.push(this.filter_list[i]); + this.filter_list.splice(i, 1); + + this.option_values[_filter.key] = _filter.values; + + _filter.values.forEach(function (value, j) { + if (value.key == filter[1]) { + this.selected_values.push(value); + + this.option_values[_filter.key].splice(j, 1); + } + }, this); + } + }, this); this.filtered.push({ - option: filter[0], + option: option, operator: '=', - value: filter[1] - }) + value: value + }); + + this.filter_index++; } }, this); } diff --git a/resources/lang/en-GB/general.php b/resources/lang/en-GB/general.php index 86eb36c0e..6d6a1a153 100644 --- a/resources/lang/en-GB/general.php +++ b/resources/lang/en-GB/general.php @@ -105,7 +105,8 @@ return [ 'to' => 'To', 'print' => 'Print', 'search' => 'Search', - 'search_placeholder' => 'Search or filter results..', + 'search_text' => 'Search for this text', + 'search_placeholder' => 'Type to search..', 'filter' => 'Filter', 'help' => 'Help', 'all' => 'All', @@ -152,6 +153,8 @@ return [ 'no_matching_data' => 'No matching data', 'clear_cache' => 'Clear Cache', 'go_to_dashboard' => 'Go to dashboard', + 'is' => 'is', + 'isnot' => 'is not', 'card' => [ 'name' => 'Name on Card', @@ -181,6 +184,11 @@ return [ 'no_file_selected' => 'No file selected...', ], + 'placeholder' => [ + 'search' => 'Type to search..', + 'search_and_filter' => 'Search or filter results..', + ], + 'date_range' => [ 'today' => 'Today', 'yesterday' => 'Yesterday', diff --git a/resources/views/components/search-string.blade.php b/resources/views/components/search-string.blade.php index d655b6dc8..fe89a5f41 100644 --- a/resources/views/components/search-string.blade.php +++ b/resources/views/components/search-string.blade.php @@ -1,7 +1,10 @@ -