Skip to content
This repository was archived by the owner on Jan 6, 2026. It is now read-only.

Commit c7caf33

Browse files
Refactor filament casting: replace FilamentTitleCast with FilamentTypeTitleCast, enhance title transformation logic, adjust models and services, and update welcome.tsx UI styling.
1 parent 51e7862 commit c7caf33

File tree

6 files changed

+66
-29
lines changed

6 files changed

+66
-29
lines changed

app/Casts/FilamentTitleCast.php

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44

55
namespace App\Casts;
66

7-
use App\Exceptions\UnknownFilamentTypeException;
87
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
98
use Illuminate\Database\Eloquent\Model;
109
use Illuminate\Support\Str;
1110

12-
use function report;
13-
1411
class FilamentTitleCast implements CastsAttributes
1512
{
1613
public function get(Model $model, string $key, mixed $value, array $attributes): string
@@ -19,28 +16,15 @@ public function get(Model $model, string $key, mixed $value, array $attributes):
1916
}
2017

2118
public function set(Model $model, string $key, mixed $value, array $attributes): string
22-
{
23-
if ($title = $this->perform($value)) {
24-
return $title;
25-
}
26-
27-
report(new UnknownFilamentTypeException($value));
28-
29-
return 'Unknown';
30-
}
31-
32-
protected function perform(string $value): string
3319
{
3420
return Str::of($value)
35-
->replace(['Generic', 'Value'], '')
3621
->replace(['High Speed', '@HS', ' HS'], '-HS', false)
3722
->replace(['High Flow', '@HF', ' HF'], '-HF', false)
3823
->replace(' plus', '+', false)
3924
->replace('-silk', ' Silk', false)
4025
->replace('-wood', ' Wood', false)
4126
->before('@')
42-
->squish()
43-
->match('/([^\d][A-Z]{2,4}[+\-\s]?([A-Z]{2,4}|Silk|Wood)?)/')
27+
->replaceMatches('/(\d+.\d+\s?.+)/', '')
4428
->replace(' CF', '-CF', false)
4529
->squish()
4630
->trim('-')
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Casts;
6+
7+
use App\Exceptions\UnknownFilamentTypeException;
8+
use Illuminate\Contracts\Database\Eloquent\CastsAttributes;
9+
use Illuminate\Database\Eloquent\Model;
10+
use Illuminate\Support\Str;
11+
12+
use function report;
13+
14+
class FilamentTypeTitleCast implements CastsAttributes
15+
{
16+
public function get(Model $model, string $key, mixed $value, array $attributes): string
17+
{
18+
return $value;
19+
}
20+
21+
public function set(Model $model, string $key, mixed $value, array $attributes): string
22+
{
23+
if ($title = $this->perform($value)) {
24+
return $title;
25+
}
26+
27+
report(new UnknownFilamentTypeException($value));
28+
29+
return 'Unknown';
30+
}
31+
32+
protected function perform(string $value): string
33+
{
34+
return Str::of($value)
35+
->replace(['Generic', 'Value'], '')
36+
->replace(['High Speed', '@HS', ' HS'], '-HS', false)
37+
->replace(['High Flow', '@HF', ' HF'], '-HF', false)
38+
->replace(' plus', '+', false)
39+
->replace('-silk', ' Silk', false)
40+
->replace('-wood', ' Wood', false)
41+
->before('@')
42+
->squish()
43+
->match('/([^\d][A-Z]{2,4}[+\-\s]?([A-Z]{2,4}|Silk|Wood)?)/')
44+
->replace(' CF', '-CF', false)
45+
->squish()
46+
->trim('-')
47+
->replaceMatches('/([A-Z]{2})[\s-]?([A-Z]{3,})/', '$2-$1')
48+
->toString();
49+
}
50+
}

app/Models/Filament.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace App\Models;
66

7+
use App\Casts\FilamentTitleCast;
78
use Illuminate\Database\Eloquent\Factories\HasFactory;
89
use Illuminate\Database\Eloquent\Model;
910
use Illuminate\Database\Eloquent\Relations\Relation;
@@ -21,6 +22,13 @@ class Filament extends Model
2122
'title',
2223
];
2324

25+
protected function casts(): array
26+
{
27+
return [
28+
'title' => FilamentTitleCast::class,
29+
];
30+
}
31+
2432
public function vendor(): Relation
2533
{
2634
return $this->belongsTo(Vendor::class);

app/Models/FilamentType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace App\Models;
66

7-
use App\Casts\FilamentTitleCast;
7+
use App\Casts\FilamentTypeTitleCast;
88
use Illuminate\Database\Eloquent\Factories\HasFactory;
99
use Illuminate\Database\Eloquent\Model;
1010
use Illuminate\Database\Eloquent\SoftDeletes;
@@ -20,7 +20,7 @@ class FilamentType extends Model
2020
protected function casts(): array
2121
{
2222
return [
23-
'title' => FilamentTitleCast::class,
23+
'title' => FilamentTypeTitleCast::class,
2424
];
2525
}
2626
}

app/Services/OrcaSlicer/ImportService.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace App\Services\OrcaSlicer;
66

7-
use App\Casts\FilamentTitleCast;
7+
use App\Casts\FilamentTypeTitleCast;
88
use App\Data\OrcaSlicer\FilamentData;
99
use App\Data\OrcaSlicer\MachineData;
1010
use App\Data\OrcaSlicer\ProfileData;
@@ -111,7 +111,7 @@ protected function userFilament(User $user, Filament $filament, FilamentData $da
111111

112112
protected function filamentType(string $name): FilamentType
113113
{
114-
$cast = (new FilamentTitleCast)->set(new FilamentType, '', $name, []);
114+
$cast = (new FilamentTypeTitleCast)->set(new FilamentType, '', $name, []);
115115

116116
if ($model = $this->filamentTypes[$cast] ?? null) {
117117
return $model;

resources/js/pages/welcome.tsx

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export default function Welcome({ settings }) {
44
return (
55
<>
66
<Head title="Welcome" />
7-
<div className="flex min-h-screen flex-col items-center bg-[#FDFDFC] p-6 text-[#1b1b18] lg:justify-center lg:p-8 dark:bg-[#0a0a0a]">
7+
<div className="flex min-h-screen flex-col items-center bg-[#EDEDFC] p-6 text-[#1b1b18] lg:justify-center lg:p-8 dark:bg-[#0a0a0a]">
88
<div className="flex w-full items-center justify-center opacity-100 transition-opacity duration-750 lg:grow starting:opacity-0">
99
<main className="flex w-full flex-col-reverse lg:max-w-4xl lg:flex-row">
1010
<table class="w-full border-collapse border border-gray-400 bg-white text-sm dark:border-gray-500 dark:bg-gray-800">
@@ -29,8 +29,7 @@ export default function Welcome({ settings }) {
2929
Max Volumetric Speed
3030
</th>
3131
<th class="border border-gray-300 p-3 text-left font-semibold text-gray-900 dark:border-gray-600 dark:text-gray-200">
32-
Nozzle Temperature<br />
33-
(first / other layers)
32+
Nozzle Temperature
3433
</th>
3534
</tr>
3635
</thead>
@@ -57,11 +56,7 @@ export default function Welcome({ settings }) {
5756
{ setting.filament_max_volumetric_speed }
5857
</td>
5958
<td class="border border-gray-300 p-3 text-left text-gray-900 dark:border-gray-600 dark:text-gray-200">
60-
{
61-
setting.nozzle_temperature === setting.nozzle_temperature_initial_layer
62-
? setting.nozzle_temperature
63-
: setting.nozzle_temperature_initial_layer + ' / ' + setting.nozzle_temperature
64-
}
59+
{ setting.nozzle_temperature }
6560
</td>
6661
</tr>
6762
)) }

0 commit comments

Comments
 (0)