Skip to content

Commit

Permalink
working on events looking good so far
Browse files Browse the repository at this point in the history
  • Loading branch information
alnutile committed Aug 18, 2024
1 parent 6d3a9a0 commit c3ff9b5
Show file tree
Hide file tree
Showing 19 changed files with 867 additions and 38 deletions.
27 changes: 16 additions & 11 deletions app/Filament/Resources/EventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,12 @@
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;
use Malzariey\FilamentDaterangepickerFilter\Filters\DateRangeFilter;

class EventResource extends Resource
{
Expand All @@ -29,15 +26,21 @@ public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('title'),
Tables\Columns\TextColumn::make('title')->searchable(),
Tables\Columns\TextColumn::make('start')
->dateTime("Y-m-d"),
Tables\Columns\TextColumn::make('end')
->dateTime("Y-m-d"),
Tables\Columns\TextColumn::make('location'),
->sortable()
->dateTime('Y-m-d'),
Tables\Columns\TextColumn::make('start_time')
->sortable()
->dateTime('h:i'),
Tables\Columns\TextColumn::make('location')->searchable(),
])
->filters([
//
Tables\Filters\SelectFilter::make('location')
->options(Event::distinct('location')->orderBy('location')->pluck('location', 'location')),
Tables\Filters\SelectFilter::make('title')
->options(Event::distinct('title')->orderBy('title')->pluck('title', 'title')),
DateRangeFilter::make('start_date'),
])
->actions([
Tables\Actions\EditAction::make(),
Expand All @@ -47,7 +50,7 @@ public static function table(Table $table): Table
Tables\Actions\DeleteBulkAction::make(),
]),
])
->defaultSort('start_date', "desc");
->defaultSort('start_date', 'desc');
}

public static function getRelations(): array
Expand All @@ -63,6 +66,8 @@ public static function getPages(): array
'index' => Pages\ListEvents::route('/'),
'create' => Pages\CreateEvent::route('/create'),
'edit' => Pages\EditEvent::route('/{record}/edit'),
'view' => Pages\ViewEvent::route('/{record}'),
'calendar' => Pages\CalendarPage::route('/calendar'),
];
}
}
21 changes: 21 additions & 0 deletions app/Filament/Resources/EventResource/Pages/CalendarPage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App\Filament\Resources\EventResource\Pages;

use App\Filament\Resources\EventResource;
use App\Filament\Widgets\CalendarWidget;
use Filament\Resources\Pages\Page;

class CalendarPage extends Page
{
protected static string $resource = EventResource::class;

protected static string $view = 'filament.resources.event-resource.pages.calendar-page';

protected function getHeaderWidgets(): array
{
return [
CalendarWidget::class,
];
}
}
1 change: 0 additions & 1 deletion app/Filament/Resources/EventResource/Pages/CreateEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace App\Filament\Resources\EventResource\Pages;

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

class CreateEvent extends CreateRecord
Expand Down
19 changes: 19 additions & 0 deletions app/Filament/Resources/EventResource/Pages/ViewEvent.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\ViewRecord;

class ViewEvent extends ViewRecord
{
protected static string $resource = EventResource::class;

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

namespace App\Filament\Widgets;

use App\Filament\Resources\EventResource;
use App\Models\Event;
use Saade\FilamentFullCalendar\Widgets\FullCalendarWidget;

class CalendarWidget extends FullCalendarWidget
{
protected static ?int $sort = 2;

public function fetchEvents(array $info): array
{

return Event::query()
->where('start_date', '>=', $info['start'])
->where('end_date', '<=', $info['end'])
->get()
->map(
fn (Event $event) => [
'title' => $event->title,
'start' => $event->start,
'end' => $event->end,
'url' => EventResource::getUrl(name: 'view', parameters: ['record' => $event]),
'shouldOpenUrlInNewTab' => true,
]
)
->all();

}
}
18 changes: 10 additions & 8 deletions app/Filament/Widgets/StatsOverview.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

class StatsOverview extends BaseWidget
{
protected static ?int $sort = 1;

protected function getStats(): array
{

Expand All @@ -23,32 +25,32 @@ protected function getStats(): array

protected function getChatMessages()
{
$title = "Chats";
$description = "Chats in the past 7 days";
$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";
$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";
$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";
$title = 'Messages';
$description = 'Messages in the past 7 days';

return $this->getTrend($title, $description, Message::class);
}
Expand Down
29 changes: 21 additions & 8 deletions app/Models/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Domains\Events\EventTypes;
use Carbon\Carbon;
use Filament\Forms\Components\DatePicker;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Components\TimePicker;
use Illuminate\Database\Eloquent\Factories\HasFactory;
Expand All @@ -30,16 +31,28 @@ class Event extends Model
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'),
Section::make('Event')
->description('Manage an Event')

->columns(1)
->schema([
TextInput::make('title')->required(),
TextInput::make('description')->required(),
TextInput::make('location'),
]),
Section::make('Dates')
->description('Manage an Event')

->columns(2)
->schema([
DatePicker::make('start_date')->required(),
TimePicker::make('start_time')->required(),
DatePicker::make('end_date')->required(),
TimePicker::make('end_time')->required(),
]),
];
}

public function collection(): BelongsTo
{
return $this->belongsTo(Collection::class);
Expand Down
2 changes: 1 addition & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
/**
* @property bool $is_admin
*/
class User extends Authenticatable implements FilamentUser
class User extends Authenticatable implements FilamentUser
{
use HasApiTokens;
use HasFactory;
Expand Down
12 changes: 10 additions & 2 deletions app/Providers/Filament/AdminPanelProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
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;
use Saade\FilamentFullCalendar\FilamentFullCalendarPlugin;

class AdminPanelProvider extends PanelProvider
{
Expand All @@ -39,10 +39,18 @@ public function panel(Panel $panel): Panel
->navigationItems([
NavigationItem::make('Collections')
->icon('heroicon-o-code-bracket')
->url("/collections"),
->url('/collections'),
])
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\\Filament\\Widgets')
->widgets([])
->plugin(
FilamentFullCalendarPlugin::make()
->selectable()
->plugins([
'dayGrid', 'timeGrid',
])
->editable()
)
->middleware([
EncryptCookies::class,
AddQueuedCookiesToResponse::class,
Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"laravel/tinker": "^2.9",
"league/html-to-markdown": "^5.1",
"maatwebsite/excel": "^3.1",
"malzariey/filament-daterangepicker-filter": "^3.0",
"nwidart/laravel-modules": "^11.0",
"opcodesio/log-viewer": "^3.10",
"openai-php/laravel": "^0.8.1",
Expand All @@ -32,6 +33,7 @@
"pusher/pusher-php-server": "^7.2",
"roach-php/core": "^3.2",
"roach-php/laravel": "^3.1",
"saade/filament-fullcalendar": "^3.0",
"smalot/pdfparser": "^2.9",
"soundasleep/html2text": "^2.1",
"spatie/browsershot": "^4.0",
Expand Down
Loading

0 comments on commit c3ff9b5

Please sign in to comment.