Skip to content

Commit

Permalink
filtro laterale per categorie, e qualche fix assortito per navigazion…
Browse files Browse the repository at this point in the history
…e mobile. closes #302
  • Loading branch information
madbob committed Jan 12, 2025
1 parent 7bf8df3 commit 83fc90e
Show file tree
Hide file tree
Showing 14 changed files with 473 additions and 304 deletions.
8 changes: 7 additions & 1 deletion code/app/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use GeneaLabs\LaravelModelCaching\Traits\Cachable;

Expand All @@ -24,9 +25,14 @@ class Category extends Model implements HasChildren
'creating' => SluggableCreating::class,
];

public function parent(): BelongsTo
{
return $this->BelongsTo(Category::class);
}

public function children(): HasMany
{
return $this->hasMany('App\Category', 'parent_id');
return $this->hasMany(Category::class, 'parent_id');
}

public static function defaultValue()
Expand Down
6 changes: 5 additions & 1 deletion code/app/Http/Controllers/SuppliersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public function show_ro($id)
return $this->easyExecute(function () use ($id) {
$supplier = $this->service->show($id);

return view('supplier.base_show', ['supplier' => $supplier, 'editable' => false]);
return view('supplier.base_show', [
'supplier' => $supplier,
'editable' => false,
'selfview' => true,
]);
});
}

Expand Down
26 changes: 22 additions & 4 deletions code/app/Models/Concerns/Iconable.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,15 @@ public function icons($group = null)
$user = Auth::user();
$obj = $this;

$ret = array_keys(array_filter($box->commons($user), function ($condition, $icon) use ($obj, $group) {
if (is_null($group) == false && (isset($condition->group) == false || $condition->group != $group)) {
$ret = array_keys(array_filter($box->commons($user), function ($condition) use ($obj, $group) {
if (is_null($group) === false && (isset($condition->group) === false || $condition->group != $group)) {
return false;
}

$t = $condition->test;

return $t($obj);
}, ARRAY_FILTER_USE_BOTH));
}));

$ret = array_reduce($box->selective(), function ($ret, $condition) use ($obj) {
$assign = $condition->assign;
Expand All @@ -86,7 +86,7 @@ public static function iconsLegend($contents = null)
$ret = [];

$box = self::myIconsBox();
if (is_null($box) == false) {
if (is_null($box) === false) {
$user = Auth::user();

$ret = array_map(function ($condition) {
Expand All @@ -110,4 +110,22 @@ public static function iconsLegend($contents = null)

return $ret;
}

public static function selectiveIconsGroup($contents, $group)
{
$box = self::myIconsBox();

foreach ($box->selective() as $icon => $condition) {
if ($icon == $group) {
$options = $condition->options;
$options = $options($contents);
return (object) [
'label' => $condition->text,
'items' => $options,
];
}
}

return null;
}
}
54 changes: 29 additions & 25 deletions code/app/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ private function extractProductPrices($product)
];

$variants = $product->variant_combos;
if ($variants->isEmpty() == false) {
if ($variants->isEmpty() === false) {
$row['variants'] = [];

foreach ($variants as $variant) {
Expand Down Expand Up @@ -337,7 +337,7 @@ private function checkConsistency($new_products)
$products_ids = $new_products->pluck('id')->toArray();

foreach ($booked_products as $bp) {
if (in_array($bp->product_id, $products_ids) == false) {
if (in_array($bp->product_id, $products_ids) === false) {
throw new \Exception("Un prodotto già prenotato non è nell'elenco dei nuovi prodotti per l'ordine! Ordine: " . $this->id . ', prodotto: ' . $bp->product_id, 1);
}
}
Expand Down Expand Up @@ -390,7 +390,7 @@ public function detachProduct($product)
*/
foreach ($this->bookings as $booking) {
$products = $booking->products()->where('product_id', $product->id)->get();
if ($products->isEmpty() == false) {
if ($products->isEmpty() === false) {
$altered_bookings++;
foreach ($products as $p) {
$p->delete();
Expand All @@ -413,22 +413,28 @@ public function detachProduct($product)
public function showableContacts()
{
$gas = currentAbsoluteGas();
$ret = null;

switch ($gas->booking_contacts) {
case 'none':
return new Collection();
$ret = new Collection();
break;

case 'manual':
return $this->users;
$ret = $this->users;
break;

default:
$role = Role::find($gas->booking_contacts);
if ($role) {
return $role->usersByTarget($this->supplier);
$ret = $role->usersByTarget($this->supplier);
}
else {
$ret = new Collection();
}

return new Collection();
}

return $ret;
}

public function enforcedContacts()
Expand Down Expand Up @@ -459,7 +465,7 @@ public function notifiableUsers($gas)
$query_users->fullEnabled();

$deliveries = $order->deliveries;
if ($deliveries->isEmpty() == false) {
if ($deliveries->isEmpty() === false) {
$query_users->where(function ($query) use ($deliveries) {
$query->whereIn('preferred_delivery_id', $deliveries->pluck('id'))->orWhere('preferred_delivery_id', '0');
});
Expand Down Expand Up @@ -509,14 +515,14 @@ public function angryBookings()
return $bookings;
}

public function isActive()
public function isActive(): bool
{
return $this->status != 'shipped' && $this->status != 'archived';
}

public function isRunning()
public function isRunning(): bool
{
return ($this->status == 'open') || ($this->status == 'closed' && $this->keep_open_packages != 'no' && $this->pendingPackages()->isEmpty() == false);
return ($this->status == 'open') || ($this->status == 'closed' && $this->keep_open_packages != 'no' && $this->pendingPackages()->isEmpty() === false);
}

public function pendingPackages()
Expand All @@ -525,7 +531,7 @@ public function pendingPackages()
$ret = new Collection();
$products = $obj->products()->where('package_size', '!=', 0)->with('measure')->get();

if ($products->isEmpty() == false) {
if ($products->isEmpty() === false) {
$order = $this;
$order_data = app()->make('GlobalScopeHub')->executedForAll($this->keep_open_packages != 'each', function () use ($order) {
return $order->reduxData();
Expand Down Expand Up @@ -579,7 +585,7 @@ public function calculateInvoicingSummary()
$price_delivered = $query->sum('final_price');
$quantity_delivered = $query->sum('delivered');

if (isset($rates[$product->vat_rate_id]) == false) {
if (isset($rates[$product->vat_rate_id]) === false) {
$rates[$product->vat_rate_id] = $product->vat_rate;
}

Expand Down Expand Up @@ -713,16 +719,16 @@ public function involvedModifiers($include_shipping_places = false)
$key = 'involved_modifiers_' . ($include_shipping_places ? 'shipping' : 'no_shipping');

return $this->innerCache($key, function ($obj) use ($include_shipping_places) {
$modifiers = $this->modifiers;
$modifiers = $obj->modifiers;

foreach ($this->products as $product) {
foreach ($obj->products as $product) {
$modifiers = $modifiers->merge($product->modifiers);
}

if ($include_shipping_places) {
$managed_shipping_places = [];

foreach ($this->bookings as $booking) {
foreach ($obj->bookings as $booking) {
$booker = $booking->user;
if ($booker->shippingplace && ! isset($managed_shipping_places[$booker->shippingplace->id])) {
$managed_shipping_places[$booker->shippingplace->id] = true;
Expand Down Expand Up @@ -756,7 +762,7 @@ public function applyModifiers($aggregate_data = null, $enforce_status = false)
*/
$has_shipped_bookings = $this->bookings->where('status', '!=', 'pending')->count() != 0;

if ($order_modifiers->isEmpty() == false || $has_shipped_bookings) {
if ($order_modifiers->isEmpty() === false || $has_shipped_bookings) {
DB::beginTransaction();

if (is_null($aggregate_data)) {
Expand Down Expand Up @@ -815,13 +821,11 @@ public function unalignedModifiers($master_summary)

foreach ($pending_modifiers as $pending_id => $pending_mod) {
foreach ($shipped_modifiers as $shipped_id => $shipped_mod) {
if ($pending_id == $shipped_id) {
if (round($pending_mod->amount, 2) != round($shipped_mod->amount, 2)) {
$ret[] = (object) [
'pending' => $pending_mod,
'shipped' => $shipped_mod,
];
}
if ($pending_id == $shipped_id && round($pending_mod->amount, 2) != round($shipped_mod->amount, 2)) {
$ret[] = (object) [
'pending' => $pending_mod,
'shipped' => $shipped_mod,
];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion code/public/css/gasdotto.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/css/gasdotto.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion code/public/js/gasdotto.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions code/public/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"/js/gasdotto.js": "/js/gasdotto.js?id=e48511f2e1f06409fa04c6e8f7a253d0",
"/css/gasdotto.css": "/css/gasdotto.css?id=98878aa82e020ef93f3f502650b0603d"
"/js/gasdotto.js": "/js/gasdotto.js?id=190e8a7a6d5240ae7eef1707d7fc7de2",
"/css/gasdotto.css": "/css/gasdotto.css?id=be8fb67e080f00aaca1403033ab2c442"
}
67 changes: 40 additions & 27 deletions code/resources/assets/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,19 @@ class Filters {
*/
$('.table-icons-legend button, .table-icons-legend a', container).click((e) => {
e.preventDefault();
this.iconsLegendTrigger($(e.currentTarget), '.table-icons-legend');

let button = $(e.currentTarget);
if (button.attr('data-bs-toggle')) {
let expanded = button.attr('aria-expanded') == 'true';
button.toggleClass('active', expanded);
if (expanded === false) {
let collapse_id = button.attr('href');
$(collapse_id).find('.active').click();
}
}
else {
this.iconsLegendTrigger(button, '.table-icons-legend');
}
});

$('.table-text-filter', container).keyup((e) => {
Expand All @@ -35,17 +47,17 @@ class Filters {

$('.table-sorter a', container).click(function(e) {
e.preventDefault();
var target = $($(this).closest('.table-sorter').attr('data-table-target'));
var attribute = $(this).attr('data-sort-by');
var is_numeric = $(this).attr('data-numeric-sorting') ? true : false;
let target = $($(this).closest('.table-sorter').attr('data-table-target'));
let attribute = $(this).attr('data-sort-by');
let is_numeric = $(this).attr('data-numeric-sorting') ? true : false;

target.each(function() {
var target_body = $(this).find('tbody');
let target_body = $(this).find('tbody');
target_body.find('> .table-sorting-header').addClass('d-none').filter('[data-sorting-' + attribute + ']').removeClass('d-none');

target_body.find('> tr[data-sorting-' + attribute + '], .table-sorting-header:visible').sort(function(a, b) {
var attr_a = $(a).attr('data-sorting-' + attribute);
var attr_b = $(b).attr('data-sorting-' + attribute);
let attr_a = $(a).attr('data-sorting-' + attribute);
let attr_b = $(b).attr('data-sorting-' + attribute);

if (is_numeric) {
return parseFloat(attr_a) - parseFloat(attr_b);
Expand All @@ -66,13 +78,13 @@ class Filters {
$('.form-filler button[type=submit]', container).click(function(event) {
event.preventDefault();

var button = $(this);
let button = $(this);
button.addClass('disabled');
var form = button.closest('.form-filler');
var target = $(form.attr('data-fill-target'));
var data = form.find('input, select').serialize();
let form = button.closest('.form-filler');
let target = $(form.attr('data-fill-target'));
let data = form.find('input, select').serialize();

var url = button.attr('data-action');
let url = button.attr('data-action');
if (url == null) {
url = form.attr('data-action');
}
Expand Down Expand Up @@ -135,13 +147,13 @@ class Filters {

static tableFilters(table_id)
{
var filters = $('[data-table-target="' + table_id + '"]');
var table = $('table' + table_id);
var elements = table.find('tbody tr');
let filters = $('[data-table-target="' + table_id + '"]');
let table = $('table' + table_id);
let elements = table.find('tbody tr');

elements.each(function() {
var display = true;
var row = $(this);
let display = true;
let row = $(this);

filters.each(function() {
if ($(this).hasClass('table-number-filters')) {
Expand Down Expand Up @@ -213,12 +225,12 @@ class Filters {
non deve essere visualizzato, evito di valutare le altre ed
esco subito dal ciclo each()
*/
if (display == false) {
if (display === false) {
return false;
}
});

row.toggleClass('hidden', (display == false));
row.toggleClass('hidden', (display === false));
});

this.compactFilter('table' + table_id, 'tbody tr', false);
Expand Down Expand Up @@ -250,14 +262,15 @@ class Filters {
}

let iter_selector = master_selector + ' ' + child_selector;
let iterables = $(iter_selector).filter(':not(.do-not-sort)');

if (node.hasClass('active')) {
node.removeClass('active');
if (node.is('a')) {
node.closest('.dropdown-menu').siblings('.dropdown-toggle').removeClass('active');
}

$(iter_selector).toggleClass('hidden', false);
iterables.toggleClass('hidden', false);
this.compactFilter(master_selector, child_selector, true);
$(master_selector).trigger('inactive-filter');
}
Expand All @@ -275,23 +288,23 @@ class Filters {
node.closest('.dropdown-menu').siblings('.dropdown-toggle').addClass('active');
}

var c = node.find('i').attr('class');
var count_hidden = 0;
let c = node.find('i').attr('class');
let count_hidden = 0;

$(iter_selector).each(function() {
var show = false;
iterables.each(function() {
let show = false;

$(this).find('i').each(function() {
var icons = $(this).attr('class');
let icons = $(this).attr('class');
show = (icons == c);
if (show) {
return false;
}
});

$(this).toggleClass('hidden', show == false);
$(this).toggleClass('hidden', show === false);

if (show == false) {
if (show === false) {
count_hidden++;
}
});
Expand Down
Loading

0 comments on commit 83fc90e

Please sign in to comment.