forked from vatsimnetwork/nattrak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Liesel Downes
committed
Apr 25, 2023
1 parent
f51a612
commit 0817456
Showing
13 changed files
with
342 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
28
database/migrations/2023_04_24_170043_create_bulletins_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.