Add additional settings; Use pilot id length from setting

This commit is contained in:
Nabeel Shahzad 2017-12-12 12:43:58 -06:00
parent 695900a008
commit e05976a982
12 changed files with 82 additions and 45 deletions

View File

@ -2,6 +2,7 @@
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="AndroidLintTypos" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="ClassOverridesFieldOfSuperClassInspection" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="ForgottenDebugOutputInspection" enabled="true" level="ERROR" enabled_by_default="true">
<option name="configuration">
<list>

View File

@ -4,7 +4,7 @@ namespace App\Models;
use Eloquent as Model;
use App\Models\Traits\Uuids;
use App\Models\Traits\HashId;
/**
* Class Flight
@ -13,7 +13,7 @@ use App\Models\Traits\Uuids;
*/
class Flight extends Model
{
use Uuids;
use HashId;
public $table = 'flights';
public $incrementing = false;

View File

@ -3,7 +3,7 @@
namespace App\Models;
use Eloquent as Model;
use App\Models\Traits\Uuids;
use App\Models\Traits\HashId;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
@ -13,7 +13,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
*/
class Pirep extends Model
{
use Uuids;
use HashId;
use SoftDeletes;
public $table = 'pireps';

View File

@ -5,21 +5,21 @@ namespace App\Models\Traits;
use Hashids\Hashids;
trait Uuids
trait HashId
{
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
static::creating(function ($model)
{
$key = $model->getKeyName();
if (empty($model->{$key})) {
$hashids = new Hashids('', 10);
$mt = str_replace('.', '', microtime(true));
$id = $hashids->encode($mt);
$model->{$key} = $id;
}
});

View File

@ -73,18 +73,15 @@ class User extends Authenticatable
*
* @var array
*/
protected $hidden
= [
protected $hidden = [
'password',
'remember_token',
];
protected $casts
= [
protected $casts = [
'flights' => 'integer',
'flight_time' => 'integer',
'balance' => 'double',
'timezone' => 'integer',
];
/**
@ -106,9 +103,10 @@ class User extends Authenticatable
return $key;
}
public function pilot_id()
public function getPilotIdAttribute($value)
{
return $this->airline->icao.str_pad($this->id, 3, '0', STR_PAD_LEFT);
$length = setting('pilots.id_length');
return $this->airline->icao . str_pad($this->id, $length, '0', STR_PAD_LEFT);
}
public function gravatar()

View File

@ -2,9 +2,11 @@
namespace App\Repositories;
use Illuminate\Support\Carbon;
use Prettus\Repository\Contracts\CacheableInterface;
use App\Models\Setting;
use App\Repositories\Traits\CacheableRepository;
use Prettus\Repository\Contracts\CacheableInterface;
class SettingRepository extends BaseRepository implements CacheableInterface
{
@ -16,17 +18,44 @@ class SettingRepository extends BaseRepository implements CacheableInterface
}
/**
* Get a setting, reading it from the cache
* @param array $key
* @return mixed|void
* Get a setting, reading it from the cache possibly
* @param string $key
* @return mixed
*/
public function get($key)
public function retrieve($key)
{
$key = strtolower($key);
$setting = $this->findWhere(['key' => $key], ['type', 'value'])->first();
if(!$setting) {
return null;
}
public function set($key, $value)
{
# cast some types
switch($setting->type) {
case 'bool':
case 'boolean':
return (bool) $setting->value;
break;
case 'date':
return Carbon::parse($setting->value);
break;
case 'int':
case 'integer':
return (int) $setting->value;
break;
default:
return $setting->value;
}
}
public function store($key, $value)
{
$setting = $this->findWhere(['key' => $key], ['id'])->first();
if (!$setting) {
return null;
}
$this->update(['value' => $value], $setting->id);
}
}

View File

@ -8,7 +8,7 @@ if (!function_exists('setting')) {
{
$settingRepo = app('setting');
if($value === null) {
return $settingRepo->get($key);
return $settingRepo->retrieve($key);
} else {
$settingRepo->set($key, $value);
}

View File

@ -23,7 +23,7 @@ class CreateUsersTable extends Migration
$table->integer('rank_id')->nullable()->unsigned();
$table->string('home_airport_id', 5)->nullable();
$table->string('curr_airport_id', 5)->nullable();
$table->uuid('last_pirep_id')->nullable();
$table->string('last_pirep_id')->nullable();
$table->bigInteger('flights')->unsigned()->default(0);
$table->bigInteger('flight_time')->unsigned()->default(0);
$table->decimal('balance', 19, 2)->nullable();

View File

@ -60,7 +60,7 @@ class CreateSettingsTable extends Migration
],
[
'order' => 20,
'name' => 'Disable flights on bid',
'name' => 'Disable flight on bid',
'group' => 'bids',
'key' => 'bids.disable_flight_on_bid',
'value' => true,
@ -85,6 +85,15 @@ class CreateSettingsTable extends Migration
'type' => 'boolean',
'description' => 'Don\'t show inactive pilots in the public view',
],
[
'order' => 31,
'name' => 'Pilot ID Length',
'group' => 'pilots',
'key' => 'pilots.id_length',
'value' => 4,
'type' => 'int',
'description' => 'The length of a pilot\'s ID',
],
];
$this->addData('settings', $settings);

24
package-lock.json generated
View File

@ -219,7 +219,7 @@
"arr-flatten": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/arr-flatten/-/arr-flatten-1.1.0.tgz",
"integrity": "sha512-L3hKV5R/p5o81R7O02IGnwpDmkp6E982XhtbuwSe3O4qOtMMMtodicASA1Cny2U+aCXcNpml+m4dPsvsJ3jatg==",
"integrity": "sha1-NgSLv/TntH4TZkQxbJlmnqWukfE=",
"dev": true
},
"array-differ": {
@ -2902,7 +2902,7 @@
"duplexify": {
"version": "3.5.1",
"resolved": "https://registry.npmjs.org/duplexify/-/duplexify-3.5.1.tgz",
"integrity": "sha512-j5goxHTwVED1Fpe5hh3q9R93Kip0Bg2KVAt4f8CEYM3UEwYcPSvWbXaUQOzdX/HtiNomipv+gU7ASQPDbV7pGQ==",
"integrity": "sha1-ThUWvmiDi8kKSZlPCzmm5ZYL780=",
"dev": true,
"requires": {
"end-of-stream": "1.4.0",
@ -5243,7 +5243,7 @@
"hosted-git-info": {
"version": "2.5.0",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.5.0.tgz",
"integrity": "sha512-pNgbURSuab90KbTqvRPsseaTxOJCZBD0a7t+haSN33piP9cCM4l0CqdzAif2hUqm716UovKB2ROmiabGAKVXyg==",
"integrity": "sha1-bWDjSzq7yDEwYsO3mO+NkBoHrzw=",
"dev": true
},
"hpack.js": {
@ -5843,7 +5843,7 @@
"is-plain-object": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz",
"integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==",
"integrity": "sha1-LBY7P6+xtgbZ0Xko8FwqHDjgdnc=",
"dev": true,
"requires": {
"isobject": "3.0.1"
@ -7031,7 +7031,7 @@
"node-emoji": {
"version": "1.8.1",
"resolved": "https://registry.npmjs.org/node-emoji/-/node-emoji-1.8.1.tgz",
"integrity": "sha512-+ktMAh1Jwas+TnGodfCfjUbJKoANqPaJFN0z0iqh41eqD8dvguNzcitVSBSVK1pidz0AqGbLKcoVuVLRVZ/aVg==",
"integrity": "sha1-buxr+wdCHiFIx1xrunJCH4UwqCY=",
"dev": true,
"requires": {
"lodash.toarray": "4.4.0"
@ -7218,7 +7218,7 @@
"normalize-package-data": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/normalize-package-data/-/normalize-package-data-2.4.0.tgz",
"integrity": "sha512-9jjUFbTPfEy3R/ad/2oNbKtW9Hgovl5O1FvFWKkKblNXoN/Oou6+9+KKohPK13Yc3/TyunyWhJp6gvRNR/PPAw==",
"integrity": "sha1-EvlaMH1YNSB1oEkHuErIvpisAS8=",
"dev": true,
"requires": {
"hosted-git-info": "2.5.0",
@ -7266,7 +7266,7 @@
"npmlog": {
"version": "4.1.2",
"resolved": "https://registry.npmjs.org/npmlog/-/npmlog-4.1.2.tgz",
"integrity": "sha512-2uUqazuKlTaSI/dC8AzicUck7+IrEaOnN/e0jd3Xtt1KcGpwx30v50mL7oPyr/h9bL3E4aZccVwpwP+5W9Vjkg==",
"integrity": "sha1-CKfyqL9zRgR3mp76StXMcXq7lUs=",
"dev": true,
"requires": {
"are-we-there-yet": "1.1.4",
@ -9790,7 +9790,7 @@
"randomatic": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz",
"integrity": "sha512-D5JUjPyJbaJDkuAazpVnSfVkLlpeO3wDlPROTMLGKG1zMFNFRgrciKo1ltz/AzNTkqE0HzDx655QOL51N06how==",
"integrity": "sha1-x6vpzIuHwLqodrGf3oP9RkeX44w=",
"dev": true,
"requires": {
"is-number": "3.0.0",
@ -10341,7 +10341,7 @@
"safe-buffer": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==",
"integrity": "sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=",
"dev": true
},
"sass-graph": {
@ -11707,7 +11707,7 @@
"uuid": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-3.1.0.tgz",
"integrity": "sha512-DIWtzUkw04M4k3bf1IcpS2tngXEL26YUD2M0tMDUpnUrz2hgzUBlD55a4FjdLGPvfHxS6uluGWvaVEqgBcVa+g==",
"integrity": "sha1-PdPT55Crwk17DToDT/q6vijrvAQ=",
"dev": true
},
"vali-date": {
@ -12130,7 +12130,7 @@
"which": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/which/-/which-1.3.0.tgz",
"integrity": "sha512-xcJpopdamTuY5duC/KnTTNBraPK54YwpenP4lzxU8H91GudWpFv38u0CKjclE1Wi2EH2EDz5LRcHcKbCIzqGyg==",
"integrity": "sha1-/wS9/AEO5UfXgL7DjhrBwnd9JTo=",
"dev": true,
"requires": {
"isexe": "2.0.0"
@ -12145,7 +12145,7 @@
"wide-align": {
"version": "1.1.2",
"resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.2.tgz",
"integrity": "sha512-ijDLlyQ7s6x1JgCLur53osjm/UXUYD9+0PbYKrBsYisYXzCxN+HC3mYDNy/dWdmf3AwqwU3CXwDCvsNgGK1S0w==",
"integrity": "sha1-Vx4PGwYEY268DfwhsDObvjE0FxA=",
"dev": true,
"requires": {
"string-width": "1.0.2"

View File

@ -4,7 +4,7 @@
<img src="{!! $pirep->pilot->gravatar() !!}" />
</div>--}}
Filed By: <a href="{!! route('admin.users.edit', [$pirep->pilot->id]) !!}" target="_blank">
{!! $pirep->pilot->pilot_id() !!} {!! $pirep->pilot->name !!}
{!! $pirep->pilot->pilot_id !!} {!! $pirep->pilot->name !!}
</a>
</div>

View File

@ -100,7 +100,7 @@
<table>
@foreach($users as $u)
<tr>
<td style="padding-right: 10px;">{!! $u->pilot_id() !!}</td>
<td style="padding-right: 10px;">{!! $u->pilot_id !!}</td>
<td><span class="description">{!! $u->name !!}</span></td>
</tr>
@endforeach