Merge pull request #1196 from openclassify/dia

#654 [customfields] Improvments
This commit is contained in:
Dia Shalabi 2021-10-12 10:45:33 +03:00 committed by GitHub
commit b7040f0bc8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 122 additions and 42 deletions

View File

@ -473,6 +473,33 @@ ul {
font-size: calc(12rem / 16);
padding: .2rem .5rem;
&.sortable {
cursor: pointer;
color: #adb4c9;
&:hover {
text-decoration: underline;
}
}
&:not(.sort-by) {
svg {
display: none;
}
}
&.sort-desc {
svg {
transform: scaleY(-1);
}
}
svg {
height: .5rem;
width: auto;
margin-left: .2rem;
}
&:first-child {
border-top-left-radius: .25rem;
}
@ -719,7 +746,7 @@ ul {
&:nth-child(odd) {
background-color: #F6F6F6;
}
img {
height: 5rem;
width: 7rem;

View File

@ -1,3 +1,29 @@
// Init tooltip
$(function () {
$('[data-toggle="tooltip"]').tooltip()
})
// Handle table header sorting
$('.sortable').on('click', function () {
const searchParams = new URLSearchParams(window.location.search);
const sortBy = searchParams.get('sort_by');
const direction = $(this).hasClass('sort-desc') ? 'asc' : 'desc';
const value = $(this).data(`sort-${direction}`);
let url = window.location.href;
if (url.slice(-1) === "#") {
url = url.slice(0, -1);
}
let goURL;
if (window.location.search == "") {
goURL = `${url}?sort_by=${value}`;
} else if (searchParams.has('sort_by')) {
const parameters = value !== 'all' ? "sort_by=" + value : "";
goURL = location.href.replace(`sort_by=${sortBy}`, parameters);
} else {
goURL = `${url}&sort_by=${value}`;
}
window.location.replace(goURL);
})

View File

@ -19,7 +19,7 @@
<div class="action-data-wrapper d-flex justify-content-center">
<div class="action-data d-flex flex-column">
{{ addBlock('list/extra-actions', {'ad': adv, 'vars': _context})|raw }}
{{ addBlock('list/extra-actions', {'ad': adv, 'vars': _context}, ['favs', 'comparisons'])|raw }}
</div>
</div>

View File

@ -4,26 +4,8 @@
<div id="listing" class="w-100 table-responsive">
<table class="w-100 text-center">
<thead>
<tr class="text-white">
<th class="text-nowrap" colspan="2">{{ trans('visiosoft.module.advs::field.ad_title') }}</th>
{% for cF in listingCFs %}
<th class="text-nowrap">{{ cF.name }}</th>
{% endfor %}
{% if listLocation %}
<th class="text-nowrap">
{{ trans('visiosoft.module.advs::field.city.name') }}
/ {{ trans('visiosoft.module.advs::field.district.name') }}
</th>
{% endif %}
{% if setting_value('visiosoft.module.advs::market_place') and showDate %}
<th class="text-nowrap">{{ trans('visiosoft.module.advs::field.date.name') }}</th>
{% endif %}
<th class="text-nowrap">{{ trans('visiosoft.module.advs::field.price.name') }}</th>
</tr>
</thead>
{% include 'visiosoft.module.advs::list/partials/thead' %}
<tbody>

View File

@ -0,0 +1,37 @@
<thead>
<tr class="text-white">
<th class="text-nowrap" colspan="2">{{ trans('visiosoft.module.advs::field.ad_title') }}</th>
{% for cF in listingCFs %}
{% set isSortable = cF.isSortable %}
<th class="text-nowrap{{ isSortable ? ' sortable' }}{{ param.sort_by == 'cf_' ~ cF.id ~ '_desc' ? ' sort-by sort-desc' : (param.sort_by == 'cf_' ~ cF.id ~ '_asc' ? ' sort-by') }}"
data-sort-asc="{{ 'cf_' ~ cF.id ~ '_asc' }}" data-sort-desc="{{ 'cf_' ~ cF.id ~ '_desc' }}">
{{ cF.name }}
{% if isSortable %}
{{ img('visiosoft.module.advs::images/sort-arrow.svg').data|raw }}
{% endif %}
</th>
{% endfor %}
{% if listLocation %}
<th class="text-nowrap sortable{{ param.sort_by == 'address_z_a' ? ' sort-by sort-desc' : (param.sort_by == 'address_a_z' ? ' sort-by') }}"
data-sort-asc="address_a_z" data-sort-desc="address_z_a">
{{ trans('visiosoft.module.advs::field.city.name') }}
/ {{ trans('visiosoft.module.advs::field.district.name') }}
{{ img('visiosoft.module.advs::images/sort-arrow.svg').data|raw }}
</th>
{% endif %}
{% if setting_value('visiosoft.module.advs::market_place') and showDate %}
<th class="text-nowrap sortable{{ param.sort_by == 'sort_time_newest' ? ' sort-by sort-desc' : (param.sort_by == 'sort_time_oldest' ? ' sort-by') }}"
data-sort-asc="sort_time_oldest" data-sort-desc="sort_time_newest">
{{ trans('visiosoft.module.advs::field.date.name') }}
{{ img('visiosoft.module.advs::images/sort-arrow.svg').data|raw }}
</th>
{% endif %}
<th class="text-nowrap sortable{{ param.sort_by == 'sort_price_up' ? ' sort-by sort-desc' : (param.sort_by == 'sort_price_down' ? ' sort-by') }}"
data-sort-asc="sort_price_down" data-sort-desc="sort_price_up">
{{ trans('visiosoft.module.advs::field.price.name') }}
{{ img('visiosoft.module.advs::images/sort-arrow.svg').data|raw }}
</th>
</tr>
</thead>

View File

@ -12,6 +12,7 @@ use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel;
use Visiosoft\AdvsModule\OptionConfiguration\OptionConfigurationModel;
use Visiosoft\AdvsModule\Support\Command\Currency;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CustomfieldsModule\CustomField\Contract\CustomFieldRepositoryInterface;
use Visiosoft\LocationModule\City\CityModel;
use Visiosoft\LocationModule\Country\CountryModel;
use Visiosoft\CartsModule\Cart\Command\GetCart;
@ -383,7 +384,25 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
public function customfields()
{
return $this->hasMany('Visiosoft\CustomfieldsModule\CustomFieldAdv\CustomFieldAdvModel', 'parent_adv_id', 'id');
if ($cFs = (array) json_decode($this->cf_json)) {
$cFs = array_keys($cFs);
$cFIDs = array_map(function ($cF) {
return ltrim($cF, 'cf');
}, $cFs);
return app(CustomFieldRepositoryInterface::class)
->newQuery()
->whereIn('id', $cFIDs)
->get();
}
return [];
}
public function cFJSON()
{
return json_decode($this->cf_json, true);
}
// public function getCustomFieldEditId($id) {

View File

@ -38,6 +38,7 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
$limit = null, $category = null, $city = null, $paginate = true
)
{
$isSort = !empty($param['sort_by']);
$isActiveDopings = new AdvModel();
$isActiveDopings = $isActiveDopings->is_enabled('dopings');
@ -161,11 +162,11 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
$query = $query->whereRaw("ST_DISTANCE(ST_GeomFromText('POINT(" . $param['dlong'] . " " . $param['dlat'] . ")'), coor) < " . $param['distance']);
}
if ($isActiveDopings) {
if ($isActiveDopings && !$isSort) {
$query = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')->search($query, $param);
}
if (!empty($param['sort_by'])) {
if ($isSort) {
switch ($param['sort_by']) {
case "popular":
$query = $query->orderBy('advs_advs.count_show_ad', 'desc');
@ -177,10 +178,10 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
$query = $query->orderBy('advs_advs.price', 'asc');
break;
case "sort_time_newest":
$query = $query->orderBy('advs_advs.created_at', 'desc');
$query = $query->orderBy('advs_advs.publish_at', 'desc');
break;
case "sort_time_oldest":
$query = $query->orderBy('advs_advs.created_at', 'asc');
$query = $query->orderBy('advs_advs.publish_at', 'asc');
break;
case "address_a_z":
$query = $query->join('location_cities_translations', 'advs_advs.city', '=', 'location_cities_translations.entry_id')
@ -201,7 +202,7 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
$query = $query->orderBy('advs_advs.created_at', 'desc');
}
if ($isActiveDopings) {
if ($isActiveDopings && !$isSort) {
$query = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')->querySelect($query, $param);
} else {
$query = $query->select('advs_advs.*', 'advs_advs_translations.name as name',

View File

@ -60,6 +60,8 @@ interface AdvInterface extends EntryInterface
public function customfields();
public function cFJSON();
public function priceFormat($adv);
public function AddAdsDefaultCoverImage($ad);

View File

@ -128,18 +128,6 @@ class AdvsController extends AdminController
$newAdvOption->save();
}
// Replicate ad custom fields
$advCustomFields = $this->model->is_enabled('customfields');
if ($advCustomFields) {
$advCustomFields = app('Visiosoft\CustomfieldsModule\CustomFieldAdv\Contract\CustomFieldAdvRepositoryInterface')
->newQuery()->where('parent_adv_id', $advID)->get();
foreach ($advCustomFields as $advCustomField) {
$newaAdvCustomField = $advCustomField->replicate();
$newaAdvCustomField->parent_adv_id = $newAdv->id;
$newaAdvCustomField->save();
}
}
$this->messages->success(trans('visiosoft.module.advs::message.replicated_success'));
}

View File

@ -22,8 +22,6 @@ use Visiosoft\AdvsModule\Adv\Form\AdvFormBuilder;
use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface;
use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface;
use Visiosoft\AdvsModule\OptionConfiguration\OptionConfigurationModel;
use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface;
use Visiosoft\AdvsModule\ProductoptionsValue\Contract\ProductoptionsValueRepositoryInterface;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\LocationModule\City\CityModel;
use Visiosoft\LocationModule\City\CityRepository;
@ -218,7 +216,7 @@ class AdvsController extends PublicController
'list', $param, $customParameters, null, $category, $cityId, false
);
if ($isActiveDopings) {
if ($isActiveDopings && empty($param['sort_by'])) {
$featuredAdvsQuery = clone $advs;
$response__featured_doping = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')
->listFeatures($featuredAdvsQuery);