refactoring of admin datatables
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Datatables\Shop;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\ArticleNature;
|
||||
use App\Repositories\Shop\ArticleNatures;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
class ArticleNaturesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'article_natures';
|
||||
|
||||
public function query(ArticleNature $model)
|
||||
{
|
||||
$model = $model::withCount('Articles');
|
||||
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('product_type', function (ArticleNature $nature) {
|
||||
return ArticleNatures::getProductTypeName($nature->product_type);
|
||||
})
|
||||
->rawColumns(['action']);
|
||||
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('product_type')->title('Famille de produit')->width(140),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('articles_count')->title('Nb Art.')->addClass('text-right')->searchable(false)->width(60),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,114 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Datatables\Shop;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Article;
|
||||
use App\Repositories\Shop\Articles;
|
||||
use App\Repositories\Shop\Tags;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
class ArticlesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'articles';
|
||||
|
||||
public $sortedColumn = 2;
|
||||
|
||||
public function query(Article $model)
|
||||
{
|
||||
$model = $model::with(['article_nature', 'image'])->withCount(['categories', 'images', 'offers', 'tags']);
|
||||
$model = self::filterByArticleNature($model);
|
||||
$model = self::filterByCategory($model);
|
||||
$model = self::filterByTag($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 filterByCategory($model, $category_id = false)
|
||||
{
|
||||
$category_id = $category_id ? $category_id : self::isFilteredByField('category_id');
|
||||
|
||||
return $category_id ? $model->byCategory($category_id) : $model;
|
||||
}
|
||||
|
||||
public static function filterByTag($model, $tag_id = false)
|
||||
{
|
||||
$tag_id = $tag_id ? $tag_id : self::isFilteredByField('tag_id');
|
||||
|
||||
return $tag_id ? $model->byTag($tag_id) : $model;
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('visible', function (Article $article) {
|
||||
return view('components.form.toggle', [
|
||||
'name' => 'visible',
|
||||
'value' => $article->visible,
|
||||
'on' => __('oui'),
|
||||
'off' => __('non'),
|
||||
'meta' => 'data-id='.$article->id,
|
||||
'size' => 'sm',
|
||||
'class' => 'visible',
|
||||
]);
|
||||
})
|
||||
->editColumn('homepage', function (Article $article) {
|
||||
return view('components.form.toggle', [
|
||||
'name' => 'homepage',
|
||||
'value' => $article->homepage,
|
||||
'on' => __('oui'),
|
||||
'off' => __('non'),
|
||||
'meta' => 'data-id='.$article->id,
|
||||
'size' => 'sm',
|
||||
'class' => 'homepage',
|
||||
]);
|
||||
})
|
||||
->editColumn('thumb', function (Article $article) {
|
||||
$image = Articles::getFullImageByArticle($article);
|
||||
|
||||
return Articles::getThumb($image, false);
|
||||
})
|
||||
->editColumn('article_nature.name', function (Article $article) {
|
||||
return $article->article_nature ? $article->article_nature->name : '';
|
||||
})
|
||||
->editColumn('tags2', function (Article $article) {
|
||||
$html = '';
|
||||
foreach ($article->tags as $tag) {
|
||||
$html .= Tags::getTagHtml($tag);
|
||||
}
|
||||
|
||||
return $html;
|
||||
})
|
||||
->editColumn('images_count2', function (Article $article) {
|
||||
return Articles::countFullImagesByArticle($article);
|
||||
})
|
||||
->rawColumns(['tags2', 'thumb', 'action']);
|
||||
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('visible')->title('Visible')->searchable(false)->width(50),
|
||||
Column::make('homepage')->title('Accueil')->searchable(false)->width(50),
|
||||
Column::make('article_nature.name')->title('Nature'),
|
||||
Column::make('thumb')->title('')->searchable(false)->orderable(false)->width(40)->class('text-center'),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('tags2')->title('Tags')->searchable(false)->orderable(false),
|
||||
Column::make('tags_count')->title('#Tag')->class('text-right')->searchable(false)->width(40),
|
||||
Column::make('categories_count')->title('#Ray')->class('text-right')->searchable(false)->width(40),
|
||||
Column::make('offers_count')->title('#Ofr')->class('text-right')->searchable(false)->width(40),
|
||||
Column::make('images_count')->title('#Pho')->class('text-right')->searchable(false)->width(40),
|
||||
Column::make('images_count2')->title('#PhoH')->class('text-right')->searchable(false)->orderable(false)->width(40),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Datatables\Shop;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Delivery;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
class DeliveriesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'deliveries';
|
||||
|
||||
public function query(Delivery $model)
|
||||
{
|
||||
$model = $model->with('sale_channel');
|
||||
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('active', function (Delivery $delivery) {
|
||||
return view('components.form.toggle', [
|
||||
'value' => $delivery->active,
|
||||
'on' => __('active'),
|
||||
'off' => __('inactive'),
|
||||
'meta' => 'data-id='.$delivery->id,
|
||||
'size' => 'sm',
|
||||
]);
|
||||
})
|
||||
->editColumn('address', function (Delivery $delivery) {
|
||||
return $delivery->address.' '.$delivery->zipcode.' '.$delivery->city;
|
||||
})
|
||||
->rawColumns(['active', 'address', 'action']);
|
||||
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('active')->title(__('active'))->width(60)->class('text-center'),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('sale_channel.name')->title(__('shop.sale_channels.name')),
|
||||
Column::make('address')->title('Adresse')->searchable(false),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Datatables\Shop;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Repositories\Shop\Offers;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
class OffersDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'offers';
|
||||
|
||||
public $sortedColumn = 1;
|
||||
|
||||
public function query(Offer $model)
|
||||
{
|
||||
$model = $model->with(['article.article_nature', 'variation', 'tariff'])->select($model->getTable().'.*');
|
||||
$model = self::filterByArticleNature($model);
|
||||
$model = self::filterByPackage($model);
|
||||
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
public static function filterByArticleNature($model, $articleNatureId = false)
|
||||
{
|
||||
$articleNatureId = $articleNatureId ? $articleNatureId : self::isFilteredByField('article_nature_id');
|
||||
|
||||
return $articleNatureId ? $model->byArticleNature($articleNatureId) : $model;
|
||||
}
|
||||
|
||||
public static function filterByPackage($model, $packageId = false)
|
||||
{
|
||||
$packageId = $packageId ? $packageId : self::isFilteredByField('package_id');
|
||||
|
||||
return $packageId ? $model->byPackage($packageId) : $model;
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
$datatables
|
||||
->editColumn('thumb', function (Offer $offer) {
|
||||
return '<img src="'.Offers::getThumbSrc($offer).'">';
|
||||
})
|
||||
->editColumn('status_id', function (Offer $offer) {
|
||||
return view('components.form.toggle', [
|
||||
'name' => 'status_id',
|
||||
'value' => $offer->status_id,
|
||||
'on' => __('active'),
|
||||
'off' => __('inactive'),
|
||||
'meta' => 'data-id='.$offer->id,
|
||||
'size' => 'xs',
|
||||
]);
|
||||
})
|
||||
->editColumn('stock_delayed', function (Offer $offer) {
|
||||
return $offer->stock_delayed.' - '.$offer->delay_type;
|
||||
})
|
||||
->rawColumns(['active', 'thumb', 'action']);
|
||||
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('status_id')->title('')->width(40)->searchable(false),
|
||||
Column::make('article.article_nature.name')->title('Nature')->defaultContent('')->searchable(false),
|
||||
Column::make('thumb')->title('')->width(30)->searchable(false)->addClass('text-center'),
|
||||
Column::make('article.name')->title('Article')->defaultContent(''),
|
||||
Column::make('variation.name')->title('Déclinaison')->defaultContent('')->searchable(false),
|
||||
Column::make('weight')->title('Poids')->searchable(false)->addClass('text-right'),
|
||||
Column::make('tariff.name')->title('Tarif')->defaultContent('')->searchable(false),
|
||||
Column::make('stock_current')->title('Appro im')->searchable(false)->addClass('text-right'),
|
||||
Column::make('stock_delayed')->title('Appro délai')->searchable(false)->addClass('text-right'),
|
||||
Column::make('stock_ondemand')->title('Dmde')->searchable(false)->addClass('text-right'),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,11 @@ class OrdersDataTable extends DataTable
|
||||
return parent::modifier($datatables);
|
||||
}
|
||||
|
||||
public function getHtmlButtons()
|
||||
{
|
||||
return self::getButtonShow();
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Datatables\Shop;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\SaleChannel;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
class SaleChannelsDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'sale_channels';
|
||||
|
||||
public function query(SaleChannel $model)
|
||||
{
|
||||
$model = $model->withCount(['deliveries', 'tariffs']);
|
||||
|
||||
return $this->buildQuery($model);
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('code')->title('Code abrégé')->width(100),
|
||||
Column::make('name')->title('Nom'),
|
||||
Column::make('deliveries_count')->title('#Distrib')->searchable(false)->class('text-right'),
|
||||
Column::make('tariffs_count')->title('#Tarifs')->searchable(false)->class('text-right'),
|
||||
$this->makeColumnButtons(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user