Skip to content

Commit

Permalink
update plugin style & fix enable/disable plugin to be global
Browse files Browse the repository at this point in the history
  • Loading branch information
3x1io committed Sep 23, 2024
1 parent ad9df70 commit 9b053e1
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 25 deletions.
Binary file added .DS_Store
Binary file not shown.
1 change: 0 additions & 1 deletion config/filament-plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,3 @@

'scan' => true
];

Binary file added resources/.DS_Store
Binary file not shown.
Binary file added resources/lang/.DS_Store
Binary file not shown.
27 changes: 24 additions & 3 deletions resources/views/pages/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
if ((bool) filament()->hasTenancy()) {
$urlParams['tenant'] = filament()->getTenant();
}
if($item->github){
$package = str($item->github)->remove('https://github.com/')->remove('https://www.github.com/')->toString();
}
else {
$package = null;
}
@endphp

<div class="bg-white border border-gray-100 dark:border-gray-700 overflow-hidden dark:bg-gray-800 rounded-lg flex flex-col shadow-sm" >
Expand All @@ -25,14 +32,28 @@
<div class="w-full">
<h1 class="font-bold">{{ json_decode($item['name'])->{app()->getLocale()} }}</h1>
</div>
<div>
<h1>{{ $item['version'] }}</h1>
</div>
@if($package)
<div>
<img class="w-32" src="https://poser.pugx.org/{{ $package }}/version.svg" alt="Latest Stable Version">
</div>
@endif

</div>
<div class="h-30 px-4">
<p class="text-gray-600 dark:text-gray-300 text-sm h-30 truncate ...">
{{ json_decode($item['description'])->{app()->getLocale()} }}
</p>
@if($item->github)
<div class="flex justify-start gap-2 mt-3">
<div>
<img class="w-12" src="https://poser.pugx.org/{{ $package }}/d/total.svg" alt="Downloads">
</div>
<div>
<img class="w-12" src="https://img.shields.io/github/stars/{{ $package }}?style=flat" alt="GitHub Repo stars">
</div>
</div>
@endif

</div>
<div class="flex justifiy-between gap-1 my-4 px-4 border-t border-gray-100 dark:border-gray-700 pt-4">
<div class="flex justifiy-start w-full gap-2">
Expand Down
3 changes: 0 additions & 3 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
<?php


Binary file added share/.DS_Store
Binary file not shown.
Binary file added share/assets/.DS_Store
Binary file not shown.
Binary file added share/lib/.DS_Store
Binary file not shown.
Binary file added share/packages/.DS_Store
Binary file not shown.
Binary file added src/.DS_Store
Binary file not shown.
Binary file added src/Console/.DS_Store
Binary file not shown.
7 changes: 7 additions & 0 deletions src/FilamentPluginsPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ public function register(Panel $panel): void
]);
}

foreach ($panel->getPlugins() as $key=>$modulePlugin){
$module = Module::find(str(get_class($modulePlugin))->explode('\\')[1]);
if($module && !$module->isEnabled()){
$panel->disablePlugin($modulePlugin);
}
}

}

public function autoDiscoverModules(bool $autoDiscoverModules = true)
Expand Down
24 changes: 24 additions & 0 deletions src/FilamentPluginsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace TomatoPHP\FilamentPlugins;

use Filament\Contracts\Plugin;
use Filament\Panel;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\File;
use Illuminate\Support\ServiceProvider;
Expand Down Expand Up @@ -62,6 +64,28 @@ public function register(): void

$this->registerModuleMacros();


Panel::macro('disablePlugin', function (Plugin $plugin): static
{
$this->resources = collect($this->resources)->filter(function ($item, $key) use ($plugin) {
$namespace = str(get_class($plugin))->explode('\\')[1];
return !str($item)->contains($namespace);
})->toArray();
$this->pages = collect($this->pages)->filter(function ($item, $key) use ($plugin) {
$namespace = str(get_class($plugin))->explode('\\')[1];
return !str($item)->contains($namespace);
})->toArray();
$this->widgets = collect($this->widgets)->filter(function ($item, $key) use ($plugin) {
$namespace = str(get_class($plugin))->explode('\\')[1];
return !str($item)->contains($namespace);
})->toArray();
$this->plugins = collect($this->plugins)->filter(function ($item, $key) use ($plugin) {
return $key !== $plugin->getId();
})->toArray();

return $this;
});

}

public function boot(): void
Expand Down
Binary file added src/Http/.DS_Store
Binary file not shown.
56 changes: 38 additions & 18 deletions src/Pages/Plugins.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Composer\Autoload\ClassLoader;
use Filament\Actions\Action;
use Filament\Actions\ActionGroup;
use Filament\Forms\Components\ColorPicker;
use Filament\Forms\Components\FileUpload;
use Filament\Forms\Components\Textarea;
Expand Down Expand Up @@ -72,7 +73,7 @@ public function table(Table $table): Table

public function disableAction(): Action
{
return Action::make('disable')
return Action::make('disableAction')
->iconButton()
->icon('heroicon-s-x-circle')
->color('danger')
Expand All @@ -88,13 +89,14 @@ public function disableAction(): Action
->success()
->send();

$this->js('window.location.reload()');
$this->redirect(static::getUrl());

});
}

public function deleteAction(): Action
{
return Action::make('delete')
return Action::make('deleteAction')
->visible(function (array $arguments) {
$module = Module::find($arguments['item']['module_name']);
if(str($module->getPath())->contains('vendor')){
Expand All @@ -119,13 +121,13 @@ public function deleteAction(): Action
->success()
->send();

$this->js('window.location.reload()');
$this->redirect(static::getUrl());
});
}

public function activeAction(): Action
{
return Action::make('active')
return Action::make('activeAction')
->iconButton()
->icon('heroicon-s-check-circle')
->tooltip(trans('filament-plugins::messages.plugins.actions.active'))
Expand All @@ -149,7 +151,7 @@ public function activeAction(): Action
->success()
->send();

$this->js('window.location.reload()');
$this->redirect(static::getUrl());

});
}
Expand Down Expand Up @@ -178,17 +180,33 @@ public function getHeaderActions(): array
->required()
])
->action(fn (array $data) => $this->createPlugin($data)),
Action::make('import')
->label(trans('filament-plugins::messages.plugins.import'))
->icon('heroicon-o-arrow-up-on-square')
->form([
FileUpload::make('file')
->label(trans('filament-plugins::messages.plugins.form.file'))
->acceptedFileTypes(['application/zip'])
->required()
->storeFiles(false)
])
->action(fn (array $data) => $this->importPlugin($data)),
ActionGroup::make([
Action::make('import')
->label(trans('filament-plugins::messages.plugins.import'))
->icon('heroicon-o-arrow-up-on-square')
->form([
FileUpload::make('file')
->label(trans('filament-plugins::messages.plugins.form.file'))
->acceptedFileTypes(['application/zip'])
->required()
->storeFiles(false)
])
->action(fn (array $data) => $this->importPlugin($data)),
Action::make('enable')
->requiresConfirmation()
->label(trans('filament-plugins::messages.plugins.enable'))
->icon('heroicon-o-check-circle')
->action(function (array $data){
collect(Module::all())->each(fn($module) => $module->enable());

$this->redirect(static::getUrl());
}),
Action::make('disable')
->requiresConfirmation()
->label(trans('filament-plugins::messages.plugins.disable'))
->icon('heroicon-o-x-circle')
->action(fn (array $data) => collect(Module::all())->each(fn($module) => $module->disable())),
])
];
}

Expand All @@ -215,7 +233,7 @@ public function importPlugin(array $data)
->success()
->send();

$this->js('window.location.reload()');
$this->redirect(static::getUrl());

}
}
Expand Down Expand Up @@ -245,5 +263,7 @@ public function createPlugin(array $data)
->body(trans('filament-plugins::messages.plugins.notifications.created.body'))
->success()
->send();

$this->redirect(static::getUrl());
}
}
Binary file added src/Resources/.DS_Store
Binary file not shown.
Binary file added src/Resources/TableResource/.DS_Store
Binary file not shown.
Binary file added src/Services/.DS_Store
Binary file not shown.
Binary file added stubs/.DS_Store
Binary file not shown.
Binary file added stubs/flutter/.DS_Store
Binary file not shown.
Binary file added tests/.DS_Store
Binary file not shown.

0 comments on commit 9b053e1

Please sign in to comment.