Add filters
This commit is contained in:
@@ -14,7 +14,7 @@ class VarietiesDataTable extends DataTable
|
||||
public function query(Variety $model)
|
||||
{
|
||||
// $model = $model::with('specie')->withCount('Articles')->select('botanic_varieties.*');
|
||||
$model = $model::joinRelationship('Specie')->select('botanic_varieties.*', 'botanic_species.name as specie_name')->with(['image','Specie'])->withCount('Articles');
|
||||
$model = $model::joinRelationship('Specie')->select('botanic_varieties.*', 'botanic_species.name as specie_name')->with(['image', 'Specie'])->withCount(['Articles', 'tags']);
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ class VarietiesDataTable extends DataTable
|
||||
Column::make('thumb')->title('')->searchable(false)->orderable(false)->width(40)->class('text-center'),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('articles_count')->title('Nb articles')->class('text-right')->searchable(false),
|
||||
Column::make('tags_count')->title('Nb tags')->class('text-right')->searchable(false),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -13,17 +13,31 @@ class OffersDataTable extends DataTable
|
||||
public function query(Offer $model)
|
||||
{
|
||||
$model = $model->with(['article.article_nature', 'variation', 'tariff']);
|
||||
$model = self::filterByArticleNature($model);
|
||||
$model = self::filterByPackage($model);
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public static function filterByArticleNature($model, $article_nature_id = false)
|
||||
{
|
||||
$article_nature_id = $article_nature_id ? $article_nature_id : self::isFilteredByField('article_nature_id');
|
||||
return $article_nature_id ? $model->byArticleNature($article_nature_id) : $model;
|
||||
}
|
||||
|
||||
public static function filterByPackage($model, $package_id = false)
|
||||
{
|
||||
$package_id = $package_id ? $package_id : self::isFilteredByField('package_id');
|
||||
return $package_id ? $model->byPackage($package_id) : $model;
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('article.name')->title('Article'),
|
||||
Column::make('article.article_nature.name')->title('Nature'),
|
||||
Column::make('variation.name')->title('Déclinaison'),
|
||||
Column::make('tariff.name')->title('Tarif'),
|
||||
$this->makeColumnButtons(),
|
||||
Column::make('article.name')->title('Article'),
|
||||
Column::make('article.article_nature.name')->title('Nature'),
|
||||
Column::make('variation.name')->title('Déclinaison'),
|
||||
Column::make('tariff.name')->title('Tarif'),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\Articles;
|
||||
use App\Repositories\Shop\ArticleNatures;
|
||||
use App\Repositories\Shop\Offers;
|
||||
use App\Repositories\Shop\Packages;
|
||||
use App\Repositories\Shop\Tariffs;
|
||||
use App\Repositories\Shop\Variations;
|
||||
use App\Datatables\Shop\OffersDataTable;
|
||||
@@ -15,6 +17,8 @@ class OfferController extends Controller
|
||||
{
|
||||
public function index(OffersDataTable $dataTable)
|
||||
{
|
||||
$data['article_natures'] = ArticleNatures::getOptions();
|
||||
$data['packages'] = Packages::getOptions();
|
||||
return $dataTable->render('Admin.Shop.Offers.list', $data ?? []);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,4 +19,9 @@ class ArticleNature extends Model
|
||||
{
|
||||
return $this->hasMany(Article::class);
|
||||
}
|
||||
|
||||
public function scopeByArticleNature($query, $id)
|
||||
{
|
||||
return $query->where($this->table . '.id', $id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,11 @@ class Customer extends Model
|
||||
{
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_customers';
|
||||
|
||||
public function CustomerAddresses()
|
||||
{
|
||||
return $this->hasMany(CustomerAddress::class);
|
||||
}
|
||||
|
||||
public function Invoices()
|
||||
{
|
||||
|
||||
@@ -38,13 +38,27 @@ class Offer extends Model
|
||||
return $query->where('article_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByArticleNature($query, $article_nature_id)
|
||||
{
|
||||
return $query->whereHas('article.article_nature', function ($query) use ($article_nature_id) {
|
||||
$query->byArticleNature($article_nature_id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByCategory($query, $category_id)
|
||||
{
|
||||
return $query->whereHas('article.categories', function ($query) use ($category_id) {
|
||||
$query->where('category_id', $category_id);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public function scopeByPackage($query, $package_id)
|
||||
{
|
||||
return $query->whereHas('variation', function ($query) use ($package_id) {
|
||||
$query->byPackage($package_id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeByStatus($query, $id)
|
||||
{
|
||||
return $query->where('status_id', $id);
|
||||
|
||||
@@ -27,4 +27,9 @@ class Variation extends Model
|
||||
{
|
||||
return $this->hasMany(Offer::class);
|
||||
}
|
||||
|
||||
public function scopeByPackage($query, $package_id)
|
||||
{
|
||||
return $query->where($this->table . '.package_id', $package_id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Repositories\Botanic\Varieties;
|
||||
use App\Models\Shop\Article;
|
||||
|
||||
use App\Traits\Repository\Imageable;
|
||||
|
||||
class Articles
|
||||
{
|
||||
use Imageable;
|
||||
@@ -50,6 +51,7 @@ class Articles
|
||||
{
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['image'] = Articles::getPreview($article->image);
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||
$data['tags'] = self::getTagsNameByArticle($article);
|
||||
@@ -164,12 +166,25 @@ class Articles
|
||||
|
||||
public static function getMeta(&$data = [])
|
||||
{
|
||||
$data['products'] = (($data['article']['product_type'] ?? false) == 'App\Models\Botanic\Variety') ? Varieties::getOptionsWithSpecie() : Species::getOptions();
|
||||
switch ($data['article']['product_type'] ?? false) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data['products'] = Varieties::getOptionsWithSpecie();
|
||||
break;
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$data['products'] = Species::getOptions();
|
||||
break;
|
||||
default:
|
||||
$data['products'] = Species::getOptions();
|
||||
}
|
||||
|
||||
$data['categories_options'] = Categories::getOptions();
|
||||
$data['natures_options'] = ArticleNatures::getOptions();
|
||||
$data['packages'] = ($data['article']['article_family_id'] ?? false) ? Packages::getSelectByFamily($data['article']['article_family_id']) : [];
|
||||
// $data['packages'] = ($data['article']['article_family_id'] ?? false) ? Packages::getSelectByFamily($data['article']['article_family_id']) : [];
|
||||
$data['tags_list'] = TagGroups::getTreeTags();
|
||||
$data['models_options'] = ['App\Models\Botanic\Specie' => 'Espèces', 'App\Models\Botanic\Variety' => 'Variétés'];
|
||||
$data['models_options'] = [
|
||||
'App\Models\Botanic\Specie' => 'Espèces',
|
||||
'App\Models\Botanic\Variety' => 'Variétés',
|
||||
];
|
||||
return $data;
|
||||
}
|
||||
|
||||
@@ -271,5 +286,4 @@ class Articles
|
||||
{
|
||||
return Tag::storeTags($article, $tags);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,12 +6,10 @@ use Spatie\Image\Manipulations;
|
||||
use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use Spatie\MediaLibrary\InteractsWithMedia;
|
||||
|
||||
use App\Repositories\Core\Medias;
|
||||
|
||||
trait Imageable
|
||||
{
|
||||
use InteractsWithMedia;
|
||||
|
||||
|
||||
public function images()
|
||||
{
|
||||
return $this->hasMany('App\Models\Core\Media', 'model_id')->where('model_type', get_class($this));
|
||||
@@ -19,7 +17,7 @@ trait Imageable
|
||||
|
||||
public function image()
|
||||
{
|
||||
return $this->hasOne('App\Models\Core\Media', 'model_id')->where('model_type', get_class($this));
|
||||
return $this->hasOne('App\Models\Core\Media', 'model_id')->where('model_type', get_class($this))->latest();
|
||||
}
|
||||
|
||||
public function registerMediaConversions(Media $media = null) : void
|
||||
@@ -30,5 +28,4 @@ trait Imageable
|
||||
$this->addMediaConversion('normal')->fit(Manipulations::FIT_CROP, 480, 480);
|
||||
// $this->addMediaConversion('zoom')->fit(Manipulations::FIT_CROP, 1200, 1200)->withResponsiveImages();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ trait Imageable
|
||||
|
||||
public static function getPreview($image)
|
||||
{
|
||||
return '<img src="' . self::getPreviewSrc($image) . '">';
|
||||
return '<img src="' . self::getPreviewSrc($image) . '" class="img-fluid">';
|
||||
}
|
||||
|
||||
public static function getPreviewSrc($image)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
@component('components.card')
|
||||
@include('components.datatable', ['route' => route('Admin.Shop.Articles.index'), 'model' => 'articles', 'with_filters' => true])
|
||||
@component('components.layout.modal', ['title' => 'Filtres', 'id' => 'modal-articles-filters'])
|
||||
@include('Admin.Shop.Articles.partials.filters')
|
||||
@include('Admin.Shop.Articles.partials.filters', ['model' => 'articles'])
|
||||
@endcomponent
|
||||
@endcomponent
|
||||
@endsection
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<form id="articles-filters">
|
||||
<form id="{{ $model }}-filters">
|
||||
<div class="row">
|
||||
<label class="col-4">{{ __('article_natures.title') }}</label>
|
||||
<div class="col-8">
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<form id="{{ $model }}-filters">
|
||||
<div class="row mb-3">
|
||||
|
||||
</div>
|
||||
</form>
|
||||
@@ -6,6 +6,11 @@
|
||||
|
||||
@section('content')
|
||||
@component('components.card')
|
||||
@include('components.datatable', ['route' => route('Admin.Shop.Offers.index'), 'model' => 'offers'])
|
||||
@include('components.datatable', ['route' => route('Admin.Shop.Offers.index'), 'model' => 'offers', 'with_filters' => true])
|
||||
@component('components.layout.modal', ['title' => 'Filtres', 'id' => 'modal-offers-filters'])
|
||||
@include('Admin.Shop.Offers.partials.filters', ['model' => 'offers'])
|
||||
@endcomponent
|
||||
@endcomponent
|
||||
@endsection
|
||||
|
||||
@include('load.form.select2')
|
||||
@@ -2,14 +2,17 @@
|
||||
<div class="col-12">
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-4">
|
||||
<div class="col-3">
|
||||
{{ Form::label('ref', 'Référence') }}<br>
|
||||
{{ $article['ref'] ?? null }}
|
||||
</div>
|
||||
<div class="col-8">
|
||||
<div class="col-5">
|
||||
{{ Form::label('name', 'Nom') }}<br>
|
||||
{{ $article['name'] ?? null }}
|
||||
</div>
|
||||
<div class="col-3">
|
||||
{!! $article['image'] !!}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
|
||||
14
resources/views/Admin/Shop/Offers/partials/filters.blade.php
Normal file
14
resources/views/Admin/Shop/Offers/partials/filters.blade.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<form id="{{ $model }}-filters">
|
||||
<div class="row mb-3">
|
||||
<label class="col-4">{{ __('shop.article_natures.title') }}</label>
|
||||
<div class="col-8">
|
||||
@include('components.form.select', ['name' => 'article_nature_id', 'list' => $article_natures ?? [], 'value' => $filters['article_nature_id'] ?? null, 'class' => 'form-control-sm select2', 'with_empty' => ''])
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-3">
|
||||
<label class="col-4">{{ __('shop.packages.title') }}</label>
|
||||
<div class="col-8">
|
||||
@include('components.form.select', ['name' => 'package_id', 'list' => $packages ?? [], 'value' => $filters['package_id'] ?? null, 'class' => 'form-control-sm select2', 'with_empty' => ''])
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
@@ -4,23 +4,28 @@
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
{{ Form::label('name', 'Groupe') }}
|
||||
@include('components.form.select', ['name' => 'tag_group_id', 'list' => $tag_groups, 'value' => isset($tag_group_id) ? $tag_group_id : null, 'required' => true, 'with_empty' => ''])
|
||||
@include('components.form.select', ['name' => 'tag_group_id', 'list' => $tag_groups, 'value' => $tag_group_id ?? null, 'required' => true, 'with_empty' => '', 'class' => 'select2'])
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
{{ Form::label('name', 'Nom') }}
|
||||
@include('components.form.input', ['name' => 'name', 'value' => isset($name) ? $name : null, 'required' => true])
|
||||
@include('components.form.input', ['name' => 'name', 'value' => $name ?? null, 'required' => true])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="float-right mt-3">
|
||||
@include('components.form.buttons.button-save')
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@include('components.save')
|
||||
|
||||
@include('load.form.select2')
|
||||
@include('load.form.save')
|
||||
|
||||
@push('js')
|
||||
<script>
|
||||
$(function() {
|
||||
initSaveForm('#tag-form');
|
||||
initSelect2();
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
@if(!defined('LOAD_DATATABLES'))
|
||||
@push('css')
|
||||
<link rel="stylesheet" href="{{ asset('assets/plugins/datatables.min.css') }}">
|
||||
@endpush
|
||||
@endpush
|
||||
|
||||
@push('scripts')
|
||||
@include('load.moment')
|
||||
@include('boilerplate::load.moment')
|
||||
<script src="{{ asset('assets/plugins/datatables.min.js') }}"></script>
|
||||
<script src="{{ asset('vendor/datatables/buttons.server-side.js') }}"></script>
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
}
|
||||
|
||||
function reloadDatatable(name) {
|
||||
// getDatatable(name).ajax.reload(null,false);
|
||||
getDatatable(name).columns.adjust().draw();
|
||||
getDatatable(name).ajax.reload(null,false);
|
||||
// getDatatable(name).columns.adjust().draw();
|
||||
}
|
||||
|
||||
function getDatatable(name) {
|
||||
@@ -84,6 +84,28 @@
|
||||
return table ? table.settings().init().columns : false;
|
||||
}
|
||||
|
||||
function setAlertWhenFiltered(model) {
|
||||
var selector = '#' + model + '-filters';
|
||||
if (checkFilterHasValues(selector)) {
|
||||
$(selector + '-badge').show();
|
||||
} else {
|
||||
$(selector + '-badge').hide();
|
||||
}
|
||||
}
|
||||
|
||||
function checkFilterHasValues(selector) {
|
||||
var tab = $(selector).serializeArray();
|
||||
var hasValue = false;
|
||||
for (item of tab) {
|
||||
if (item.value) {
|
||||
var selector2 = selector + ' input[name="' + item.name + '"]';
|
||||
var isHidden = ( $(selector2).attr('type') == 'hidden' );
|
||||
if (!isHidden) hasValue = true;
|
||||
}
|
||||
}
|
||||
return hasValue;
|
||||
}
|
||||
|
||||
(function() {
|
||||
var searchType = jQuery.fn.DataTable.ext.type.search;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user