Add refreshing for inherited data
This commit is contained in:
@@ -3,18 +3,20 @@
|
||||
namespace App\Datatables\Shop;
|
||||
|
||||
use Yajra\DataTables\Html\Column;
|
||||
|
||||
use App\Datatables\ParentDataTable as DataTable;
|
||||
use App\Models\Shop\Article;
|
||||
|
||||
class ArticlesDataTable extends DataTable
|
||||
{
|
||||
public $model_name = 'articles';
|
||||
public $sortedColumn = 1;
|
||||
|
||||
public function query(Article $model)
|
||||
{
|
||||
// $model = $model::with('Family')->select('shop_articles.*','family.name as family_name')->join('shop_article_families as family', 'family.id', '=', 'shop_articles.article_family_id')->groupBy('shop_articles.id');
|
||||
$model = $model::with('article_nature')->select('shop_articles.*');
|
||||
// $model = $model::joinRelations('Family')->select('shop_articles.*','shop_article_families.name as family_name');
|
||||
// $model = $model::with('article_nature')->select('shop_articles.*');
|
||||
$model = $model::with('article_nature')->joinRelationship('article_nature')->select('shop_articles.*','shop_article_natures.name as nature_name');
|
||||
$model = self::filterByArticleNature($model);
|
||||
return self::buildQuery($model);
|
||||
}
|
||||
@@ -28,7 +30,7 @@ class ArticlesDataTable extends DataTable
|
||||
protected function getColumns()
|
||||
{
|
||||
return [
|
||||
Column::make('article_nature.name')->title('Nature')->orderable(false),
|
||||
Column::make('article_nature.name')->data('nature_name')->title('Nature'),
|
||||
Column::make('name')->title('Nom'),
|
||||
self::makeColumnButtons(),
|
||||
];
|
||||
|
||||
@@ -45,6 +45,8 @@ class ArticleController extends Controller
|
||||
public function edit($id)
|
||||
{
|
||||
$data = Articles::getFull($id);
|
||||
// dump($data);
|
||||
// exit;
|
||||
return view('Admin.Shop.Articles.edit', $data);
|
||||
}
|
||||
|
||||
@@ -53,6 +55,24 @@ class ArticleController extends Controller
|
||||
return Articles::destroy($id);
|
||||
}
|
||||
|
||||
public function getProductDescription($product_id, $model)
|
||||
{
|
||||
$data['article']['inherited'] = Articles::getInheritedByProduct($product_id, base64_decode($model));
|
||||
return view('Admin.Shop.Articles.partials.product.description', $data);
|
||||
}
|
||||
|
||||
public function getProductTags($product_id, $model)
|
||||
{
|
||||
$data = Articles::getInheritedByProduct($product_id, base64_decode($model));
|
||||
return view('Admin.Shop.Articles.partials.product.tags', $data);
|
||||
}
|
||||
|
||||
public function getProductImages($product_id, $model)
|
||||
{
|
||||
$data = Articles::getInheritedByProduct($product_id, base64_decode($model));
|
||||
return view('Admin.Shop.Articles.partials.product.images', $data);
|
||||
}
|
||||
|
||||
public function getImages(Request $request, $id = false)
|
||||
{
|
||||
$id = $id ? $id : $request->input('id');
|
||||
|
||||
@@ -31,7 +31,7 @@ class CategoryController extends Controller
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$ret = Categories::store($request->all());
|
||||
$ret = Categories::storeFull($request->all());
|
||||
return redirect()->route('Admin.Shop.Categories.index');
|
||||
}
|
||||
|
||||
|
||||
@@ -14,12 +14,13 @@ use Spatie\MediaLibrary\MediaCollections\Models\Media;
|
||||
use BeyondCode\Comments\Traits\HasComments;
|
||||
use Rinvex\Categories\Traits\Categorizable;
|
||||
use Rinvex\Tags\Traits\Taggable;
|
||||
use Kirschbaum\PowerJoins\PowerJoins;
|
||||
use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin;
|
||||
use Wildside\Userstamps\Userstamps;
|
||||
|
||||
class Article extends Model implements HasMedia
|
||||
{
|
||||
use Categorizable, EloquentJoin, HasComments, InteractsWithMedia, Taggable, SoftDeletes, UserStamps;
|
||||
use Categorizable, EloquentJoin, HasComments, InteractsWithMedia, Powerjoins, Taggable, SoftDeletes, UserStamps;
|
||||
|
||||
protected $guarded = ['id'];
|
||||
protected $table = 'shop_articles';
|
||||
|
||||
@@ -35,7 +35,7 @@ class Articles
|
||||
|
||||
public static function getArticle($id)
|
||||
{
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesNameByArticle($article);
|
||||
@@ -53,7 +53,7 @@ class Articles
|
||||
|
||||
public static function getArticleEdit($id)
|
||||
{
|
||||
$article = Article::with('product.tags')->findOrFail($id);
|
||||
$article = self::get($id);
|
||||
$data = $article->toArray();
|
||||
$data['inherited'] = self::getInherited($id);
|
||||
$data['categories'] = self::getCategoriesByArticle($article);
|
||||
@@ -81,6 +81,26 @@ class Articles
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getInheritedByProduct($product_id, $product_type)
|
||||
{
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$product = Varieties::get($product_id);
|
||||
$data[] = ['name' => 'Espèces', 'description' => Species::getDescription($product->specie_id), 'tags' => Species::getTags($product->specie_id)];
|
||||
$data[] = ['name' => 'Variétés', 'description' => $product->description, 'tags' => $product->tags->toArray()];
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$product = Species::get($product_id);
|
||||
$data[] = ['name' => 'Espèces', 'description' => $product->description, 'tags' => $product->tags->toArray()];
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$product = Merchandises::get($product_id);
|
||||
$data[] = ['name' => 'Marchandise', 'description' => $product->description, 'tags' => $product->tags->toArray()];
|
||||
break;
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function getMeta(&$data = [])
|
||||
{
|
||||
$data['products'] = (($data['article']['product_type'] ?? false) == 'App\Models\Botanic\Variety') ? Varieties::getOptionsWithSpecie() : Species::getOptions();
|
||||
|
||||
@@ -28,10 +28,10 @@ class Categories
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$images = isset($data['images']) ? $data['images'] : false;
|
||||
$images = $data['images'] ?? false;
|
||||
unset($data['images']);
|
||||
|
||||
$tags = isset($data['tags']) ? $data['tags'] : false;
|
||||
$tags = $data['tags'] ?? false;
|
||||
unset($data['tags']);
|
||||
|
||||
$category = self::store($data);
|
||||
@@ -54,6 +54,7 @@ class Categories
|
||||
return (int) $item;
|
||||
}
|
||||
)->toArray();
|
||||
|
||||
return $category->syncTags($tags, true);
|
||||
} else {
|
||||
return false;
|
||||
|
||||
@@ -33,11 +33,11 @@ class CategoryTrees
|
||||
|
||||
switch ($type) {
|
||||
case 'after':
|
||||
dump("$node_id After $target_id");
|
||||
// dump("$node_id After $target_id");
|
||||
$category->afterNode($category_target);
|
||||
break;
|
||||
case 'inside':
|
||||
dump("$node_id inside $target_id");
|
||||
// dump("$node_id inside $target_id");
|
||||
$category_target->appendNode($category);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
</div>
|
||||
<div class="col-4">
|
||||
{{ Form::label('article_nature_id', __('shop.article_natures.name')) }}<br>
|
||||
@include('components.select', ['name' => 'article_nature_id', 'list' => $natures_options, 'value' => $article['article_nature_id'] ?? null, 'class' => 'select2', 'with_empty' => ''])
|
||||
@include('components.select', ['name' => 'article_nature_id', 'list' => $natures_options, 'value' => $article['article_nature_id'] ?? null, 'class' => 'select2', 'with_empty' => '', 'required' => true])
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-12">
|
||||
<div class="col-12" id="product_description">
|
||||
@include('Admin.Shop.Articles.partials.product.description')
|
||||
</div>
|
||||
</div>
|
||||
@@ -69,6 +69,16 @@
|
||||
var product = $('#product_id').select2('data');
|
||||
var name = product[0]['text'];
|
||||
$('input[name="name"]').val(name);
|
||||
console.log(product);
|
||||
|
||||
var product_type = $('#product_type').select2('data');
|
||||
var name = product_type[0]['id'];
|
||||
console.log(product_type);
|
||||
console.log(name);
|
||||
|
||||
var url = "{{ route('Admin.Shop.Articles.getProductDescription') }}/" + product[0]['id'] + '/' + btoa(name);
|
||||
console.log(url);
|
||||
$('#product_description').load(url);
|
||||
});
|
||||
|
||||
$('#product_type').change( function() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@if (!empty($article['product']['description']))
|
||||
@component('components.layout.box-collapse', ['id' => 'product_description', 'title' => 'Informations héritées'])
|
||||
@if (count($article['inherited'] ?? []))
|
||||
@component('components.layout.box-collapse', ['id' => 'product_description_box', 'title' => 'Informations héritées'])
|
||||
@foreach ($article['inherited'] as $inherited)
|
||||
@component('components.card', ['title' => $inherited['name'], 'class' => 'mb-3'])
|
||||
{!! $inherited['description'] !!}
|
||||
|
||||
@@ -12,5 +12,9 @@ Route::prefix('Articles')->name('Articles.')->group(function () {
|
||||
|
||||
Route::any('autocomplete/{q?}', 'ArticleController@autocomplete')->name('autocomplete');
|
||||
|
||||
Route::get('getProductDescription/{product_id?}/{model?}', 'ArticleController@getProductDescription')->name('getProductDescription');
|
||||
Route::get('getProductTags/{product_id?}/{model?}', 'ArticleController@getProductTags')->name('getProductTags');
|
||||
Route::get('getProductImages/{product_id?}/{model?}', 'ArticleController@getProductImages')->name('getProductImages');
|
||||
});
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user