search-string config check columns

This commit is contained in:
Cüneyt Şentürk 2020-11-11 14:33:49 +03:00
parent d4a3f9c1a3
commit 2b0255b487
6 changed files with 213 additions and 54 deletions

View File

@ -4,6 +4,7 @@ namespace App\View\Components;
use Illuminate\View\Component;
use Illuminate\Support\Str;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
class SearchString extends Component
{
@ -45,6 +46,10 @@ class SearchString extends Component
$column = $options;
}
if (!$this->isFilter($column, $options)) {
continue;
}
$this->filters[] = [
'key' => $this->getFilterKey($column, $options),
'value' => $this->getFilterName($column),
@ -58,6 +63,17 @@ class SearchString extends Component
return view('components.search-string');
}
protected function isFilter($column, $options)
{
$filter = true;
if (empty($this->getFilterUrl($column, $options)) && (!isset($options['date']) && !isset($options['boolean']))) {
$filter = false;
}
return $filter;
}
protected function getFilterKey($column, $options)
{
if (isset($options['relationship'])) {
@ -71,20 +87,22 @@ class SearchString extends Component
{
if (strpos($column, '_id') !== false) {
$column = str_replace('_id', '', $column);
} else if (strpos($column, '_code') !== false) {
$column = str_replace('_code', '', $column);
}
$plural = Str::plural($column, 2);
if (trans_choice('general.' . $plural, 1) !== 'general.' . $plural) {
return trans_choice('general.' . $plural, 1);
} elseif (trans_choice('search_string.colmuns.' . $plural, 1) !== 'search_string.colmuns.' . $plural) {
return trans_choice('search_string.colmuns.' . $plural, 1);
} elseif (trans_choice('search_string.columns.' . $plural, 1) !== 'search_string.columns.' . $plural) {
return trans_choice('search_string.columns.' . $plural, 1);
}
$name = trans('general.' . $column);
if ($name == 'general.' . $column) {
$name = trans('search_string.colmuns.' . $column);
$name = trans('search_string.columns.' . $column);
}
return $name;
@ -98,6 +116,10 @@ class SearchString extends Component
$type = 'boolean';
}
if (isset($options['date'])) {
$type = 'date';
}
return $type;
}
@ -105,7 +127,7 @@ class SearchString extends Component
{
$url = '';
if (isset($options['boolean'])) {
if (isset($options['boolean']) || isset($options['date'])) {
return $url;
}
@ -128,7 +150,11 @@ class SearchString extends Component
$plural = Str::plural($column, 2);
try {
$url = route($url . $plural . '.index');
} catch (\Exception $e) {
$url = '';
}
}
return $url;

View File

@ -69,7 +69,9 @@ return [
'number' => ['searchable' => true],
'bank_name' => ['searchable' => true],
'bank_address' => ['searchable' => true],
'currency' => ['relationship' => true],
'currency_code' => [
'route' => 'currencies.index'
],
'enabled' => ['boolean' => true],
],
],
@ -87,16 +89,24 @@ return [
App\Models\Banking\Transaction::class => [
'columns' => [
'type',
'account_id',
'account_id' => [
'route' => 'accounts.index'
],
'paid_at' => ['date' => true],
'amount',
'currency_code',
'currency_code' => [
'route' => 'currencies.index'
],
'document_id',
'contact_id',
'contact_id' => [
'route' => 'customers.index'
],
'description' => ['searchable' => true],
'payment_method',
'reference',
'category_id',
'category_id' => [
'route' => 'categories.index'
],
'parent_id',
],
],
@ -123,6 +133,8 @@ return [
'category_id' => [
'route' => ['categories.index', 'search=type:item']
],
'sales_price',
'purchase_price',
],
],
@ -135,7 +147,9 @@ return [
'phone' => ['searchable' => true],
'address' => ['searchable' => true],
'website' => ['searchable' => true],
'currency_code',
'currency_code' => [
'route' => 'currencies.index'
],
'reference',
'user_id',
'enabled' => ['boolean' => true],
@ -150,14 +164,20 @@ return [
'billed_at' => ['date' => true],
'due_at' => ['date' => true],
'amount',
'currency_code',
'contact_id',
'currency_code' => [
'route' => 'currencies.index'
],
'contact_id' => [
'route' => 'vendors.index'
],
'contact_name' => ['searchable' => true],
'contact_email' => ['searchable' => true],
'contact_tax_number',
'contact_phone' => ['searchable' => true],
'contact_address' => ['searchable' => true],
'category_id',
'category_id' => [
'route' => 'categories.index'
],
'parent_id',
],
],
@ -170,14 +190,20 @@ return [
'invoiced_at' => ['date' => true],
'due_at' => ['date' => true],
'amount',
'currency_code',
'contact_id',
'currency_code' => [
'route' => 'currencies.index'
],
'contact_id' => [
'route' => 'customer.index'
],
'contact_name' => ['searchable' => true],
'contact_email' => ['searchable' => true],
'contact_tax_number',
'contact_phone' => ['searchable' => true],
'contact_address' => ['searchable' => true],
'category_id',
'category_id' => [
'route' => 'categories.index'
],
'parent_id',
],
],

View File

@ -17,6 +17,7 @@
<div class="dropdown input-full">
<input
v-if="!show_date"
type="text"
class="form-control"
:placeholder="placeholder"
@ -27,6 +28,20 @@
@keyup.enter="onInputConfirm"
/>
<flat-picker
v-else
@on-open="onInputFocus"
:config="dateConfig"
class="form-control datepicker"
:placeholder="placeholder"
:ref="'input-search-date-field-' + _uid"
v-model="search"
@focus="onInputFocus"
@input="onInputDateSelected"
@keyup.enter="onInputConfirm"
>
</flat-picker>
<button type="button" class="btn btn-link clear" @click="onSearchAndFilterClear">
<i class="el-tag__close el-icon-close"></i>
</button>
@ -62,9 +77,16 @@
</template>
<script>
import flatPicker from "vue-flatpickr-component";
import "flatpickr/dist/flatpickr.css";
export default {
name: 'akaunting-search',
components: {
flatPicker
},
props: {
placeholder: {
type: String,
@ -106,6 +128,8 @@ export default {
default: () => [],
description: 'List of filters'
},
dateConfig: null,
},
model: {
@ -131,6 +155,7 @@ export default {
selected_values: [],
values: [],
current_value: null,
show_date: false,
};
},
@ -140,15 +165,61 @@ export default {
return;
}
if (this.filter_last_step != 'values' || (this.filter_last_step == 'values' && this.selected_options[this.filter_index].type != 'date')) {
this.visible[this.filter_last_step] = true;
this.$nextTick(() => {
this.$refs['input-search-field-' + this._uid].focus();
});
} else {
this.show_date = true;
this.$nextTick(() => {
this.$refs['input-search-date-field-' + this._uid].focus();
});
}
console.log('Focus :' + this.filter_last_step);
},
onInputDateSelected(event) {
this.filtered[this.filter_index].value = event;
this.selected_values.push({
key: event,
value: event,
});
this.$emit('change', this.filtered);
this.show_date = false;
this.search = '';
this.$nextTick(() => {
this.$refs['input-search-field-' + this._uid].focus();
});
this.filter_index++;
if (this.filter_list.length) {
this.visible = {
options: true,
operator: false,
values: false,
};
} else {
this.visible = {
options: false,
operator: false,
values: false,
};
}
this.show_date = false;
this.filter_last_step = 'options';
},
onInput(evt) {
this.search = evt.target.value;
@ -158,6 +229,7 @@ export default {
option_url += '?search=' + this.search;
}
if (option_url) {
window.axios.get(option_url)
.then(response => {
this.values = [];
@ -176,6 +248,7 @@ export default {
.catch(error => {
});
}
this.$emit('input', evt.target.value);
},
@ -202,7 +275,6 @@ export default {
args += this.selected_options[index].key + ':' + this.selected_values[index].key + ' ';
serach_string[path][this.selected_options[index].key] = {
'key': this.selected_values[index].key,
'value': this.selected_values[index].value
@ -218,7 +290,7 @@ export default {
this.current_value = value;
let option = false;
let option_url = url;
let option_url = false;
for (let i = 0; i < this.filter_list.length; i++) {
if (this.filter_list[i].key == value) {
@ -249,14 +321,14 @@ export default {
this.search = '';
if (!this.option_values[value]) {
if (!this.option_values[value] && option_url) {
window.axios.get(option_url)
.then(response => {
let data = response.data.data;
data.forEach(function (item) {
this.values.push({
key: item.id,
key: (item.code) ? item.code : item.id,
value: (item.title) ? item.title : (item.display_name) ? item.display_name : item.name
});
}, this);
@ -267,7 +339,7 @@ export default {
});
} else {
this.values = this.option_values[value];
this.values = (this.option_values[value]) ? this.option_values[value] : [];
}
this.$nextTick(() => {
@ -288,6 +360,7 @@ export default {
this.$emit('change', this.filtered);
if (this.selected_options[this.filter_index].type != 'date') {
this.$nextTick(() => {
this.$refs['input-search-field-' + this._uid].focus();
});
@ -297,6 +370,19 @@ export default {
operator: false,
values: true,
};
} else {
this.show_date = true;
this.$nextTick(() => {
this.$refs['input-search-date-field-' + this._uid].focus();
});
this.visible = {
options: false,
operator: false,
values: false,
};
}
this.filter_last_step = 'values';
},
@ -338,6 +424,8 @@ export default {
};
}
this.show_date = false;
this.filter_last_step = 'options';
},
@ -586,4 +674,8 @@ export default {
-webkit-box-shadow: none !important;
box-shadow: none !important;
}
.searh-field .form-control.datepicker.flatpickr-input {
padding: inherit !important;
}
</style>

View File

@ -0,0 +1,9 @@
<?php
return [
'columns' => [
'last_logged_in_at' => 'Last Login',
],
];

View File

@ -11,18 +11,12 @@
@section('content')
<div class="card">
<div class="card-header border-bottom-0" :class="[{'bg-gradient-primary': bulk_action.show}]">
{!! Form::open([
'method' => 'GET',
'route' => 'users.index',
'role' => 'form',
'class' => 'mb-0'
]) !!}
<div class="align-items-center" v-if="!bulk_action.show">
<x-search-string model="App\Models\Auth\User" />
</div>
{{ Form::bulkActionRowGroup('general.users', $bulk_actions, ['group' => 'auth', 'type' => 'users']) }}
{!! Form::close() !!}
</div>
<div class="table-responsive">

View File

@ -7,4 +7,16 @@
no-matching-data-text="{{ trans('general.no_matching_data') }}"
value="{{ request()->get('search', null) }}"
:filters="{{ json_encode($filters) }}"
:date-config="{
allowInput: true,
altInput: true,
altFormat: 'Y-m-d',
dateFormat: 'Y-m-d',
@if (!empty($attributes['min-date']))
minDate: {{ $attributes['min-date'] }}
@endif
@if (!empty($attributes['max-date']))
maxDate: {{ $attributes['max-date'] }}
@endif
}"
></akaunting-search>