Fixes on unities, remove old code
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\DataTables;
|
||||
namespace App\Datatables;
|
||||
|
||||
use Yajra\DataTables\Html\Button;
|
||||
use Yajra\DataTables\Html\Column;
|
||||
@@ -10,172 +10,195 @@ use Yajra\DataTables\Services\DataTable;
|
||||
|
||||
class ParentDataTable extends DataTable
|
||||
{
|
||||
public $rowReorder; // ['selector' => 'tr']
|
||||
public $colReorder = true;
|
||||
public $fixedColumns = false;
|
||||
public $rowReorder = true;
|
||||
public $rowReorderSelector; // ['selector' => 'tr']
|
||||
public $colReorder = false;
|
||||
public $fixedColumns = false;
|
||||
public $scrollX = false;
|
||||
public $scrollCollapse = true;
|
||||
public $sortedColumn = 0;
|
||||
public $sortedOrder = 'asc';
|
||||
public $stateSave = false;
|
||||
|
||||
/**
|
||||
* Build DataTable class.
|
||||
*
|
||||
* @param mixed $query Results from query() method.
|
||||
* @return \Yajra\DataTables\DataTableAbstract
|
||||
*/
|
||||
public function dataTable($query)
|
||||
{
|
||||
return $this->modifier(datatables()->eloquent($query));
|
||||
}
|
||||
/**
|
||||
* Build DataTable class.
|
||||
*
|
||||
* @param mixed $query Results from query() method.
|
||||
* @return \Yajra\DataTables\DataTableAbstract
|
||||
*/
|
||||
public function dataTable($query)
|
||||
{
|
||||
return $this->modifier(datatables()->eloquent($query));
|
||||
}
|
||||
|
||||
public function modifier($datatables)
|
||||
{
|
||||
return $this->addButtons($datatables->setRowId('{{$id}}'));
|
||||
}
|
||||
public function modifier($datatables)
|
||||
{
|
||||
return $this->addButtons($datatables->setRowId('{{$id}}'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add buttons DataTable class.
|
||||
*
|
||||
* @param mixed $query Results from query() method.
|
||||
* @return \Yajra\DataTables\DataTableAbstract
|
||||
*/
|
||||
public function addButtons($datatables)
|
||||
{
|
||||
return $datatables->addColumn('action', $this->getHtmlButtons());
|
||||
}
|
||||
/**
|
||||
* Add buttons DataTable class.
|
||||
*
|
||||
* @param mixed $query Results from query() method.
|
||||
* @return \Yajra\DataTables\DataTableAbstract
|
||||
*/
|
||||
public function addButtons($datatables)
|
||||
{
|
||||
return $datatables->addColumn('action', $this->getHtmlButtons());
|
||||
}
|
||||
|
||||
public function getHtmlButtons()
|
||||
{
|
||||
$buttons = '';
|
||||
public function getHtmlButtons()
|
||||
{
|
||||
$buttons = '';
|
||||
|
||||
// $buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-secondary btn-show mr-2"><i class="fa fa-fw fa-eye"></i></button>';
|
||||
// $buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-primary btn-edit mr-2"><i class="fa fa-fw fa-leaf-alt"></i></button>';
|
||||
$buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-primary btn-edit mr-2"><i class="fa fa-fw fa-pencil-alt"></i></button>';
|
||||
$buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-danger btn-del"><i class="fa fa-fw fa-trash"></i></button>';
|
||||
return $buttons;
|
||||
// return view('components.datatables.buttons.row_action');
|
||||
}
|
||||
// $buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-secondary btn-show mr-2"><i class="fa fa-fw fa-eye"></i></button>';
|
||||
// $buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-primary btn-edit mr-2"><i class="fa fa-fw fa-leaf-alt"></i></button>';
|
||||
$buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-primary btn-edit mr-2"><i class="fa fa-fw fa-pencil-alt"></i></button>';
|
||||
$buttons .= '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-danger btn-del"><i class="fa fa-fw fa-trash"></i></button>';
|
||||
return $buttons;
|
||||
// return view('components.datatables.buttons.row_action');
|
||||
}
|
||||
|
||||
public function makeColumnButtons()
|
||||
{
|
||||
return Column::computed('action')
|
||||
->title('')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
->searchable(false)
|
||||
->addClass('text-center text-nowrap');
|
||||
}
|
||||
public function makeColumnButtons()
|
||||
{
|
||||
return Column::computed('action')
|
||||
->title('')
|
||||
->exportable(false)
|
||||
->printable(false)
|
||||
->searchable(false)
|
||||
->width("74")
|
||||
->addClass('text-center text-nowrap');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get query source of dataTable.
|
||||
*
|
||||
* @param \App\Family $model
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function buildQuery($model)
|
||||
{
|
||||
return $model->newQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional method if you want to use html builder.
|
||||
*
|
||||
* @return \Yajra\DataTables\Html\Builder
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
return $this->buildHtml(strtolower($this->model_name) . '-table');
|
||||
}
|
||||
public static function isFilteredByField($field)
|
||||
{
|
||||
return (request()->has('filters.' . $field)) ? request()->input('filters.'. $field) : (request()->has($field) ? request()->input($field) : false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional method if you want to use html builder.
|
||||
*
|
||||
* @return \Yajra\DataTables\Html\Builder
|
||||
*/
|
||||
public function buildHtml($id)
|
||||
{
|
||||
return $this->builder()
|
||||
->setTableId($id)
|
||||
->parameters($this->getParameters())
|
||||
->columns($this->getColumns())
|
||||
->ajax(['data' => "function(d) { d.filters = $('#filters').serializeJSON(); }"])
|
||||
->dom($this->getDom())
|
||||
->orderBy(0,'asc')
|
||||
->buttons($this->getButtons());
|
||||
}
|
||||
/**
|
||||
* Get query source of dataTable.
|
||||
*
|
||||
* @param \App\Family $model
|
||||
* @return \Illuminate\Database\Eloquent\Builder
|
||||
*/
|
||||
public function buildQuery($model)
|
||||
{
|
||||
return $model->newQuery();
|
||||
}
|
||||
|
||||
/**
|
||||
* Optional method if you want to use html builder.
|
||||
*
|
||||
* @return \Yajra\DataTables\Html\Builder
|
||||
*/
|
||||
public function html()
|
||||
{
|
||||
return $this->buildHtml(strtolower($this->model_name) . '-table');
|
||||
}
|
||||
|
||||
public function getButtons() {
|
||||
return [
|
||||
Button::make('export'),
|
||||
Button::make('print'),
|
||||
Button::make('colvis'),
|
||||
Button::make('columnsToggle')
|
||||
];
|
||||
}
|
||||
/**
|
||||
* Optional method if you want to use html builder.
|
||||
*
|
||||
* @return \Yajra\DataTables\Html\Builder
|
||||
*/
|
||||
public function buildHtml($table_id = false, $selector = false)
|
||||
{
|
||||
$table_id = $table_id ? $table_id : strtolower($this->model_name) . '-table';
|
||||
$selector = $selector ? $selector : '#' . $this->model_name . '-filters';
|
||||
return $this->builder()
|
||||
->setTableId($table_id)
|
||||
->parameters($this->getParameters())
|
||||
->columns($this->getColumns())
|
||||
->ajax([
|
||||
'data' => 'function(d) { d.filters = $("' . $selector . '").serializeJSON(); }',
|
||||
'url' => isset($this->url) ? $this->url : ''
|
||||
])
|
||||
->dom($this->getDom())
|
||||
->orderBy($this->sortedColumn,$this->sortedOrder)
|
||||
->buttons($this->getButtons());
|
||||
}
|
||||
|
||||
public function getParameters()
|
||||
{
|
||||
return [
|
||||
'pageLength' => 5,
|
||||
'scrollX' => true,
|
||||
'scrollCollapse' => true,
|
||||
'colReorder' => $this->colReorder,
|
||||
'rowReorder' => $this->rowReorder,
|
||||
'fixedColumns' => $this->fixedColumns,
|
||||
];
|
||||
}
|
||||
public function getButtons() {
|
||||
return [
|
||||
Button::make('export'),
|
||||
Button::make('print'),
|
||||
Button::make('colvis'),
|
||||
Button::make('columnsToggle')
|
||||
];
|
||||
}
|
||||
|
||||
public function getDom()
|
||||
{
|
||||
$dom = '';
|
||||
// $dom .= $this->getDatatablesHeaderDefault();
|
||||
$dom .= "rt";
|
||||
$dom .= $this->getDatatablesFooterDefault();
|
||||
return $dom;
|
||||
}
|
||||
public function getParameters()
|
||||
{
|
||||
$data = [
|
||||
'pageLength' => 5,
|
||||
'scrollX' => $this->scrollX,
|
||||
'scrollCollapse' => $this->scrollCollapse,
|
||||
'searchDelay' => 500,
|
||||
'colReorder' => $this->colReorder,
|
||||
'fixedColumns' => $this->fixedColumns,
|
||||
// 'autoWidth' => false,
|
||||
'stateSave' => $this->stateSave
|
||||
];
|
||||
if ($this->rowReorder) {
|
||||
$data['rowReorder'] = ['selector' => $this->rowReorderSelector];
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getDatatablesHeader() {
|
||||
return view('components.datatables.header');
|
||||
}
|
||||
public function getDom()
|
||||
{
|
||||
$dom = '';
|
||||
// $dom .= $this->getDatatablesHeaderDefault();
|
||||
$dom .= "rt";
|
||||
$dom .= $this->getDatatablesFooterDefault();
|
||||
return $dom;
|
||||
}
|
||||
|
||||
public function getDatatablesHeaderDefault() {
|
||||
// return "<div class'row'><div class='col'></div></div>";
|
||||
/*
|
||||
|
||||
$dom = 't<"row datatable-pager light"<"col-md-12"'
|
||||
. '<"datatable-more-export-buttons filter-buttons pull-left">'
|
||||
. '<"datatable-more-export-favorites-buttons filter-buttons pull-left">'
|
||||
. '<"datatable-more-export-basket-buttons filter-buttons pull-left">'
|
||||
. '<"datatable-download-buttons filter-buttons pull-left">'
|
||||
. '>>'
|
||||
. '<"dt-toolbar-footer"<"col"i><"col pull-right datatable-pager light nopadding-right"p>>';
|
||||
public function getDatatablesHeader() {
|
||||
return view('components.datatables.header');
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
$dom = "<'row dt-toolbar-header'<'col-lg-4'l><'col-lg-4'B><'col-lg-4 text-right add'f>>";
|
||||
return $dom;
|
||||
// return 't<"row datatable-pager light"<"col-md-12"<"datatable-more-export-buttons filter-buttons pull-left"><"datatable-more-export-favorites-buttons filter-buttons pull-left"><"datatable-more-export-basket-buttons filter-buttons pull-left"><"datatable-download-buttons filter-buttons pull-left">>><"dt-toolbar-footer"<"col-md-6"i><"col-md-6 pull-right datatable-pager light nopadding-right"p>>';
|
||||
public function getDatatablesHeaderDefault() {
|
||||
// return "<div class'row'><div class='col'></div></div>";
|
||||
/*
|
||||
|
||||
$dom = 't<"row datatable-pager light"<"col-md-12"'
|
||||
. '<"datatable-more-export-buttons filter-buttons pull-left">'
|
||||
. '<"datatable-more-export-favorites-buttons filter-buttons pull-left">'
|
||||
. '<"datatable-more-export-basket-buttons filter-buttons pull-left">'
|
||||
. '<"datatable-download-buttons filter-buttons pull-left">'
|
||||
. '>>'
|
||||
. '<"dt-toolbar-footer"<"col"i><"col pull-right datatable-pager light nopadding-right"p>>';
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
$dom = "<'row dt-toolbar-header'<'col-lg-4'l><'col-lg-4'B><'col-lg-4 text-right add'f>>";
|
||||
return $dom;
|
||||
// return 't<"row datatable-pager light"<"col-md-12"<"datatable-more-export-buttons filter-buttons pull-left"><"datatable-more-export-favorites-buttons filter-buttons pull-left"><"datatable-more-export-basket-buttons filter-buttons pull-left"><"datatable-download-buttons filter-buttons pull-left">>><"dt-toolbar-footer"<"col-md-6"i><"col-md-6 pull-right datatable-pager light nopadding-right"p>>';
|
||||
|
||||
public function getDatatablesFooterDefault() {
|
||||
return "<'row pt-3 dt-toolbar-footer'<'col-md-6'i><'col-md-6'p>>";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filename for export.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function filename()
|
||||
{
|
||||
return self::buildFilename($this->model_name);
|
||||
}
|
||||
public function getDatatablesFooterDefault() {
|
||||
return "<'row pt-3 dt-toolbar-footer'<'col-md-6'i><'col-md-6'p>>";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filename for export.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildFilename($name)
|
||||
{
|
||||
return $name . '_' . date('YmdHis');
|
||||
}
|
||||
/**
|
||||
* Get filename for export.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function filename()
|
||||
{
|
||||
return self::buildFilename($this->model_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get filename for export.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function buildFilename($name)
|
||||
{
|
||||
return $name . '_' . date('YmdHis');
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,16 @@ class UnitiesDataTable extends DataTable
|
||||
public function query(Unity $model)
|
||||
{
|
||||
$model = $model::with(['package.article_family'])->select('shop_unities.*');
|
||||
$model = self::filterByFamily($model);
|
||||
return self::buildQuery($model);
|
||||
}
|
||||
|
||||
public static function filterByFamily($model, $family_id = false)
|
||||
{
|
||||
$family_id = $family_id ? $family_id : self::isFilteredByField('family_id');
|
||||
return $family_id ? $model->byArticleFamily($family_id) : $model;
|
||||
}
|
||||
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace App\Http\Controllers\Shop\Admin;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
use App\Repositories\Shop\ArticleFamilies;
|
||||
use App\Repositories\Shop\Packages;
|
||||
use App\Repositories\Shop\Unities;
|
||||
use App\DataTables\Shop\UnitiesDataTable;
|
||||
@@ -13,6 +14,7 @@ class UnityController extends Controller
|
||||
{
|
||||
public function index(UnitiesDataTable $dataTable)
|
||||
{
|
||||
$data['families'] = ArticleFamilies::getOptions();
|
||||
$data['packages'] = Packages::getOptions();
|
||||
return $dataTable->render('Shop.Admin.Unities.list', $data);
|
||||
}
|
||||
@@ -25,7 +27,7 @@ class UnityController extends Controller
|
||||
public function getOptionsByPackage(Request $request)
|
||||
{
|
||||
$id = $request->input('package_id');
|
||||
return response()->json(Unities::getSelectByPackage($id));
|
||||
return response()->json(Unities::getOptionsByPackage($id));
|
||||
}
|
||||
|
||||
public function create()
|
||||
|
||||
@@ -19,7 +19,7 @@ class Package extends Model
|
||||
return $this->hasMany('App\Models\Shop\Unity');
|
||||
}
|
||||
|
||||
public function scopeByFamily($query, $id)
|
||||
public function scopeByArticleFamily($query, $id)
|
||||
{
|
||||
return $query->where('article_family_id', $id);
|
||||
}
|
||||
|
||||
@@ -28,4 +28,19 @@ class Unity extends Model
|
||||
{
|
||||
return $query->where('package_id', $id);
|
||||
}
|
||||
|
||||
public function scopeByArticleFamily($query, $id)
|
||||
{
|
||||
return $query->whereHas('package', function ($query) use ($id) {
|
||||
$query->byArticleFamily($id);
|
||||
});
|
||||
}
|
||||
|
||||
public function scopeActive($query, $active = 1)
|
||||
{
|
||||
return $query->whereHas('third_party', function ($query) use ($active) {
|
||||
$query->active($active);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class Packages
|
||||
|
||||
public static function getSelectByFamily($family_id)
|
||||
{
|
||||
return Package::orderBy('value','asc')->byFamily($family_id)->pluck('value','id')->toArray();
|
||||
return Package::orderBy('value','asc')->byArticleFamily($family_id)->pluck('value','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
|
||||
@@ -2,68 +2,51 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
use Yajra\DataTables\DataTables;
|
||||
|
||||
use App\Models\Shop\Unity;
|
||||
|
||||
class Unities
|
||||
{
|
||||
|
||||
public static function getDatatable()
|
||||
{
|
||||
return Datatables::of($model)->make(true);
|
||||
}
|
||||
public static function getOptions()
|
||||
{
|
||||
return Unity::orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getOptions()
|
||||
{
|
||||
return Unity::orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
public static function getOptionsByPackage($package_id)
|
||||
{
|
||||
return Unity::byPackage($package_id)->orderBy('value','asc')->get()->pluck('value','id')->toArray();
|
||||
}
|
||||
|
||||
public static function getSelectByPackage($package_id)
|
||||
{
|
||||
$values = Unity::byPackage($package_id)->get();
|
||||
$data = [];
|
||||
foreach ($values as $value)
|
||||
{
|
||||
$data[] = ['id' => $value->id, 'text' => $value->value];
|
||||
}
|
||||
return collect($data)->sortBy('text')->values()->all();
|
||||
}
|
||||
public static function getAll()
|
||||
{
|
||||
return Unity::orderBy('value','asc')->get();
|
||||
}
|
||||
|
||||
public static function getAll()
|
||||
{
|
||||
return Unity::orderBy('value','asc')->get();
|
||||
}
|
||||
public static function get($id)
|
||||
{
|
||||
return Unity::find($id);
|
||||
}
|
||||
|
||||
public static function get($id)
|
||||
{
|
||||
return Unity::find($id);
|
||||
}
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
|
||||
public static function store($data)
|
||||
{
|
||||
$id = isset($data['id']) ? $data['id'] : false;
|
||||
$item = $id ? self::update($data) : self::create($data);
|
||||
return $item->id;
|
||||
}
|
||||
public static function create($data)
|
||||
{
|
||||
return Unity::create($data);
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Unity::create($data);
|
||||
}
|
||||
public static function update($data)
|
||||
{
|
||||
return Unity::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function update($data)
|
||||
{
|
||||
return Unity::find($id)->update($data);
|
||||
}
|
||||
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Unity::destroy($id);
|
||||
}
|
||||
public static function destroy($id)
|
||||
{
|
||||
return Unity::destroy($id);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user