Skip to content

Commit

Permalink
Basic events in place in filament
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Aug 18, 2024
1 parent 5541eda commit 6d3a9a0
Show file tree
Hide file tree
Showing 32 changed files with 2,594 additions and 405 deletions.
68 changes: 68 additions & 0 deletions app/Filament/Resources/EventResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\EventResource\Pages;
use App\Filament\Resources\EventResource\RelationManagers;
use App\Models\Event;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Resources\Resource;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;

class EventResource extends Resource
{
protected static ?string $model = Event::class;

protected static ?string $navigationIcon = 'heroicon-o-calendar-date-range';

public static function form(Form $form): Form
{
return $form
->schema(Event::getForm());
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('title'),
Tables\Columns\TextColumn::make('start')
->dateTime("Y-m-d"),
Tables\Columns\TextColumn::make('end')
->dateTime("Y-m-d"),
Tables\Columns\TextColumn::make('location'),
])
->filters([
//
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->defaultSort('start_date', "desc");
}

public static function getRelations(): array
{
return [
//
];
}

public static function getPages(): array
{
return [
'index' => Pages\ListEvents::route('/'),
'create' => Pages\CreateEvent::route('/create'),
'edit' => Pages\EditEvent::route('/{record}/edit'),
];
}
}
12 changes: 12 additions & 0 deletions app/Filament/Resources/EventResource/Pages/CreateEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Filament\Resources\EventResource\Pages;

use App\Filament\Resources\EventResource;
use Filament\Actions;
use Filament\Resources\Pages\CreateRecord;

class CreateEvent extends CreateRecord
{
protected static string $resource = EventResource::class;
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/EventResource/Pages/EditEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\EventResource\Pages;

use App\Filament\Resources\EventResource;
use Filament\Actions;
use Filament\Resources\Pages\EditRecord;

class EditEvent extends EditRecord
{
protected static string $resource = EventResource::class;

protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
];
}
}
19 changes: 19 additions & 0 deletions app/Filament/Resources/EventResource/Pages/ListEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Filament\Resources\EventResource\Pages;

use App\Filament\Resources\EventResource;
use Filament\Actions;
use Filament\Resources\Pages\ListRecords;

class ListEvents extends ListRecords
{
protected static string $resource = EventResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
76 changes: 76 additions & 0 deletions app/Filament/Widgets/StatsOverview.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace App\Filament\Widgets;

use App\Models\Chat;
use App\Models\Document;
use App\Models\Event;
use App\Models\Message;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
use Flowframe\Trend\Trend;
use Flowframe\Trend\TrendValue;

class StatsOverview extends BaseWidget
{
protected function getStats(): array
{

return [
$this->getDocuments(),
$this->getChatMessages(), $this->getDocuments(), $this->getEvents(), $this->getMessages()];
}

protected function getChatMessages()
{
$title = "Chats";
$description = "Chats in the past 7 days";

return $this->getTrend($title, $description, Chat::class);
}

protected function getDocuments()
{
$title = "Documents";
$description = "Documents in the past 7 days";

return $this->getTrend($title, $description, Document::class);
}

protected function getEvents()
{
$title = "Events";
$description = "Events in the past 7 days";

return $this->getTrend($title, $description, Event::class);
}

protected function getMessages()
{
$title = "Messages";
$description = "Messages in the past 7 days";

return $this->getTrend($title, $description, Message::class);
}

protected function getTrend(
string $title,
string $description,
string $model,
) {

$data = Trend::model($model)
->between(
start: now()->subDays(7),
end: now()->endOfDay(),
)
->perDay()
->count();

return Stat::make($title, $data->map(fn (TrendValue $value) => $value->aggregate)->sum())
->description($description)
->descriptionIcon('heroicon-m-arrow-trending-up')
->chart($data->map(fn (TrendValue $value) => $value->aggregate)->toArray())
->color('success');
}
}
16 changes: 16 additions & 0 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use App\Domains\Events\EventTypes;
use Carbon\Carbon;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\TimePicker;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
Expand All @@ -24,6 +27,19 @@ class Event extends Model
'end_time' => 'timestamp',
];

public static function getForm(): array
{
return [
TextInput::make('title')->required(),
TextInput::make('description')->required(),
DatePicker::make('start_date')->required(),
TimePicker::make('start_time')->required(),
DatePicker::make('end_date')->required(),
TimePicker::make('end_time')->required(),
TextInput::make('location')->required(),
TextInput::make('summary'),
];
}
public function collection(): BelongsTo
{
return $this->belongsTo(Collection::class);
Expand Down
9 changes: 8 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Filament\Models\Contracts\FilamentUser;
use Filament\Panel;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
Expand All @@ -14,7 +16,7 @@
/**
* @property bool $is_admin
*/
class User extends Authenticatable
class User extends Authenticatable implements FilamentUser
{
use HasApiTokens;
use HasFactory;
Expand Down Expand Up @@ -77,4 +79,9 @@ public function isAdmin(): bool
{
return $this->is_admin;
}

public function canAccessPanel(Panel $panel): bool
{
return true;
}
}
61 changes: 61 additions & 0 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace App\Providers\Filament;

use Filament\Http\Middleware\Authenticate;
use Filament\Http\Middleware\DisableBladeIconComponents;
use Filament\Http\Middleware\DispatchServingFilamentEvent;
use Filament\Navigation\NavigationItem;
use Filament\Pages;
use Filament\Panel;
use Filament\PanelProvider;
use Filament\Support\Colors\Color;
use Filament\Widgets;
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
use Illuminate\Routing\Middleware\SubstituteBindings;
use Illuminate\Session\Middleware\AuthenticateSession;
use Illuminate\Session\Middleware\StartSession;
use Illuminate\View\Middleware\ShareErrorsFromSession;

class AdminPanelProvider extends PanelProvider
{
public function panel(Panel $panel): Panel
{
return $panel
->default()
->id('admin')
->path('admin')
->login()
->colors([
'primary' => Color::Amber,
])
->discoverResources(in: app_path('Filament/Resources'), for: 'App\\Filament\\Resources')
->discoverPages(in: app_path('Filament/Pages'), for: 'App\\Filament\\Pages')
->pages([
Pages\Dashboard::class,
])
->navigationItems([
NavigationItem::make('Collections')
->icon('heroicon-o-code-bracket')
->url("/collections"),
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([])
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
StartSession::class,
AuthenticateSession::class,
ShareErrorsFromSession::class,
VerifyCsrfToken::class,
SubstituteBindings::class,
DisableBladeIconComponents::class,
DispatchServingFilamentEvent::class,
])
->authMiddleware([
Authenticate::class,
]);
}
}
5 changes: 3 additions & 2 deletions bootstrap/providers.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

return [
App\Domains\Sources\WebSearch\WebSearchProvider::class,
App\Providers\AppServiceProvider::class,
App\Providers\Filament\AdminPanelProvider::class,
App\Providers\FortifyServiceProvider::class,
App\Providers\HorizonServiceProvider::class,
App\Providers\JetstreamServiceProvider::class,
\LlmLaraHub\LlmDriver\LlmServiceProvider::class,
App\Domains\Sources\WebSearch\WebSearchProvider::class,
LlmLaraHub\LlmDriver\LlmServiceProvider::class,
];
9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"php": "^8.2",
"archtechx/enums": "^0.3.2",
"fakerphp/faker": "^1.23",
"filament/filament": "^3.2",
"flowframe/laravel-trend": "^0.2.0",
"inertiajs/inertia-laravel": "^1.0",
"laravel/framework": "^11.0",
"laravel/horizon": "^5.23",
Expand Down Expand Up @@ -79,7 +81,8 @@
"scripts": {
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump",
"@php artisan package:discover --ansi"
"@php artisan package:discover --ansi",
"@php artisan filament:upgrade"
],
"post-update-cmd": [
"@php artisan vendor:publish --tag=laravel-assets --ansi --force"
Expand All @@ -99,8 +102,8 @@
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/alnutile/php-presentation-fix"
"type": "vcs",
"url": "https://github.com/alnutile/php-presentation-fix"
}
],
"extra": {
Expand Down
Loading

0 comments on commit 6d3a9a0

Please sign in to comment.