Skip to content

Commit

Permalink
Merge pull request #20 from riodwanto/feat/general-improvement
Browse files Browse the repository at this point in the history
Feat/general improvement
  • Loading branch information
riodwanto authored May 24, 2024
2 parents 41f2dad + a431776 commit 2008da0
Show file tree
Hide file tree
Showing 31 changed files with 945 additions and 951 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ Generate key:
php artisan key:generate
```

Run with:
Run :

```bash
npm run dev
OR
npm run build
```

```bash
php artisan serve
Expand Down
181 changes: 141 additions & 40 deletions app/Filament/Resources/BannerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,78 +14,154 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
use League\CommonMark\CommonMarkConverter;

class BannerResource extends Resource
{
protected static ?string $model = Banner::class;
protected static int $globalSearchResultsLimit = 20;
protected static int $globalSearchResultsLimit = 10;

protected static ?int $navigationSort = -1;
protected static ?string $navigationIcon = 'fluentui-image-shadow-24';

protected static function getLastSortValue(): int
{
return Banner::max('sort') ?? 0;
}

public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('banner_category_id')
->relationship('category', 'name')
->searchable()
->required(),
Forms\Components\TextInput::make('sort')
->required()
->numeric()
->default(0),
Forms\Components\TextInput::make('title')
->maxLength(255),
Forms\Components\TextInput::make('description')
->maxLength(500),
SpatieMediaLibraryFileUpload::make('media')
->collection('banners')
->multiple()
->reorderable()
->required(),
Forms\Components\Toggle::make('is_visible')
->required(),
Forms\Components\DateTimePicker::make('start_date'),
Forms\Components\DateTimePicker::make('end_date'),
Forms\Components\TextInput::make('click_url')
->maxLength(255),
Forms\Components\Select::make('click_url_target')
->options([
'_blank' => 'New Tab',
'_self' => 'Current Tab',
// '_parent',
// '_top'
Forms\Components\Tabs::make('Banner Details')
->tabs([
Forms\Components\Tabs\Tab::make('General')
->icon('heroicon-o-information-circle')
->schema([
Forms\Components\Section::make('Main Details')
->description('Fill out the main details of the banner')
->icon('heroicon-o-clipboard')
->schema([
Forms\Components\Select::make('banner_category_id')
->label('Category')
->relationship('category', 'name')
->searchable()
->required(),
Forms\Components\Select::make('is_visible')
->label('Is Visible')
->default(1)
->options([
0 => "No",
1 => "Yes",
])
->native(false)
->required(),
Forms\Components\TextInput::make('title')
->label('Title')
->maxLength(255)
->columnSpan(2),
Forms\Components\MarkdownEditor::make('description')
->label('Description')
->helperText('Provide a description for the banner')
->maxLength(500)
->columnSpanFull(),
])
->compact()
->columns(2),
]),
Forms\Components\Tabs\Tab::make('Images')
->icon('heroicon-o-photo')
->schema([
Forms\Components\Section::make('Image')
->description('Upload banner images here')
->schema([
SpatieMediaLibraryFileUpload::make('media')
->hiddenLabel()
->helperText('Select and upload images for the banner')
->collection('banners')
->multiple()
->reorderable()
->required(),
])
->compact(),
]),
Forms\Components\Tabs\Tab::make('Scheduling')
->icon('heroicon-o-calendar')
->schema([
Forms\Components\Section::make('Schedule')
->description('Set the scheduling details for the banner')
->schema([
Forms\Components\DateTimePicker::make('start_date')
->label('Start Date')
->helperText('Select the start date and time'),
Forms\Components\DateTimePicker::make('end_date')
->label('End Date')
->helperText('Select the end date and time'),
])
->compact()
->columns(2),
]),
Forms\Components\Tabs\Tab::make('Additional Settings')
->icon('heroicon-o-cog')
->schema([
Forms\Components\Section::make('Settings')
->description('Additional settings for the banner')
->schema([
Forms\Components\TextInput::make('sort')
->label('Sort Order')
->helperText('Set the sort order of the banner')
->required()
->numeric()
->default(static::getLastSortValue() + 1),
Forms\Components\TextInput::make('click_url')
->label('Click URL')
->helperText('Enter the URL to navigate to when the banner is clicked')
->default('#')
->maxLength(255),
Forms\Components\Select::make('click_url_target')
->label('Click URL Target')
->helperText('Select how the URL should be opened')
->options([
'_blank' => 'New Tab',
'_self' => 'Current Tab',
'_parent' => 'Parent Frame',
'_top' => 'Full Body of the Window'
])
->native(false),
])
->compact(),
]),
])
->native(false),
->columnSpanFull(),
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
SpatieMediaLibraryImageColumn::make('media')
SpatieMediaLibraryImageColumn::make('media')->label('Images')
->collection('banners')
->wrap(),
Tables\Columns\TextColumn::make('title')
->description(fn(Model $record): string => strip_tags((new CommonMarkConverter())->convert($record->description)->getContent()))
->lineClamp(2)
->description(fn (Model $record): string => \Illuminate\Support\Str::limit($record->description, 50) ?? '')->wrap()
->searchable(),
->wrap()
->searchable()
->extraAttributes(['class' => '!w-96']),
Tables\Columns\TextColumn::make('category.name')
->searchable()
->alignCenter()
->lineClamp(1),
Tables\Columns\IconColumn::make('is_visible')->label('Active')
->lineClamp(2),
Tables\Columns\IconColumn::make('is_visible')
->boolean()
->alignCenter(),
Tables\Columns\TextColumn::make('start_date')
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('end_date')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
->sortable(),
Tables\Columns\TextColumn::make('click_url')
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('created_at')
Expand All @@ -98,10 +174,34 @@ public static function table(Table $table): Table
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
//
Tables\Filters\SelectFilter::make('category')
->relationship('category', 'name')
->searchable(),
Tables\Filters\TernaryFilter::make('is_visible')
->label('Visibility')
->trueLabel('Visible')
->falseLabel('Hidden')
->nullable(),
Tables\Filters\Filter::make('start_date')
->form([
Forms\Components\DatePicker::make('start_date'),
])
->query(function (Builder $query, array $data) {
return $query
->when($data['start_date'] ?? null, fn($query, $date) => $query->whereDate('start_date', '>=', $date));
}),
Tables\Filters\Filter::make('end_date')
->form([
Forms\Components\DatePicker::make('end_date'),
])
->query(function (Builder $query, array $data) {
return $query
->when($data['end_date'] ?? null, fn($query, $date) => $query->whereDate('end_date', '<=', $date));
}),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\ViewAction::make(),
Tables\Actions\DeleteAction::make(),
])
->bulkActions([
Expand All @@ -113,6 +213,7 @@ public static function table(Table $table): Table
->reorderable('sort');
}


public static function getRelations(): array
{
return [
Expand All @@ -134,7 +235,7 @@ public static function getGlobalSearchEloquentQuery(): Builder
return parent::getGlobalSearchEloquentQuery()->with(['category']);
}

public static function getGlobalSearchResultTitle(Model $record): string | Htmlable
public static function getGlobalSearchResultTitle(Model $record): string|Htmlable
{
return $record->title;
}
Expand Down
Loading

0 comments on commit 2008da0

Please sign in to comment.