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:
2011-12-21 01:13:06 +00:00
parent 59dd99cca2
commit a119ca81d5
5 changed files with 94 additions and 10 deletions

View File

@@ -42,12 +42,23 @@ class StatusBoard_Incident extends StatusBoard_DatabaseObject {
return $this->current_status; 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 * Returns the status of the most severe incident in the given set
* *
* @param array(StatusBoard_Incident) $incidents * @param array(StatusBoard_Incident) $incidents
*/ */
public static function highestSeverityStatus(array $incidents) { public static function highestSeverityStatus(array $incidents, $time = null) {
if ( ! $incidents) { if ( ! $incidents) {
return StatusBoard_Status::STATUS_Resolved; return StatusBoard_Status::STATUS_Resolved;
} }
@@ -55,7 +66,13 @@ class StatusBoard_Incident extends StatusBoard_DatabaseObject {
// Check for the highest severity incident. // Check for the highest severity incident.
$status = StatusBoard_Status::STATUS_Maintenance; $status = StatusBoard_Status::STATUS_Maintenance;
foreach ($incidents as $incident) { 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)) { if (StatusBoard_Status::isMoreSevere($status, $incident_status)) {
$status = $incident_status; $status = $incident_status;
} }
@@ -72,6 +89,17 @@ class StatusBoard_Incident extends StatusBoard_DatabaseObject {
return $this->statuses; 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;
}
} }
?> ?>

View File

@@ -10,9 +10,21 @@ class StatusBoard_IncidentStatus extends StatusBoard_DatabaseObject {
protected $_db_description; protected $_db_description;
protected $_db_ctime; 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); 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;
}
} }
?> ?>

View File

@@ -24,11 +24,55 @@ try {
throw new StatusBoard_Exception_FileNotFound(); 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(); $statuses = $incident->statusChanges();
$this->smarty->assign('service', $service); $this->smarty->assign('service', $service);
$this->smarty->assign('site', $site); $this->smarty->assign('site', $site);
$this->smarty->assign('incident', $incident); $this->smarty->assign('incident', $incident);
$this->smarty->assign('statuses', $statuses); $this->smarty->assign('statuses', $statuses);
$this->smarty->assign('messages', $messages);
?> ?>

View File

@@ -10,7 +10,7 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="span16"> <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> <fieldset>
<legend>Edit Incident</legend> <legend>Edit Incident</legend>
@@ -40,7 +40,7 @@
<div class="row"> <div class="row">
<div class="span16"> <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> <fieldset>
<legend>Change Status</legend> <legend>Change Status</legend>
@@ -64,7 +64,7 @@
<div class="input"> <div class="input">
<div class="clearfix"> <div class="clearfix">
<input type="submit" class="btn primary" value="Edit Incident">&nbsp;<button type="reset" class="btn">Cancel</button> <input type="submit" class="btn primary" value="Change Status">&nbsp;<button type="reset" class="btn">Cancel</button>
</div> </div>
</div> </div>
</fieldset> </fieldset>

View File

@@ -24,15 +24,15 @@
</td> </td>
<td> <td>
{$status=$site->status()} {$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> </td>
{foreach from=array(1,2,3,4,5,6) item=day} {foreach from=array(1,2,3,4,5,6) item=day}
{$start=mktime(0,0,0,date("n"),date("j")-$day-1)} {$start=mktime(0,0,0,date("n"),date("j")-$day-1)}
{$end=mktime(0,0,0,date("n"),date("j")-$day)} {$end=mktime(0,0,0,date("n"),date("j")-$day)}
{$incidents=$site->openIncidentsDuring($start, $end)} {$incidentsDuring=$site->openIncidentsDuring($start, $end)}
{$status=StatusBoard_Incident::highestSeverityStatus($incidents)} {$statusDuring=StatusBoard_Incident::highestSeverityStatus($incidentsDuring, $end)}
<td> <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> </td>
{/foreach} {/foreach}
</tr> </tr>