Add admin backend to edit incident and change status
Also fixes Status Board display on homepage to show correct status on each day. It was previously reusing the currnent status for all previous days on which the incidents were open.
This commit is contained in:
@@ -42,12 +42,23 @@ class StatusBoard_Incident extends StatusBoard_DatabaseObject {
|
||||
return $this->current_status;
|
||||
}
|
||||
|
||||
public function statusAtTime($time) {
|
||||
$database = StatusBoard_Main::instance()->database();
|
||||
$row = $database->selectOne('SELECT `status` FROM `incidentstatus` WHERE `incident`=:incident AND ctime < :time ORDER BY ctime DESC LIMIT 1', array(
|
||||
array('name' => 'incident', 'value' => $this->id, 'type' => PDO::PARAM_INT),
|
||||
array('name' => 'time', 'value' => $time, 'type' => PDO::PARAM_INT),
|
||||
)
|
||||
);
|
||||
|
||||
return $row['status'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the status of the most severe incident in the given set
|
||||
*
|
||||
* @param array(StatusBoard_Incident) $incidents
|
||||
*/
|
||||
public static function highestSeverityStatus(array $incidents) {
|
||||
public static function highestSeverityStatus(array $incidents, $time = null) {
|
||||
if ( ! $incidents) {
|
||||
return StatusBoard_Status::STATUS_Resolved;
|
||||
}
|
||||
@@ -55,7 +66,13 @@ class StatusBoard_Incident extends StatusBoard_DatabaseObject {
|
||||
// Check for the highest severity incident.
|
||||
$status = StatusBoard_Status::STATUS_Maintenance;
|
||||
foreach ($incidents as $incident) {
|
||||
$incident_status = $incident->currentStatus();
|
||||
$incident_status = null;
|
||||
if ($time) {
|
||||
$incident_status = $incident->statusAtTime($time);
|
||||
} else {
|
||||
$incident_status = $incident->currentStatus();
|
||||
}
|
||||
|
||||
if (StatusBoard_Status::isMoreSevere($status, $incident_status)) {
|
||||
$status = $incident_status;
|
||||
}
|
||||
@@ -72,6 +89,17 @@ class StatusBoard_Incident extends StatusBoard_DatabaseObject {
|
||||
return $this->statuses;
|
||||
}
|
||||
|
||||
public function changeStatus($status, $description) {
|
||||
if ($this->statuses === null) {
|
||||
$this->statuses = StatusBoard_IncidentStatus::all_for('incident', $this->id);
|
||||
}
|
||||
|
||||
$new_status = StatusBoard_IncidentStatus::newForIncident($this, $status, $description);
|
||||
$this->statuses[] = $new_status;
|
||||
|
||||
return $new_status;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -10,9 +10,21 @@ class StatusBoard_IncidentStatus extends StatusBoard_DatabaseObject {
|
||||
protected $_db_description;
|
||||
protected $_db_ctime;
|
||||
|
||||
protected function all_for_incident(StatusBoard_Incident $incident) {
|
||||
public function all_for_incident(StatusBoard_Incident $incident) {
|
||||
return static::all_for('incident', $incident->id);
|
||||
}
|
||||
|
||||
public function newForIncident(StatusBoard_Incident $incident, $status, $description) {
|
||||
$new_status = new self();
|
||||
$new_status->incident = $incident->id;
|
||||
$new_status->status = $status;
|
||||
$new_status->description = $description;
|
||||
$new_status->ctime = time();
|
||||
|
||||
$new_status->create();
|
||||
|
||||
return $new_status;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -24,11 +24,55 @@ try {
|
||||
throw new StatusBoard_Exception_FileNotFound();
|
||||
}
|
||||
|
||||
if ($request->exists('do')) {
|
||||
$activity = $request->get('do');
|
||||
switch ($activity) {
|
||||
|
||||
case 'edit': {
|
||||
$reference = StatusBoard_Main::issetelse($_POST['reference'], 'Sihnon_Exception_InvalidParameters');
|
||||
$description = StatusBoard_Main::issetelse($_POST['description'], 'Sihnon_Exception_InvalidParameters');
|
||||
|
||||
if ($reference) {
|
||||
$incident->reference = $reference;
|
||||
}
|
||||
if ($description) {
|
||||
$incident->description = $description;
|
||||
}
|
||||
if ($reference || $description) {
|
||||
$incident->save();
|
||||
$messages[] = array(
|
||||
'severity' => 'success',
|
||||
'content' => 'The incident was updated succesfully.',
|
||||
);
|
||||
} else {
|
||||
$messages[] = 'No changes were necessary.';
|
||||
}
|
||||
|
||||
} break;
|
||||
|
||||
case 'change-status': {
|
||||
$status = StatusBoard_Main::issetelse($_POST['status'], 'Sihnon_Exception_InvalidParameters');
|
||||
$description = StatusBoard_Main::issetelse($_POST['description'], 'Sihnon_Exception_InvalidParameters');
|
||||
|
||||
$incident->changeStatus($status, $description);
|
||||
$messages[] = array(
|
||||
'severity' => 'success',
|
||||
'content' => 'The incident status was changed successfully.',
|
||||
);
|
||||
} break;
|
||||
|
||||
default: {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$statuses = $incident->statusChanges();
|
||||
|
||||
$this->smarty->assign('service', $service);
|
||||
$this->smarty->assign('site', $site);
|
||||
$this->smarty->assign('incident', $incident);
|
||||
$this->smarty->assign('statuses', $statuses);
|
||||
$this->smarty->assign('messages', $messages);
|
||||
|
||||
?>
|
||||
@@ -10,7 +10,7 @@
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="span16">
|
||||
<form id="admin_incident_edit" method="post" action="{$base_uri}admin/incident/id/{$incident->id}/do/edit/">
|
||||
<form id="admin_incident_edit" method="post" action="{$base_uri}admin/incident/service/{$service->id}/site/{$site->id}/id/{$incident->id}/do/edit/">
|
||||
<fieldset>
|
||||
<legend>Edit Incident</legend>
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
|
||||
<div class="row">
|
||||
<div class="span16">
|
||||
<form id="admin_incident_changestatus" method="post" action="{$base_uri}admin/incident/id/{$incident->id}/do/change-status/">
|
||||
<form id="admin_incident_changestatus" method="post" action="{$base_uri}admin/incident/service/{$service->id}/site/{$site->id}/id/{$incident->id}/do/change-status/">
|
||||
<fieldset>
|
||||
<legend>Change Status</legend>
|
||||
|
||||
@@ -64,7 +64,7 @@
|
||||
|
||||
<div class="input">
|
||||
<div class="clearfix">
|
||||
<input type="submit" class="btn primary" value="Edit Incident"> <button type="reset" class="btn">Cancel</button>
|
||||
<input type="submit" class="btn primary" value="Change Status"> <button type="reset" class="btn">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
@@ -24,15 +24,15 @@
|
||||
</td>
|
||||
<td>
|
||||
{$status=$site->status()}
|
||||
{include nocache file="fragments/site-status.tpl" start=null end=null}
|
||||
{include file="fragments/site-status.tpl" nocache start=null end=null}
|
||||
</td>
|
||||
{foreach from=array(1,2,3,4,5,6) item=day}
|
||||
{$start=mktime(0,0,0,date("n"),date("j")-$day-1)}
|
||||
{$end=mktime(0,0,0,date("n"),date("j")-$day)}
|
||||
{$incidents=$site->openIncidentsDuring($start, $end)}
|
||||
{$status=StatusBoard_Incident::highestSeverityStatus($incidents)}
|
||||
{$incidentsDuring=$site->openIncidentsDuring($start, $end)}
|
||||
{$statusDuring=StatusBoard_Incident::highestSeverityStatus($incidentsDuring, $end)}
|
||||
<td>
|
||||
{include nocache file="fragments/site-status.tpl" start=$start end=$end status=$status incidents=$incidents}
|
||||
{include file="fragments/site-status.tpl" nocache start=$start end=$end status=$statusDuring incidents=$incidentsDuring}
|
||||
</td>
|
||||
{/foreach}
|
||||
</tr>
|
||||
|
||||
Reference in New Issue
Block a user