Fix PIREP submission and field slug problems on PIREP edit
This commit is contained in:
@@ -73,6 +73,7 @@ class CreateFlightTables extends Migration
|
||||
$table->bigIncrements('id');
|
||||
$table->string('flight_id', \App\Interfaces\Model::ID_MAX_LENGTH);
|
||||
$table->string('name', 50);
|
||||
$table->string('slug', 50)->nullable();
|
||||
$table->text('value');
|
||||
$table->timestamps();
|
||||
|
||||
|
||||
@@ -394,18 +394,20 @@ flights:
|
||||
|
||||
flight_fields:
|
||||
- name: Departure Gate
|
||||
slug: departure_gate
|
||||
slug: departure-gate
|
||||
- name: Arrival Gate
|
||||
slug: arrival_gate
|
||||
slug: arrival-gate
|
||||
|
||||
flight_field_values:
|
||||
- id: 1
|
||||
flight_id: flightid_1
|
||||
name: cost index
|
||||
slug: cost-index
|
||||
value: 80
|
||||
- id: 2
|
||||
flight_id: flightid_2
|
||||
name: cost index
|
||||
slug: cost-index
|
||||
value: 100
|
||||
|
||||
flight_subfleet:
|
||||
@@ -539,24 +541,24 @@ pirep_fares:
|
||||
pirep_fields:
|
||||
- id: 1
|
||||
name: departure gate
|
||||
slug: departure_gate
|
||||
slug: departure-gate
|
||||
required: 1
|
||||
- id: 2
|
||||
name: arrival gate
|
||||
slug: arrival_gate
|
||||
slug: arrival-gate
|
||||
required: 0
|
||||
|
||||
pirep_field_values:
|
||||
- id: 1
|
||||
pirep_id: pirepid_1
|
||||
name: arrival gate
|
||||
slug: arrival_gate
|
||||
slug: arrival-gate
|
||||
value: 10
|
||||
source: manual
|
||||
- id: 2
|
||||
pirep_id: pirepid_1
|
||||
name: departure gate
|
||||
slug: departure_gate
|
||||
slug: departure-gate
|
||||
value: B32
|
||||
source: manual
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ class PirepController extends Controller
|
||||
|
||||
$custom_fields[] = [
|
||||
'name' => $field->name,
|
||||
'slug' => $field->slug,
|
||||
'value' => $request->input($field->slug),
|
||||
'source' => PirepSource::MANUAL
|
||||
];
|
||||
@@ -304,7 +305,10 @@ class PirepController extends Controller
|
||||
// Depending on the button they selected, set an initial state
|
||||
// Can be saved as a draft or just submitted
|
||||
if ($attrs['submit'] === 'save') {
|
||||
$pirep->state = PirepState::DRAFT;
|
||||
if(!$pirep->read_only) {
|
||||
$pirep->state = PirepState::DRAFT;
|
||||
}
|
||||
|
||||
$pirep->save();
|
||||
Flash::success('PIREP saved successfully.');
|
||||
} else if ($attrs['submit'] === 'submit') {
|
||||
@@ -334,6 +338,10 @@ class PirepController extends Controller
|
||||
|
||||
# set the custom fields
|
||||
foreach ($pirep->fields as $field) {
|
||||
if($field->slug == null) {
|
||||
$field->slug = str_slug($field->name);
|
||||
}
|
||||
|
||||
$pirep->{$field->slug} = $field->value;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,11 +18,21 @@ class FlightFieldValue extends Model
|
||||
protected $fillable = [
|
||||
'flight_id',
|
||||
'name',
|
||||
'slug',
|
||||
'value',
|
||||
];
|
||||
|
||||
public static $rules = [];
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*/
|
||||
public function setNameAttribute($name): void
|
||||
{
|
||||
$this->attributes['name'] = $name;
|
||||
$this->attributes['slug'] = str_slug($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationships
|
||||
*/
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Observers;
|
||||
|
||||
use App\Models\PirepField;
|
||||
|
||||
/**
|
||||
* Class PirepFieldObserver
|
||||
* @package App\Models\Observers
|
||||
*/
|
||||
class PirepFieldObserver
|
||||
{
|
||||
/**
|
||||
* @param PirepField $model
|
||||
*/
|
||||
public function creating(PirepField $model): void
|
||||
{
|
||||
$model->slug = str_slug($model->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param PirepField $model
|
||||
*/
|
||||
public function updating(PirepField $model): void
|
||||
{
|
||||
$model->slug = str_slug($model->name);
|
||||
}
|
||||
}
|
||||
35
app/Models/Observers/Sluggable.php
Normal file
35
app/Models/Observers/Sluggable.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Observers;
|
||||
|
||||
/**
|
||||
* Create a slug from a name
|
||||
* @package App\Models\Observers
|
||||
*/
|
||||
class Sluggable
|
||||
{
|
||||
/**
|
||||
* @param $model
|
||||
*/
|
||||
public function creating($model): void
|
||||
{
|
||||
$model->slug = str_slug($model->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $model
|
||||
*/
|
||||
public function updating($model): void
|
||||
{
|
||||
$model->slug = str_slug($model->name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*/
|
||||
public function setNameAttribute($name): void
|
||||
{
|
||||
$this->attributes['name'] = $name;
|
||||
$this->attributes['slug'] = str_slug($name);
|
||||
}
|
||||
}
|
||||
@@ -45,6 +45,7 @@ use PhpUnitsOfMeasure\Exception\NonStringUnitName;
|
||||
* @property Carbon submitted_at
|
||||
* @property Carbon created_at
|
||||
* @property Carbon updated_at
|
||||
* @property bool read_only
|
||||
* @property Acars position
|
||||
* @property Acars[] acars
|
||||
* @package App\Models
|
||||
@@ -127,9 +128,9 @@ class Pirep extends Model
|
||||
* If a PIREP is in these states, then it can't be changed.
|
||||
*/
|
||||
public static $read_only_states = [
|
||||
PirepState::PENDING,
|
||||
PirepState::ACCEPTED,
|
||||
PirepState::REJECTED,
|
||||
//PirepState::PENDING,
|
||||
PirepState::CANCELLED,
|
||||
];
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ class PirepFieldValues extends Model
|
||||
protected $fillable = [
|
||||
'pirep_id',
|
||||
'name',
|
||||
'slug',
|
||||
'value',
|
||||
'source',
|
||||
];
|
||||
@@ -23,6 +24,15 @@ class PirepFieldValues extends Model
|
||||
'name' => 'required',
|
||||
];
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
*/
|
||||
public function setNameAttribute($name): void
|
||||
{
|
||||
$this->attributes['name'] = $name;
|
||||
$this->attributes['slug'] = str_slug($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Foreign Keys
|
||||
*/
|
||||
|
||||
@@ -4,21 +4,23 @@ namespace App\Providers;
|
||||
|
||||
use App\Models\Aircraft;
|
||||
use App\Models\Airport;
|
||||
use App\Models\FlightField;
|
||||
use App\Models\FlightFieldValue;
|
||||
use App\Models\Journal;
|
||||
use App\Models\JournalTransaction;
|
||||
use App\Models\Observers\AircraftObserver;
|
||||
use App\Models\Observers\AirportObserver;
|
||||
use App\Models\Observers\JournalObserver;
|
||||
use App\Models\Observers\JournalTransactionObserver;
|
||||
use App\Models\Observers\PirepFieldObserver;
|
||||
use App\Models\Observers\Sluggable;
|
||||
use App\Models\Observers\SettingObserver;
|
||||
use App\Models\Observers\SubfleetObserver;
|
||||
use App\Models\PirepField;
|
||||
use App\Models\PirepFieldValues;
|
||||
use App\Models\Setting;
|
||||
use App\Models\Subfleet;
|
||||
use App\Repositories\SettingRepository;
|
||||
use App\Services\ModuleService;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use View;
|
||||
@@ -42,10 +44,15 @@ class AppServiceProvider extends ServiceProvider
|
||||
Airport::observe(AirportObserver::class);
|
||||
Journal::observe(JournalObserver::class);
|
||||
JournalTransaction::observe(JournalTransactionObserver::class);
|
||||
PirepField::observe(PirepFieldObserver::class);
|
||||
|
||||
FlightField::observe(Sluggable::class);
|
||||
FlightFieldValue::observe(Sluggable::class);
|
||||
|
||||
PirepField::observe(Sluggable::class);
|
||||
PirepFieldValues::observe(Sluggable::class);
|
||||
|
||||
Setting::observe(SettingObserver::class);
|
||||
Subfleet::observe(SubfleetObserver::class);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +62,6 @@ class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
# Only dev environment stuff
|
||||
if ($this->app->environment() === 'dev') {
|
||||
|
||||
# Only load the IDE helper if it's included. This lets use distribute the
|
||||
# package without any dev dependencies
|
||||
if (class_exists(\Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider::class)) {
|
||||
|
||||
@@ -13,6 +13,7 @@ use App\Models\Bid;
|
||||
use App\Models\Enums\AcarsType;
|
||||
use App\Models\Enums\PirepSource;
|
||||
use App\Models\Enums\PirepState;
|
||||
use App\Models\Enums\PirepStatus;
|
||||
use App\Models\Enums\UserState;
|
||||
use App\Models\Navdata;
|
||||
use App\Models\Pirep;
|
||||
@@ -211,6 +212,10 @@ class PirepService extends Service
|
||||
}
|
||||
}
|
||||
|
||||
$pirep->state = $default_state;
|
||||
$pirep->status = PirepStatus::ARRIVED;
|
||||
$pirep->save();
|
||||
|
||||
Log::info('New PIREP filed', [$pirep]);
|
||||
event(new PirepFiled($pirep));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user