Closes #137 - fast component status updates.
This commit is contained in:
@@ -12,4 +12,26 @@ $(function() {
|
||||
|
||||
$('[data-toggle="tooltip"]').tooltip();
|
||||
|
||||
$('button.close').on('click', function() {
|
||||
$(this).parents('div.alert').addClass('hide');
|
||||
});
|
||||
|
||||
// Toggle inline component statuses.
|
||||
$('form.component-inline').on('click', 'input[type=radio]', function() {
|
||||
var $form = $(this).parents('form');
|
||||
var formData = $form.serializeObject();
|
||||
|
||||
$.ajax({
|
||||
async: true,
|
||||
url: '/dashboard/api/components/' + formData['component_id'],
|
||||
type: 'POST',
|
||||
data: formData,
|
||||
success: function(component) {
|
||||
$('.alert').removeClass('hide');
|
||||
},
|
||||
error: function(a, b, c) {
|
||||
alert('Something went wrong updating the component.');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class DashAPIController extends Controller
|
||||
{
|
||||
/**
|
||||
* Updates a component with the entered info.
|
||||
* @param Component $component
|
||||
* @return array
|
||||
*/
|
||||
public function postUpdateComponent(Component $component)
|
||||
{
|
||||
$componentData = Input::all();
|
||||
unset($componentData['_token']);
|
||||
if ($component->update($componentData))
|
||||
{
|
||||
return $component;
|
||||
}
|
||||
else
|
||||
{
|
||||
App::abort(500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,10 @@ class DashboardController extends Controller
|
||||
public function showDashboard()
|
||||
{
|
||||
// TODO: Find steps needed to complete setup.
|
||||
return View::make('dashboard.index');
|
||||
$components = Component::all();
|
||||
return View::make('dashboard.index')->with([
|
||||
'components' => $components
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -33,4 +33,10 @@ Route::group(['before' => 'auth', 'prefix' => 'dashboard'], function () {
|
||||
// User Settings
|
||||
Route::get('user', ['as' => 'dashboard.user', 'uses' => 'DashUserController@showUser']);
|
||||
Route::post('user', 'DashUserController@postUser');
|
||||
|
||||
// Internal API.
|
||||
// This should only be used for making requests within the dashboard.
|
||||
Route::group(['prefix' => 'api'], function() {
|
||||
Route::post('components/{component}', 'DashAPIController@postUpdateComponent');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,7 +9,42 @@
|
||||
<div class="content-wrapper">
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<p class='lead'>Let's put cool things here.</p>
|
||||
<h4 class='sub-header'>Component Statuses</h4>
|
||||
<div class='panel panel-default'>
|
||||
<div class='list-group'>
|
||||
@forelse($components as $component)
|
||||
<div class='list-group-item'>
|
||||
{{ Form::open(['class' => 'component-inline']) }}
|
||||
<div class='row striped-list-item'>
|
||||
<div class='col-md-4'>
|
||||
<strong>{{ $component->name }}</strong>
|
||||
</div>
|
||||
<div class='col-md-8 text-right'>
|
||||
@foreach(Lang::get('cachet.component.status') as $statusID => $status)
|
||||
<div class='radio-inline'>
|
||||
<label>
|
||||
<input type='radio' name='status' value='{{ $statusID }}' {{ $component->status === $statusID ? "checked" : null }} />
|
||||
{{ $status }}
|
||||
</label>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
<input type='hidden' name='component_id' value='{{ $component->id }}' />
|
||||
{{ Form::close() }}
|
||||
</div>
|
||||
@empty
|
||||
<div class='list-group-item text-danger'>You should add a component.</div>
|
||||
@endforelse
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='alert alert-success alert-dismissable hide fade in out' role='alert'>
|
||||
<button type='button' class='close'>
|
||||
<span aria-hidden='true'>×</span>
|
||||
</button>
|
||||
Component updated.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user