Start on settings feature

This commit is contained in:
Ryan Scherler
2020-12-06 20:32:31 -08:00
parent 32600a3e78
commit fd6b0aadc5
15 changed files with 142 additions and 65 deletions
+1
View File
@@ -77,5 +77,6 @@ php artisan filament:user
## Roadmap
- [ ] Settings feature & related tests
- [ ] Resource stubs and associated Artisan commands (e.g. `artisan filament:resource Page --options`)
- [ ] DOCUMENTATION FOR ALL THE THINGS.
+2 -1
View File
@@ -11,7 +11,8 @@
"blade-ui-kit/blade-heroicons": "^0.3",
"league/glide-laravel": "^1.0",
"livewire/livewire": "^2.2",
"thomaswelton/laravel-gravatar": "~1.0",
"spatie/valuestore": "^1.2",
"thomaswelton/laravel-gravatar": "^1.0",
"watson/active": "^6.0"
},
"require-dev": {
+28 -46
View File
@@ -16,7 +16,9 @@ return [
'features' => [
Features::registration(),
Features::dashboard(),
Features::profile(),
// Features::settings(),
Features::resources(),
],
@@ -57,39 +59,6 @@ return [
],
/*
|--------------------------------------------------------------------------
| Home
|--------------------------------------------------------------------------
|
| The path to the "home" route for Filament.
| This is used by Filament authentication to redirect users after login.
|
*/
'home' => 'filament.dashboard', // string or named route
/*
|--------------------------------------------------------------------------
| Navigation
|--------------------------------------------------------------------------
|
| Navigations used by Filament.
|
*/
'nav' => [
'dashboard' => [
'path' => 'filament.dashboard', // string or named route
'active' => 'filament.dashboard', // string or named route (may also be an array @link https://github.com/dwightwatson/active)
'label' => 'Dashboard',
'icon' => 'heroicon-o-home', // optional icon name (Blade UI Kit @link https://github.com/blade-ui-kit/blade-heroicons)
'sort' => -9999, // sort order used by the navigation
],
],
/*
|--------------------------------------------------------------------------
| Components
@@ -124,21 +93,9 @@ return [
'dashboard' => Filament\Http\Livewire\Dashboard::class,
'profile' => Filament\Http\Livewire\Profile::class,
'account' => Filament\Http\Livewire\Account::class,
'settings' => Filament\Http\Livewire\Settings::class,
],
/*
|--------------------------------------------------------------------------
| Cache
|--------------------------------------------------------------------------
|
| This is the cache disk Filament will use, you may
| use any of the disks defined in the `config/filesystems.php`.
|
*/
'cache_disk' => env('FILAMENT_CACHE_DISK', 'local'),
'cache_path' => 'filament-tmp',
/*
|--------------------------------------------------------------------------
| Storage
@@ -151,4 +108,29 @@ return [
'storage_disk' => env('FILAMENT_STORAGE_DISK', 'public'),
/*
|--------------------------------------------------------------------------
| Cache
|--------------------------------------------------------------------------
|
| This is the cache disk Filament will use, you may
| use any of the disks defined in the `config/filesystems.php`.
|
*/
'cache_disk' => env('FILAMENT_CACHE_DISK', 'local'),
'cache_path_prefix' => 'filament/cache',
/*
|--------------------------------------------------------------------------
| Settings
|--------------------------------------------------------------------------
|
| This is the path Filament will use to store and retrieve settings as
| loose values. Stored values are saved as a json file.
|
*/
'settings_path' => storage_path('app/filament/settings.json'),
];
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,6 +1,6 @@
{
"/js/filament.js": "/js/filament.js?id=9995e728ce8648b81f5d",
"/css/filament.css": "/css/filament.css?id=ee5d10364ff0ea52a03a",
"/css/filament.css": "/css/filament.css?id=777f65851975bd896183",
"/js/filament.js.map": "/js/filament.js.map?id=1d3615b89069bfd79261",
"/css/filament.css.map": "/css/filament.css.map?id=3da57234a2c617fd88f8"
"/css/filament.css.map": "/css/filament.css.map?id=8a7842639ac77e680c3a"
}
+1 -1
View File
@@ -1,5 +1,5 @@
.btn {
@apply cursor-pointer text-sm font-semibold py-2 px-4 border border-gray-300 bg-gray-100 text-gray-800 rounded transition duration-200 shadow-sm inline-block relative focus:ring focus:ring-indigo-200 focus:ring-opacity-50 hover:bg-gray-200;
@apply cursor-pointer text-sm font-semibold py-2 px-6 border border-gray-300 bg-gray-100 text-gray-800 rounded transition duration-200 shadow-sm inline-block relative focus:ring focus:ring-indigo-200 focus:ring-opacity-50 hover:bg-gray-200;
&-primary {
@apply border-transparent bg-blue-700 text-white hover:bg-blue-800;
@@ -0,0 +1,3 @@
<x-filament::form>
</x-filament::form>
+5
View File
@@ -39,6 +39,11 @@ Route::group(['middleware' => ['auth.filament']], function () {
Route::get('/profile', config('filament.livewire.profile'))->name('profile');
}
// Settings
if (Features::hasSettings()) {
Route::get('/settings', config('filament.livewire.settings'))->name('settings');
}
// Resources
if (Features::hasResources()) {
Route::get('/resources/{resource}/{action?}/{id?}', ResourceController::class)->name('resource');
+40
View File
@@ -25,6 +25,16 @@ class Features
return static::enabled(static::registration());
}
/**
* Determine if the application has a dashboard.
*
* @return bool
*/
public static function hasDashboard()
{
return static::enabled(static::dashboard());
}
/**
* Determine if the application has a user profile.
*
@@ -35,6 +45,16 @@ class Features
return static::enabled(static::profile());
}
/**
* Determine if the application has settings.
*
* @return bool
*/
public static function hasSettings()
{
return static::enabled(static::settings());
}
/**
* Determine if the application has resources.
*
@@ -45,6 +65,16 @@ class Features
return static::enabled(static::resources());
}
/**
* Enable the dashboard feature.
*
* @return string
*/
public static function dashboard()
{
return 'dashboard';
}
/**
* Enable the user registration feature.
*
@@ -65,6 +95,16 @@ class Features
return 'profile';
}
/**
* Enable the settings feature.
*
* @return string
*/
public static function settings()
{
return 'settings';
}
/**
* Enable the resources feature.
*
+4 -2
View File
@@ -2,6 +2,7 @@
namespace Filament;
use App\Providers\RouteServiceProvider;
use Illuminate\Container\Container;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\{
@@ -174,8 +175,9 @@ class Filament
*/
public function home()
{
$home = config('filament.home');
return Route::has($home) ? route($home) : $home;
return Features::hasDashboard() ?
config('filament.home', route('filament.dashboard'))
: RouteServiceProvider::HOME;
}
/**
+36 -8
View File
@@ -12,6 +12,7 @@ use Illuminate\Support\Facades\{
Cache,
};
use Livewire\Livewire;
use Spatie\Valuestore\Valuestore;
use Filament\Providers\RouteServiceProvider;
use Filament\Features;
use Filament\Helpers\{
@@ -37,7 +38,7 @@ class FilamentServiceProvider extends ServiceProvider
$this->bootModelBindings();
$this->bootLoaders();
$this->bootDirectives();
$this->bootResources();
$this->bootNavigation();
$this->bootCommands();
$this->bootPublishing();
}
@@ -46,9 +47,15 @@ class FilamentServiceProvider extends ServiceProvider
{
$this->app->singleton('filament', Filament::class);
$this->app->singleton(Navigation::class, function () {
$this->app->singleton('Filament\Navigation', function () {
return new Navigation(config('filament.nav', []));
});
if (Features::hasSettings()) {
$this->app->singleton('Filament\Settings', function () {
return Valuestore::make(config('filament.settings_path'));
});
}
}
protected function registerLivewireComponents(): void
@@ -118,10 +125,31 @@ class FilamentServiceProvider extends ServiceProvider
], 'filament-assets');
}
protected function bootResources(): void
protected function bootNavigation(): void
{
if (Features::hasResources()) {
$this->app->booted(function () {
$this->app->booted(function () {
if (Features::hasDashboard()) {
app('Filament\Navigation')->dashboard = [
'path' => 'filament.dashboard',
'active' => 'filament.dashboard',
'label' => 'Dashboard',
'icon' => 'heroicon-o-home',
'sort' => -9999,
];
}
if (Features::hasSettings()) {
app('Filament\Navigation')->settings = [
'path' => 'filament.settings',
'active' => 'filament.settings',
'label' => 'Settings',
'icon' => 'heroicon-o-adjustments',
'sort' => -9998,
];
}
if (Features::hasResources()) {
$this->app->filament->resources()->each(function ($item, $key) {
$resource = $this->app->make($item);
@@ -129,7 +157,7 @@ class FilamentServiceProvider extends ServiceProvider
$route = route('filament.resource', ['resource' => $key]);
$routePath = implode('/', array_slice(explode('/', $route), -3, 2, true)).'/'.$key;
app(Navigation::class)->$key = [
app('Filament\Navigation')->$key = [
'path' => $route,
'active' => [
$routePath,
@@ -142,8 +170,8 @@ class FilamentServiceProvider extends ServiceProvider
];
}
});
});
}
}
});
}
protected function bootCommands(): void
+1 -1
View File
@@ -26,7 +26,7 @@ class ImageController extends Controller
'response' => new LaravelResponseFactory(app('request')),
'source' => Storage::disk(config('filament.storage_disk'))->getDriver(),
'cache' => Storage::disk(config('filament.cache_disk'))->getDriver(),
'cache_path_prefix' => config('filament.cache_path'),
'cache_path_prefix' => config('filament.cache_path_prefix'),
'base_url' => 'image',
]);
+14
View File
@@ -0,0 +1,14 @@
<?php
namespace Filament\Http\Livewire;
use Livewire\Component;
class Settings extends Component
{
public function render()
{
return view('filament::livewire.settings')
->layout('filament::layouts.app', ['title' => __('Settings')]);
}
}
+3 -2
View File
@@ -3,7 +3,6 @@
namespace Filament\View\Components;
use Illuminate\View\Component;
use Filament\Helpers\Navigation;
class Nav extends Component
{
@@ -18,7 +17,9 @@ class Nav extends Component
*/
public function __construct()
{
$this->nav = app(Navigation::class)->items()
$nav = app('Filament\Navigation');
$this->nav = $nav->items()
->groupBy('group')
->sortBy('sort')
->all();