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.
*