From fb1333a4dfdc195d9c26de4b7df5767a5c6c5f1b Mon Sep 17 00:00:00 2001 From: Fenrikur <3359222+Fenrikur@users.noreply.github.com> Date: Thu, 10 Aug 2023 01:30:34 +0200 Subject: [PATCH 01/28] initial draft for front desk system --- app/Enums/ApplicationStatus.php | 14 ++ app/Http/Controllers/FrontdeskController.php | 36 ++++ app/Models/Application.php | 32 ++- app/Models/Comment.php | 30 +++ app/Policies/ApplicationPolicy.php | 24 +++ app/Policies/CommentPolicy.php | 69 +++++++ database/factories/UserFactory.php | 2 +- ...023_08_08_215547_create_comments_table.php | 31 +++ ...23_08_09_222220_add_checked_out_status.php | 28 +++ resources/views/frontdesk.blade.php | 191 ++++++++++++++++++ routes/web.php | 8 + 11 files changed, 463 insertions(+), 2 deletions(-) create mode 100644 app/Http/Controllers/FrontdeskController.php create mode 100644 app/Models/Comment.php create mode 100644 app/Policies/ApplicationPolicy.php create mode 100644 app/Policies/CommentPolicy.php create mode 100644 database/migrations/2023_08_08_215547_create_comments_table.php create mode 100644 database/migrations/2023_08_09_222220_add_checked_out_status.php create mode 100644 resources/views/frontdesk.blade.php diff --git a/app/Enums/ApplicationStatus.php b/app/Enums/ApplicationStatus.php index 2a3fc7f..f528016 100644 --- a/app/Enums/ApplicationStatus.php +++ b/app/Enums/ApplicationStatus.php @@ -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)) { @@ -41,17 +44,25 @@ function orWhere(\Illuminate\Database\Eloquent\Builder $query) ApplicationStatus::CheckedIn => $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) @@ -59,6 +70,7 @@ function orWhere(\Illuminate\Database\Eloquent\Builder $query) 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) @@ -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) @@ -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) diff --git a/app/Http/Controllers/FrontdeskController.php b/app/Http/Controllers/FrontdeskController.php new file mode 100644 index 0000000..4dea1ad --- /dev/null +++ b/app/Http/Controllers/FrontdeskController.php @@ -0,0 +1,36 @@ + \Auth::user() ]); + } + + public function search(Request $request) + { + $reg_id = $request->get('reg_id'); + $user = $reg_id ? User::where('reg_id', $reg_id)->first() : false; + if ($user === false) { + Log::info("No reg ID provided."); + } elseif ($user === null) { + Log::info("User not found."); + } + $application = $user ? Application::where('user_id', $user->id)->first() : false; + if ($application === null) { + Log::info("No application found for user."); + } + + return view('frontdesk', [ 'user' => \Auth::user(), 'application' => $application ]); + } +} diff --git a/app/Models/Application.php b/app/Models/Application.php index 65a851b..e8736bc 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -32,6 +32,7 @@ class Application extends Model "canceled_at" => "datetime", "waiting_at" => "datetime", "checked_in_at" => "datetime", + "checked_out_at" => "datetime", "offer_sent_at" => "datetime", "offer_accepted_at" => "datetime", ]; @@ -120,10 +121,16 @@ public function children() return $this->hasMany(__CLASS__, 'parent'); } - public function profile() { + public function profile() + { return $this->belongsTo(Profile::class, 'id', 'application_id', 'profiles'); } + public function comments() + { + return $this->hasMany(Comment::class, 'application_id'); + } + public function getStatus() { return ApplicationStatus::for($this); @@ -134,6 +141,20 @@ public function isActive() return $this->getStatus() !== ApplicationStatus::Canceled; } + public function checkIn() { + if ($this->status === ApplicationStatus::TableAccepted) { + $this->status = ApplicationStatus::CheckedIn; + $this->save(); + } + } + + public function checkOut() { + if ($this->status === ApplicationStatus::CheckedIn) { + $this->status = ApplicationStatus::CheckedOut; + $this->save(); + } + } + public function cancel() { $this->canceled_at = now(); @@ -272,6 +293,14 @@ public function setStatusAttribute(ApplicationStatus|string $status) if ($status === ApplicationStatus::CheckedIn) { $this->update([ 'checked_in_at' => now(), + 'checked_out_at' => null, + 'canceled_at' => null, + ]); + } + + if ($status === ApplicationStatus::CheckedOut) { + $this->update([ + 'checked_out_at' => now(), 'canceled_at' => null, ]); } @@ -333,6 +362,7 @@ public static function getAllApplicationsForExport() 'offer_sent_at', 'offer_accepted_at', 'checked_in_at', + 'checked_out_at', 'canceled_at', 'profiles.*', ) diff --git a/app/Models/Comment.php b/app/Models/Comment.php new file mode 100644 index 0000000..9d26901 --- /dev/null +++ b/app/Models/Comment.php @@ -0,0 +1,30 @@ + 'boolean', + 'text' => 'string', + ]; + protected $attributes = [ + 'adminOnly' => false, + ]; + + public function application() + { + return $this->belongsTo(Application::class); + } + + public function author() + { + return $this->belongsTo(User::class, 'user_id'); + } +} diff --git a/app/Policies/ApplicationPolicy.php b/app/Policies/ApplicationPolicy.php new file mode 100644 index 0000000..6d904cf --- /dev/null +++ b/app/Policies/ApplicationPolicy.php @@ -0,0 +1,24 @@ +isFrontdesk(); + } + + public function checkIn(User $user, Application $application): bool + { + return $user->isFrontdesk(); + } + + public function checkOut(User $user, Application $application): bool + { + return $user->isFrontdesk(); + } +} diff --git a/app/Policies/CommentPolicy.php b/app/Policies/CommentPolicy.php new file mode 100644 index 0000000..166a54c --- /dev/null +++ b/app/Policies/CommentPolicy.php @@ -0,0 +1,69 @@ +isAdmin(); + } + + /** + * Determine whether the user can view the model. + */ + public function view(User $user, Comment $comment): bool + { + if ($comment->admin_only) { + return $user->isAdmin(); + } else { + return $user->isFrontdesk(); + } + } + + /** + * Determine whether the user can create models. + */ + public function create(User $user): bool + { + return $user->isFrontdesk(); + } + + /** + * Determine whether the user can update the model. + */ + public function update(User $user, Comment $comment): bool + { + return false; + } + + /** + * Determine whether the user can delete the model. + */ + public function delete(User $user, Comment $comment): bool + { + return $user->isAdmin(); + } + + /** + * Determine whether the user can restore the model. + */ + public function restore(User $user, Comment $comment): bool + { + return $user->isAdmin(); + } + + /** + * Determine whether the user can permanently delete the model. + */ + public function forceDelete(User $user, Comment $comment): bool + { + return false; + } +} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index 882dac8..125f14d 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -21,7 +21,7 @@ public function definition(): array 'name' => fake()->name(), 'email' => fake()->unique()->safeEmail(), 'identity_id' => fake()->uuid(), - 'groups' => [], + 'groups' => '[]', ]; } diff --git a/database/migrations/2023_08_08_215547_create_comments_table.php b/database/migrations/2023_08_08_215547_create_comments_table.php new file mode 100644 index 0000000..cb2bdb9 --- /dev/null +++ b/database/migrations/2023_08_08_215547_create_comments_table.php @@ -0,0 +1,31 @@ +uuid(); + $table->foreignIdFor(\App\Models\User::class)->constrained()->cascadeOnUpdate(); + $table->foreignIdFor(\App\Models\Application::class)->constrained()->cascadeOnUpdate()->cascadeOnDelete(); + $table->string('text'); + $table->boolean('admin_only'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('comments'); + } +}; diff --git a/database/migrations/2023_08_09_222220_add_checked_out_status.php b/database/migrations/2023_08_09_222220_add_checked_out_status.php new file mode 100644 index 0000000..4dd651a --- /dev/null +++ b/database/migrations/2023_08_09_222220_add_checked_out_status.php @@ -0,0 +1,28 @@ +timestamp('checked_out_at')->nullable()->default(null); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::table('applications', function (Blueprint $table) { + $table->dropColumn('checked_out_at'); + }); + } +}; diff --git a/resources/views/frontdesk.blade.php b/resources/views/frontdesk.blade.php new file mode 100644 index 0000000..de9dede --- /dev/null +++ b/resources/views/frontdesk.blade.php @@ -0,0 +1,191 @@ + + + + + + + + + Frontdesk - Dealer's Registration - Eurofurence + + + @vite(['resources/css/app.scss', 'resources/js/app.js']) + + + +
+ + + + + +
+
+
+
+ + @csrf +
+
+
+ + + +
+
+ + + +
+
+ + + +
+
+ + + +
+
+
+
+ @if ($application === false) +
+
+ User not found +
+
+ @elseif ($application === null) +
+
+ No application attached to user +
+
+ @else + @if ($application->status === \App\Enums\ApplicationStatus::TableAccepted) +
+
+ {{ $application->status->name }} – Ready for Check-In +
+
+ @elseif ($application->status === \App\Enums\ApplicationStatus::CheckedIn) +
+
+ {{ $application->status->name }} – + Ready for Check-Out +
+
+ @else +
+
+ {{ $application->status->name }} +
+
+ @endif +
+
+ {{ $application->type->name }} + {{ $application->user()->first()->name }} + {{ $application->is_afterdark }} + {{ $application->table_number }} + {{ $application->assignedTable->first()->name }} +
+
+ @endif +
+
+ @if ($application) +
+
+
+ +
+ +
+ @csrf +
+ @foreach ($application->comments()->get() as $comment) + @can('view', $comment) +
+
+ {{ $comment->text }} +
+ +
+ @endcan + @endforeach + @endif +
+
+
+
+ + + diff --git a/routes/web.php b/routes/web.php index 2bb98ed..b0b590e 100755 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,8 @@ use App\Http\Controllers\ProfileController; use App\Http\Controllers\Applications\ApplicationController; +use App\Models\Application; +use App\Models\Comment; use Illuminate\Support\Facades\Route; /* @@ -60,8 +62,14 @@ Route::get('admin/export/appdata', [ApplicationController::class, 'exportAppDataAdmin']); Route::get('admin/export/csv', [ApplicationController::class, 'exportCsvAdmin']); + Route::get('frontdesk',\App\Http\Controllers\FrontdeskController::class)->name('frontdesk')->can('viewAny', Application::class); + Route::post('frontdesk',[\App\Http\Controllers\FrontdeskController::class, 'search'])->name('frontdesk.search')->can('viewAny', Application::class); + Route::put('frontdesk/check-in',[\App\Http\Controllers\FrontdeskController::class,'checkIn'])->name('frontdesk.check-in')->can('checkIn', Application::class); + Route::put('frontdesk/check-out',[\App\Http\Controllers\FrontdeskController::class,'checkOut'])->name('frontdesk.check-out')->can('checkOut', Application::class); + Route::post('frontdesk/comment',[\App\Http\Controllers\FrontdeskController::class,'comment'])->name('frontdesk.comment')->can('create', Comment::class); }); + // Basic auth using credentials from env Route::middleware('auth.api.basic')->group(function () { Route::get('export/appdata', [ApplicationController::class, 'exportAppData']); From 1bd72b914d9fdc49686937f7b71a923ed36dd33d Mon Sep 17 00:00:00 2001 From: JulSteele <20680187+julsteele@users.noreply.github.com> Date: Thu, 10 Aug 2023 23:05:35 +0200 Subject: [PATCH 02/28] Added comment resource for admin area --- .../Resources/ApplicationResource.php | 1 + .../CommentRelationManager.php | 56 +++++++++++++ app/Filament/Resources/CommentResource.php | 79 +++++++++++++++++++ .../CommentResource/Pages/CreateComment.php | 12 +++ .../CommentResource/Pages/EditComment.php | 19 +++++ .../CommentResource/Pages/ListComments.php | 19 +++++ .../ApplicationRelationManager.php | 56 +++++++++++++ app/Models/Comment.php | 9 ++- app/Policies/CommentPolicy.php | 2 +- 9 files changed, 250 insertions(+), 3 deletions(-) create mode 100644 app/Filament/Resources/ApplicationResource/RelationManagers/CommentRelationManager.php create mode 100644 app/Filament/Resources/CommentResource.php create mode 100644 app/Filament/Resources/CommentResource/Pages/CreateComment.php create mode 100644 app/Filament/Resources/CommentResource/Pages/EditComment.php create mode 100644 app/Filament/Resources/CommentResource/Pages/ListComments.php create mode 100644 app/Filament/Resources/CommentResource/Pages/RelationManagers/ApplicationRelationManager.php diff --git a/app/Filament/Resources/ApplicationResource.php b/app/Filament/Resources/ApplicationResource.php index 23e6c51..f2963be 100755 --- a/app/Filament/Resources/ApplicationResource.php +++ b/app/Filament/Resources/ApplicationResource.php @@ -357,6 +357,7 @@ public static function getRelations(): array RelationManagers\ParentRelationManager::class, RelationManagers\UserRelationManager::class, RelationManagers\ProfileRelationManager::class, + RelationManagers\CommentRelationManager::class, ]; } diff --git a/app/Filament/Resources/ApplicationResource/RelationManagers/CommentRelationManager.php b/app/Filament/Resources/ApplicationResource/RelationManagers/CommentRelationManager.php new file mode 100644 index 0000000..4b00816 --- /dev/null +++ b/app/Filament/Resources/ApplicationResource/RelationManagers/CommentRelationManager.php @@ -0,0 +1,56 @@ +schema([ + Forms\Components\TextInput::make('text') + ->required() + ->maxLength(255), + ]); + } + + 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'), + ]) + ->filters([ + // + ]) + ->headerActions([ + ]) + ->actions([ + Tables\Actions\Action::make('Show') + ->url(fn(Comment $record): string => CommentResource::getUrl('edit', ['record' => $record])), + + ]) + ->bulkActions([ + ]); + } +} diff --git a/app/Filament/Resources/CommentResource.php b/app/Filament/Resources/CommentResource.php new file mode 100644 index 0000000..1379000 --- /dev/null +++ b/app/Filament/Resources/CommentResource.php @@ -0,0 +1,79 @@ +schema([ + Forms\Components\Textarea::make('text') + ->required() + ->maxLength(2048), + Forms\Components\Toggle::make('admin_only'), + Forms\Components\Select::make('user_id')->searchable()->relationship('author', 'name') + ->required(), + Forms\Components\Select::make('application_id')->searchable()->relationship('application', 'id') + ->required(), + + ]); + } + + 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(), + Tables\Columns\TextColumn::make('author.name') + ->searchable(), + Tables\Columns\IconColumn::make('admin_only') + ->boolean(), + Tables\Columns\TextColumn::make('text'), + ]) + ->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'), + ]; + } +} diff --git a/app/Filament/Resources/CommentResource/Pages/CreateComment.php b/app/Filament/Resources/CommentResource/Pages/CreateComment.php new file mode 100644 index 0000000..b1815a4 --- /dev/null +++ b/app/Filament/Resources/CommentResource/Pages/CreateComment.php @@ -0,0 +1,12 @@ +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([ + ]); + } +} diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 9d26901..6365fb8 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -10,12 +10,17 @@ class Comment extends Model { use HasFactory, HasUuids; public $timestamps = true; + + protected $primaryKey = 'uuid'; + + protected $guarded = []; + protected $casts = [ - 'adminOnly' => 'boolean', + 'admin_only' => 'boolean', 'text' => 'string', ]; protected $attributes = [ - 'adminOnly' => false, + 'admin_only' => false, ]; public function application() diff --git a/app/Policies/CommentPolicy.php b/app/Policies/CommentPolicy.php index 166a54c..8d38056 100644 --- a/app/Policies/CommentPolicy.php +++ b/app/Policies/CommentPolicy.php @@ -40,7 +40,7 @@ public function create(User $user): bool */ public function update(User $user, Comment $comment): bool { - return false; + return $user->isAdmin(); } /** From f4a21de4d9804203af6a631cee16cbc376c05003 Mon Sep 17 00:00:00 2001 From: JulSteele <20680187+julsteele@users.noreply.github.com> Date: Thu, 10 Aug 2023 23:10:37 +0200 Subject: [PATCH 03/28] Formatting --- app/Filament/Resources/ApplicationResource.php | 2 -- .../RelationManagers/CommentRelationManager.php | 4 ---- app/Filament/Resources/CommentResource.php | 5 ++--- .../Pages/RelationManagers/ApplicationRelationManager.php | 8 ++++---- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/app/Filament/Resources/ApplicationResource.php b/app/Filament/Resources/ApplicationResource.php index f2963be..4a625fc 100755 --- a/app/Filament/Resources/ApplicationResource.php +++ b/app/Filament/Resources/ApplicationResource.php @@ -348,8 +348,6 @@ public static function table(Table $table): Table ]); } - - public static function getRelations(): array { return [ diff --git a/app/Filament/Resources/ApplicationResource/RelationManagers/CommentRelationManager.php b/app/Filament/Resources/ApplicationResource/RelationManagers/CommentRelationManager.php index 4b00816..205c165 100644 --- a/app/Filament/Resources/ApplicationResource/RelationManagers/CommentRelationManager.php +++ b/app/Filament/Resources/ApplicationResource/RelationManagers/CommentRelationManager.php @@ -3,10 +3,7 @@ namespace App\Filament\Resources\ApplicationResource\RelationManagers; use App\Filament\Resources\CommentResource; -use App\Filament\Resources\UserResource; -use App\Http\Controllers\Client\RegSysClientController; use App\Models\Comment; -use App\Models\User; use Filament\Forms; use Filament\Resources\Form; use Filament\Resources\RelationManagers\RelationManager; @@ -16,7 +13,6 @@ class CommentRelationManager extends RelationManager { protected static string $relationship = 'comments'; - protected static ?string $title = "Comments"; protected static ?string $label = "Comment"; protected static ?string $recordTitleAttribute = 'text'; diff --git a/app/Filament/Resources/CommentResource.php b/app/Filament/Resources/CommentResource.php index 1379000..5b99de4 100644 --- a/app/Filament/Resources/CommentResource.php +++ b/app/Filament/Resources/CommentResource.php @@ -11,7 +11,6 @@ use Filament\Resources\Table; use Filament\Tables; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Database\Eloquent\SoftDeletingScope; class CommentResource extends Resource { @@ -39,7 +38,7 @@ 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('uuid')->hidden()->url(fn($record) => CommentResource::getUrl('edit', ['record' => $record->uuid])), Tables\Columns\TextColumn::make('application_id') ->searchable(), Tables\Columns\TextColumn::make('author.name') @@ -50,7 +49,7 @@ public static function table(Table $table): Table ]) ->filters([ Tables\Filters\Filter::make('admin_only') - ->query(fn (Builder $query): Builder => $query->where('admin_only', '=', '1')) + ->query(fn(Builder $query): Builder => $query->where('admin_only', '=', '1')) ->label('Is Admin only'), ]) ->actions([ diff --git a/app/Filament/Resources/CommentResource/Pages/RelationManagers/ApplicationRelationManager.php b/app/Filament/Resources/CommentResource/Pages/RelationManagers/ApplicationRelationManager.php index 369e137..759019b 100644 --- a/app/Filament/Resources/CommentResource/Pages/RelationManagers/ApplicationRelationManager.php +++ b/app/Filament/Resources/CommentResource/Pages/RelationManagers/ApplicationRelationManager.php @@ -32,10 +32,10 @@ public static function table(Table $table): Table 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 - ]), + 'secondary', + 'success' => ApplicationStatus::TableAccepted->value, + 'danger' => ApplicationStatus::Canceled->value + ]), Tables\Columns\TextColumn::make('assignedTable.name'), Tables\Columns\TextColumn::make('table_number'), From b5544b1f1579dd4e07691c921714c15e810677e8 Mon Sep 17 00:00:00 2001 From: JulSteele <20680187+julsteele@users.noreply.github.com> Date: Thu, 10 Aug 2023 23:25:47 +0200 Subject: [PATCH 04/28] Added dates, formatted comment view --- app/Filament/Resources/CommentResource.php | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app/Filament/Resources/CommentResource.php b/app/Filament/Resources/CommentResource.php index 5b99de4..8471a7d 100644 --- a/app/Filament/Resources/CommentResource.php +++ b/app/Filament/Resources/CommentResource.php @@ -21,15 +21,24 @@ class CommentResource extends Resource public static function form(Form $form): Form { return $form + ->columns(3) ->schema([ - Forms\Components\Textarea::make('text') - ->required() - ->maxLength(2048), - Forms\Components\Toggle::make('admin_only'), - Forms\Components\Select::make('user_id')->searchable()->relationship('author', 'name') - ->required(), - Forms\Components\Select::make('application_id')->searchable()->relationship('application', 'id') - ->required(), + 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(2048), + ]), + 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() ?? '-'), + ]), ]); } From c858e98b01a38b551cc49d31c9313d9c1d9fb35d Mon Sep 17 00:00:00 2001 From: Fenrikur <3359222+Fenrikur@users.noreply.github.com> Date: Fri, 11 Aug 2023 00:12:21 +0200 Subject: [PATCH 05/28] render application data in frontdesk --- app/Http/Controllers/FrontdeskController.php | 62 +++- .../frontdesk/applicationbutton.blade.php | 15 + resources/views/frontdesk.blade.php | 290 +++++++++++++----- routes/web.php | 1 - 4 files changed, 272 insertions(+), 96 deletions(-) create mode 100644 resources/views/components/frontdesk/applicationbutton.blade.php diff --git a/app/Http/Controllers/FrontdeskController.php b/app/Http/Controllers/FrontdeskController.php index 4dea1ad..e490a99 100644 --- a/app/Http/Controllers/FrontdeskController.php +++ b/app/Http/Controllers/FrontdeskController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Models\Application; +use App\Enums\ApplicationType; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Log; @@ -14,23 +15,56 @@ class FrontdeskController extends Controller */ public function __invoke(Request $request) { - return view('frontdesk', [ 'user' => \Auth::user() ]); - } + $search = $request->get('search'); - public function search(Request $request) - { - $reg_id = $request->get('reg_id'); - $user = $reg_id ? User::where('reg_id', $reg_id)->first() : false; - if ($user === false) { - Log::info("No reg ID provided."); - } elseif ($user === null) { - Log::info("User not found."); + if (empty($search)) { + return view('frontdesk', [ + 'user' => \Auth::user(), + 'search' => null, + 'application' => null, + 'applicant' => null + ]); } - $application = $user ? Application::where('user_id', $user->id)->first() : false; - if ($application === null) { - Log::info("No application found for user."); + + // 1. search by user user_id + $user = User::where('reg_id', $search)->first(); + + // 2. search by application table_number + // 3. search by user name + // 4. search by dealership display_name + + + $application = $user ? Application::where('user_id', $user->id)->first() : null; + + $table = $application && $application->assignedTable ? $application->assignedTable->first() : null; + + $parent = $application && $application->parent() ? $application->parent()->first() : null; + $parentApplicant = $parent ? $parent->user()->first() : null; + + $children = $application && $application->children() ? $application->children()->get() : []; + Log::info(print_r($children, true)); + $shares = []; + $assistants = []; + foreach ($children as $child) { + if ($child->type === ApplicationType::Share) { + array_push($shares, $child); + } elseif ($child->type === ApplicationType::Assistant) { + array_push($assistants, $child); + } else { + Log::warning('Encountered child of unexpected type.', ['parent' => $parent, 'child' => $child]); + } } - return view('frontdesk', [ 'user' => \Auth::user(), 'application' => $application ]); + return view('frontdesk', [ + 'user' => \Auth::user(), + 'search' => $search, + 'application' => $application, + 'applicant' => $user, + 'table' => $table, + 'parent' => $parent, + 'parentApplicant' => $parentApplicant, + 'shares' => $shares, + 'assistants' => $assistants, + ]); } } diff --git a/resources/views/components/frontdesk/applicationbutton.blade.php b/resources/views/components/frontdesk/applicationbutton.blade.php new file mode 100644 index 0000000..3f140e4 --- /dev/null +++ b/resources/views/components/frontdesk/applicationbutton.blade.php @@ -0,0 +1,15 @@ +@props(['applicant', 'application']) + + $application->status === \App\Enums\ApplicationStatus::CheckedIn, + 'btn-warning' => $application->status === \App\Enums\ApplicationStatus::TableOffered || + $application->status === \App\Enums\ApplicationStatus::CheckedOut, + 'btn-danger' => $application->status !== \App\Enums\ApplicationStatus::CheckedIn && $application->status !== \App\Enums\ApplicationStatus::TableOffered && + $application->status !== \App\Enums\ApplicationStatus::CheckedOut, + ])> + {{ $applicant->name }} ({{$applicant->reg_id}}) – {{ $application->status->name }} diff --git a/resources/views/frontdesk.blade.php b/resources/views/frontdesk.blade.php index de9dede..a082503 100644 --- a/resources/views/frontdesk.blade.php +++ b/resources/views/frontdesk.blade.php @@ -10,163 +10,285 @@ @vite(['resources/css/app.scss', 'resources/js/app.js']) + + +
- -