Filter Location Upgrade Bootsrap 4 and multiple search

This commit is contained in:
vedatakd 2020-01-06 12:33:57 +03:00
parent 87be96103b
commit 4752571175
10 changed files with 187 additions and 250 deletions

View File

@ -74,7 +74,7 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
if (!empty($param['country'])) {
$query = $query->where('country_id', $param['country']);
}
if (!empty($param['city'])) {
if (isset($param['city']) and !empty(array_filter($param['city']))) {
$query = $query->whereIn('city', $param['city']);
}
if (!empty($param['cat'])) {
@ -90,14 +90,14 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
if (!empty($param['user'])) {
$query = $query->where('advs_advs.created_by_id', $param['user']);
}
if (!empty($param['district'])) {
$query = $query->where('district', $param['district']);
if (isset($param['district']) and !empty(array_filter($param['district']))) {
$query = $query->whereIn('district', $param['district']);
}
if (!empty($param['neighborhood'])) {
$query = $query->where('neighborhood', $param['neighborhood']);
if (isset($param['neighborhood']) and !empty(array_filter($param['neighborhood']))) {
$query = $query->whereIn('neighborhood', $param['neighborhood']);
}
if (!empty($param['village'])) {
$query = $query->where('village', $param['village']);
if (isset($param['village']) and !empty(array_filter($param['village']))) {
$query = $query->whereIn('village', $param['village']);
}
if (!empty($param['min_price'])) {
$num = $param['min_price'];

View File

@ -19,4 +19,11 @@ return [
'default_value' => true,
],
],
'default_country' => [
'type' => 'anomaly.field_type.relationship',
"config" => [
"related" => \Visiosoft\LocationModule\Country\CountryModel::class,
'default_value' => 212,
]
],
];

View File

@ -16,4 +16,14 @@
.filter-location-body ul li:hover {
background: #227af3;
color: #fff;
}
.filter-location-body .countries,
.filter-location-body .cities,
.filter-location-body .districts,
.filter-location-body .neighborhoods,
.filter-location-body .village {
height: 200px;
overflow: auto;
display: none
}

View File

@ -1,160 +1,3 @@
// let searchParams = new URLSearchParams(window.location.search);
//
// //Set Select2 Type for Location Fields
// $('.cities, .countries, .districts, .neighborhoods, .village').select2({
// placeholder: select_trans
// });
//
//
// FindLocations = (id, table, typeDb, divId, paramName = null) => {
// $.ajax({
// type: 'get',
// url: '/getlocations',
// data: {
// id: id,
// table: table,
// typeDb: typeDb,
// },
// success: function (response) {
// setLocations(response, id, table, typeDb, divId, paramName);
// return response;
// },
// error: function (err) {
// reject(Error("It broke"));
// }
// });
// };
//
//
// setLocations = (response, id, table, typeDb, divId, paramName) => {
//
// //Add Options
// if(divId != ".cities")
// {
// $(divId).append("<option value></option>")
// }
// response.forEach(function (options) {
// $(divId).append("<option value=" + options.id + ">" + options.name + "</option>")
// });
//
// //Set Selected Option
// if (paramName != null) {
// if (divId == ".cities") {
// $('.countries').val(searchParams.get('country'));
// $('.countries').select2();
// $('.cities').val(findParam("city[]"));
// } else {
// $(divId).val(searchParams.get(paramName));
// }
// $(divId).select2();
// }
//
// };
//
// //Category Change
// $('.countries').on('change', function () {
// $('.cities').empty();
// var table = "cities";
// var typeDb = 'parent_country_id';
// var id = $(this).val();
// var divId = ".cities";
//
// FindLocations(id, table, typeDb, divId);
// });
//
// //City Change
// $('.cities, .select2-selection__choice__remove').on('change', function () {
// $('.districts').empty();
// var table = "districts";
// var typeDb = 'parent_city_id';
// var id = $(this).val();
// var divId = ".districts";
//
// FindLocations(id, table, typeDb, divId);
// });
//
// //Districts Change
// $('.districts').on('change', function () {
// var table = "neighborhoods";
// var typeDb = 'parent_district_id';
// var id = $(this).val();
// var divId = ".neighborhoods";
//
// FindLocations(id, table, typeDb, divId);
// });
//
// //Neighborhoods Change
// $('.neighborhoods').on('change', function () {
// var table = "village";
// var typeDb = 'parent_neighborhood_id';
// var id = $(this).val();
// var divId = ".village";
//
// FindLocations(id, table, typeDb, divId);
// });
//
//
// jQuery(document).ready(function ($) {
//
// }).promise().done(function () {
//
// //Get City && Set Country
// if (searchParams.get('country') != '') {
// $('.cities').empty();
// var table = "cities";
// var typeDb = 'parent_country_id';
// var id = searchParams.get('country');
// var divId = ".cities";
// var paramName = 'city';
//
// FindLocations(id, table, typeDb, divId, paramName);
// }
//
// }).promise().done(function () {
//
// //get District && set city
// if (findParam('city[]').length) {
// $('.districts').empty();
// var table = "districts";
// var typeDb = 'parent_city_id';
// var id = findParam('city[]');
// var divId = ".districts";
// var paramName = 'district';
//
// FindLocations(id, table, typeDb, divId, paramName);
// }
//
// }).promise().done(function () {
//
// //get neighborhood && set districts
// if (searchParams.get('district') != '') {
// $('.neighborhoods').empty();
// var table = "neighborhoods";
// var typeDb = 'parent_district_id';
// var id = searchParams.get('district');
// var divId = ".neighborhoods";
// var paramName = 'neighborhood';
//
// FindLocations(id, table, typeDb, divId, paramName);
// }
//
// }).promise().done(function () {
//
// //get village && set neighborhoods
// if (searchParams.get('neighborhood') != '') {
// $('.village').empty();
// var table = "village";
// var typeDb = 'parent_neighborhood_id';
// var id = searchParams.get('neighborhood');
// var divId = ".village";
// var paramName = 'village';
//
// FindLocations(id, table, typeDb, divId, paramName);
// }
//
// });
var countries;
var cities;
var districts;
@ -173,6 +16,8 @@ $('.filter-country-btn').on('click', function () {
});
if (countries == "")
$('.filter-location-modal .countries').html(null_msg);
else if ($('input[name="country"]').val() != "")
$(".filter-location-body .countries li[data-id='" + $('input[name="country"]').val() + "'] input[type='checkbox']").prop('checked', true);
resolve();
})
});
@ -190,6 +35,7 @@ $('.filter-country-btn').on('click', function () {
//City
$('.filter-city-btn').on('click', function () {
var countries_value = $('input[name="country"]').val();
var selected__city_request = $('input[name="city[]"]').val();
if (cities == undefined || $(this).attr('data-parent') != countries_value) {
$(this).attr('data-parent', countries_value)
var promiseForCities = new Promise(function (resolve, reject) {
@ -201,6 +47,11 @@ $('.filter-city-btn').on('click', function () {
});
if (cities == "")
$('.filter-location-modal .cities').html(null_msg);
else if (selected__city_request != "") {
$.each(selected__city_request.split(','), function (index, value) {
$(".filter-location-body .cities li[data-id='" + value + "'] input[type='checkbox']").prop('checked', true);
});
}
resolve();
})
});
@ -217,7 +68,8 @@ $('.filter-city-btn').on('click', function () {
//District
$('.filter-district-btn').on('click', function () {
var city_value = $('input[name="city"]').val();
var city_value = $('input[name="city[]"]').val();
var selected_district_request = $('input[name="district[]"]').val();
if (districts == undefined || $(this).attr('data-parent') != city_value) {
$(this).attr('data-parent', city_value)
var promiseForDistricts = new Promise(function (resolve, reject) {
@ -229,6 +81,11 @@ $('.filter-district-btn').on('click', function () {
});
if (districts == "")
$('.filter-location-modal .districts').html(null_msg);
else if (selected_district_request != "") {
$.each(selected_district_request.split(','), function (index, value) {
$(".filter-location-body .districts li[data-id='" + value + "'] input[type='checkbox']").prop('checked', true);
});
}
resolve();
})
});
@ -245,7 +102,8 @@ $('.filter-district-btn').on('click', function () {
//Neighborhood
$('.filter-neighborhood-btn').on('click', function () {
var district_value = $('input[name="district"]').val();
var district_value = $('input[name="district[]"]').val();
var selected_neighborhood_request = $('input[name="neighborhood[]"]').val();
if (neighborhoods == undefined || $(this).attr('data-parent') != district_value) {
$(this).attr('data-parent', district_value)
var promiseForNeighborhoods = new Promise(function (resolve, reject) {
@ -257,6 +115,11 @@ $('.filter-neighborhood-btn').on('click', function () {
});
if (neighborhoods == "")
$('.filter-location-modal .neighborhoods').html(null_msg);
else if (selected_neighborhood_request != "") {
$.each(selected_neighborhood_request.split(','), function (index, value) {
$(".filter-location-body .neighborhoods li[data-id='" + value + "'] input[type='checkbox']").prop('checked', true);
});
}
resolve();
})
});
@ -273,7 +136,8 @@ $('.filter-neighborhood-btn').on('click', function () {
//Village
$('.filter-village-btn').on('click', function () {
var neighborhood_value = $('input[name="neighborhood"]').val();
var neighborhood_value = $('input[name="neighborhood[]"]').val();
var selected_village_request = $('input[name="village[]"]').val();
if (village == undefined || $(this).attr('data-parent') != neighborhood_value) {
$(this).attr('data-parent', neighborhood_value)
var promiseForVillage = new Promise(function (resolve, reject) {
@ -285,6 +149,11 @@ $('.filter-village-btn').on('click', function () {
});
if (village == "")
$('.filter-location-modal .village').html(null_msg);
else if (selected_village_request != "") {
$.each(selected_village_request.split(','), function (index, value) {
$(".filter-location-body .village li[data-id='" + value + "'] input[type='checkbox']").prop('checked', true);
});
}
resolve();
})
});
@ -318,24 +187,40 @@ function SelectOnClick() {
$('.loading').hide();
return $(".filter-location-body input[type='checkbox']").change(function () {
resetValue($(this).attr('data-field'), false, true)
var input = $('input[name="' + $(this).attr('data-field') + '"]');
var input_val = input.val()
var input_name = $('.selected-'+$(this).attr('data-field')+' small').html("")
var input = $('input[name="' + $(this).attr('data-field') + '[]"]');
var input_text = $(this).parent().find('small').html();
var text_html = $('.selected-' + $(this).attr('data-field') + ' small');
var text = "";
var input_val = input.val();
var id = $(this).attr('data-id');
var name = $(this).attr('data-id');
if (input_val != "") {
input_val = input_val.split(',');
if ($(this).attr('data-field') == "country") {
input.val(id)
text_html.html(input_text)
$(".filter-location-body input[type='checkbox']").prop('checked', false);
$(".filter-location-body li[data-id='" + id + "'] input[type='checkbox']").prop('checked', true);
} else {
input_val = [];
if (input_val != "") {
input_val = input_val.split(',');
text = text_html.html().split(',');
} else {
input_val = [];
text = [];
}
if (this.checked) {
input_val.push(id);
text.push(input_text)
} else {
input_val.splice($.inArray(id, input_val), 1);
text.splice($.inArray(input_text, text), 1);
}
input.val(input_val.join(','))
text_html.html(text.join(','))
}
if (this.checked) {
input_val.push(id);
} else {
input_val.splice($.inArray(id, input_val), 1);
}
input.val(input_val.join(','))
$('.selected-'+$(this).attr('data-field')+' small').html("")
});
}
@ -430,8 +315,9 @@ function scroolToModal() {
}
function searchLocationName() {
$("#searchLocation").unbind();
$("#searchLocation").on("keyup", function () {
var searchField = $("#searchLocation");
searchField.unbind();
searchField.on("keyup", function () {
var value = this.value.toLowerCase().trim();
$('.filter-location-modal li').show().filter(function () {
return $(this).text().toLowerCase().trim().indexOf(value) == -1;

View File

@ -31,4 +31,7 @@ return [
'pick_option' => [
'name' => 'Pick an option',
],
'address' => [
'name' => 'Address',
],
];

View File

@ -13,4 +13,7 @@ return [
'show_search_location_btn' => [
'name' => 'Show Search Location Button',
],
'default_country' => [
'name' => 'Default Country',
],
];

View File

@ -37,5 +37,8 @@ return[
"name" =>"ıklama",
],
'address' => [
'name' => 'Adres',
],
];

View File

@ -1,57 +1,16 @@
{#<div class="row w-100 px-2 m-0">#}
{# <div class="col-12 px-0 py-1">#}
{# <label class="label-filter-location">{{ trans("visiosoft.module.location::field.country.name") }}</label>#}
{# <select class="form-control countries" name="country" id="countries">#}
{# {% for country in params.countries %}#}
{# <option value="{{ country.id }}">{{ country.name }}</option>#}
{# {% endfor %}#}
{# </select>#}
{# </div>#}
{# <div class="col-12 px-0 py-1">#}
{# <label class="label-filter-location">{{ trans("visiosoft.module.location::field.city.name") }}</label>#}
{# <select class="form-control cities" name="city[]" id="cities" multiple>#}
{# {% for city in params.cities %}#}
{# <option value="{{ city.id }}">{{ city.name }}</option>#}
{# {% endfor %}#}
{# </select>#}
{# </div>#}
{# <div class="col-12 px-0 py-1">#}
{# <label class="label-filter-location">{{ trans("visiosoft.module.location::field.district.name") }}</label>#}
{# <select class="form-control districts" name="district" id="districts">#}
{# {% for district in params.districts %}#}
{# <option value="{{ district.id }}">{{ district.name }}</option>#}
{# {% endfor %}#}
{# </select>#}
{# </div>#}
{# <div class="col-12 px-0 py-1">#}
{# <label class="label-filter-location">{{ trans("visiosoft.module.location::field.neighborhood.name") }}</label>#}
{# <select class="form-control neighborhoods" name="neighborhood" id="neighborhoods">#}
{# {% for neighborhood in params.neighborhoods %}#}
{# <option value="{{ neighborhood.id }}">{{ neighborhood.name }}</option>#}
{# {% endfor %}#}
{# </select>#}
{# </div>#}
{# <div class="col-12 px-0 py-1">#}
{# <label class="label-filter-location">{{ trans("visiosoft.module.location::field.village.name") }}</label>#}
{# <select class="form-control village" name="village" id="village">#}
{# {% for village in params.villages %}#}
{# <option value="{{ village.id }}">{{ village.name }}</option>#}
{# {% endfor %}#}
{# </select>#}
{# </div>#}
{#</div>#}
<div class="row w-100 px-2 m-0">
<div class="col-12 px-0 py-1">
<button type="button" class="btn btn-default border border-1 w-100 filter-country-btn" data-toggle="modal">
<span class="float-left">{{ trans("visiosoft.module.location::field.country.name") }}</span>
<i class="fas fa-sort-down float-right"></i>
</button>
<div class="text-muted selected-country">
<small></small>
</div>
<input name="country" type="hidden">
<div class="col-12 px-0 py-1 px-2">
<b>
<span class="float-left">{{ trans('visiosoft.module.location::field.address.name') }}</span>
</b>
<a href="#" class="a-sahibinden-type selected-country filter-country-btn float-right">
<small>{{ getCountry(setting_value('visiosoft.module.location::default_country')).name }}</small>
</a>
{% set country = setting_value('visiosoft.module.location::default_country') %}
{% if app.request.get('country') %}
{% set country = app.request.get('country') %}
{% endif %}
<input name="country" value="{{ country }}" type="hidden">
</div>
<div class="col-12 px-0 py-1">
<button type="button" class="btn btn-default border border-1 w-100 filter-city-btn" data-toggle="modal"
@ -59,10 +18,15 @@
<span class="float-left">{{ trans("visiosoft.module.location::field.city.name") }}</span>
<i class="fas fa-sort-down float-right"></i>
</button>
{% set selected_cities = app.request.get('city') %}
{% set selected_cities_name = [] %}
{% for selected_city in selected_cities[0]|split(',') %}
{% set selected_cities_name = selected_cities_name|merge([getCity(selected_city|trim(',')).name]) %}
{% endfor %}
<div class="text-muted selected-city">
<small></small>
<small>{{ selected_cities_name|join(',') }}</small>
</div>
<input name="city" type="hidden">
<input name="city[]" value="{{ app.request.get('city')|join(',') }}" type="hidden">
</div>
<div class="col-12 px-0 py-1">
<button type="button" class="btn btn-default border border-1 w-100 filter-district-btn" data-toggle="modal"
@ -70,10 +34,15 @@
<span class="float-left">{{ trans("visiosoft.module.location::field.district.name") }}</span>
<i class="fas fa-sort-down float-right"></i>
</button>
{% set selected_districts = app.request.get('district') %}
{% set selected_districts_name = [] %}
{% for selected_district in selected_districts[0]|split(',') %}
{% set selected_districts_name = selected_districts_name|merge([getDistrict(selected_district|trim(',')).name]) %}
{% endfor %}
<div class="text-muted selected-district">
<small></small>
<small>{{ selected_districts_name|join(',') }}</small>
</div>
<input name="district" type="hidden">
<input name="district[]" value="{{ app.request.get('district')|join(',') }}" type="hidden">
</div>
<div class="col-12 px-0 py-1">
<button type="button" class="btn btn-default border border-1 w-100 filter-neighborhood-btn" data-toggle="modal"
@ -81,10 +50,15 @@
<span class="float-left">{{ trans("visiosoft.module.location::field.neighborhood.name") }}</span>
<i class="fas fa-sort-down float-right"></i>
</button>
{% set selected_neighborhoods = app.request.get('neighborhood') %}
{% set selected_neighborhoods_name = [] %}
{% for selected_neighborhood in selected_neighborhoods[0]|split(',') %}
{% set selected_neighborhoods_name = selected_neighborhoods_name|merge([getNeighborhood(selected_neighborhood|trim(',')).name]) %}
{% endfor %}
<div class="text-muted selected-neighborhood">
<small></small>
<small>{{ selected_neighborhoods_name|join(',') }}</small>
</div>
<input name="neighborhood" type="hidden">
<input name="neighborhood[]" value="{{ app.request.get('neighborhood')|join(',') }}" type="hidden">
</div>
<div class="col-12 px-0 py-1">
<button type="button" class="btn btn-default border border-1 w-100 filter-village-btn" data-toggle="modal"
@ -92,10 +66,15 @@
<span class="float-left">{{ trans("visiosoft.module.location::field.village.name") }}</span>
<i class="fas fa-sort-down float-right"></i>
</button>
{% set selected_villages = app.request.get('village') %}
{% set selected_villages_name = [] %}
{% for selected_village in selected_villages[0]|split(',') %}
{% set selected_villages_name = selected_villages_name|merge([getVillage(selected_village|trim(',')).name]) %}
{% endfor %}
<div class="text-muted selected-village">
<small></small>
<small>{{ selected_villages_name|join(',') }}</small>
</div>
<input name="village" type="hidden">
<input name="village[]" value="{{ app.request.get('village')|join(',') }}" type="hidden">
</div>
</div>
@ -109,15 +88,15 @@
</div>
<div class="modal-body filter-location-body">
<div class="loading"></div>
<ul class="list-unstyled countries" style="height: 200px; overflow: auto;display: none"></ul>
<ul class="list-unstyled cities" style="height: 200px; overflow: auto;display: none"></ul>
<ul class="list-unstyled districts" style="height: 200px; overflow: auto;display: none"></ul>
<ul class="list-unstyled neighborhoods" style="height: 200px; overflow: auto;display: none"></ul>
<ul class="list-unstyled village" style="height: 200px; overflow: auto;display: none"></ul>
<ul class="list-unstyled countries"></ul>
<ul class="list-unstyled cities"></ul>
<ul class="list-unstyled districts"></ul>
<ul class="list-unstyled neighborhoods"></ul>
<ul class="list-unstyled village"></ul>
</div>
</div>
<div class="filter-location-back" style="display: none"></div>
<script>
var null_msg = "{{ trans('visiosoft.module.location::message.null_msg') }}!"
</script>
</script>

View File

@ -5,6 +5,7 @@ use Visiosoft\LocationModule\City\Command\GetCity;
use Visiosoft\LocationModule\Country\Command\GetCountry;
use Visiosoft\LocationModule\District\Command\GetDistrict;
use Visiosoft\LocationModule\Neighborhood\Command\GetNeighborhood;
use Visiosoft\LocationModule\Village\Command\GetVillage;
class LocationModulePlugin extends Plugin
{
@ -56,6 +57,17 @@ class LocationModulePlugin extends Plugin
return null;
}
return $ad;
}
),
new \Twig_SimpleFunction(
'getVillage',
function ($id) {
if (!$ad = $this->dispatch(new GetVillage($id))) {
return null;
}
return $ad;
}
),

View File

@ -0,0 +1,34 @@
<?php namespace Visiosoft\LocationModule\Village\Command;
use Visiosoft\LocationModule\Village\VillageModel;
class GetVillage
{
/**
* @var $id
*/
protected $id;
/**
* GetProduct constructor.
* @param $id
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* @param VillageModel $groups
* @return |null
*/
public function handle(VillageModel $groups)
{
if ($this->id) {
return $groups->find($this->id);
}
return null;
}
}