Skip to content

Commit

Permalink
Merge pull request #33 from eurofurence/feature/frontdesk
Browse files Browse the repository at this point in the history
Front desk UI for on-site staff
  • Loading branch information
Fenrikur authored Sep 1, 2023
2 parents 8d79004 + 626fc8c commit c1295f2
Show file tree
Hide file tree
Showing 23 changed files with 1,411 additions and 5 deletions.
14 changes: 14 additions & 0 deletions app/Enums/ApplicationStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@ enum ApplicationStatus: string
case TableOffered = 'table_offered';
case TableAccepted = 'table_accepted';
case CheckedIn = 'checked_in';
case CheckedOut = 'checked_out';

static function for(\App\Models\Application $application): ApplicationStatus
{
if (!is_null($application->canceled_at)) {
return ApplicationStatus::Canceled;
} elseif (!is_null($application->checked_out_at)) {
return ApplicationStatus::CheckedOut;
} elseif (!is_null($application->checked_in_at)) {
return ApplicationStatus::CheckedIn;
} elseif (!is_null($application->waiting_at)) {
Expand All @@ -38,27 +41,36 @@ function orWhere(\Illuminate\Database\Eloquent\Builder $query)
fn (\Illuminate\Database\Eloquent\Builder $query) =>
$query->where('canceled_at', '!=', null)
),
ApplicationStatus::CheckedOut => $query->orWhere(
fn (\Illuminate\Database\Eloquent\Builder $query) =>
$query->where('canceled_at', '=', null)
->where('checked_out_at', '!=', null)
),
ApplicationStatus::CheckedIn => $query->orWhere(
fn (\Illuminate\Database\Eloquent\Builder $query) =>
$query->where('canceled_at', '=', null)
->where('checked_out_at', '=', null)
->where('checked_in_at', '!=', null)
),
ApplicationStatus::Waiting => $query->orWhere(
fn (\Illuminate\Database\Eloquent\Builder $query) =>
$query->where('canceled_at', '=', null)
->where('checked_out_at', '=', null)
->where('checked_in_at', '=', null)
->where('waiting_at', '!=', null)
),
ApplicationStatus::TableAccepted => $query->orWhere(
fn (\Illuminate\Database\Eloquent\Builder $query) =>
$query->where('canceled_at', '=', null)
->where('checked_out_at', '=', null)
->where('checked_in_at', '=', null)
->where('waiting_at', '=', null)
->where('offer_accepted_at', '!=', null)
),
ApplicationStatus::TableOffered => $query->orWhere(
fn (\Illuminate\Database\Eloquent\Builder $query) =>
$query->where('canceled_at', '=', null)
->where('checked_out_at', '=', null)
->where('checked_in_at', '=', null)
->where('waiting_at', '=', null)
->where('offer_accepted_at', '=', null)
Expand All @@ -67,6 +79,7 @@ function orWhere(\Illuminate\Database\Eloquent\Builder $query)
ApplicationStatus::TableAssigned => $query->orWhere(
fn (\Illuminate\Database\Eloquent\Builder $query) =>
$query->where('canceled_at', '=', null)
->where('checked_out_at', '=', null)
->where('checked_in_at', '=', null)
->where('waiting_at', '=', null)
->where('offer_accepted_at', '=', null)
Expand All @@ -81,6 +94,7 @@ function orWhere(\Illuminate\Database\Eloquent\Builder $query)
ApplicationStatus::Open => $query->orWhere(
fn (\Illuminate\Database\Eloquent\Builder $query) =>
$query->where('canceled_at', '=', null)
->where('checked_out_at', '=', null)
->where('checked_in_at', '=', null)
->where('waiting_at', '=', null)
->where('offer_accepted_at', '=', null)
Expand Down
7 changes: 4 additions & 3 deletions app/Filament/Resources/ApplicationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public static function form(Form $form): Form
"table_assigned" => "Table assigned (Open)",
"table_offered" => "Table offered",
"table_accepted" => "Table accepted",
"checked_in" => "Checked in (on-site)"
"checked_in" => "Checked in (on-site)",
"checked_out" => "Checked out (on-site)",
])->disablePlaceholderSelection()->required()->reactive(),
Forms\Components\TextInput::make('table_number')
->maxLength(255),
Expand Down Expand Up @@ -96,6 +97,7 @@ public static function form(Form $form): Form
Forms\Components\Placeholder::make('offer_accepted_at')->content(fn (?Application $record): string => $record?->offer_accepted_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('waiting_at')->content(fn (?Application $record): string => $record?->waiting_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('checked_in_at')->content(fn (?Application $record): string => $record?->checked_in_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('checked_out_at')->content(fn (?Application $record): string => $record?->checked_out_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('canceled_at')->content(fn (?Application $record): string => $record?->canceled_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('updated_at')->content(fn (?Application $record): string => $record?->updated_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('created_at')->content(fn (?Application $record): string => $record?->created_at?->diffForHumans() ?? '-'),
Expand Down Expand Up @@ -348,15 +350,14 @@ public static function table(Table $table): Table
]);
}



public static function getRelations(): array
{
return [
RelationManagers\ChildrenRelationManager::class,
RelationManagers\ParentRelationManager::class,
RelationManagers\UserRelationManager::class,
RelationManagers\ProfileRelationManager::class,
RelationManagers\CommentRelationManager::class,
];
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace App\Filament\Resources\ApplicationResource\RelationManagers;

use App\Filament\Resources\CommentResource;
use App\Filament\Resources\CommentResource\Pages\CreateComment;
use App\Models\Comment;
use Filament\Forms;
use Filament\Forms\Components\Select;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;

class CommentRelationManager extends RelationManager
{
protected static string $relationship = 'comments';
protected static ?string $title = "Comments";
protected static ?string $label = "Comment";
protected static ?string $recordTitleAttribute = 'text';

public static function form(Form $form): Form
{
return $form
->schema([
//
]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('author.name'),
Tables\Columns\IconColumn::make('admin_only')
->boolean(),
Tables\Columns\TextColumn::make('text'),
Tables\Columns\TextColumn::make('created_at')
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->sortable(),
])
->filters([
//
])
->headerActions([
Tables\Actions\Action::make('New comment')
->form([
Forms\Components\TextInput::make('application_id')
->default(function (RelationManager $livewire) {
return $livewire->ownerRecord->id;
})
->required(),
Forms\Components\TextInput::make('user_id')
->label("User ID (Author)")
->default(\Auth::user()->id)
->required(),
Forms\Components\Toggle::make('admin_only'),
Forms\Components\Textarea::make('text')
->required()
->maxLength(4096),

])
->action(function (array $data): void {
Comment::create([
'text' => $data['text'],
'admin_only' => $data['admin_only'],
'application_id' => $data['application_id'],
'user_id' => $data['user_id'],
]);
})
->icon('heroicon-o-pencil'),

])
->actions([
Tables\Actions\Action::make('Show')
->url(fn(Comment $record): string => CommentResource::getUrl('edit', ['record' => $record])),

])
->bulkActions([
]);
}
}
92 changes: 92 additions & 0 deletions app/Filament/Resources/CommentResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace App\Filament\Resources;

use App\Filament\Resources\CommentResource\Pages;
use App\Filament\Resources\CommentResource\RelationManagers;
use App\Models\Comment;
use Filament\Forms;
use Filament\Resources\Form;
use Filament\Resources\Resource;
use Filament\Resources\Table;
use Filament\Tables;
use Illuminate\Database\Eloquent\Builder;

class CommentResource extends Resource
{
protected static ?string $model = Comment::class;

protected static ?string $navigationIcon = 'heroicon-o-pencil';

public static function form(Form $form): Form
{
return $form
->columns(3)
->schema([
Forms\Components\Group::make()->columnSpan(2)->columns()->schema([
Forms\Components\Group::make()->columns(1)->schema([
Forms\Components\Select::make('user_id')->searchable()->relationship('author', 'name')
->required(),
Forms\Components\Select::make('application_id')->searchable()->relationship('application', 'id')
->required(),
Forms\Components\Toggle::make('admin_only'),
]),
Forms\Components\Textarea::make('text')
->required()
->maxLength(4096),
]),
Forms\Components\Fieldset::make('Dates')->columnSpan(1)->columns()->schema([
Forms\Components\Placeholder::make('created_at')->content(fn (?Comment $record): string => $record?->created_at?->diffForHumans() ?? '-'),
Forms\Components\Placeholder::make('updated_at')->content(fn (?Comment $record): string => $record?->updated_at?->diffForHumans() ?? '-'),
]),

]);
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('uuid')->hidden()->url(fn($record) => CommentResource::getUrl('edit', ['record' => $record->uuid])),
Tables\Columns\TextColumn::make('application_id')
->searchable()
->sortable(),
Tables\Columns\TextColumn::make('author.name')
->searchable(),
Tables\Columns\IconColumn::make('admin_only')
->boolean(),
Tables\Columns\TextColumn::make('text'),
Tables\Columns\TextColumn::make('created_at')
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->sortable(),
])
->filters([
Tables\Filters\Filter::make('admin_only')
->query(fn(Builder $query): Builder => $query->where('admin_only', '=', '1'))
->label('Is Admin only'),
])
->actions([
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make(),
]);
}

public static function getRelations(): array
{
return [
RelationManagers\ApplicationRelationManager::class,
];
}

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

namespace App\Filament\Resources\CommentResource\Pages;

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

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

namespace App\Filament\Resources\CommentResource\Pages;

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

class EditComment extends EditRecord
{
protected static string $resource = CommentResource::class;

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

namespace App\Filament\Resources\CommentResource\Pages;

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

class ListComments extends ListRecords
{
protected static string $resource = CommentResource::class;

protected function getActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace App\Filament\Resources\CommentResource\RelationManagers;

use App\Enums\ApplicationStatus;
use App\Filament\Resources\ApplicationResource;
use App\Models\Application;
use Filament\Resources\Form;
use Filament\Resources\RelationManagers\RelationManager;
use Filament\Resources\Table;
use Filament\Tables;


class ApplicationRelationManager extends RelationManager
{
protected static string $relationship = 'application';

protected static ?string $title = "Application";
protected static ?string $label = "application";

public static function form(Form $form): Form
{
return $form;
}

public static function table(Table $table): Table
{
return $table
->columns([
Tables\Columns\TextColumn::make('user.name'),
Tables\Columns\TextColumn::make('type'),
Tables\Columns\BadgeColumn::make('status')->enum(ApplicationStatus::cases())->formatStateUsing(function (Application $record) {
return $record->status->name;
})->colors([
'secondary',
'success' => ApplicationStatus::TableAccepted->value,
'danger' => ApplicationStatus::Canceled->value
]),
Tables\Columns\TextColumn::make('assignedTable.name'),
Tables\Columns\TextColumn::make('table_number'),

])
->filters([
//
])
->headerActions([
])
->actions([
Tables\Actions\Action::make('Show')
->url(fn(Application $record): string => ApplicationResource::getUrl('edit', ['record' => $record])),

])
->bulkActions([
]);
}
}
Loading

0 comments on commit c1295f2

Please sign in to comment.