Skip to content

Commit

Permalink
Add config parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
invaders-xx committed May 8, 2024
1 parent f6dca16 commit 25637cc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions config/gridstack-dashboard.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

use App\Models\User;
use InvadersXX\FilamentGridstackDashboard\Models\GridStackDashboard;

return [
'table' => 'filament_gridstack_dashboards',
'model' => GridStackDashboard::class,
'field' => 'parameters',
'foreign_key' => 'user_id',
'users' => [
'model' => User::class,
'table' => 'users',
Expand Down
4 changes: 4 additions & 0 deletions resources/lang/en/component.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@
'save' => 'Save',
'cancel' => 'Cancel',
],
'notifications' => [
'saved' => 'Successfully saved.',
'success' => 'Well done!',
],
];
12 changes: 6 additions & 6 deletions src/Filament/Pages/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ public function saveLayout(): void
]])->all();

$this->designMode = false;
GridStackDashboard::updateOrCreate(
['user_id' => auth()->id()],
['parameters' => $data]
config('gridstack-dashboard.model', GridStackDashboard::class)::updateOrCreate(
[config('gridstack-dashboard.foreign_key', 'user_id') => auth()->id()],
[config('gridstack-dashboard.field', 'parameters') => $data]
);
Notification::make()->success()->title(__('Well done!'))->body(__('Successfully updated.'))->send();
Notification::make()->success()->title(__('filament-gridstack-dashboard::component.notifications.success'))->body(__('filament-gridstack-dashboard::component.notifications.saved'))->send();
}

public function cancelLayout(): void
Expand Down Expand Up @@ -124,9 +124,9 @@ protected function getHeaderActions(): array

protected function getVisibleWidgetsForGrid(): array
{
$item = GridStackDashboard::query()->where('user_id', auth()->id())->first();
$item = config('gridstack-dashboard.model', GridStackDashboard::class)::query()->where(config('gridstack-dashboard.foreign_key', 'user_id'), auth()->id())->first();
if ($item) {
return $item->parameters;
return $item->{config('gridstack-dashboard.field', 'parameters')};
}

return [];
Expand Down

0 comments on commit 25637cc

Please sign in to comment.