Skip to content

Commit f7a82bf

Browse files
committed
small fixes for QR code and labels generator
1 parent 573f0c1 commit f7a82bf

File tree

3 files changed

+43
-27
lines changed

3 files changed

+43
-27
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ Still some part are in WIP status: I need to add queue worker to docker-compose.
9595
- [x] Add spotlight. Click: CTRL + K or CMD + K or CTRL + / or CMD + /
9696
- [x] Add Label Generator
9797
- [ ] Add REST API
98-
98+
- [ ] Add backup [via spatie package](https://github.com/shuvroroy/filament-spatie-laravel-backu)
99+
- [ ] add https://github.com/CodeWithDennis/filament-select-tree
100+
99101

100102
## Contributing
101103

app/Filament/Pages/LabelsGenerator.php

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,23 @@ public function form(Form $form): Form
7676
->label('Label Height (inches)')
7777
->numeric()
7878
->required()
79-
->default($this->cardHeight),
79+
->default($this->cardHeight)
80+
->rules(['required', 'numeric', 'min:0.1', function($attribute, $value, $fail) {
81+
$availableHeight = $this->pageHeight - $this->pageTopPadding - $this->pageBottomPadding;
82+
if ($value > $availableHeight) {
83+
$fail("The card height must not exceed the available page height.");
84+
}
85+
}]),
8086
TextInput::make('cardWidth')
8187
->label('Label Width (inches)')
8288
->numeric()
8389
->required()
90+
->rules(['required', 'numeric', 'min:0.1', function($attribute, $value, $fail) {
91+
$availableWidth = $this->pageWidth - $this->pageLeftPadding - $this->pageRightPadding;
92+
if ($value > $availableWidth) {
93+
$fail("The card width must not exceed the available page width.");
94+
}
95+
}])
8496
->default($this->cardWidth),
8597
TextInput::make('pageWidth')
8698
->label('Page Width (inches)')
@@ -124,7 +136,7 @@ public function form(Form $form): Form
124136
])->columns(2);
125137
}
126138

127-
public function generatePages($showNotification = true)
139+
public function generatePages($showNotification = true): void
128140
{
129141
$this->validate();
130142
$this->init();
@@ -181,11 +193,10 @@ private function calculateGridData()
181193
];
182194
}
183195

184-
$cols = floor($availablePageWidth / $this->cardWidth);
185-
$rows = floor($availablePageHeight / $this->cardHeight);
186-
$gapX = ($availablePageWidth - $cols * $this->cardWidth) / ($cols - 1);
187-
$gapY = ($this->pageHeight - $rows * $this->cardHeight) / ($rows - 1);
188-
196+
$cols = max(1, floor($availablePageWidth / $this->cardWidth));
197+
$rows = max(1, floor($availablePageHeight / $this->cardHeight));
198+
$gapX = $cols > 1 ? ($availablePageWidth - $cols * $this->cardWidth) / ($cols - 1) : 0;
199+
$gapY = $rows > 1 ? ($availablePageHeight - $rows * $this->cardHeight) / ($rows - 1) : 0;
189200
return [
190201
'cols' => $cols,
191202
'rows' => $rows,

routes/web.php

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@
1515
Route::get('/dashboard', function () {
1616
return redirect()->to('/app');
1717
})->name('dashboard');
18+
19+
20+
Route::get('/a/{asset_id}', function (string $asset_id) {
21+
$team_id = auth()?->user()?->currentTeam()?->getChild()?->id ?: auth()->user()->ownedTeams()->first()->id;
22+
23+
// todo: put this logic in one place
24+
$asset_id = ltrim($asset_id, '0');
25+
$asset_id = ltrim($asset_id, '-');
26+
27+
$asset = \App\Models\Item::where('asset_id', $asset_id)
28+
->where('team_id', $team_id)
29+
->first();
30+
if (! $asset) {
31+
// create new empty one with this asset id
32+
$asset = new \App\Models\Item();
33+
$asset->asset_id = $asset_id;
34+
$asset->team_id = $team_id;
35+
$asset->save();
36+
}
37+
38+
return redirect()->to(ItemResource::getUrl('edit', ['record' => $asset, 'tenant' => $team_id]));
39+
})->name('asset');
1840
});
1941

20-
Route::get('/a/{asset_id}', function (string $asset_id) {
21-
$team_id = auth()?->user()?->currentTeam()?->getChild()?->id;
22-
// todo: put this logic in one place
23-
$asset_id = ltrim($asset_id, '0');
24-
$asset_id = ltrim($asset_id, '-');
25-
26-
$asset = \App\Models\Item::where('asset_id', $asset_id)
27-
->where('team_id', $team_id)
28-
->first();
29-
if (! $asset) {
30-
// create new empty one with this asset id
31-
$asset = new \App\Models\Item();
32-
$asset->asset_id = $asset_id;
33-
$asset->team_id = $team_id;
34-
$asset->save();
35-
}
36-
37-
return redirect()->to(ItemResource::getUrl('edit', ['record' => $asset, 'tenant' => $team_id]));
38-
})->name('asset');

0 commit comments

Comments
 (0)