This commit is contained in:
Ludovic CANDELLIER
2021-08-21 19:48:21 +02:00
parent 9a0601d473
commit 81fbec892c
24 changed files with 423 additions and 65 deletions

View File

@@ -0,0 +1,35 @@
<?php
namespace App\Datatables\Admin\Core;
use Yajra\DataTables\Html\Column;
use App\Datatables\ParentDataTable as DataTable;
use App\Models\Admin\Core\Comment;
use App\Repositories\Core\Comments;
class CommentsDataTable extends DataTable
{
public $model_name = 'comments';
public function __construct()
{
$this->url = route('Admin.Core.Comments.index');
}
public function query(Comment $model)
{
$model = $model::with(['user'])->select('*');
return self::buildQuery($model);
}
protected function getColumns()
{
return [
Column::make('updated_at')->title(__('date'))->width('80')->class('text-center')->searchable(false),
Column::make('user.name')->title(__('name'))->searchable(false),
Column::make('comment')->title(__('comments'))->searchable(false),
self::makeColumnButtons(),
];
}
}

View File

@@ -10,22 +10,24 @@ use Yajra\DataTables\Services\DataTable;
class ParentDataTable extends DataTable class ParentDataTable extends DataTable
{ {
public $rowReorder = true; public $autoWidth = false;
public $rowReorderSelector; // ['selector' => 'tr']
public $colReorder = false; public $colReorder = false;
public $fixedColumns = false; public $fixedColumns = false;
public $fixedHeader = false;
public $rowReorder = false;
public $rowReorderSelector; // ['selector' => 'tr']
public $scrollCollapse = false;
public $scrollX = false; public $scrollX = false;
public $scrollCollapse = true;
public $sortedColumn = 0; public $sortedColumn = 0;
public $sortedOrder = 'asc'; public $sortedOrder = 'asc';
public $stateSave = false; public $stateSave = false;
/** /**
* Build DataTable class. * Build DataTable class.
* *
* @param mixed $query Results from query() method. * @param mixed $query Results from query() method.
* @return \Yajra\DataTables\DataTableAbstract * @return \Yajra\DataTables\DataTableAbstract
*/ */
public function dataTable($query) public function dataTable($query)
{ {
return $this->modifier(datatables()->eloquent($query)); return $this->modifier(datatables()->eloquent($query));
@@ -39,7 +41,7 @@ class ParentDataTable extends DataTable
/** /**
* Add buttons DataTable class. * Add buttons DataTable class.
* *
* @param mixed $query Results from query() method. * @param mixed $query Results from query() method.
* @return \Yajra\DataTables\DataTableAbstract * @return \Yajra\DataTables\DataTableAbstract
*/ */
public function addButtons($datatables) public function addButtons($datatables)
@@ -50,15 +52,27 @@ class ParentDataTable extends DataTable
public function getHtmlButtons() public function getHtmlButtons()
{ {
$buttons = ''; $buttons = '';
$buttons .= self::getButtonEdit();
// $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 .= self::getButtonDel();
// $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 $buttons;
// return view('components.datatables.buttons.row_action'); // return view('components.datatables.buttons.row_action');
} }
public function getButtonEdit()
{
return '<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>';
}
public function getButtonShow()
{
return '<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>';
}
public function getButtonDel()
{
return '<button type="button" data-id="{{$id}}" class="btn btn-xs btn-danger btn-del"><i class="fa fa-fw fa-trash"></i></button>';
}
public function makeColumnButtons() public function makeColumnButtons()
{ {
return Column::computed('action') return Column::computed('action')
@@ -66,7 +80,7 @@ class ParentDataTable extends DataTable
->exportable(false) ->exportable(false)
->printable(false) ->printable(false)
->searchable(false) ->searchable(false)
->width("74") ->width(74)
->addClass('text-center text-nowrap'); ->addClass('text-center text-nowrap');
} }
@@ -78,7 +92,7 @@ class ParentDataTable extends DataTable
/** /**
* Get query source of dataTable. * Get query source of dataTable.
* *
* @param \App\Family $model * @param \App\Family $model
* @return \Illuminate\Database\Eloquent\Builder * @return \Illuminate\Database\Eloquent\Builder
*/ */
public function buildQuery($model) public function buildQuery($model)
@@ -106,24 +120,22 @@ class ParentDataTable extends DataTable
$table_id = $table_id ? $table_id : strtolower($this->model_name) . '-table'; $table_id = $table_id ? $table_id : strtolower($this->model_name) . '-table';
$selector = $selector ? $selector : '#' . $this->model_name . '-filters'; $selector = $selector ? $selector : '#' . $this->model_name . '-filters';
return $this->builder() return $this->builder()
->setTableId($table_id) ->setTableId($table_id)
->parameters($this->getParameters()) ->parameters($this->getParameters())
->columns($this->getColumns()) ->columns($this->getColumns())
->ajax( ->ajax([
[
'data' => 'function(d) { d.filters = $("' . $selector . '").serializeJSON(); }', 'data' => 'function(d) { d.filters = $("' . $selector . '").serializeJSON(); }',
'url' => isset($this->url) ? $this->url : '' 'url' => isset($this->url) ? $this->url : ''
] ])
) ->dom($this->getDom())
->dom($this->getDom()) ->orderBy($this->sortedColumn, $this->sortedOrder)
->orderBy($this->sortedColumn, $this->sortedOrder) ->buttons($this->getButtons());
->buttons($this->getButtons());
} }
public function getButtons() public function getButtons()
{ {
return [ return [
Button::make('export'), // Button::make('export'),
Button::make('print'), Button::make('print'),
Button::make('colvis'), Button::make('colvis'),
Button::make('columnsToggle') Button::make('columnsToggle')
@@ -133,13 +145,14 @@ class ParentDataTable extends DataTable
public function getParameters() public function getParameters()
{ {
$data = [ $data = [
'pageLength' => 5, 'autoWidth' => $this->autoWidth,
'scrollX' => $this->scrollX,
'scrollCollapse' => $this->scrollCollapse,
'searchDelay' => 500,
'colReorder' => $this->colReorder, 'colReorder' => $this->colReorder,
'fixedColumns' => $this->fixedColumns, 'fixedColumns' => $this->fixedColumns,
// 'autoWidth' => false, 'fixedHeader' => $this->fixedHeader,
'pageLength' => 5,
'searchDelay' => 500,
'scrollX' => $this->scrollX,
'scrollCollapse' => $this->scrollCollapse,
'stateSave' => $this->stateSave 'stateSave' => $this->stateSave
]; ];
if ($this->rowReorder) { if ($this->rowReorder) {

View File

@@ -0,0 +1,46 @@
<?php
namespace App\Http\Controllers\Admin\Core;
use Illuminate\Http\Request;
use App\Repositories\Core\Comments;
use App\Datatables\Admin\Core\CommentsDataTable;
class CommentController extends Controller
{
public function index(CommentsDataTable $dataTable, $model, $model_id)
{
$data['model'] = $model;
$data['model_id'] = $model_id;
return $dataTable->render('Admin.Core.Comment.index', $data);
}
public function create($model, $model_id)
{
$data['comment']['commentable_type'] = $model;
$data['comment']['commentable_id'] = $model_id;
return view('Admin.Core.Comments.partials.modal', $data);
}
public function edit(Request $request, $id = false)
{
$id = $id ? $id : $request->input('id');
$data = Comments::get($id);
return view('Admin.Core.Comments.partials.modal', $data);
}
public function store(Request $request)
{
$data = $request->all();
Comments::store($data);
return response()->json(['error' => 0]);
}
public function destroy(Request $request, $id = false)
{
$id = $id ? $id : $request->input('id');
Comments::destroy($id);
return response()->json(['error' => 0]);
}
}

View File

@@ -25,6 +25,7 @@ class ArticleController extends Controller
public function create() public function create()
{ {
$data = Articles::getMeta(); $data = Articles::getMeta();
// $data['comment']['']
return view('Admin.Shop.Articles.create', $data); return view('Admin.Shop.Articles.create', $data);
} }

View File

@@ -22,6 +22,8 @@ class OfferController extends Controller
public function store(Request $request) public function store(Request $request)
{ {
dump($request->all());
exit;
$ret = Offers::store($request->all()); $ret = Offers::store($request->all());
return redirect()->route('Admin.Shop.Offers.index'); return redirect()->route('Admin.Shop.Offers.index');
} }

View File

@@ -2,15 +2,22 @@
namespace App\Models\Core; namespace App\Models\Core;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\SoftDeletes;
use Venturecraft\Revisionable\RevisionableTrait; use App\Repositories\Core\DateTime;
use Wildside\Userstamps\Userstamps;
use BeyondCode\Comments\Comment as parentComment; class Comment extends Model
class Comment extends parentComment
{ {
use SoftDeletes, Userstamps; protected $guarded = [];
public function user()
{
return $this->belongsTo(\App\Models\Core\Auth\User::class);
}
public function getUpdatedAtAttribute($value)
{
return DateTime::DateToLocale($value);
}
} }

View File

@@ -2,23 +2,50 @@
namespace App\Repositories\Core; namespace App\Repositories\Core;
use BeyondCode\Comments\Comment;
use App\Models\Core\Comment as rawComment;
use App\Repositories\Core\Auth\Users;
use App\Datatables\Admin\Core\CommentsDataTable;
class Comments class Comments
{ {
public static function get($id)
{
return rawComment::find($id);
}
public static function getDatatable()
{
$model = new CommentsDataTable();
return $model->html();
}
public static function getCommentsByClass($class, $id)
{
return self::getByModel(self::getModel($class, $id));
}
public static function getModel($class, $id)
{
return $$class::find($id);
}
public static function getClass($class)
{
return 'App\Models\\' . str_replace('.','\\', $class);
}
public static function getByModel($model) public static function getByModel($model)
{ {
if (!$model) { return $model ? $model->comments : false;
return false;
}
return $model->comments;
} }
public static function storeComments($model, $comments) public static function storeComments($model, $comments)
{ {
if ($comments) { foreach (($comments ?? []) as $comment) {
foreach ($comments as $comment) { self::storeComment($model, $comment);
self::storeComment($model, $comment);
}
} }
} }
@@ -27,6 +54,31 @@ class Comments
return $model->comment($comment); return $model->comment($comment);
} }
public static function store($data)
{
$id = $data['id'] ?? false;
unset($data['_token']);
$data['commentable_type'] = Comments::getClass($data['commentable_type']);
$data['commentable_id'] = (int) $data['commentable_id'];
return $id ? self::update($data, $id) : self::create($data);
}
public static function create($data)
{
unset($data['id']);
$data['is_approved'] = true;
$data['user_id'] = Users::getId();
return rawComment::create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$model = self::get($id);
$model->update($data);
return $model;
}
public static function deleteComments($model) public static function deleteComments($model)
{ {
return true; return true;

View File

@@ -6,6 +6,7 @@ use Illuminate\Support\Str;
use App\Repositories\Core\Tag; use App\Repositories\Core\Tag;
use App\Repositories\Core\Media; use App\Repositories\Core\Media;
use App\Repositories\Core\Comments;
use App\Repositories\Botanic\Species; use App\Repositories\Botanic\Species;
use App\Repositories\Botanic\Varieties; use App\Repositories\Botanic\Varieties;
use App\Models\Shop\Article; use App\Models\Shop\Article;
@@ -37,6 +38,10 @@ class Articles
$data['article']['categories'] = self::getCategoriesByArticle($article); $data['article']['categories'] = self::getCategoriesByArticle($article);
$data['article']['tags'] = self::getTagsByArticle($article); $data['article']['tags'] = self::getTagsByArticle($article);
// $data['article']['prices'] = self::getPricesByArticle($article); // $data['article']['prices'] = self::getPricesByArticle($article);
// $data['datatables']['comments'] = Comments::getDatatable();
$data['article']['comments'] = $article->comments;
self::getMeta($data); self::getMeta($data);
return $data; return $data;
} }

View File

@@ -0,0 +1,53 @@
<?php
namespace App\Repositories\Shop;
use App\Models\Shop\Offer;
class Offers
{
public static function getOptions()
{
return Offer::orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
}
public static function getOptionsByPackage($package_id)
{
return Offer::byPackage($package_id)->orderBy('value', 'asc')->get()->pluck('value', 'id')->toArray();
}
public static function getAll()
{
return Offer::orderBy('value', 'asc')->get();
}
public static function get($id)
{
return Offer::findOrFail($id);
}
public static function store($data)
{
$id = isset($data['id']) ? $data['id'] : false;
$item = $id ? self::update($data, $id) : self::create($data);
return $item->id;
}
public static function create($data)
{
return Offer::create($data);
}
public static function update($data, $id = false)
{
$id = $id ? $id : $data['id'];
$item = self::get($id);
$item->update($data);
return $item;
}
public static function destroy($id)
{
return Offer::destroy($id);
}
}

View File

@@ -8,7 +8,7 @@ class Tariffs
{ {
public static function autocomplete($str) public static function autocomplete($str)
{ {
$data = Tariff::where('name', 'LIKE', "%${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id'); $data = Tariff::where('name', 'LIKE', "%${str}%")->orWhere('ref', 'LIKE', "${str}%")->orWhere('code', 'LIKE', "${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
$export = []; $export = [];
foreach ($data as $key => $name) { foreach ($data as $key => $name) {
$export[] = ['value' => $key, 'text' => $name]; $export[] = ['value' => $key, 'text' => $name];

58
resources/lang/fr.json Normal file
View File

@@ -0,0 +1,58 @@
{
"Date": "Date",
"The list of logs is empty!": "La liste des logs est vide !",
"All": "Tous",
"Emergency": "Urgence",
"Alert": "Alerte",
"Critical": "Critique",
"Error": "Erreur",
"Warning": "Avertissement",
"Notice": "Notice",
"Info": "Info",
"Debug": "Debogage",
"name": "Nom",
"gender": "Civilité",
"mr": "M.",
"mrs": "Mme",
"firstname": "Prénom",
"lastname": "Nom",
"position": "Poste",
"department": "Service",
"office": "Bureau",
"fax": "Fax",
"email": "Email",
"phone": "Téléphone",
"phone_central": "Téléphone Accueil",
"mobile": "Mobile",
"zipcode": "Code postal",
"country": "Pays",
"company": "Entreprise",
"address": "Adresse",
"street": "Rue",
"state": "Région",
"postal_address": "Adresse postale",
"city": "Ville",
"copyright": "© JardinEnvie 2021",
"records": "enregistrements",
"delay": "Délai",
"rows_on": "lignes sur",
"selection": "Sélection",
"others": "Autres",
"list": "Liste",
"active": "Actif",
"yes": "Oui",
"no": "Non",
"choose_a_file": "Choisissez un fichier",
"select_a_value": "Selectionnez une valeur",
"members_area": "Espace réservé",
"login_to_your_account": "Se connecter à votre compte",
"sign_in": "connexion",
"password_reset": "Réinitialisation du mot de passe",
"login": "Identifiant",
"password": "Mot de passe",
"updated_at": "Mis à jour",
"cancel": "Annuler",
"save": "Sauver",
"comments": "Notes internes",
"comment_add": "Ajout de Note interne"
}

View File

@@ -1,11 +1,35 @@
@component('components.layout.box-collapse', ['id' => 'comments', 'title' => __('comments')]) @component('components.layout.box-collapse', ['id' => 'comments', 'title' => __('comments')])
@if (!empty($comments)) @if (!empty($comments))
@foreach ($comments as $comment) @foreach ($comments as $comment)
{!! $comment !!} <div class="row">
<div class="col-6">
<strong>{{ App\Repositories\Core\Auth\Users::getName($comment->user_id) }}</strong>
</div>
<div class="col-6 text-right"><i>{{ App\Repositories\Core\DateTime::DateToLocale($comment->updated_at) }}</i></div>
<div class="col-12">
{!! $comment->comment !!}
</div>
</div>
@endforeach @endforeach
@endif @endif
<button type="button" class="btn btn-primary">
Ajout note interne <button type="button" class="btn btn-xs btn-primary" id="add-comment">
{{ __('comment_add') }}
<i class="fa fa-plus"></i> <i class="fa fa-plus"></i>
</button> </button>
@endcomponent @endcomponent
@push('js')
<script>
function handleAddComment() {
$('#add-comment').click(function() {
openModal('{{ __('comment_add') }}', '#comment-form', '{{ route('Admin.Core.Comments.create', ['model' => $model, 'model_id' => $model_id]) }}', '{{ route('Admin.Core.Comments.store') }}' );
});
}
$(document).ready(function () {
handleAddComment();
});
</script>
@endpush

View File

@@ -0,0 +1,7 @@
@if ($model['id'] ?? true)
@include('components.datatable', ['route' => route('Admin.Core.Comments.index'), 'model' => 'comments', 'with_filters' => false, 'with_print' => false, 'dataTable' => $datatables['comments'], 'create_callback' => 'CommentCreate();', 'edit_callback' => 'CommentEdit(id);', 'delete_callback' => 'CommentRefresh();'])
@component('components.layout.modal', ['title' => 'Filtres', 'id' => 'modal-comments-filters'])
@include('Admin.Core.Comments.partials.filters')
@endcomponent
@endif

View File

@@ -0,0 +1,2 @@
<form id="comments-filters">
</form>

View File

@@ -0,0 +1,34 @@
{{ Form::open(['route' => 'Admin.Core.Comments.store', 'id' => 'comment-form', 'autocomplete' => 'off']) }}
<input type="hidden" name="id" value="{{ $comment['id'] ?? null }}">
<input type="hidden" name="commentable_type" value="{{ $comment['commentable_type'] ?? null }}">
<input type="hidden" name="commentable_id" value="{{ $comment['commentable_id'] ?? null }}">
@if ($comment['id'] ?? null)
<div class="row mb-3">
<div class="col-8">
{{ $comment['user_id'] }}
</div>
<div class="col-4">
{{ $comment['created_at'] }}
</div>
</div>
@endif
<div class="row mb-3">
<div class="col-12">
{{ Form::label('name', __('commentaire')) }}<br/>
@include('components.form.editor', ['name' => 'comment', 'value' => $comment['comment'] ?? null])
</div>
</div>
</form>
@include('load.form.editor')
<script>
$(function() {
initEditor();
});
</script>

View File

@@ -9,6 +9,7 @@
Caractéristiques Caractéristiques
</a> </a>
</li> </li>
<!--
<li class="nav-item"> <li class="nav-item">
<a href="#offers" class="nav-link" data-toggle="tab" aria-expanded="true"> <a href="#offers" class="nav-link" data-toggle="tab" aria-expanded="true">
{{ __('Shop.offers.title') }} {{ __('Shop.offers.title') }}
@@ -32,6 +33,7 @@
Référencement Référencement
</a> </a>
</li> </li>
-->
</ul> </ul>
<div class="card-tools"> <div class="card-tools">
@@ -80,6 +82,7 @@
@include('load.form.toggle') @include('load.form.toggle')
@include('load.form.upload.fileinput') @include('load.form.upload.fileinput')
@include('load.layout.chevron') @include('load.layout.chevron')
@include('load.layout.modal')
@push('js') @push('js')
<script> <script>

View File

@@ -58,7 +58,7 @@
<div class="col-md-4"> <div class="col-md-4">
@include('Admin.Shop.Articles.partials.product.images') @include('Admin.Shop.Articles.partials.product.images')
@include('components.uploader.widget', ['load_url' => route('Admin.Shop.Articles.getImages', ['id' => $article['id'] ?? false]), 'delete_url' => route('Admin.Shop.Articles.deleteImage'), 'title' => 'Photos', 'name' => 'images' ]) @include('components.uploader.widget', ['load_url' => route('Admin.Shop.Articles.getImages', ['id' => $article['id'] ?? false]), 'delete_url' => route('Admin.Shop.Articles.deleteImage'), 'title' => 'Photos', 'name' => 'images' ])
@include('Admin.Core.Comments.partials.comments') @include('Admin.Core.Comments.partials.comments', ['model' => 'Shop.Article', 'model_id' => $article['id'] ?? false, 'comments' => $article['comments']])
</div> </div>
</div> </div>

View File

@@ -1,7 +1,7 @@
@extends('layout.index', [ @extends('layout.index', [
'title' => __('offers.title'), 'title' => __('Shop.offers.title'),
'subtitle' => __('offers.create.title'), 'subtitle' => __('Shop.offers.add'),
'breadcrumb' => [__('offers.title'), __('offers.create.title')] 'breadcrumb' => [__('Shop.offers.title'), __('Shop.offers.add')]
]) ])
@section('content') @section('content')

View File

@@ -1,12 +1,12 @@
@extends('layout.index', [ @extends('layout.index', [
'title' => 'Offre', 'title' => __('Shop.offers.title'),
'subtitle' => 'Edition d\'une offre', 'subtitle' => __('Shop.offers.edit'),
'breadcrumb' => ['Offres'] 'breadcrumb' => [__('Shop.offers.title'), __('Shop.offers.edit')]
]) ])
@section('content') @section('content')
{{ Form::open(['route' => 'Admin.Shop.Offers.update', 'id' => 'offer-form', 'autocomplete' => 'off']) }} {{ Form::open(['route' => 'Admin.Shop.Offers.store', 'id' => 'offer-form', 'autocomplete' => 'off']) }}
<input type="hidden" name="id" value="{{ $id }}"> <input type="hidden" name="id" value="{{ $id }}">
@include('Admin.Shop.Offers.form') @include('Admin.Shop.Offers.form')
</form> </form>

View File

@@ -1,4 +1,4 @@
<div class="row"> <div class="row mb-3">
<div class="col-8"> <div class="col-8">
<div class="row mb-3"> <div class="row mb-3">
<div class="col-8"> <div class="col-8">

View File

@@ -7,7 +7,7 @@
@if(!defined('LOAD_EDITOR')) @if(!defined('LOAD_EDITOR'))
@include('load.form.editor.editor') @include('load.form.editor')
@push('js') @push('js')
<script> <script>
$(function() { $(function() {

View File

@@ -0,0 +1,10 @@
<?php
Route::prefix('Comments')->name('Comments.')->group(function () {
Route::get('{model?}/{model_id?}', 'CommentController@index')->name('index');
Route::get('create/{model?}/{model_id?}', 'CommentController@create')->name('create');
Route::delete('destroy/{id?}', 'CommentController@destroy')->name('destroy');
Route::post('store', 'CommentController@store')->name('store');
Route::get('edit/{id}', 'CommentController@edit')->name('edit');
});

View File

@@ -0,0 +1,5 @@
<?php
Route::prefix('Core')->namespace('Core')->name('Core.')->group(function () {
include( __DIR__ . '/Comments.php');
});

View File

@@ -1,7 +1,8 @@
<?php <?php
Route::middleware('auth')->prefix('Admin')->namespace('Admin')->name('Admin.')->group(function () { Route::middleware('auth')->prefix('Admin')->namespace('Admin')->name('Admin.')->group(function () {
Route::get('', 'HomeController@index')->name('home'); Route::get('', 'HomeController@index')->name('home');
include( __DIR__ . '/Botanic/route.php'); include( __DIR__ . '/Botanic/route.php');
include( __DIR__ . '/Shop/route.php'); include( __DIR__ . '/Core/route.php');
include( __DIR__ . '/Shop/route.php');
}); });