Skip to content

Commit 0319384

Browse files
committed
aggiustamenti estetici
1 parent 3494503 commit 0319384

37 files changed

Lines changed: 405 additions & 164 deletions

code/app/Aggregate.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@
1414
use App\Models\Concerns\AttachableTrait;
1515
use App\Models\Concerns\ModifiableTrait;
1616
use App\Models\Concerns\ReducibleTrait;
17+
use App\Models\Concerns\HasPicture;
1718
use App\Models\Concerns\WithinGas;
1819
use App\Events\AttachableToGas;
1920

2021
class Aggregate extends Model
2122
{
22-
use GASModel, HasFactory, AttachableTrait, ModifiableTrait, ReducibleTrait, WithinGas;
23+
use GASModel, HasFactory, AttachableTrait, ModifiableTrait, ReducibleTrait, HasPicture, WithinGas;
2324

2425
protected $dispatchesEvents = [
2526
'created' => AttachableToGas::class,
@@ -215,7 +216,7 @@ public function printableDates()
215216

216217
public function printableHeader()
217218
{
218-
return $this->printableName() . $this->headerIcons() . sprintf('<br/><small>%s</small>', $this->printableDates());
219+
return $this->headerIcons() . $this->formatAvatar() . $this->printableName() . sprintf('<br/><small class="text-muted">%s</small>', $this->printableDates());
219220
}
220221

221222
public function printableUserHeader()
@@ -524,6 +525,13 @@ public function involvedModifiers($include_groups = false)
524525
return $ret;
525526
}
526527

528+
/************************************************************* HasPicture */
529+
530+
public function getPictureUrlAttribute()
531+
{
532+
return $this->orders->first()->picture_url;
533+
}
534+
527535
/********************************************************* ReducibleTrait */
528536

529537
protected function reduxBehaviour()

code/app/GASModel.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
use Illuminate\Support\Str;
66
use Illuminate\Database\Eloquent\SoftDeletes;
77

8-
use URL;
9-
use Schema;
8+
use Illuminate\Support\Facades\URL;
9+
use Illuminate\Support\Facades\Schema;
1010

1111
use App\Models\Concerns\Iconable;
12+
use App\Models\Concerns\HasPicture;
1213
use App\Models\Concerns\ManagesInnerCache;
1314

1415
trait GASModel
@@ -65,7 +66,13 @@ public function getPrintableNameAttribute()
6566

6667
public function printableHeader()
6768
{
68-
return $this->printableName() . $this->headerIcons();
69+
$avatar = '';
70+
71+
if (hasTrait($this, HasPicture::class)) {
72+
$avatar = $this->formatAvatar();
73+
}
74+
75+
return $avatar . $this->printableName() . $this->headerIcons();
6976
}
7077

7178
public function printableDate($name)

code/app/Helpers/Status.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,23 @@ public static function orders()
2424
$statuses['open'] = (object) [
2525
'label' => __('texts.orders.booking.statuses.open'),
2626
'icon' => 'play',
27+
'color' => 'success',
2728
'default_display' => true,
2829
'aggregate_priority' => 1,
2930
];
3031

3132
$statuses['closed'] = (object) [
3233
'label' => __('texts.orders.booking.statuses.closed'),
3334
'icon' => 'stop-fill',
35+
'color' => 'danger',
3436
'default_display' => true,
3537
'aggregate_priority' => 2,
3638
];
3739

3840
$statuses['shipped'] = (object) [
3941
'label' => __('texts.orders.booking.statuses.shipped'),
4042
'icon' => 'skip-forward',
43+
'color' => 'secondary',
4144
'default_display' => true,
4245
'aggregate_priority' => 4,
4346
];
@@ -46,6 +49,7 @@ public static function orders()
4649
$statuses['user_payment'] = (object) [
4750
'label' => __('texts.orders.booking.statuses.paying'),
4851
'icon' => 'cash',
52+
'color' => 'danger',
4953
'default_display' => true,
5054
'aggregate_priority' => 3,
5155
];
@@ -54,13 +58,15 @@ public static function orders()
5458
$statuses['archived'] = (object) [
5559
'label' => __('texts.orders.booking.statuses.archived'),
5660
'icon' => 'eject',
61+
'color' => 'light',
5762
'default_display' => false,
5863
'aggregate_priority' => 5,
5964
];
6065

6166
$statuses['suspended'] = (object) [
6267
'label' => __('texts.orders.booking.statuses.suspended'),
6368
'icon' => 'pause',
69+
'color' => 'warning',
6470
'default_display' => true,
6571
'aggregate_priority' => 0,
6672
];

code/app/Http/Controllers/BackedController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ protected function commonInit($parameters)
1717
parent::commonInit($parameters);
1818
}
1919

20+
public function getBackedService()
21+
{
22+
return $this->service;
23+
}
24+
2025
public function ensureAuth($permissions = [], $or = true)
2126
{
2227
return $this->service->ensureAuth($permissions, $or);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Http\Controllers\Concerns;
4+
5+
trait RoutesPictures
6+
{
7+
public function picture($id)
8+
{
9+
return $this->easyExecute(function () use ($id) {
10+
return $this->getBackedService()->picture($id);
11+
});
12+
}
13+
}

code/app/Http/Controllers/ProductsController.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@
33
namespace App\Http\Controllers;
44

55
use Illuminate\Http\Request;
6-
7-
use DB;
8-
use Auth;
6+
use Illuminate\Support\Facades\DB;
7+
use Illuminate\Support\Facades\Auth;
98

109
use App\Services\ProductsService;
11-
10+
use App\Http\Controllers\Concerns\RoutesPictures;
1211
use App\Order;
1312
use App\Product;
1413
use App\VariantCombo;
1514

1615
class ProductsController extends BackedController
1716
{
17+
use RoutesPictures;
18+
1819
public function __construct(ProductsService $service)
1920
{
2021
$this->service = $service;
@@ -125,13 +126,6 @@ public function massiveUpdate(Request $request)
125126
});
126127
}
127128

128-
public function picture($id)
129-
{
130-
return $this->easyExecute(function () use ($id) {
131-
return $this->service->picture($id);
132-
});
133-
}
134-
135129
public function price(Request $request)
136130
{
137131
$product_id = $request->input('id');

code/app/Http/Controllers/SuppliersController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44

55
use Illuminate\Http\Request;
66

7-
87
use App\Services\SuppliersService;
8+
use App\Http\Controllers\Concerns\RoutesPictures;
99

1010
class SuppliersController extends BackedController
1111
{
12+
use RoutesPictures;
13+
1214
public function __construct(SuppliersService $service)
1315
{
1416
$this->middleware('auth');

code/app/Http/Controllers/UsersController.php

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44

55
use Illuminate\Http\Request;
66

7-
use App\User;
8-
use App\Group;
9-
use App\Aggregate;
10-
117
use App\Services\UsersService;
128
use App\Formatters\User as UserFormatter;
139
use App\Exceptions\AuthException;
10+
use App\Http\Controllers\Concerns\RoutesPictures;
11+
use App\User;
12+
use App\Group;
13+
use App\Aggregate;
1414

1515
class UsersController extends BackedController
1616
{
17+
use RoutesPictures;
18+
1719
public function __construct(UsersService $service)
1820
{
1921
$this->commonInit([
@@ -169,13 +171,6 @@ public function show_ro($id)
169171
});
170172
}
171173

172-
public function picture($id)
173-
{
174-
return $this->easyExecute(function () use ($id) {
175-
return $this->service->picture($id);
176-
});
177-
}
178-
179174
private function testInternalFunctionsAccess($requester, $target, $type)
180175
{
181176
$admin_editable = $requester->can('users.admin', $target->gas);
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace App\Models\Concerns;
4+
5+
trait HasPicture
6+
{
7+
abstract public function getPictureUrlAttribute();
8+
9+
public function formatAvatar(): string
10+
{
11+
return sprintf('<img class="avatar shadow" src="%s" loading="lazy">', $this->picture_url);
12+
}
13+
}

code/app/Models/Concerns/Iconable.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,17 @@ protected function formatIcons($icons)
1616
$ret = '';
1717

1818
if (! empty($icons)) {
19-
$ret .= '<div class="float-end">';
19+
$visible = array_filter($icons, fn($i) => substr($i, 0, 6) != 'hidden');
20+
if (!empty($visible)) {
21+
$color = $this->dominantColor();
22+
$ret .= '<div class="header-icons text-bg-' . $color . '">';
23+
}
24+
else {
25+
$ret .= '<div>';
26+
}
2027

2128
foreach ($icons as $i) {
2229
$ret .= '<i class="bi-' . $i . '"></i>';
23-
if (substr($i, 0, 6) != 'hidden') {
24-
$ret .= '&nbsp;';
25-
}
2630
}
2731

2832
$ret .= '</div>';
@@ -52,6 +56,12 @@ private static function myIconsBox()
5256
}
5357
}
5458

59+
private function dominantColor()
60+
{
61+
$box = self::myIconsBox();
62+
return $box->dominantColor($this);
63+
}
64+
5565
public function icons($group = null)
5666
{
5767
$ret = [];
@@ -86,7 +96,7 @@ public static function iconsLegend($contents = null)
8696
$ret = [];
8797

8898
$box = self::myIconsBox();
89-
if (is_null($box) === false) {
99+
if ($box) {
90100
$user = Auth::user();
91101

92102
$icons = $box->commons($user);

0 commit comments

Comments
 (0)