Skip to content

Commit

Permalink
Merge pull request #1 from awcodes/feat/excludes
Browse files Browse the repository at this point in the history
Feat: add includes and excludes to config
  • Loading branch information
awcodes authored Mar 15, 2023
2 parents 0a1fb12 + b8a596a commit 4a712e4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 21 deletions.
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,27 @@ You can install the package via composer:
composer require awcodes/overlook
```

Optionally, you can publish the views using
## Usage

By default, Overlook will display any resource registered with Filament, while still honoring the `canViewAny` policy. This can be undesired and also slow down the dashboard. To prevent this behavior publish the config file with:

```bash
php artisan vendor:publish --tag="overlook-views"
php artisan vendor:publish --tag="overlook-config"
```

Inside the config you will have options to either "include" or "exclude" resources from being displayed.

```php
return [
'includes' => [
App\Filament\Resources\Blog\AuthorResource::class,
App\Filament\Resources\Blog\CategoryResource::class,
App\Filament\Resources\Blog\PostResource::class,
],
'excludes' => [
// App\Filament\Resources\Blog\AuthorResource::class,
],
];
```

## Changelog
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"php": "^8.0",
"php": "^8.1",
"filament/filament": "^2.0",
"spatie/laravel-package-tools": "^1.13.5"
},
Expand Down
10 changes: 10 additions & 0 deletions config/overlook.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

return [
'includes' => [
// App\Filament\Resources\Blog\AuthorResource::class,
],
'excludes' => [
// App\Filament\Resources\Blog\AuthorResource::class,
],
];
2 changes: 1 addition & 1 deletion resources/dist/overlook.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions resources/lang/en/overlook.php

This file was deleted.

13 changes: 5 additions & 8 deletions resources/views/widget.blade.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
<x-filament::widget id="overlook-widget">
<x-filament::widget id="overlook-widget" @class(['hidden' => ! $data])>
@if($data)
<h2 class="font-semibold text-sm uppercase">{{ __('overlook::overlook.heading') }}</h2>

<ul class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-6 mt-4">
<ul class="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 gap-6">
@foreach($data as $resource)
<li class="rounded-xl border border-gray-200 dark:border-gray-800 relative h-24 bg-gradient-to-tr from-gray-100 via-white to-white dark:from-gray-900 dark:via-gray-800 dark:to-gray-800" wire:key="{{ $resource['name'] }}">
<a href="{{ $resource['url'] }}" class="overflow-hidden absolute inset-0 py-2 px-3 text-gray-600 font-medium rounded-xl ring-primary-500 dark:text-gray-400 group hover:ring-2 focus:ring-2">
@if ($resource['icon'])
<x-dynamic-component
:component="$resource['icon']"
class="w-auto h-24 absolute left-0 top-8 text-primary-500 opacity-20 dark:opacity-20 transition group-hover:scale-110 group-hover:-rotate-12 group-hover:opacity-40 dark:group-hover:opacity-80"
/>
@svg($resource['icon'], 'w-auto h-24 absolute left-0 top-8 text-primary-500 opacity-20 dark:opacity-20 transition group-hover:scale-110 group-hover:-rotate-12 group-hover:opacity-40 dark:group-hover:opacity-80')
@endif
{{ $resource['name'] }}
<span class="text-gray-600 dark:text-gray-300 absolute bottom-4 right-4 text-3xl font-bold">{{ $resource['count'] }}</span>
</a>
</li>
@endforeach
</ul>
@else
<div class="-my-8"></div>
@endif
</x-filament::widget>

21 changes: 18 additions & 3 deletions src/Overlook.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Awcodes\Overlook;

use Filament\Facades\Filament;
use Filament\Resources\Resource;
use Filament\Widgets\Widget;
use Illuminate\Support\Str;

Expand All @@ -14,19 +15,33 @@ class Overlook extends Widget

public array $data = [];

private array $excludes = [];
protected array $excludes = [];

protected array $includes = [];

public function mount(): void
{
$this->data = $this->getData();
}

public function getIncludes(): array
{
return $this->includes = config('overlook.includes');
}

public function getExcludes(): array
{
return $this->excludes = config('overlook.excludes');
}

public function getData(): array
{
$rawResources = Filament::getResources();
$rawResources = filled($this->getIncludes())
? $this->getIncludes()
: Filament::getResources();

return collect($rawResources)->filter(function ($resource) {
return ! in_array(Str::of($resource)->afterLast('\\'), $this->excludes);
return ! in_array($resource, $this->getExcludes());
})->transform(function ($resource) {
$res = app($resource);
$model = $res->getModel();
Expand Down
2 changes: 1 addition & 1 deletion src/OverlookServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function configurePackage(Package $package): void

$package
->name(static::$name)
->hasTranslations()
->hasConfigFile()
->hasViews(static::$viewNamespace);
}

Expand Down

0 comments on commit 4a712e4

Please sign in to comment.