Skip to content

Commit

Permalink
Bulletins/NOTAMs added
Browse files Browse the repository at this point in the history
  • Loading branch information
Liesel Downes committed Apr 25, 2023
1 parent f51a612 commit 0817456
Show file tree
Hide file tree
Showing 13 changed files with 342 additions and 4 deletions.
38 changes: 38 additions & 0 deletions app/Http/Controllers/BulletinsController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\BulletinRequest;
use App\Models\Bulletin;

class BulletinsController extends Controller
{
public function index()
{
return view('bulletins.index', [
'bulletins' => 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');
}
}
4 changes: 2 additions & 2 deletions app/Http/Controllers/ViewsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', [
Expand Down
20 changes: 20 additions & 0 deletions app/Http/Requests/BulletinRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class BulletinRequest extends FormRequest
{
public function rules(): array
{
return [
'title' => ['required'],
'subtitle' => ['nullable'],
'content' => ['required'],
'action_url' => ['nullable', 'url'],
'alert_controllers' => ['nullable'],
'alert_pilots' => ['nullable'],
];
}
}
54 changes: 54 additions & 0 deletions app/Models/Bulletin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

/**
* App\Models\Bulletin
*
* @property int $id
* @property string $title
* @property string|null $subtitle
* @property string $content
* @property string|null $action_url
* @property int $alert_controllers
* @property int $alert_pilots
* @property \Illuminate\Support\Carbon|null $deleted_at
* @property \Illuminate\Support\Carbon|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
*
* @method static \Database\Factories\BulletinFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin onlyTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin query()
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin whereActionUrl($value)
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin whereAlertControllers($value)
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin whereAlertPilots($value)
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin whereContent($value)
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin whereDeletedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin whereId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin whereSubtitle($value)
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin whereTitle($value)
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin whereUpdatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|Bulletin withoutTrashed()
* @mixin \Eloquent
*/
class Bulletin extends Model
{
use SoftDeletes, HasFactory;

protected $fillable = [
'title',
'subtitle',
'content',
'action_url',
'alert_controllers',
'alert_pilots',
];
}
47 changes: 47 additions & 0 deletions app/Policies/BulletinPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Policies;

use App\Models\Bulletin;
use App\Models\VatsimAccount;
use Illuminate\Auth\Access\HandlesAuthorization;

class BulletinPolicy
{
use HandlesAuthorization;

public function viewAny(?VatsimAccount $user): bool
{
return true;
}

public function view(?VatsimAccount $user): bool
{
return true;
}

public function create(VatsimAccount $user): bool
{
return $user->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');
}
}
23 changes: 23 additions & 0 deletions database/factories/BulletinFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Database\Factories;

use App\Models\Bulletin;
use Illuminate\Database\Eloquent\Factories\Factory;

class BulletinFactory extends Factory
{
protected $model = Bulletin::class;

public function definition(): array
{
return [
'title' => $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(),
];
}
}
28 changes: 28 additions & 0 deletions database/migrations/2023_04_24_170043_create_bulletins_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
public function up(): void
{
Schema::create('bulletins', function (Blueprint $table) {
$table->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');
}
};
14 changes: 14 additions & 0 deletions database/seeders/BulletinsSeeder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Database\Seeders;

use App\Models\Bulletin;
use Illuminate\Database\Seeder;

class BulletinsSeeder extends Seeder
{
public function run(): void
{
Bulletin::factory()->count(10)->create();
}
}
3 changes: 3 additions & 0 deletions resources/views/_layouts/main.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
<li>
<a href="{{ route('administration.activity-log') }}">Activity log</a>
</li>
<li>
<a href="{{ route('notams.index') }}">NOTAMs</a>
</li>
</ul>
</div>
</li>
Expand Down
39 changes: 39 additions & 0 deletions resources/views/bulletins/create.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
@extends('_layouts.main')
@section('page')
<div class="uk-container uk-padding uk-padding-remove-right uk-padding-remove-left">
<div class="uk-flex uk-flex-row uk-flex-between">
<h2 class="uk-text-bold uk-text-primary">Create NOTAM</h2>
</div>
<hr>
@if ($errors->any())
<div class="uk-alert uk-alert-danger" role="alert">
<p class="uk-text-bold">Some input was incorrect.</p>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@endif
<form method="POST" action="{{ route('notams.store') }}">
@csrf
<fieldset class="uk-fieldset">
<div class="uk-margin">
<input class="uk-input" type="text" name="title" placeholder="Title" required>
</div>
<div class="uk-margin">
<input type="text" class="uk-input" name="subtitle" placeholder="Subtitle (optional)">
</div>
<div class="uk-margin">
<textarea class="uk-textarea" rows="5" name="content" placeholder="Content" required></textarea>
</div>
<div class="uk-margin">
<input type="url" class="uk-input" name="action_url" placeholder="Action button URL (optional)">
</div>
<div class="uk-margin">
<button class="uk-button uk-button-primary">Create</button>
</div>
</fieldset>
</form>
</div>
@endsection
60 changes: 60 additions & 0 deletions resources/views/bulletins/index.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
@extends('_layouts.main')
@section('page')
<div class="uk-container uk-padding uk-padding-remove-right uk-padding-remove-left">
<div class="uk-flex uk-flex-row uk-flex-between">
<h2 class="uk-text-bold uk-text-primary">NOTAMs</h2>
@can('create', \App\Models\Bulletin::class)
<a href="{{ route('notams.create') }}" class="uk-button uk-button-default">Create</a>
@endcan
</div>
<hr>
<div class="uk-grid-medium uk-child-width-1-2@s uk-grid-match" uk-grid>
@foreach($bulletins as $bulletin)
<div>
<div class="uk-card uk-card-default">
<div class="uk-card-header">
<div class="uk-grid-small uk-flex-middle" uk-grid>
<div class="uk-width-expand">
<h3 class="uk-card-title uk-margin-remove-bottom">{{ $bulletin->title }}</h3>
<p class="uk-text-meta uk-margin-remove-top">
{{ $bulletin->created_at->toDayDateTimeString() }}
</p>
</div>
</div>
</div>
<div class="uk-card-body">
@if ($bulletin->subtitle)
<p class="uk-text-italic">
{{ $bulletin->subtitle }}
</p>
@endif
<p>{{ $bulletin->content }}</p>
</div>
<div class="uk-card-footer">
<div class="uk-flex uk-flex-row uk-flex-between">
@if ($bulletin->action_url)
<div>
<a target="_blank" href="{{ $bulletin->action_url }}" class="uk-button uk-button-text">Read more</a>
</div>
@endif
@can('delete', $bulletin)
<div>
<form action="{{ route('notams.destroy', $bulletin) }}" method="post">
{{ csrf_field() }}
{{ method_field('DELETE') }}
<button class="uk-button uk-button-danger">Delete</button>
</form>
</div>
@endcan
</div>
</div>

</div>
</div>
@endforeach
</div>
<div style="margin-top: 20px;">
{{ $bulletins->links() }}
</div>
</div>
@endsection
8 changes: 6 additions & 2 deletions resources/views/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<li class="{{ $loop->first ? 'uk-open' : '' }}">
<a href="" class="uk-accordion-title">{{ $notam->title }}</a>
<div class="uk-accordion-content">
<p class="uk-text-italic">
{{ $notam->created_at->toDayDateTimeString() }}
</p>
@if ($notam->subtitle)
<p class="uk-text-italic">
{{ $notam->subtitle }}
Expand All @@ -29,12 +32,13 @@
<p>
{{ $notam->content }}
</p>
@if ($notam->url)
<a href="{{ $notam->url }}" class="card-link">Read more</a>
@if ($notam->action_url)
<a href="{{ $notam->action_url }}" class="card-link">Read more</a>
@endif
</div>
</li>
@endforeach
</ul>
<a href="{{ route('notams.index') }}">View all NOTAMs</a>
</div>
@endsection
Loading

0 comments on commit 0817456

Please sign in to comment.