From 1179b5ca31ed99a28ca88cd9593d307d5dd6ba28 Mon Sep 17 00:00:00 2001 From: Ludovic CANDELLIER Date: Sun, 26 Jul 2020 16:51:45 +0200 Subject: [PATCH] Fix some enhancements & new features --- Gruntfile.js | 32 +++- app/DataTables/ParentDataTable.php | 14 +- .../ArticleAttributeFamiliesDataTable.php | 5 +- .../Shop/ArticleAttributeValuesDataTable.php | 2 +- .../ArticleAttributeFamilyController.php | 2 +- app/Models/Shop/Article.php | 35 ++-- app/Models/Shop/ArticleAttribute.php | 21 ++- app/Models/Shop/ArticleAttributeFamily.php | 10 +- app/Models/Shop/ArticleAttributeValue.php | 16 +- app/Models/Shop/ArticleCategory.php | 4 +- app/Models/Shop/ArticleFamily.php | 5 +- app/Models/Shop/ArticlePrice.php | 17 +- build/js/include/app.js | 69 -------- build/js/include/check_fields.js | 27 --- build/js/include/core/appender.js | 75 +++++++++ build/js/include/{ => core}/cache.js | 0 build/js/include/core/handlebars.js | 70 ++++++++ build/js/include/core/lang.js | 12 ++ build/js/include/core/objectLength.js | 5 + build/js/include/core/session.js | 6 + build/js/include/core/url.js | 4 + build/js/include/{ => core}/user.js | 0 build/js/include/datetime.js | 67 -------- build/js/include/form/check_fields.js | 39 +++++ build/js/include/form/checkbox.js | 42 +++++ build/js/include/form/datetime.js | 130 +++++++++++++++ build/js/include/form/multi-select.js | 154 ++++++++++++++++++ build/js/include/form/radio.js | 5 + .../js/include/{chosen.js => form/select.js} | 12 +- build/js/include/{ => form}/set_options.js | 0 build/js/include/form/upload.js | 21 +++ build/js/include/form/validator.js | 74 +++++++++ build/js/include/{ => layout}/animate.js | 0 build/js/include/layout/message.js | 9 + build/js/include/layout/modal.js | 37 +++++ build/js/include/layout/scroll.js | 24 +++ build/js/include/layout/tooltip.js | 7 + build/js/include/rights.js | 20 --- build/js/include/validator.js | 17 -- .../Botanic/Admin/Families/list.blade.php | 10 +- .../views/Botanic/Admin/Genres/list.blade.php | 8 +- .../Botanic/Admin/Species/list.blade.php | 8 +- .../Botanic/Admin/Varieties/list.blade.php | 8 +- .../ArticleAttributeFamilies/index.blade.php | 39 +++++ .../ArticleAttributeValues/list.blade.php | 4 - .../views/components/datatable.blade.php | 11 +- .../datatables/buttons/colvis.blade.php | 18 ++ .../datatables/buttons/download.blade.php | 34 ++-- .../datatables/buttons/exports.blade.php | 5 +- .../datatables/buttons/print.blade.php | 10 +- .../components/datatables/search.blade.php | 20 ++- .../views/components/js/datatable.blade.php | 27 ++- resources/views/layout/index.blade.php | 2 - resources/views/load/datatables.blade.php | 23 +++ 54 files changed, 975 insertions(+), 341 deletions(-) delete mode 100644 build/js/include/check_fields.js create mode 100644 build/js/include/core/appender.js rename build/js/include/{ => core}/cache.js (100%) create mode 100644 build/js/include/core/handlebars.js create mode 100644 build/js/include/core/lang.js create mode 100644 build/js/include/core/objectLength.js create mode 100644 build/js/include/core/session.js create mode 100644 build/js/include/core/url.js rename build/js/include/{ => core}/user.js (100%) delete mode 100644 build/js/include/datetime.js create mode 100644 build/js/include/form/check_fields.js create mode 100644 build/js/include/form/checkbox.js create mode 100644 build/js/include/form/datetime.js create mode 100644 build/js/include/form/multi-select.js create mode 100644 build/js/include/form/radio.js rename build/js/include/{chosen.js => form/select.js} (78%) rename build/js/include/{ => form}/set_options.js (100%) create mode 100644 build/js/include/form/upload.js create mode 100644 build/js/include/form/validator.js rename build/js/include/{ => layout}/animate.js (100%) create mode 100644 build/js/include/layout/message.js create mode 100644 build/js/include/layout/modal.js create mode 100644 build/js/include/layout/scroll.js create mode 100644 build/js/include/layout/tooltip.js delete mode 100644 build/js/include/rights.js delete mode 100644 build/js/include/validator.js create mode 100644 resources/views/Shop/Admin/ArticleAttributeFamilies/index.blade.php create mode 100644 resources/views/load/datatables.blade.php diff --git a/Gruntfile.js b/Gruntfile.js index ef54fe49..848679ba 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -3,6 +3,33 @@ var jsCompatibilty = [ 'node_modules/es6-promise/dist/es6-promise.min.js' ] +var jsCoreInclude = [ + 'build/include/core/appender.js', + 'build/include/core/cache.js', + 'build/include/core/handlebars.js', + 'build/include/core/lang.js', + 'build/include/core/objectLength.js', + 'build/include/core/session.js', + 'build/include/core/url.js', + 'build/include/core/user.js', + 'build/include/form/check_fields.js', + 'build/include/form/checkbox.js', + 'build/include/form/datetime.js', + 'build/include/form/multi-select.js', + 'build/include/form/radio.js', + 'build/include/form/select.js', + 'build/include/form/upload.js', + 'build/include/form/validator.js', + 'build/include/layout/animate.js', + 'build/include/layout/message.js', + 'build/include/layout/modal.js', + 'build/include/layout/scroll.js', + 'build/include/layout/tooltip.js', + 'build/include/datatable.js', + 'build/include/file.js', + 'build/include/uploader.js', +] + var jsMain = [ // 'node_modules/sweetalert2/dist/sweetalert2.all.min.js', 'node_modules/inputmask/dist/min/jquery.inputmask.bundle.min.js', @@ -28,11 +55,8 @@ var jsMain = [ 'node_modules/numeral/min/numeral.min.js', 'node_modules/numeral/min/locales/fr.min.js', 'build/js/include/plugins/jquery.hcaptions.js', - 'build/js/include/url_on_tab.js', - 'build/js/include/set_options.js', + jsCoreInclude // 'build/js/include/confirm.js', - 'build/js/include/appender.js', - 'build/js/include/app.js', ] var cssMain = [ diff --git a/app/DataTables/ParentDataTable.php b/app/DataTables/ParentDataTable.php index b7d145e8..d0e8b167 100644 --- a/app/DataTables/ParentDataTable.php +++ b/app/DataTables/ParentDataTable.php @@ -10,9 +10,9 @@ use Yajra\DataTables\Services\DataTable; class ParentDataTable extends DataTable { - public $rowReorder; - public $colReorder; // ['selector' => 'tr'] - public $fixedColumns; // ['leftColumns' => 1, 'rightColumns' => 1] + public $rowReorder; // ['selector' => 'tr'] + public $colReorder = true; + public $fixedColumns = false; /** * Build DataTable class. @@ -27,7 +27,7 @@ class ParentDataTable extends DataTable public function modifier($datatables) { - return $this->addButtons($datatables); + return $this->addButtons($datatables->setRowId('{{$id}}')); } /** @@ -50,6 +50,7 @@ class ParentDataTable extends DataTable $buttons .= ''; $buttons .= ''; return $buttons; + // return view('components.datatables.buttons.row_action'); } public function makeColumnButtons() @@ -72,8 +73,7 @@ class ParentDataTable extends DataTable { return $model->newQuery(); } - - + /** * Optional method if you want to use html builder. * @@ -126,7 +126,7 @@ class ParentDataTable extends DataTable { $dom = ''; // $dom .= $this->getDatatablesHeaderDefault(); - $dom .= "<'overlay-block'r>"; + $dom .= "rt"; $dom .= $this->getDatatablesFooterDefault(); return $dom; } diff --git a/app/DataTables/Shop/ArticleAttributeFamiliesDataTable.php b/app/DataTables/Shop/ArticleAttributeFamiliesDataTable.php index 6aeceff0..c1e7e1a8 100644 --- a/app/DataTables/Shop/ArticleAttributeFamiliesDataTable.php +++ b/app/DataTables/Shop/ArticleAttributeFamiliesDataTable.php @@ -12,7 +12,7 @@ class ArticleAttributeFamiliesDataTable extends DataTable public function query(ArticleAttributeFamily $model) { - $model = $model::withCount(['Attributes']); + $model = $model::withCount(['values','articles']); return self::buildQuery($model); } @@ -20,7 +20,8 @@ class ArticleAttributeFamiliesDataTable extends DataTable { return [ Column::make('name')->title('Nom'), - Column::make('attributes_count')->title('Nb attributs')->searchable(false)->addClass('text-right'), + Column::make('values_count')->title('Nb attributs')->searchable(false)->addClass('text-right'), + Column::make('articles_count')->title('Nb d\'articles')->searchable(false)->addClass('text-right'), self::makeColumnButtons(), ]; } diff --git a/app/DataTables/Shop/ArticleAttributeValuesDataTable.php b/app/DataTables/Shop/ArticleAttributeValuesDataTable.php index 60ba3eaf..cbb626e9 100644 --- a/app/DataTables/Shop/ArticleAttributeValuesDataTable.php +++ b/app/DataTables/Shop/ArticleAttributeValuesDataTable.php @@ -12,7 +12,7 @@ class ArticleAttributeValuesDataTable extends DataTable public function query(ArticleAttributeValue $model) { - $model = $model::with(['ArticleAttributeFamily']); + $model = $model::with(['article_attribute_family']); return self::buildQuery($model); } diff --git a/app/Http/Controllers/Shop/Admin/ArticleAttributeFamilyController.php b/app/Http/Controllers/Shop/Admin/ArticleAttributeFamilyController.php index 98a0a7bb..6958909b 100644 --- a/app/Http/Controllers/Shop/Admin/ArticleAttributeFamilyController.php +++ b/app/Http/Controllers/Shop/Admin/ArticleAttributeFamilyController.php @@ -12,7 +12,7 @@ class ArticleAttributeFamilyController extends Controller { public function index(ArticleAttributeFamiliesDataTable $dataTable) { - return $dataTable->render('Shop.Admin.ArticleAttributeFamilies.list'); + return $dataTable->render('Shop.Admin.ArticleAttributeFamilies.index'); } public function getDatatable(Request $request) diff --git a/app/Models/Shop/Article.php b/app/Models/Shop/Article.php index 422b6402..ec7b8971 100644 --- a/app/Models/Shop/Article.php +++ b/app/Models/Shop/Article.php @@ -11,40 +11,37 @@ use Fico7489\Laravel\EloquentJoin\Traits\EloquentJoin; class Article extends Model implements HasMedia { - use Categorizable; - use Taggable; - use HasMediaTrait; - use EloquentJoin; + use Categorizable, Taggable, HasMediaTrait, EloquentJoin; protected $guarded = ['id']; protected $table = 'shop_articles'; - public function Family() + public function article_family() { - return $this->belongsTo('App\Models\Shop\ArticleFamily','article_family_id'); + return $this->belongsTo('App\Models\Shop\ArticleFamily'); } - public function Inventories() + public function attributes() + { + return $this->hasMany('App\Models\Shop\ArticleAttribute'); + } + + public function prices() + { + return $this->hasManyThrough('App\Models\Shop\ArticlePrice','App\Models\Shop\ArticleAttribute'); + } + + public function inventories() { return $this->hasMany('App\Models\Shop\Inventory'); } - public function Prices() - { - return $this->hasMany('App\Models\Shop\ArticlePrice'); - } - - public function Attributes() - { - return $this->hasManyThrough('App\Models\Shop\ArticleAttribute','App\Models\Shop\ArticlePrice'); - } - - public function InvoiceItems() + public function invoiceItems() { return $this->hasMany('App\Models\Shop\InvoiceItem'); } - public function Product() + public function product() { return $this->belongsTo($this->model, 'model_id'); } diff --git a/app/Models/Shop/ArticleAttribute.php b/app/Models/Shop/ArticleAttribute.php index 67fceee5..ec8b93f8 100644 --- a/app/Models/Shop/ArticleAttribute.php +++ b/app/Models/Shop/ArticleAttribute.php @@ -9,23 +9,28 @@ class ArticleAttribute extends Model protected $guarded = ['id']; protected $table = 'shop_article_attributes'; - public function Price() + public function article() + { + return $this->belongsTo('App\Models\Shop\Article'); + } + + public function attribute_value() { - return $this->belongsTo('App\Models\Shop\ArticlePrice','article_price_id'); + return $this->belongsTo('App\Models\Shop\ArticleAttributeValue'); } - public function Value() + public function prices() { - return $this->belongsTo('App\Models\Shop\ArticleAttributeValue','attribute_value_id'); + return $this->hasMany('App\Models\Shop\ArticlePrice'); } - public function scopeByPrice($query, $article_price_id) + public function scopeByArticle($query, $id) { - return $query->where('article_price_id', $article_price_id); + return $query->where('article_id', $id); } - public function scopeByAttribueValue($query, $article_value_id) + public function scopeByAttributeValue($query, $id) { - return $query->where('article_value_id', $article_value_id); + return $query->where('attribute_value_id', $id); } } \ No newline at end of file diff --git a/app/Models/Shop/ArticleAttributeFamily.php b/app/Models/Shop/ArticleAttributeFamily.php index 8e7151cf..4300664c 100644 --- a/app/Models/Shop/ArticleAttributeFamily.php +++ b/app/Models/Shop/ArticleAttributeFamily.php @@ -3,15 +3,23 @@ namespace App\Models\Shop; use Illuminate\Database\Eloquent\Model; +use Staudenmeir\EloquentHasManyDeep\HasRelationships; class ArticleAttributeFamily extends Model { + use HasRelationships; + protected $guarded = ['id']; protected $table = 'shop_article_attribute_families'; - public function Attributes() + public function values() { return $this->hasMany('App\Models\Shop\ArticleAttributeValue'); } + public function articles() + { + return $this->hasManyThrough('App\Models\Shop\ArticleAttribute','App\Models\Shop\ArticleAttributeValue'); + } + } \ No newline at end of file diff --git a/app/Models/Shop/ArticleAttributeValue.php b/app/Models/Shop/ArticleAttributeValue.php index 74afe4be..027cd9b9 100644 --- a/app/Models/Shop/ArticleAttributeValue.php +++ b/app/Models/Shop/ArticleAttributeValue.php @@ -9,14 +9,24 @@ class ArticleAttributeValue extends Model protected $guarded = ['id']; protected $table = 'shop_article_attribute_values'; - public function ArticleAttributeFamily() + public function article_attribute_family() { return $this->belongsTo('App\Models\Shop\ArticleAttributeFamily'); } - public function scopeByFamily($query, $attribute_family_id) + public function attributes() + { + return $this->hasMany('App\Models\Shop\ArticleAttribute'); + } + + public function articles() + { + return $this->hasMany('App\Models\Shop\ArticleAttribute')->groupBy('article_id'); + } + + public function scopeByFamily($query, $id) { - return $query->where('article_attribute_family_id', $attribute_family_id); + return $query->where('article_attribute_family_id', $id); } } \ No newline at end of file diff --git a/app/Models/Shop/ArticleCategory.php b/app/Models/Shop/ArticleCategory.php index 2c452111..db0eb9f6 100644 --- a/app/Models/Shop/ArticleCategory.php +++ b/app/Models/Shop/ArticleCategory.php @@ -9,12 +9,12 @@ class ArticleCategory extends Model protected $guarded = ['id']; protected $table = 'shop_article_categories'; - public function Article() + public function article() { return $this->belongsTo('App\Models\Shop\Article'); } - public function Category() + public function category() { return $this->belongsTo('App\Models\Shop\Category'); } diff --git a/app/Models/Shop/ArticleFamily.php b/app/Models/Shop/ArticleFamily.php index 9209afc2..b4aa3f60 100644 --- a/app/Models/Shop/ArticleFamily.php +++ b/app/Models/Shop/ArticleFamily.php @@ -9,10 +9,7 @@ class ArticleFamily extends Model protected $guarded = ['id']; protected $table = 'shop_article_families'; - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo - */ - public function Articles() + public function articles() { return $this->hasMany('App\Models\Shop\Article'); } diff --git a/app/Models/Shop/ArticlePrice.php b/app/Models/Shop/ArticlePrice.php index fa98ab55..863fa12b 100644 --- a/app/Models/Shop/ArticlePrice.php +++ b/app/Models/Shop/ArticlePrice.php @@ -9,19 +9,14 @@ class ArticlePrice extends Model protected $guarded = ['id']; protected $table = 'shop_article_prices'; - public function Article() + public function article_attribute() + { + return $this->belongsTo('App\Models\Shop\ArticleAttribute'); + } + + public function article() { return $this->belongsTo('App\Models\Shop\Article'); } - public function ArticleAttributes() - { - return $this->hasMany('App\Models\Shop\ArticleAttribute'); - } - - public function scopeByArticle($query, $id) - { - return $query->where('article_id', $id); - } - } \ No newline at end of file diff --git a/build/js/include/app.js b/build/js/include/app.js index 87dd225d..82c4bc37 100644 --- a/build/js/include/app.js +++ b/build/js/include/app.js @@ -3,75 +3,6 @@ function sleep(ms) { } (function($) { - "use strict"; // Start of use strict - - // Toggle the side navigation - $("#sidebarToggle, #sidebarToggleTop").on('click', function(e) { - $("body").toggleClass("sidebar-toggled"); - $(".sidebar").toggleClass("toggled"); - if ($(".sidebar").hasClass("toggled")) { - $('.sidebar .collapse').collapse('hide'); - }; - }); - - // Close any open menu accordions when window is resized below 768px - $(window).resize(function() { - if ($(window).width() < 768) { - $('.sidebar .collapse').collapse('hide'); - }; - }); - - // Prevent the content wrapper from scrolling when the fixed side navigation hovered over - $('body.fixed-nav .sidebar').on('mousewheel DOMMouseScroll wheel', function(e) { - if ($(window).width() > 768) { - var e0 = e.originalEvent, - delta = e0.wheelDelta || -e0.detail; - this.scrollTop += (delta < 0 ? 1 : -1) * 30; - e.preventDefault(); - } - }); - - // Scroll to top button appear - $(document).on('scroll', function() { - var scrollDistance = $(this).scrollTop(); - if (scrollDistance > 100) { - $('.scroll-to-top').fadeIn(); - } else { - $('.scroll-to-top').fadeOut(); - } - }); - - // Smooth scrolling using jQuery easing - $(document).on('click', 'a.scroll-to-top', function(e) { - var $anchor = $(this); - $('html, body').stop().animate({ - scrollTop: ($($anchor.attr('href')).offset().top) - }, 1000, 'easeInOutExpo'); - e.preventDefault(); - }); - - $('#changePassword-submit').click(function(e){ - e.preventDefault(); - - $.ajax({ - url: '/changePassword', - data: $('#password-form-data').serialize(), - method : 'POST', - success: function(resp){ - if (resp.success) { - $('#changePasswordMessage').html(resp.message); - // await sleep(1000); - $('#changepasswordModal').modal('hide'); - $('#password-form-data').each(function(){ - this.reset(); - }); - } else { - $('#changePasswordMessage').html(resp.message); - } - } - }); - }); - numeral.locale('fr'); })(jQuery); // End of use strict diff --git a/build/js/include/check_fields.js b/build/js/include/check_fields.js deleted file mode 100644 index e00f2cf0..00000000 --- a/build/js/include/check_fields.js +++ /dev/null @@ -1,27 +0,0 @@ -function checkCollapsedFields(selector) -{ - var selector = selector + ' input,textarea,select'; - var nb_fields = $(selector).length(); - var nb_required = $(selector).filter('[required]').length(); - var nb_filled = 0; - var nb_necessary = 0; - - $(selector).each(function(i, Field){ - if ($(Field).val() != '') - { - nb_filled++; - } - }); - - $(selector).filter('[required]').each(function(i, required){ - if ($(required).val() != '') - { - nb_necessary++; - } - }); - - result = nb_filled + " / " + nb_fields; - result + " | " + nb_necessary + " / " + nb_required; - - $(selector + ' .check').html(result); -} diff --git a/build/js/include/core/appender.js b/build/js/include/core/appender.js new file mode 100644 index 00000000..6c2f2a60 --- /dev/null +++ b/build/js/include/core/appender.js @@ -0,0 +1,75 @@ +(function ($) { + $.fn.appender = function (settings) { + let appendArea = this; + let rowHtml = $(settings.rowSection)[0].outerHTML; + + settings.hideSection ? $(settings.rowSection).remove() : ""; + + let rowCounter = 1; + + if (settings.rowNumberStart) { + rowCounter = Number(settings.rowNumberStart); + } + + $(document).on('click', settings.addBtn, function (event) { + + $(appendArea).append(rowHtml); + + if (settings.appendEffect === 'fade') { + $(settings.rowSection).last().hide().fadeIn(); + } else if (settings.appendEffect === 'slide') { + $(settings.rowSection).last().hide().slideDown(200); + } + + $(settings.rowSection).last().addClass(settings.addClass); + + $(settings.rowNumber).last().text(rowCounter); + + if (settings.type) { + type = settings.type; + } else { + type = settings.rowSection; + } + + $(type).each(function(rowIndex) { + $(this).find('input[name]').each(function(){ + var name; + name = $(this).attr('name'); + name = name.replace(/\[[0-9]?\]/g, '['+rowIndex+']'); + $(this).attr('name',name); + }); + $(this).find('select[name]').each(function(){ + var name; + name = $(this).attr('name'); + name = name.replace(/\[[0-9]?\]/g, '['+rowIndex+']'); + $(this).attr('name',name); + }); + $(this).find('textarea[name]').each(function(){ + var name; + name = $(this).attr('name'); + name = name.replace(/\[[0-9]?\]/g, '['+rowIndex+']'); + $(this).attr('name',name); + }); + }); + + rowCounter++; + + if (settings.callback) { + settings.callback(); + } + + }); + + + if(settings.deleteBtn) { + $(document).on('click', settings.deleteBtn, function (e) { + $(e.target).closest(settings.rowSection).remove(); + if (settings.callback) { + settings.callback(); + } + }) + + } + }; + +}(jQuery)); \ No newline at end of file diff --git a/build/js/include/cache.js b/build/js/include/core/cache.js similarity index 100% rename from build/js/include/cache.js rename to build/js/include/core/cache.js diff --git a/build/js/include/core/handlebars.js b/build/js/include/core/handlebars.js new file mode 100644 index 00000000..bec5d1f1 --- /dev/null +++ b/build/js/include/core/handlebars.js @@ -0,0 +1,70 @@ +function renderContractDriveTPL(filename, data, selector) { + if (typeof(data) == 'undefined') { + var data = {}; + } + data.translate = translate; + var path = '/assets/apps/ContractDrive/templates/'; + var content = getTemplate(path + filename, data); + if (typeof(selector) == 'undefined') + { + return content; + } else { + $(selector).html(content); + } +} + +function getTemplate(file, data) { + var source = getSource(file); + var template = Handlebars.compile(source); + return template(data); +} + +function getSource(file) { + var source = null; + $.ajax({ + async: false, + dataType: 'html', + type: 'GET', + url: file + '?' + Date.now(), + success: function(data) { + source = data; + } + }); + return source; +} + +function view(template_id, data) { + // console.log(template_id); + // console.log(data); + var source = document.getElementById(template_id).innerHTML; + var template = Handlebars.compile(source); + return template(data); +} + +function helperSelect(name, items, selected, options) { + + // If the selected value is an array, then convert the + // select to a multiple select + if (selected instanceof Array) { + options.hash.multiple = 'multiple'; + } + + // Generate the list of options + var optionsHtml = ''; + for (var i = 0, j = items.length; i < j; i++) { + + //