Cleanup for settings table and moved some seed data into the migrations

This commit is contained in:
Nabeel Shahzad 2017-12-09 21:21:49 -06:00
parent b165cd28b6
commit d34e30666d
19 changed files with 323 additions and 204 deletions

View File

@ -3,7 +3,6 @@ APP_KEY=base64:ve66Z5Kt/zTN3p++0zOPu854PHfZkwJE5VuoFAlzHtI=
APP_DEBUG=true APP_DEBUG=true
APP_LOCALE=en APP_LOCALE=en
APP_URL=http://localhost APP_URL=http://localhost
APP_SETTINGS_STORE=json
APP_LOG=daily APP_LOG=daily
APP_LOG_LEVEL=debug APP_LOG_LEVEL=debug

View File

@ -3,7 +3,6 @@ APP_KEY=base64:ve66Z5Kt/zTN3p++0zOPu854PHfZkwJE5VuoFAlzHtI=
APP_DEBUG=false APP_DEBUG=false
APP_LOG_LEVEL=info APP_LOG_LEVEL=info
APP_URL=http://localhost APP_URL=http://localhost
APP_SETTINGS_STORE=json
DB_CONNECTION=travis DB_CONNECTION=travis
DB_HOST=127.0.0.1 DB_HOST=127.0.0.1

View File

@ -3,7 +3,6 @@ APP_KEY=base64:ve66Z5Kt/zTN3p++0zOPu854PHfZkwJE5VuoFAlzHtI=
APP_DEBUG=true APP_DEBUG=true
APP_LOG_LEVEL=debug APP_LOG_LEVEL=debug
APP_URL=http://localhost APP_URL=http://localhost
APP_SETTINGS_STORE=json
DB_CONNECTION=mysql DB_CONNECTION=mysql
DB_HOST=127.0.0.1 DB_HOST=127.0.0.1

View File

@ -3,6 +3,7 @@
namespace App\Http\Controllers\Admin; namespace App\Http\Controllers\Admin;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Setting;
class SettingsController extends BaseController class SettingsController extends BaseController
{ {
@ -13,13 +14,15 @@ class SettingsController extends BaseController
*/ */
public function index() public function index()
{ {
$settings = array_filter(Setting::all(), function ($key) { /*$settings = array_filter(Setting::all(), function ($key) {
if (strpos($key, '_descrip') !== false) { return true; } if (strpos($key, '_descrip') !== false) { return true; }
return false; return false;
}); });*/
$settings = [];
return $this->view('admins.settings.index') return view('admin.settings.index',[
->with('settings', $settings); 'settings' => $settings,
]);
} }
/** /**
@ -32,8 +35,8 @@ class SettingsController extends BaseController
*/ */
public function update(Setting $setting, Request $request) public function update(Setting $setting, Request $request)
{ {
$this->validate($request, Setting::$rules, Setting::$messages); $/*this->validate($request, Setting::$rules, Setting::$messages);
$this->updateEntry($setting, $request->all()); $this->updateEntry($setting, $request->all());*/
return redirect("/admin/settings"); return redirect("/admin/settings");
} }

View File

@ -0,0 +1,31 @@
<?php
/**
* Migration base class with some extra functionality
*/
namespace App\Models\Migrations;
use DB;
use Illuminate\Database\Migrations\Migration as MigrationBase;
class Migration extends MigrationBase
{
/**
* Add rows to a table
* @param $table
* @param $rows
*/
public function addData($table, $rows)
{
foreach ($rows as $row) {
try {
DB::table($table)->insert($row);
} catch (Exception $e) {
# setting already exists
if ($e->getCode() === 23000) {
continue;
}
}
}
}
}

View File

@ -21,8 +21,7 @@ class Pirep extends Model
protected $dates = ['deleted_at']; protected $dates = ['deleted_at'];
public $fillable public $fillable = [
= [
'user_id', 'user_id',
'flight_id', 'flight_id',
'flight_number', 'flight_number',
@ -47,8 +46,7 @@ class Pirep extends Model
* *
* @var array * @var array
*/ */
protected $casts protected $casts = [
= [
'flight_time' => 'integer', 'flight_time' => 'integer',
'level' => 'integer', 'level' => 'integer',
'fuel_used' => 'integer', 'fuel_used' => 'integer',

30
app/Models/Setting.php Normal file
View File

@ -0,0 +1,30 @@
<?php
/**
* Created by IntelliJ IDEA.
* User: nshahzad
* Date: 12/9/17
* Time: 6:24 PM
*/
namespace App\Models;
use Eloquent as Model;
class Setting extends Model
{
public $table = 'settings';
public $fillable = [
'name',
'key',
'value',
'group',
'type',
'options',
'description',
];
public $casts = [
'options' => 'array',
];
}

View File

@ -33,7 +33,6 @@
"symfony/dom-crawler": "v3.4.0", "symfony/dom-crawler": "v3.4.0",
"league/geotools": "0.7.0", "league/geotools": "0.7.0",
"toin0u/geotools-laravel": "^1.0", "toin0u/geotools-laravel": "^1.0",
"anlutro/l4-settings": "0.6.0",
"webpatser/laravel-uuid": "3.0.1", "webpatser/laravel-uuid": "3.0.1",
"chrisbjr/api-guard": "4.1.0", "chrisbjr/api-guard": "4.1.0",
"spatie/laravel-fractal": "5.3.0", "spatie/laravel-fractal": "5.3.0",
@ -47,7 +46,8 @@
"sebastiaanluca/laravel-helpers": "1.0.2", "sebastiaanluca/laravel-helpers": "1.0.2",
"tivie/php-os-detector": "1.1.0", "tivie/php-os-detector": "1.1.0",
"jackiedo/timezonelist": "^5.0", "jackiedo/timezonelist": "^5.0",
"nesbot/carbon": "^1.22", "nesbot/carbon": "1.22.*",
"pragmarx/version": "0.2.1",
"tremby/laravel-git-version": "^1.1", "tremby/laravel-git-version": "^1.1",
"nabeel/laravel-installer": "dev-master", "nabeel/laravel-installer": "dev-master",
"nabeel/vacentral": "dev-master" "nabeel/vacentral": "dev-master"

180
composer.lock generated
View File

@ -4,65 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "459233f5328b1d32bc905cdf05d8b523", "content-hash": "beec22933bfc1504008682e0c932df55",
"packages": [ "packages": [
{
"name": "anlutro/l4-settings",
"version": "0.6.0",
"source": {
"type": "git",
"url": "https://github.com/anlutro/laravel-settings.git",
"reference": "48c9adb5c6c0736f7ace44c29c48759fc1163e0b"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/anlutro/laravel-settings/zipball/48c9adb5c6c0736f7ace44c29c48759fc1163e0b",
"reference": "48c9adb5c6c0736f7ace44c29c48759fc1163e0b",
"shasum": ""
},
"require": {
"illuminate/support": ">=4.1 <6.0",
"php": ">=5.3.0"
},
"require-dev": {
"illuminate/database": ">=4.1 <6.0",
"illuminate/filesystem": ">=4.1 <6.0",
"mockery/mockery": "0.9.*",
"phpunit/phpunit": ">=4.8, <6"
},
"suggest": {
"illuminate/database": "Save settings to a database table.",
"illuminate/filesystem": "Save settings to a JSON file."
},
"type": "library",
"extra": {
"laravel": {
"aliases": {
"Setting": "anlutro\\LaravelSettings\\Facade"
},
"providers": [
"anlutro\\LaravelSettings\\ServiceProvider"
]
}
},
"autoload": {
"psr-4": {
"anlutro\\LaravelSettings\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Andreas Lutro",
"email": "anlutro@gmail.com"
}
],
"description": "Persistent settings in Laravel.",
"time": "2017-11-08T18:16:13+00:00"
},
{ {
"name": "chrisbjr/api-guard", "name": "chrisbjr/api-guard",
"version": "4.1.0", "version": "4.1.0",
@ -3436,6 +3379,127 @@
], ],
"time": "2017-08-03T14:08:16+00:00" "time": "2017-08-03T14:08:16+00:00"
}, },
{
"name": "pragmarx/version",
"version": "v0.2.1",
"source": {
"type": "git",
"url": "https://github.com/antonioribeiro/version.git",
"reference": "fd2eec365012f2f6e00a20f39e23e8efb8913ae9"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/antonioribeiro/version/zipball/fd2eec365012f2f6e00a20f39e23e8efb8913ae9",
"reference": "fd2eec365012f2f6e00a20f39e23e8efb8913ae9",
"shasum": ""
},
"require": {
"laravel/framework": "^5.5",
"php": "^7.0",
"pragmarx/yaml": "^0.1",
"symfony/process": "^3.3"
},
"require-dev": {
"orchestra/testbench": "^3.5",
"phpunit/phpunit": "^6.4"
},
"type": "library",
"extra": {
"component": "package",
"laravel": {
"providers": [
"PragmaRX\\Version\\Package\\ServiceProvider"
],
"aliases": {
"Version": "PragmaRX\\Version\\Package\\Facade"
}
}
},
"autoload": {
"psr-4": {
"PragmaRX\\Version\\Package\\": "src/package",
"PragmaRX\\Version\\Tests\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Antonio Carlos Ribeiro",
"email": "acr@antoniocarlosribeiro.com",
"role": "Creator & Designer"
}
],
"description": "Take control over your Laravel app version",
"keywords": [
"laravel",
"version",
"versioning"
],
"time": "2017-12-02T23:56:29+00:00"
},
{
"name": "pragmarx/yaml",
"version": "v0.1.4",
"source": {
"type": "git",
"url": "https://github.com/antonioribeiro/yaml.git",
"reference": "b510623eb5008cc468e00a31259a3c860dd2b267"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/antonioribeiro/yaml/zipball/b510623eb5008cc468e00a31259a3c860dd2b267",
"reference": "b510623eb5008cc468e00a31259a3c860dd2b267",
"shasum": ""
},
"require": {
"laravel/framework": "^5.5",
"php": "^7.0",
"symfony/yaml": "^3.3"
},
"require-dev": {
"orchestra/testbench": "^3.5",
"phpunit/phpunit": "^6.4"
},
"type": "library",
"extra": {
"component": "package",
"laravel": {
"providers": [
"PragmaRX\\Yaml\\Package\\ServiceProvider"
],
"aliases": {
"Yaml": "PragmaRX\\Yaml\\Package\\Facade"
}
}
},
"autoload": {
"psr-4": {
"PragmaRX\\Yaml\\Package\\": "src/package",
"PragmaRX\\Yaml\\Tests\\": "tests/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Antonio Carlos Ribeiro",
"email": "acr@antoniocarlosribeiro.com",
"role": "Creator & Designer"
}
],
"description": "Load your Laravel config files using yaml",
"keywords": [
"config",
"laravel",
"yaml"
],
"time": "2017-12-05T20:32:21+00:00"
},
{ {
"name": "prettus/l5-repository", "name": "prettus/l5-repository",
"version": "2.6.28", "version": "2.6.28",

View File

@ -58,7 +58,6 @@ return [
InfyOm\Generator\InfyOmGeneratorServiceProvider::class, InfyOm\Generator\InfyOmGeneratorServiceProvider::class,
InfyOm\AdminLTETemplates\AdminLTETemplatesServiceProvider::class, InfyOm\AdminLTETemplates\AdminLTETemplatesServiceProvider::class,
Zizaco\Entrust\EntrustServiceProvider::class, Zizaco\Entrust\EntrustServiceProvider::class,
anlutro\LaravelSettings\ServiceProvider::class,
Spatie\Fractal\FractalServiceProvider::class, Spatie\Fractal\FractalServiceProvider::class,
SebastiaanLuca\Helpers\Methods\GlobalHelpersServiceProvider::class, SebastiaanLuca\Helpers\Methods\GlobalHelpersServiceProvider::class,
SebastiaanLuca\Helpers\Collections\CollectionMacrosServiceProvider::class, SebastiaanLuca\Helpers\Collections\CollectionMacrosServiceProvider::class,

View File

@ -16,25 +16,6 @@ return [
*/ */
'skin' => 'default', 'skin' => 'default',
/**
* Start date. Set the date of when your VA has started
* Used as an anchor point for some financials and things
*
* YYYY-MM-DD format
*/
'start_date' => '2017-07-07',
/**
* Pick one of:
* dollar, euro, gbp, yen, jpy, rupee, ruble
*/
'currency' => 'dollar',
/**
* Restrict showing flights from the user's current airport
*/
'only_flights_from_current' => false,
/** /**
* Your vaCentral API key * Your vaCentral API key
*/ */

View File

@ -1,46 +0,0 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Foundation\Application;
use Illuminate\Support\Facades\Config;
class CreateSettingsTable extends Migration
{
public function __construct()
{
$this->tablename = Config::get('settings.table');
$this->keyColumn = Config::get('settings.keyColumn');
$this->valueColumn = Config::get('settings.valueColumn');
}
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create($this->tablename, function (Blueprint $table) {
$table->increments('id');
$table->string($this->keyColumn)->index();
$table->text($this->valueColumn);
$table->timestamps();
});
#Setting::set('currency', 'dollar');
#Setting::set('currency_descrip', 'Currency to use');
#Setting::save();
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop($this->tablename);
}
}

View File

@ -1,8 +1,8 @@
<?php <?php
use App\Models\Migrations\Migration;
use Illuminate\Support\Facades\Schema; use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration class CreateUsersTable extends Migration
{ {
@ -81,7 +81,21 @@ class CreateUsersTable extends Migration
}); });
# create a default user/role # create a default user/role
$roles = [
[
'id' => 1,
'name' => 'admin',
'display_name' => 'Administrators',
],
[
'id' => 2,
'name' => 'user',
'display_name' => 'Pilot'
],
];
$this->addData('roles', $roles);
} }
/** /**

View File

@ -0,0 +1,84 @@
<?php
use App\Models\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateSettingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('settings', function (Blueprint $table) {
$table->increments('id');
$table->integer('order')->default(1);
$table->string('name')->default('');
$table->string('key');
$table->string('value');
$table->string('group')->default('general');
$table->text('type')->default('text');
$table->text('options')->nullable();
$table->text('description')->nullable();
$table->timestamps();
$table->unique('key');
});
/**
* Initial default settings
*/
$settings = [
[
'order' => 1,
'name' => 'Start Date',
'group' => '',
'key' => 'general.start_date',
'value' => '',
'type' => 'date',
'description' => 'The date your VA started',
],
[
'order' => 2,
'name' => 'Currency to Use',
'group' => 'general',
'key' => 'general.currency',
'value' => 'dollar',
'type' => 'text',
'options' => 'dollar,euro,gbp,yen,jpy,rupee,ruble',
'description' => 'Currency to show in the interface',
],
[
'order' => 10,
'name' => 'Flights from Current',
'group' => 'flights',
'key' => 'flights.only_flights_from_current',
'value' => 'true',
'type' => 'boolean',
'description' => 'Only allow flights from current location',
],
[
'order' => 20,
'name' => 'Hide Inactive Pilots',
'group' => 'pilots',
'key' => 'pilots.hide_inactive',
'value' => 'true',
'type' => 'boolean',
'description' => 'Don\'t show inactive pilots in the public view',
],
];
$this->addData('settings', $settings);
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop($this->tablename);
}
}

View File

@ -1,12 +1,4 @@
# #
roles:
- id: 1
name: admin
display_name: Administrators
- id: 2
name: user
display_name: Pilot
users: users:
- id: 1 - id: 1
name: Admin User name: Admin User

View File

@ -3,14 +3,6 @@
# want to modify or erase any of this here # want to modify or erase any of this here
# #
roles:
- id: 1
name: admin
display_name: Administrators
- id: 2
name: user
display_name: Pilot
ranks: ranks:
- id: 1 - id: 1
name: New Pilot name: New Pilot

View File

@ -35,6 +35,7 @@
class="pe-7s-map-marker"></i>airports</a></li> class="pe-7s-map-marker"></i>airports</a></li>
<li><a href="{!! url('/admin/users') !!}"><i class="pe-7s-users"></i>users</a></li> <li><a href="{!! url('/admin/users') !!}"><i class="pe-7s-users"></i>users</a></li>
<li><a href="{!! url('/admin/ranks') !!}"><i class="pe-7s-id"></i>ranks</a></li> <li><a href="{!! url('/admin/ranks') !!}"><i class="pe-7s-id"></i>ranks</a></li>
<li><a href="{!! url('/admin/settings') !!}"><i class="pe-7s-id"></i>settings</a></li>
</ul> </ul>
</div> </div>
</li> </li>

View File

@ -1,23 +1,10 @@
@extends('admin.app') @extends('admin.app')
@section('title', 'Settings')
@section('content') @section('content')
<section class="content-header"> <div class="card">
<h1 class="pull-left">Settings</h1>
{{--<h1 class="pull-right">
<a class="btn btn-primary pull-right" style="margin-top: -10px;margin-bottom: 5px" href="{!! route('admin.settings.create') !!}">Add New</a>
</h1>--}}
</section>
<div class="content">
<div class="clearfix"></div>
@include('flash::message') @include('flash::message')
<div class="clearfix"></div>
<div class="box box-primary">
<div class="box-body">
@include('admin.settings.table') @include('admin.settings.table')
</div> </div>
</div>
</div>
@endsection @endsection

View File

@ -8,14 +8,6 @@ airlines:
created_at: now created_at: now
updated_at: now updated_at: now
roles:
- id: 1
name: admin
display_name: Administrators
- id: 2
name: user
display_name: Pilot
users: users:
- id: 1 - id: 1
name: Admin User name: Admin User