From 5420ff91f7588d59db3a5b51b25f41eb7202d45d Mon Sep 17 00:00:00 2001 From: James Brooks Date: Sat, 13 Dec 2014 12:43:11 +0000 Subject: [PATCH] Create components from the dashboard --- app/controllers/DashboardController.php | 9 +++++++-- app/models/Component.php | 6 +++--- app/routes/dashboard.php | 2 ++ app/views/dashboard/components.blade.php | 20 +++++++++++++++----- app/views/dashboard/index.blade.php | 4 +++- 5 files changed, 30 insertions(+), 11 deletions(-) diff --git a/app/controllers/DashboardController.php b/app/controllers/DashboardController.php index 976351a0..14aca739 100644 --- a/app/controllers/DashboardController.php +++ b/app/controllers/DashboardController.php @@ -11,8 +11,6 @@ class DashboardController extends Controller { public function createIncidentAction() { $_incident = Input::get('incident'); - $_incident['user_id'] = Auth::user()->id; - $incident = Incident::create($_incident); return Redirect::back()->with('incident', $incident); @@ -31,6 +29,13 @@ class DashboardController extends Controller { ]); } + public function createComponentAction() { + $_component = Input::get('component'); + $component = Component::create($_component); + + return Redirect::back()->with('component', $component); + } + /** * Shows the incidents view. * @return \Illuminate\View\View diff --git a/app/models/Component.php b/app/models/Component.php index 302816e9..6e386d07 100644 --- a/app/models/Component.php +++ b/app/models/Component.php @@ -6,12 +6,12 @@ class Component extends Eloquent implements \Dingo\Api\Transformer\Transformable use ValidatingTrait; protected $rules = [ - 'user_id' => 'required|integer', + 'user_id' => 'integer|required', 'name' => 'required', - 'status' => 'required|integer' + 'status' => 'integer' ]; - protected $fillable = ['name', 'description', 'status']; + protected $fillable = ['name', 'description', 'status', 'user_id']; /** * Lookup all of the incidents reported on the component. diff --git a/app/routes/dashboard.php b/app/routes/dashboard.php index 93bc6995..43ce9a09 100644 --- a/app/routes/dashboard.php +++ b/app/routes/dashboard.php @@ -5,6 +5,8 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard'], function() { Route::post('/', 'DashboardController@createIncidentAction'); Route::get('components', ['as' => 'dashboard.components', 'uses' => 'DashboardController@showComponents']); + Route::post('components/create', 'DashboardController@createComponentAction'); + Route::get('incidents', ['as' => 'dashboard.incidents', 'uses' => 'DashboardController@showIncidents']); Route::get('metrics', ['as' => 'dashboard.metrics', 'uses' => 'DashboardController@showMetrics']); Route::get('notifications', ['as' => 'dashboard.notifications', 'uses' => 'DashboardController@showNotifications']); diff --git a/app/views/dashboard/components.blade.php b/app/views/dashboard/components.blade.php index aa0b9a3f..eda5c340 100644 --- a/app/views/dashboard/components.blade.php +++ b/app/views/dashboard/components.blade.php @@ -10,7 +10,6 @@
@@ -38,8 +37,7 @@ @endforeach
-
-
+

Create a component

@@ -47,7 +45,17 @@
- {{ Form::open(['name' => 'CreateComponentForm', 'class' => 'form-vertical', 'role' => 'form']) }} + @if($component = Session::get('component')) +
+ @if($component->isValid()) + Awesome. Component added. + @else + Whoops. Something went wrong with the component. {{ $component->getErrors() }} + @endif +
+ @endif + +
@@ -58,8 +66,10 @@
+ - {{ Form::close() }} + +
diff --git a/app/views/dashboard/index.blade.php b/app/views/dashboard/index.blade.php index 5b2a62fc..581dad7e 100644 --- a/app/views/dashboard/index.blade.php +++ b/app/views/dashboard/index.blade.php @@ -22,7 +22,7 @@
@if($incident = Session::get('incident')) -
+
@if($incident->isValid()) Awesome. Incident added. @else @@ -57,7 +57,9 @@
+ + {{ Form::close() }}