Merge pull request #775 from openclassify/vedatakd

added sorting optional for location
This commit is contained in:
Dia Shalabi 2020-11-05 12:37:20 +03:00 committed by GitHub
commit f6fd4e59d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 103 additions and 26 deletions

View File

@ -1,6 +1,8 @@
/* Location Data */ /* Location Data */
var boundsAction = false; var boundsAction = false;
getCountries();
var getCountry = $('.country-data').data('content'); var getCountry = $('.country-data').data('content');
if (getCountry == "") { if (getCountry == "") {
getCountry = default_country; getCountry = default_country;
@ -206,3 +208,11 @@ function editMarket() {
} }
} }
} }
function getCountries() {
crud('', '/ajax/getCountry', 'GET', function (callback) {
$.each(callback, function (index, value) {
$('select[name="country"]').append("<option value='" + value.id + "'>" + value.name + "</option>");
});
})
}

View File

@ -201,6 +201,7 @@
var default_currency = "{{ setting_value('streams::currency') }}"; var default_currency = "{{ setting_value('streams::currency') }}";
var default_GET = "{{ setting_value('visiosoft.module.advs::default_GET') }}"; var default_GET = "{{ setting_value('visiosoft.module.advs::default_GET') }}";
var adv_id = "{{ id }}"; var adv_id = "{{ id }}";
var pick_option = "{{ trans('visiosoft.module.location::field.pick_option.name') }}"
</script> </script>
{{ asset_add("scripts.js", "visiosoft.module.advs::js/new-create.js") }} {{ asset_add("scripts.js", "visiosoft.module.advs::js/new-create.js") }}

View File

@ -7,7 +7,10 @@ return [
'general' => [ 'general' => [
'title' => 'visiosoft.module.location::section.general', 'title' => 'visiosoft.module.location::section.general',
'fields' => [ 'fields' => [
'home_page_location', 'list_page_location', 'detail_page_location', 'create_ad_page_location', 'country_for_phone_field' 'sorting_column','sorting_type',
'home_page_location', 'list_page_location',
'detail_page_location', 'create_ad_page_location',
'country_for_phone_field'
], ],
], ],
'map' => [ 'map' => [

View File

@ -33,19 +33,19 @@ return [
'default_value' => 212, 'default_value' => 212,
] ]
], ],
'country_for_phone_field' => [ 'country_for_phone_field' => [
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
'required' => false, 'required' => false,
'config' => [ 'config' => [
'default_value' => function () { 'default_value' => function () {
return config('visiosoft.theme.base::countries.default'); return config('visiosoft.theme.base::countries.default');
}, },
'options' => function () { 'options' => function () {
$array = \Visiosoft\LocationModule\Country\CountryModel::query()->get()->pluck('name', 'abv')->toArray(); $array = \Visiosoft\LocationModule\Country\CountryModel::query()->get()->pluck('name', 'abv')->toArray();
return $array; return $array;
}, },
], ],
], ],
'default_city' => [ 'default_city' => [
'type' => 'anomaly.field_type.select', 'type' => 'anomaly.field_type.select',
], ],
@ -88,4 +88,24 @@ return [
'default_value' => false, 'default_value' => false,
], ],
], ],
'sorting_column' => [
'type' => 'anomaly.field_type.select',
'config' => [
'default_value' => 'slug',
'options' => [
'slug' => 'slug',
'id' => 'id',
'order' => 'order'
],
],
],
'sorting_type' => [
'type' => 'anomaly.field_type.select',
'config' => [
'default_value' => 'ASC',
'options' => [
'ASC' => 'ASC', 'DESC' => 'DESC'
],
],
],
]; ];

View File

@ -46,5 +46,11 @@ return [
], ],
'country_for_phone_field' => [ 'country_for_phone_field' => [
'name' => 'Default Country For Register Phone Field' 'name' => 'Default Country For Register Phone Field'
] ],
'sorting_column' => [
'name' => 'Sorting Column',
],
'sorting_type' => [
'name' => 'Sorting Type',
],
]; ];

View File

@ -19,7 +19,7 @@
<ul style="padding: 0" class="list-unstyled"> <ul style="padding: 0" class="list-unstyled">
<li class="country-data" data-content="{{ adv['country_id'] }}" <li class="country-data" data-content="{{ adv['country_id'] }}"
data-default="{{ setting_value('visiosoft.module.location::default_country') }}" data-default="{{ setting_value('visiosoft.module.location::default_country') }}"
class="location-field country-data">{{ form.fields.country|raw }}</li> class="location-field country-data">{{ form.fields.country.setOptions({})|raw }}</li>
<li class="city-data" data-content="{{ adv['city'] }}" <li class="city-data" data-content="{{ adv['city'] }}"
data-default="{{ setting_value('visiosoft.module.location::default_city') }}" data-default="{{ setting_value('visiosoft.module.location::default_city') }}"
class="location-field city-data">{{ form.fields.city|raw }}</li> class="location-field city-data">{{ form.fields.city|raw }}</li>

View File

@ -57,8 +57,10 @@ class AjaxController extends PublicController
{ {
if ($this->request->id) if ($this->request->id)
return $this->country_model->find($this->request->id); return $this->country_model->find($this->request->id);
else else {
return $this->country_model->orderBy('order', 'ASC')->get(); $query = $this->country_model;
return $this->queryOrder($query);
}
} }
/** /**
@ -68,7 +70,9 @@ class AjaxController extends PublicController
{ {
if ($this->request->id) { if ($this->request->id) {
$id = explode(',', $this->request->id); $id = explode(',', $this->request->id);
return $this->city_model->whereIn('parent_country_id', $id)->orderBy('order', 'ASC')->get(); $query = $this->city_model->whereIn('parent_country_id', $id);
return $this->queryOrder($query);
} }
} }
@ -79,7 +83,10 @@ class AjaxController extends PublicController
{ {
if ($this->request->id) { if ($this->request->id) {
$id = explode(',', $this->request->id); $id = explode(',', $this->request->id);
return $this->district_model->whereIn('parent_city_id', $id)->orderBy('order', 'ASC')->get();
$query = $this->district_model->whereIn('parent_city_id', $id);
return $this->queryOrder($query);
} }
} }
@ -90,7 +97,10 @@ class AjaxController extends PublicController
{ {
if ($this->request->id) { if ($this->request->id) {
$id = explode(',', $this->request->id); $id = explode(',', $this->request->id);
return $this->neighborhood_model->whereIn('parent_district_id', $id)->orderBy('order', 'ASC')->get();
$query = $this->neighborhood_model->whereIn('parent_district_id', $id);
return $this->queryOrder($query);
} }
} }
@ -101,7 +111,10 @@ class AjaxController extends PublicController
{ {
if ($this->request->id) { if ($this->request->id) {
$id = explode(',', $this->request->id); $id = explode(',', $this->request->id);
return $this->village_model->whereIn('parent_neighborhood_id', $id)->orderBy('order', 'ASC')->get();
$query = $this->village_model->whereIn('parent_neighborhood_id', $id);
return $this->queryOrder($query);
} }
} }
@ -112,11 +125,19 @@ class AjaxController extends PublicController
{ {
if ($this->request->name) { if ($this->request->name) {
$slug = Str::slug($this->request->name, '_'); $slug = Str::slug($this->request->name, '_');
if ($city = $this-> city_model->newQuery()->where('slug', 'LIKE', $slug . '%')->first()) { if ($city = $this->city_model->newQuery()->where('slug', 'LIKE', $slug . '%')->first()) {
return ['success' => true, 'city' => $city]; return ['success' => true, 'city' => $city];
} else { } else {
return ['success' => false]; return ['success' => false];
} }
} }
} }
public function queryOrder($query)
{
$sorting_type = setting_value('visiosoft.module.location::sorting_type');
$sorting_column = setting_value('visiosoft.module.location::sorting_column');
return $query->orderBy($sorting_column, $sorting_type)->get();
}
} }

View File

@ -5,6 +5,8 @@ $(document).on('change', 'select[name="city"]', function () {
Locations($(this).val(), 2, "district") Locations($(this).val(), 2, "district")
}); });
getCountries();
function Locations(cat, level, name) { function Locations(cat, level, name) {
$.ajax({ $.ajax({
type: "GET", type: "GET",
@ -48,4 +50,15 @@ if (country != "") {
} }
} }
phoneMask("input[name='adress_gsm_phone']"); phoneMask("input[name='adress_gsm_phone']");
function getCountries() {
crud('', '/ajax/getCountry', 'GET', function (callback) {
$('select[name="country"]').html("<option>" + pick_option + "</option>");
$.each(callback, function (index, value) {
$('select[name="country"]').append("<option value='" + value.id + "'>" + value.name + "</option>");
});
$('select[name="country"]').val(country);
})
}

View File

@ -12,7 +12,7 @@
</div> </div>
<div class="row form-group location-map"> <div class="row form-group location-map">
<div class="col-sm-4 font-weight-bold"> <div class="col-sm-4 font-weight-bold">
{{ form.fields.country|raw }} {{ form.fields.country.setOptions({})|raw }}
</div> </div>
<div class="col-sm-4 location-field city-data font-weight-bold" <div class="col-sm-4 location-field city-data font-weight-bold"
@ -33,4 +33,7 @@
{{ form.fields.adress_content.input|raw }} {{ form.fields.adress_content.input|raw }}
</div> </div>
</div> </div>
</div> </div>
<script>
var pick_option = "{{ trans('visiosoft.module.location::field.pick_option.name') }}"
</script>