Create components from the dashboard
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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']);
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
<div role='tabpanel'>
|
||||
<ul class="nav nav-tabs" role='tablist'>
|
||||
<li role='presentation' class='active'><a data-toggle='tab' role='tab' href="#active">Active Components</a></li>
|
||||
<li role='presentation' class=''><a data-toggle='tab' role='tab' href="#create">Create Component</a></li>
|
||||
</ul>
|
||||
<div class="tab-content">
|
||||
<div role='tabpanel' class='tab-pane active' id="active">
|
||||
@@ -38,8 +37,7 @@
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
<div role='tabpanel' class='tab-pane' id="create">
|
||||
|
||||
<div class='row'>
|
||||
<div class='col-md-12'>
|
||||
<h3>Create a component</h3>
|
||||
@@ -47,7 +45,17 @@
|
||||
</div>
|
||||
<div class='row'>
|
||||
<div class="col-md-12">
|
||||
{{ Form::open(['name' => 'CreateComponentForm', 'class' => 'form-vertical', 'role' => 'form']) }}
|
||||
@if($component = Session::get('component'))
|
||||
<div class='alert alert-{{ $component->isValid() ? "success" : "danger" }}'>
|
||||
@if($component->isValid())
|
||||
<strong>Awesome.</strong> Component added.
|
||||
@else
|
||||
<strong>Whoops.</strong> Something went wrong with the component. {{ $component->getErrors() }}
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<form name='CreateComponentForm' class='form-vertical' role='form' action='/dashboard/components/create' method='POST'>
|
||||
<fieldset>
|
||||
<div class='form-group'>
|
||||
<label for='incident-name'>Component Name</label>
|
||||
@@ -58,8 +66,10 @@
|
||||
<textarea name='component[description]' class='form-control' rows='5'></textarea>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
{{ Form::close() }}
|
||||
<input type='hidden' name='component[user_id]' value='{{ Auth::user()->id }}' />
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<div class='row'>
|
||||
<div class='col-md-12'>
|
||||
@if($incident = Session::get('incident'))
|
||||
<div class='alert alert-{{ $incident->isValid() ? "success" : "error" }}'>
|
||||
<div class='alert alert-{{ $incident->isValid() ? "success" : "danger" }}'>
|
||||
@if($incident->isValid())
|
||||
<strong>Awesome.</strong> Incident added.
|
||||
@else
|
||||
@@ -57,7 +57,9 @@
|
||||
<textarea name='incident[message]' class='form-control' rows='5'></textarea>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
<input type='hidden' name='component[user_id]' value='{{ Auth::user()->id }}' />
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user