#23 initial scaffolding for rankings

This commit is contained in:
Nabeel Shahzad 2017-06-21 12:10:25 -05:00
parent 381a713882
commit b5c41626c5
16 changed files with 535 additions and 1 deletions

View File

@ -42,7 +42,6 @@ test:
vendor/bin/phpunit --testdox tests
schema:
#php artisan infyom:scaffold Airlines --fieldsFile=database/schema/airlines.json
#php artisan infyom:scaffold Aircraft --fieldsFile=database/schema/aircraft.json
echo ""

View File

@ -0,0 +1,156 @@
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Requests\CreateRankingRequest;
use App\Http\Requests\UpdateRankingRequest;
use App\Repositories\RankingRepository;
use App\Http\Controllers\AppBaseController as InfyOmBaseController;
use Illuminate\Http\Request;
use Flash;
use Prettus\Repository\Criteria\RequestCriteria;
use Response;
class RankingController extends InfyOmBaseController
{
/** @var RankingRepository */
private $rankingRepository;
public function __construct(RankingRepository $rankingRepo)
{
$this->rankingRepository = $rankingRepo;
}
/**
* Display a listing of the Ranking.
*
* @param Request $request
* @return Response
*/
public function index(Request $request)
{
$this->rankingRepository->pushCriteria(new RequestCriteria($request));
$rankings = $this->rankingRepository->all();
return view('admin.rankings.index')
->with('rankings', $rankings);
}
/**
* Show the form for creating a new Ranking.
*
* @return Response
*/
public function create()
{
return view('admin.rankings.create');
}
/**
* Store a newly created Ranking in storage.
*
* @param CreateRankingRequest $request
*
* @return Response
*/
public function store(CreateRankingRequest $request)
{
$input = $request->all();
$ranking = $this->rankingRepository->create($input);
Flash::success('Ranking saved successfully.');
return redirect(route('admin.rankings.index'));
}
/**
* Display the specified Ranking.
*
* @param int $id
*
* @return Response
*/
public function show($id)
{
$ranking = $this->rankingRepository->findWithoutFail($id);
if (empty($ranking)) {
Flash::error('Ranking not found');
return redirect(route('admin.rankings.index'));
}
return view('admin.rankings.show')->with('ranking', $ranking);
}
/**
* Show the form for editing the specified Ranking.
*
* @param int $id
*
* @return Response
*/
public function edit($id)
{
$ranking = $this->rankingRepository->findWithoutFail($id);
if (empty($ranking)) {
Flash::error('Ranking not found');
return redirect(route('admin.rankings.index'));
}
return view('admin.rankings.edit')->with('ranking', $ranking);
}
/**
* Update the specified Ranking in storage.
*
* @param int $id
* @param UpdateRankingRequest $request
*
* @return Response
*/
public function update($id, UpdateRankingRequest $request)
{
$ranking = $this->rankingRepository->findWithoutFail($id);
if (empty($ranking)) {
Flash::error('Ranking not found');
return redirect(route('admin.rankings.index'));
}
$ranking = $this->rankingRepository->update($request->all(), $id);
Flash::success('Ranking updated successfully.');
return redirect(route('admin.rankings.index'));
}
/**
* Remove the specified Ranking from storage.
*
* @param int $id
*
* @return Response
*/
public function destroy($id)
{
$ranking = $this->rankingRepository->findWithoutFail($id);
if (empty($ranking)) {
Flash::error('Ranking not found');
return redirect(route('admin.rankings.index'));
}
$this->rankingRepository->delete($id);
Flash::success('Ranking deleted successfully.');
return redirect(route('admin.rankings.index'));
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
use App\Models\Ranking;
class CreateRankingRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return Ranking::$rules;
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace App\Http\Requests;
use App\Http\Requests\Request;
use App\Models\Ranking;
class UpdateRankingRequest extends Request
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return Ranking::$rules;
}
}

42
app/Models/Ranking.php Normal file
View File

@ -0,0 +1,42 @@
<?php
namespace App\Models;
use Eloquent as Model;
/**
* Class Ranking
* @package App\Models
*/
class Ranking extends Model
{
public $table = 'rankings';
public $fillable = [
'name',
'hours',
'auto_approve_acars',
'auto_approve_manual',
'auto_promote'
];
/**
* The attributes that should be casted to native types.
*
* @var array
*/
protected $casts = [
'name' => 'string',
'hours' => 'integer'
];
/**
* Validation rules
*
* @var array
*/
public static $rules = [
];
}

View File

@ -0,0 +1,24 @@
<?php
namespace App\Repositories;
use App\Models\Ranking;
use InfyOm\Generator\Common\BaseRepository;
class RankingRepository extends BaseRepository
{
/**
* @var array
*/
protected $fieldSearchable = [
];
/**
* Configure the Model
**/
public function model()
{
return Ranking::class;
}
}

View File

@ -0,0 +1,36 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
class CreateRankingsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('rankings', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->integer('hours')->default(0);
$table->bool('auto_approval_acars')->default(false);
$table->bool('auto_approval_manual')->default(false);
$table->bool('auto_promote')->default(true);
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('rankings');
}
}

View File

@ -17,3 +17,8 @@ elixir(mix => {
mix.sass('app.scss')
.webpack('app.js');
});
gulp.task('reset', function() {
exec('php artisan migrate:refresh --seed --seeder DevelopmentSeeder');
});

View File

@ -0,0 +1,24 @@
@extends('layouts.app')
@section('content')
<section class="content-header">
<h1>
$MODEL_NAME_HUMAN$
</h1>
</section>
<div class="content">
@include('adminlte-templates::common.errors')
<div class="box box-primary">
<div class="box-body">
<div class="row">
{!! Form::open(['route' => 'admin.rankings.store']) !!}
@include('admin.rankings.fields')
{!! Form::close() !!}
</div>
</div>
</div>
</div>
@endsection

View File

@ -0,0 +1,23 @@
@extends('layouts.app')
@section('content')
<section class="content-header">
<h1>
$MODEL_NAME_HUMAN$
</h1>
</section>
<div class="content">
@include('adminlte-templates::common.errors')
<div class="box box-primary">
<div class="box-body">
<div class="row">
{!! Form::model($ranking, ['route' => ['admin.rankings.update', $ranking->$PRIMARY_KEY_NAME$], 'method' => 'patch']) !!}
@include('admin.rankings.fields')
{!! Form::close() !!}
</div>
</div>
</div>
</div>
@endsection

View File

@ -0,0 +1,35 @@
<!-- Name Field -->
<div class="form-group col-sm-6">
{!! Form::label('name', 'Name:') !!}
{!! Form::text('name', null, ['class' => 'form-control']) !!}
</div>
<!-- Hours Field -->
<div class="form-group col-sm-6">
{!! Form::label('hours', 'Hours:') !!}
{!! Form::text('hours', null, ['class' => 'form-control']) !!}
</div>
<!-- Auto Approve Acars Field -->
<div class="form-group col-sm-6">
{!! Form::label('auto_approve_acars', 'Auto Approve Acars:') !!}
{!! Form::text('auto_approve_acars', null, ['class' => 'form-control']) !!}
</div>
<!-- Auto Approve Manual Field -->
<div class="form-group col-sm-6">
{!! Form::label('auto_approve_manual', 'Auto Approve Manual:') !!}
{!! Form::text('auto_approve_manual', null, ['class' => 'form-control']) !!}
</div>
<!-- Auto Promote Field -->
<div class="form-group col-sm-6">
{!! Form::label('auto_promote', 'Auto Promote:') !!}
{!! Form::text('auto_promote', null, ['class' => 'form-control']) !!}
</div>
<!-- Submit Field -->
<div class="form-group col-sm-12">
{!! Form::submit('Save', ['class' => 'btn btn-primary']) !!}
<a href="{!! route('admin.rankings.index') !!}" class="btn btn-default">Cancel</a>
</div>

View File

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

View File

@ -0,0 +1,19 @@
@extends('layouts.app')
@section('content')
<section class="content-header">
<h1>
$MODEL_NAME_HUMAN$
</h1>
</section>
<div class="content">
<div class="box box-primary">
<div class="box-body">
<div class="row" style="padding-left: 20px">
@include('admin.rankings.show_fields')
<a href="{!! route('admin.rankings.index') !!}" class="btn btn-default">Back</a>
</div>
</div>
</div>
</div>
@endsection

View File

@ -0,0 +1,48 @@
<!-- Id Field -->
<div class="form-group">
{!! Form::label('id', 'Id:') !!}
<p>{!! $ranking->id !!}</p>
</div>
<!-- Name Field -->
<div class="form-group">
{!! Form::label('name', 'Name:') !!}
<p>{!! $ranking->name !!}</p>
</div>
<!-- Hours Field -->
<div class="form-group">
{!! Form::label('hours', 'Hours:') !!}
<p>{!! $ranking->hours !!}</p>
</div>
<!-- Auto Approve Acars Field -->
<div class="form-group">
{!! Form::label('auto_approve_acars', 'Auto Approve Acars:') !!}
<p>{!! $ranking->auto_approve_acars !!}</p>
</div>
<!-- Auto Approve Manual Field -->
<div class="form-group">
{!! Form::label('auto_approve_manual', 'Auto Approve Manual:') !!}
<p>{!! $ranking->auto_approve_manual !!}</p>
</div>
<!-- Auto Promote Field -->
<div class="form-group">
{!! Form::label('auto_promote', 'Auto Promote:') !!}
<p>{!! $ranking->auto_promote !!}</p>
</div>
<!-- Created At Field -->
<div class="form-group">
{!! Form::label('created_at', 'Created At:') !!}
<p>{!! $ranking->created_at !!}</p>
</div>
<!-- Updated At Field -->
<div class="form-group">
{!! Form::label('updated_at', 'Updated At:') !!}
<p>{!! $ranking->updated_at !!}</p>
</div>

View File

@ -0,0 +1,30 @@
<table class="table table-responsive" id="rankings-table">
<thead>
<th>Name</th>
<th>Hours</th>
<th>Auto Approve Acars</th>
<th>Auto Approve Manual</th>
<th>Auto Promote</th>
<th colspan="3">Action</th>
</thead>
<tbody>
@foreach($rankings as $ranking)
<tr>
<td>{!! $ranking->name !!}</td>
<td>{!! $ranking->hours !!}</td>
<td>{!! $ranking->auto_approve_acars !!}</td>
<td>{!! $ranking->auto_approve_manual !!}</td>
<td>{!! $ranking->auto_promote !!}</td>
<td>
{!! Form::open(['route' => ['admin.rankings.destroy', $ranking->$PRIMARY_KEY_NAME$], 'method' => 'delete']) !!}
<div class='btn-group'>
<a href="{!! route('admin.rankings.show', [$ranking->$PRIMARY_KEY_NAME$]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-eye-open"></i></a>
<a href="{!! route('admin.rankings.edit', [$ranking->$PRIMARY_KEY_NAME$]) !!}" class='btn btn-default btn-xs'><i class="glyphicon glyphicon-edit"></i></a>
{!! Form::button('<i class="glyphicon glyphicon-trash"></i>', ['type' => 'submit', 'class' => 'btn btn-danger btn-xs', 'onclick' => "return confirm('Are you sure?')"]) !!}
</div>
{!! Form::close() !!}
</td>
</tr>
@endforeach
</tbody>
</table>

View File

@ -17,3 +17,13 @@ Route::group([
Auth::routes();
require base_path('routes/admin.php');
Route::get('admin/rankings', ['as'=> 'admin.rankings.index', 'uses' => 'RankingController@index']);
Route::post('admin/rankings', ['as'=> 'admin.rankings.store', 'uses' => 'RankingController@store']);
Route::get('admin/rankings/create', ['as'=> 'admin.rankings.create', 'uses' => 'RankingController@create']);
Route::put('admin/rankings/{rankings}', ['as'=> 'admin.rankings.update', 'uses' => 'RankingController@update']);
Route::patch('admin/rankings/{rankings}', ['as'=> 'admin.rankings.update', 'uses' => 'RankingController@update']);
Route::delete('admin/rankings/{rankings}', ['as'=> 'admin.rankings.destroy', 'uses' => 'RankingController@destroy']);
Route::get('admin/rankings/{rankings}', ['as'=> 'admin.rankings.show', 'uses' => 'RankingController@show']);
Route::get('admin/rankings/{rankings}/edit', ['as'=> 'admin.rankings.edit', 'uses' => 'RankingController@edit']);