Merge pull request #647 from cachethq/change-incident-timestamps

Allow changing of incident dates. Closes #615
This commit is contained in:
James Brooks
2015-05-19 20:17:24 +01:00
11 changed files with 92 additions and 24 deletions
@@ -13,6 +13,7 @@
namespace CachetHQ\Cachet\Http\Controllers\Admin;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Http\Controllers\AbstractController;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup;
@@ -20,8 +21,10 @@ use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\IncidentTemplate;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
use Jenssegers\Date\Date;
class IncidentController extends AbstractController
{
@@ -115,6 +118,12 @@ class IncidentController extends AbstractController
$incidentData['user_id'] = Auth::user()->id;
$componentStatus = array_pull($incidentData, 'component_status');
if (array_has($incidentData, 'created_at')) {
$incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
$incidentData['created_at'] = $incidentDate;
$incidentData['updated_at'] = $incidentDate;
}
$incident = Incident::create($incidentData);
if (!$incident->isValid()) {
@@ -286,6 +295,13 @@ class IncidentController extends AbstractController
{
$incidentData = Binput::get('incident');
$incidentData['user_id'] = Auth::user()->id;
if (array_has($incidentData, 'created_at')) {
$incidentDate = Date::createFromFormat('d/m/Y H:i', $incidentData['created_at'], Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
$incidentData['created_at'] = $incidentDate;
$incidentData['updated_at'] = $incidentDate;
}
$incident->update($incidentData);
if (!$incident->isValid()) {
+10 -1
View File
@@ -54,7 +54,16 @@ class Incident extends Model implements HasPresenter
*
* @var string[]
*/
protected $fillable = ['user_id', 'component_id', 'name', 'status', 'message', 'scheduled_at'];
protected $fillable = [
'user_id',
'component_id',
'name',
'status',
'message',
'scheduled_at',
'created_at',
'updated_at',
];
/**
* The accessors to append to the model's serialized form.
+10
View File
@@ -74,6 +74,16 @@ class IncidentPresenter extends BasePresenter
->format('l jS F Y H:i:s'));
}
/**
* Formats the created_at time ready to be used by bootstrap-datetimepicker.
*
* @return string
*/
public function created_at_datetimepicker()
{
return $this->wrappedObject->created_at->setTimezone($this->tz)->format('d/m/Y H:i');
}
/**
* Present formatted date time.
*
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+2 -2
View File
@@ -1,4 +1,4 @@
{
"dist/css/all.css": "dist/css/all-11e30ad0.css",
"dist/js/all.js": "dist/js/all-5d9782c6.js"
"dist/css/all.css": "dist/css/all-85d5201e.css",
"dist/js/all.js": "dist/js/all-030dc0bd.js"
}
+15
View File
@@ -126,6 +126,21 @@ $(function() {
}
});
$('input[rel=datepicker-any]').datetimepicker({
format: "DD/MM/YYYY HH:mm",
sideBySide: true,
icons: {
time: 'ion-clock',
date: 'ion-android-calendar',
up: 'ion-ios-arrow-up',
down: 'ion-ios-arrow-down',
previous: 'ion-ios-arrow-left',
next: 'ion-ios-arrow-right',
today: 'ion-android-home',
clear: 'ion-trash-a',
}
});
// Sortable components.
var componentList = document.getElementById("component-list");
if (componentList) {
+7 -6
View File
@@ -37,12 +37,13 @@ return [
// Incidents form fields
'incidents' => [
'name' => 'Name',
'status' => 'Status',
'component' => 'Component',
'message' => 'Message',
'message-help' => 'You may also use Markdown.',
'scheduled_at' => 'When to schedule the maintenance for?',
'name' => 'Name',
'status' => 'Status',
'component' => 'Component',
'message' => 'Message',
'message-help' => 'You may also use Markdown.',
'scheduled_at' => 'When to schedule the maintenance for?',
'incident_time' => 'When did this incident occur?',
'templates' => [
'name' => 'Name',
@@ -94,6 +94,11 @@
<textarea name="incident[message]" class="form-control autosize" rows="5" required>{{ Input::old('incident.message') }}</textarea>
</div>
</div>
<div class="form-group">
<label>{{ trans('forms.incidents.incident_time') }}</label>
<input type="text" name="incident[created_at]" class="form-control" rel="datepicker-any">
<span class="help-block">{{ trans('forms.optional') }}</span>
</div>
</fieldset>
<div class="form-group">
@@ -50,6 +50,11 @@
<textarea name="incident[message]" class="form-control autosize" rows="5" required>{{ $incident->message }}</textarea>
</div>
</div>
<div class="form-group">
<label>{{ trans('forms.incidents.incident_time') }}</label>
<input type="text" name="incident[created_at]" class="form-control" rel="datepicker-any" value="{{ $incident->created_at_datetimepicker }}">
<span class="help-block">{{ trans('forms.optional') }}</span>
</div>
</fieldset>
<input type="hidden" name="incident[id]" value={{$incident->id}}>