Skip to content

Commit

Permalink
tidy up
Browse files Browse the repository at this point in the history
  • Loading branch information
danharrin committed Jul 31, 2023
1 parent aa0ace7 commit 2778012
Show file tree
Hide file tree
Showing 18 changed files with 146 additions and 43 deletions.
2 changes: 2 additions & 0 deletions app/Filament/Resources/Blog/AuthorResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static function form(Form $form): Form
->required(),

Forms\Components\TextInput::make('email')
->label('Email address')
->required()
->email()
->unique(Author::class, 'email', ignoreRecord: true),
Expand Down Expand Up @@ -61,6 +62,7 @@ public static function table(Table $table): Table
->alignLeft(),

Tables\Columns\TextColumn::make('email')
->label('Email address')
->searchable()
->sortable()
->color('gray')
Expand Down
6 changes: 4 additions & 2 deletions app/Filament/Resources/Blog/CategoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ public static function table(Table $table): Table
Tables\Columns\TextColumn::make('slug')
->searchable()
->sortable(),
Tables\Columns\BooleanColumn::make('is_visible')
->label('Visibility'),
Tables\Columns\IconColumn::make('is_visible')
->label('Visibility')
->boolean(),
Tables\Columns\TextColumn::make('updated_at')
->label('Last Updated')
->date(),
Expand Down Expand Up @@ -97,6 +98,7 @@ public static function infolist(Infolist $infolist): Infolist
TextEntry::make('slug'),
TextEntry::make('description'),
IconEntry::make('is_visible')
->label('Visibility')
->boolean(),
TextEntry::make('updated_at')
->dateTime(),
Expand Down
18 changes: 6 additions & 12 deletions app/Filament/Resources/Blog/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Filament\Infolists\Infolist;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Support\Colors\Color;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
Expand Down Expand Up @@ -141,7 +142,8 @@ public static function table(Table $table): Table

Tables\Columns\TextColumn::make('comments.customer.name')
->label('Comment Authors')
->listWithLineBreaks(),
->listWithLineBreaks()
->limitList(2),
])
->filters([
Tables\Filters\Filter::make('published_at')
Expand All @@ -154,11 +156,11 @@ public static function table(Table $table): Table
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['published_from'],
$data['published_from'] ?? null,
fn (Builder $query, $date): Builder => $query->whereDate('published_at', '>=', $date),
)
->when(
$data['published_until'],
$data['published_until'] ?? null,
fn (Builder $query, $date): Builder => $query->whereDate('published_at', '<=', $date),
);
})
Expand Down Expand Up @@ -206,10 +208,7 @@ public static function infolist(Infolist $infolist): Infolist
Components\TextEntry::make('published_at')
->badge()
->date()
->color('danger'),
Components\IconEntry::make('test')
->boolean()
->getStateUsing(fn () => rand(0, 1)),
->color('success'),
]),
Components\Group::make([
Components\TextEntry::make('author.name'),
Expand All @@ -232,11 +231,6 @@ public static function infolist(Infolist $infolist): Infolist
->hiddenLabel(),
])
->collapsible(),
Components\RepeatableEntry::make('comments')
->schema([
Components\TextEntry::make('title'),
Components\TextEntry::make('customer.name'),
]),
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace App\Filament\Resources\Blog\PostResource\RelationManagers;

use Filament\Actions\ViewAction;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Infolists\Components\IconEntry;
use Filament\Infolists\Components\TextEntry;
use Filament\Infolists\Infolist;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Tables;
use Filament\Tables\Table;
Expand Down Expand Up @@ -37,6 +41,21 @@ public function form(Form $form): Form
->columns(1);
}

public function infolist(Infolist $infolist): Infolist
{
return $infolist
->columns(1)
->schema([
TextEntry::make('title'),
TextEntry::make('customer.name'),
IconEntry::make('is_visible')
->label('Visibility')
->boolean(),
TextEntry::make('content')
->markdown(),
]);
}

public function table(Table $table): Table
{
return $table
Expand All @@ -51,8 +70,9 @@ public function table(Table $table): Table
->searchable()
->sortable(),

Tables\Columns\BooleanColumn::make('is_visible')
Tables\Columns\IconColumn::make('is_visible')
->label('Visibility')
->boolean()
->sortable(),
])
->filters([
Expand All @@ -62,6 +82,7 @@ public function table(Table $table): Table
Tables\Actions\CreateAction::make(),
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
])
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Resources/Shop/BrandResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ public static function table(Table $table): Table
->label('Website')
->searchable()
->sortable(),
Tables\Columns\BooleanColumn::make('is_visible')
Tables\Columns\IconColumn::make('is_visible')
->label('Visibility')
->boolean()
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated Date')
Expand Down
3 changes: 2 additions & 1 deletion app/Filament/Resources/Shop/CategoryResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public static function table(Table $table): Table
->label('Parent')
->searchable()
->sortable(),
Tables\Columns\BooleanColumn::make('is_visible')
Tables\Columns\IconColumn::make('is_visible')
->label('Visibility')
->boolean()
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated Date')
Expand Down
2 changes: 2 additions & 0 deletions app/Filament/Resources/Shop/CustomerResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public static function form(Form $form): Form
->required(),

Forms\Components\TextInput::make('email')
->label('Email address')
->required()
->email()
->unique(ignoreRecord: true),
Expand Down Expand Up @@ -77,6 +78,7 @@ public static function table(Table $table): Table
->searchable(isIndividual: true)
->sortable(),
Tables\Columns\TextColumn::make('email')
->label('Email address')
->searchable(isIndividual: true, isGlobal: false)
->sortable(),
Tables\Columns\TextColumn::make('country')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ public function form(Form $form): Form
'stripe' => 'Stripe',
'paypal' => 'PayPal',
])
->required(),
->required()
->native(false),

Forms\Components\Select::make('method')
->options([
'credit_card' => 'Credit card',
'bank_transfer' => 'Bank transfer',
'paypal' => 'PayPal',
])
->required(),
->required()
->native(false),
]);
}

Expand Down
15 changes: 10 additions & 5 deletions app/Filament/Resources/Shop/OrderResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,11 @@ public static function table(Table $table): Table
->query(function (Builder $query, array $data): Builder {
return $query
->when(
$data['created_from'],
$data['created_from'] ?? null,
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '>=', $date),
)
->when(
$data['created_until'],
$data['created_until'] ?? null,
fn (Builder $query, $date): Builder => $query->whereDate('created_at', '<=', $date),
);
})
Expand Down Expand Up @@ -228,9 +228,11 @@ public static function getFormSchema(string $section = null): array
->afterStateUpdated(fn ($state, callable $set) => $set('unit_price', Product::find($state)?->price ?? 0))
->columnSpan([
'md' => 5,
]),
])
->searchable(),

Forms\Components\TextInput::make('qty')
->label('Quantity')
->numeric()
->default(1)
->columnSpan([
Expand Down Expand Up @@ -274,6 +276,7 @@ public static function getFormSchema(string $section = null): array
->required(),

Forms\Components\TextInput::make('email')
->label('Email address')
->required()
->email()
->unique(),
Expand All @@ -286,7 +289,8 @@ public static function getFormSchema(string $section = null): array
'male' => 'Male',
'female' => 'Female',
])
->required(),
->required()
->native(false),
])
->createOptionAction(function (Forms\Components\Actions\Action $action) {
return $action
Expand All @@ -303,7 +307,8 @@ public static function getFormSchema(string $section = null): array
'delivered' => 'Delivered',
'cancelled' => 'Cancelled',
])
->required(),
->required()
->native(false),

Forms\Components\Select::make('currency')
->searchable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@

use App\Filament\Resources\Shop\OrderResource;
use Filament\Pages\Actions;
use Filament\Pages\Concerns\ExposesTableToWidgets;
use Filament\Resources\Pages\ListRecords;

class ListOrders extends ListRecords
{
use ExposesTableToWidgets;

protected static string $resource = OrderResource::class;

protected function getActions(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ public function form(Form $form): Form
'stripe' => 'Stripe',
'paypal' => 'PayPal',
])
->required(),
->required()
->native(false),

Forms\Components\Select::make('method')
->options([
'credit_card' => 'Credit card',
'bank_transfer' => 'Bank transfer',
'paypal' => 'PayPal',
])
->required(),
->required()
->native(false),
]);
}

Expand Down
15 changes: 12 additions & 3 deletions app/Filament/Resources/Shop/OrderResource/Widgets/OrderStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,25 @@

namespace App\Filament\Resources\Shop\OrderResource\Widgets;

use App\Filament\Resources\Shop\OrderResource\Pages\ListOrders;
use App\Models\Shop\Order;
use Filament\Widgets\Concerns\InteractsWithPageTable;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Card;
use Flowframe\Trend\Trend;
use Flowframe\Trend\TrendValue;

class OrderStats extends BaseWidget
{
use InteractsWithPageTable;

protected static ?string $pollingInterval = null;

protected function getTablePage(): string
{
return ListOrders::class;
}

protected function getCards(): array
{
$orderData = Trend::model(Order::class)
Expand All @@ -23,14 +32,14 @@ protected function getCards(): array
->count();

return [
Card::make('Orders', Order::count())
Card::make('Orders', $this->getPageTableQuery()->count())
->chart(
$orderData
->map(fn (TrendValue $value) => $value->aggregate)
->toArray()
),
Card::make('Open orders', Order::whereIn('status', ['open', 'processing'])->count()),
Card::make('Average price', number_format(Order::avg('total_price'), 2)),
Card::make('Open orders', $this->getPageTableQuery()->whereIn('status', ['open', 'processing'])->count()),
Card::make('Average price', number_format($this->getPageTableQuery()->avg('total_price'), 2)),
];
}
}
23 changes: 17 additions & 6 deletions app/Filament/Resources/Shop/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ public static function form(Form $form): Form
->searchable()
->hiddenOn(ProductsRelationManager::class),

Forms\Components\MultiSelect::make('categories')
Forms\Components\Select::make('categories')
->relationship('categories', 'name')
->multiple()
->required(),
]),
])
Expand All @@ -177,17 +178,25 @@ public static function table(Table $table): Table
->sortable()
->toggleable(),

Tables\Columns\IconColumn::make('is_visible')
->label('Visibility')
->boolean()
->sortable()
->toggleable(),

Tables\Columns\TextColumn::make('price')
->label('Price')
->searchable()
->sortable(),

Tables\Columns\TextColumn::make('sku')
->label('SKU')
->searchable()
->sortable()
->toggleable(),

Tables\Columns\TextColumn::make('qty')
->label('Quantity')
->searchable()
->sortable()
->toggleable(),
Expand All @@ -198,11 +207,6 @@ public static function table(Table $table): Table
->toggleable()
->toggledHiddenByDefault(),

Tables\Columns\BooleanColumn::make('is_visible')
->label('Visibility')
->sortable()
->toggleable(),

Tables\Columns\TextColumn::make('published_at')
->label('Publish Date')
->date()
Expand All @@ -216,6 +220,13 @@ public static function table(Table $table): Table
->preload()
->multiple()
->searchable(),

Tables\Filters\TernaryFilter::make('is_visible')
->label('Visibility')
->boolean()
->trueLabel('Only visible')
->falseLabel('Only hidden')
->native(false),
])
->actions([
Tables\Actions\EditAction::make(),
Expand Down
Loading

0 comments on commit 2778012

Please sign in to comment.