diff --git a/app/Http/Controllers/BulletinsController.php b/app/Http/Controllers/BulletinsController.php new file mode 100644 index 0000000..ae2c5cf --- /dev/null +++ b/app/Http/Controllers/BulletinsController.php @@ -0,0 +1,38 @@ + Bulletin::orderByDesc('created_at')->paginate(5), + ]); + } + + public function create() + { + return view('bulletins.create'); + } + + public function store(BulletinRequest $request) + { + $bulletin = new Bulletin($request->all()); + $bulletin->save(); + flashAlert(type: 'success', title: null, message: 'NOTAM created!', toast: true, timer: true); + + return redirect()->route('notams.index'); + } + + public function destroy(Bulletin $bulletin) + { + $bulletin->delete(); + flashAlert(type: 'info', title: null, message: 'NOTAM deleted.', toast: true, timer: true); + + return redirect()->route('notams.index'); + } +} diff --git a/app/Http/Controllers/ViewsController.php b/app/Http/Controllers/ViewsController.php index dd99bc9..ccf63bf 100644 --- a/app/Http/Controllers/ViewsController.php +++ b/app/Http/Controllers/ViewsController.php @@ -2,15 +2,15 @@ namespace App\Http\Controllers; +use App\Models\Bulletin; use Illuminate\Support\Facades\Cache; -use Illuminate\Support\Facades\Http; class ViewsController extends Controller { public function welcome() { $notams = Cache::remember('notams', now()->addMinutes(10), function () { - return json_decode(Http::timeout(5)->get('https://gist.githubusercontent.com/liessdow/78c35cbdeeb97add6a721d3d6b6f0078/raw')); + return Bulletin::orderByDesc('created_at')->take(3)->get(); }); return view('welcome', [ diff --git a/app/Http/Requests/BulletinRequest.php b/app/Http/Requests/BulletinRequest.php new file mode 100644 index 0000000..f611732 --- /dev/null +++ b/app/Http/Requests/BulletinRequest.php @@ -0,0 +1,20 @@ + ['required'], + 'subtitle' => ['nullable'], + 'content' => ['required'], + 'action_url' => ['nullable', 'url'], + 'alert_controllers' => ['nullable'], + 'alert_pilots' => ['nullable'], + ]; + } +} diff --git a/app/Models/Bulletin.php b/app/Models/Bulletin.php new file mode 100644 index 0000000..58ddcf4 --- /dev/null +++ b/app/Models/Bulletin.php @@ -0,0 +1,54 @@ +can('administrate'); + } + + public function update(VatsimAccount $user, Bulletin $bulletin): bool + { + return $user->can('administrate'); + } + + public function delete(VatsimAccount $user, Bulletin $bulletin): bool + { + return $user->can('administrate'); + } + + public function restore(VatsimAccount $user, Bulletin $bulletin): bool + { + return $user->can('administrate'); + } + + public function forceDelete(VatsimAccount $user, Bulletin $bulletin): bool + { + return $user->can('administrate'); + } +} diff --git a/database/factories/BulletinFactory.php b/database/factories/BulletinFactory.php new file mode 100644 index 0000000..c0ec675 --- /dev/null +++ b/database/factories/BulletinFactory.php @@ -0,0 +1,23 @@ + $this->faker->sentence(), + 'subtitle' => $this->faker->sentence(), + 'content' => $this->faker->realText(), + 'action_url' => $this->faker->url(), + 'alert_controllers' => $this->faker->boolean(), + 'alert_pilots' => $this->faker->boolean(), + ]; + } +} diff --git a/database/migrations/2023_04_24_170043_create_bulletins_table.php b/database/migrations/2023_04_24_170043_create_bulletins_table.php new file mode 100644 index 0000000..743f854 --- /dev/null +++ b/database/migrations/2023_04_24_170043_create_bulletins_table.php @@ -0,0 +1,28 @@ +id(); + $table->string('title'); + $table->string('subtitle')->nullable(); + $table->text('content'); + $table->string('action_url')->nullable(); + $table->boolean('alert_controllers')->default(false); + $table->boolean('alert_pilots')->default(false); + $table->softDeletes(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists('bulletins'); + } +}; diff --git a/database/seeders/BulletinsSeeder.php b/database/seeders/BulletinsSeeder.php new file mode 100644 index 0000000..66d450d --- /dev/null +++ b/database/seeders/BulletinsSeeder.php @@ -0,0 +1,14 @@ +count(10)->create(); + } +} diff --git a/resources/views/_layouts/main.blade.php b/resources/views/_layouts/main.blade.php index 2232603..bdb7faa 100644 --- a/resources/views/_layouts/main.blade.php +++ b/resources/views/_layouts/main.blade.php @@ -96,6 +96,9 @@
  • Activity log
  • +
  • + NOTAMs +
  • diff --git a/resources/views/bulletins/create.blade.php b/resources/views/bulletins/create.blade.php new file mode 100644 index 0000000..c52bb19 --- /dev/null +++ b/resources/views/bulletins/create.blade.php @@ -0,0 +1,39 @@ +@extends('_layouts.main') +@section('page') +
    +
    +

    Create NOTAM

    +
    +
    + @if ($errors->any()) + + @endif +
    + @csrf +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    + +
    +
    +
    +
    +@endsection diff --git a/resources/views/bulletins/index.blade.php b/resources/views/bulletins/index.blade.php new file mode 100644 index 0000000..7f1d0ca --- /dev/null +++ b/resources/views/bulletins/index.blade.php @@ -0,0 +1,60 @@ +@extends('_layouts.main') +@section('page') +
    +
    +

    NOTAMs

    + @can('create', \App\Models\Bulletin::class) + Create + @endcan +
    +
    +
    + @foreach($bulletins as $bulletin) +
    +
    +
    +
    +
    +

    {{ $bulletin->title }}

    +

    + {{ $bulletin->created_at->toDayDateTimeString() }} +

    +
    +
    +
    +
    + @if ($bulletin->subtitle) +

    + {{ $bulletin->subtitle }} +

    + @endif +

    {{ $bulletin->content }}

    +
    + + +
    +
    + @endforeach +
    +
    + {{ $bulletins->links() }} +
    +
    +@endsection diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php index 3f080b7..a7182e5 100644 --- a/resources/views/welcome.blade.php +++ b/resources/views/welcome.blade.php @@ -21,6 +21,9 @@
  • {{ $notam->title }}
    +

    + {{ $notam->created_at->toDayDateTimeString() }} +

    @if ($notam->subtitle)

    {{ $notam->subtitle }} @@ -29,12 +32,13 @@

    {{ $notam->content }}

    - @if ($notam->url) - Read more + @if ($notam->action_url) + Read more @endif
  • @endforeach + View all NOTAMs @endsection diff --git a/routes/web.php b/routes/web.php index eb124a0..7fffb7b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ name('.revert-to-voice'); }); }); + +Route::prefix('notams')->name('notams')->controller(BulletinsController::class)->group(function () { + Route::get('/', 'index')->name('.index'); + Route::get('/create', 'create')->name('.create'); + Route::post('/', 'store')->name('.store'); + Route::delete('/{bulletin:id}', 'destroy')->name('.destroy'); +});