Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
markvaneijk committed Oct 31, 2024
1 parent e3b5cc6 commit 145b8fc
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
30 changes: 19 additions & 11 deletions src/Resources/RedirectResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,34 @@ public static function form(Form $form): Form
->prefixIcon('heroicon-o-link')
->options(Site::orderBy('default', 'desc')->orderBy('name', 'asc')->pluck('name', 'ulid'))
->default(Site::where('default', true)->first()?->ulid)
->visible(fn () => Schema::hasColumn('redirects', 'content_ulid') && Site::count() > 0)
->hidden(fn () => Schema::hasColumn('redirects', 'content_ulid') && Site::count() === 1),
->visible(fn() => Schema::hasColumn('redirects', 'content_ulid') && Site::count() > 0)
->hidden(fn() => Schema::hasColumn('redirects', 'content_ulid') && Site::count() === 1),
Select::make('country_code')
->label(__('Country'))
->columnSpan(4)
->placeholder(__('Select Country'))
->prefixIcon('heroicon-o-flag')
->options(Language::whereNotNull('country_code')->distinct('country_code')->get()->mapWithKeys(fn ($language) => [$language->country_code => Locale::getDisplayRegion('-' . $language->country_code, app()->getLocale())])->sort())
->prefixIcon('heroicon-o-globe-europe-africa')
->options(Language::whereNotNull('country_code')->distinct('country_code')->get()->mapWithKeys(fn($language) => [
$language->code => '<img src="data:image/svg+xml;base64,' . base64_encode(file_get_contents(base_path('vendor/vormkracht10/backstage/resources/img/flags/' . $language->code . '.svg'))) . '" class="w-5 inline-block relative" style="top: -1px; margin-right: 3px;"> ' . Locale::getDisplayLanguage($language->code, app()->getLocale())
])->sort())
->allowHtml()
->default(Language::whereNotNull('country_code')->distinct('country_code')->count() === 1 ? Language::whereNotNull('country_code')->first()->country_code : null)
->visible(fn () => Schema::hasColumn('redirects', 'content_ulid') && Language::whereNotNull('country_code')->distinct('country_code')->count() > 0)
->hidden(fn () => Schema::hasColumn('redirects', 'content_ulid') && Language::whereNotNull('country_code')->distinct('country_code')->count() === 1),
->visible(fn() => Schema::hasColumn('redirects', 'content_ulid') && Language::whereNotNull('country_code')->distinct('country_code')->count() > 0)
->hidden(fn() => Schema::hasColumn('redirects', 'content_ulid') && Language::whereNotNull('country_code')->distinct('country_code')->count() === 1),
Select::make('language_code')
->label(__('Language'))
->columnSpan(4)
->placeholder(__('Select Language'))
->prefixIcon('heroicon-o-language')
->options(Language::get()->mapWithKeys(fn ($language) => [$language->code => Locale::getDisplayLanguage($language->code, app()->getLocale())])->sort())
->options(
Language::get()->mapWithKeys(fn($language) => [
$language->code => '<img src="data:image/svg+xml;base64,' . base64_encode(file_get_contents(base_path('vendor/vormkracht10/backstage/resources/img/flags/' . $language->code . '.svg'))) . '" class="w-5 inline-block relative" style="top: -1px; margin-right: 3px;"> ' . Locale::getDisplayLanguage($language->code, app()->getLocale())
])->sort()
)
->allowHtml()
->default(Language::count() === 1 ? Language::first()->code : Language::where('default', true)->first()->code)
->visible(fn () => Schema::hasColumn('redirects', 'content_ulid') && Language::count() > 0)
->hidden(fn () => Schema::hasColumn('redirects', 'content_ulid') && Language::count() === 1),
->visible(fn() => Schema::hasColumn('redirects', 'content_ulid') && Language::count() > 0)
->hidden(fn() => Schema::hasColumn('redirects', 'content_ulid') && Language::count() === 1),
TextInput::make('source')
->label(__('Source'))
->columnSpan(12)
Expand All @@ -92,7 +100,7 @@ public static function form(Form $form): Form
->label(__('Type'))
->columnSpan(4)
->native(false)
->options(collect(config('redirects.status_codes'))->map(fn (string $type, int $code) => $type . ' (' . $code . ')'))
->options(collect(config('redirects.status_codes'))->map(fn(string $type, int $code) => $type . ' (' . $code . ')'))
->searchable()
->required()
->default(config('redirects.default_status_code'))
Expand All @@ -104,7 +112,7 @@ public static function form(Form $form): Form
->placeholder('Content')
->prefixIcon('heroicon-o-link')
->helperText(__('Select a content page to redirect to the current URL.'))
->visible(fn () => Schema::hasColumn('redirects', 'content_ulid')),
->visible(fn() => Schema::hasColumn('redirects', 'content_ulid')),
TextInput::make('destination')
->label(__('Destination'))
->columnSpan(12)
Expand Down
19 changes: 16 additions & 3 deletions src/Resources/RedirectResource/Pages/ListRedirects.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace Vormkracht10\FilamentRedirects\Resources\RedirectResource\Pages;

use Filament\Actions;
use Filament\Actions\ActionGroup;
use Filament\Support\Colors\Color;
use Filament\Support\Enums\ActionSize;
use Filament\Resources\Pages\ListRecords;
use Vormkracht10\FilamentRedirects\Imports\RedirectImporter;
use Vormkracht10\FilamentRedirects\Resources\RedirectResource;
Expand All @@ -14,9 +17,19 @@ class ListRedirects extends ListRecords
protected function getHeaderActions(): array
{
return [
Actions\ImportAction::make()
->label(__('Import'))
->importer(RedirectImporter::class),
ActionGroup::make([
Actions\Action::make('import-paste')
->label(__('Import by pasting text'))
->icon('heroicon-o-clipboard-document-list'),
Actions\ImportAction::make('import-file')
->label(__('Import by file'))
->icon('heroicon-o-arrow-up-on-square-stack')
->importer(RedirectImporter::class),
])->label(__('Import'))
->color('gray')
->icon('heroicon-o-arrow-up-tray')
->size(ActionSize::Small)
->button(),
Actions\CreateAction::make(),
];
}
Expand Down

0 comments on commit 145b8fc

Please sign in to comment.