Skip to content

Commit

Permalink
Add created and state columns to dispatch queue table.
Browse files Browse the repository at this point in the history
  • Loading branch information
wsanchez committed Aug 14, 2014
1 parent f6486e2 commit b7776c5
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 39 deletions.
9 changes: 2 additions & 7 deletions ims/element/incident.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from twisted.web.template import renderer, tags

from .base import BaseElement
from .util import normalize_priority
from .util import normalize_priority, formatTime



Expand Down Expand Up @@ -154,11 +154,6 @@ def location_address_input(self, request, tag):
return tag(**attrs)


def formatTime(self, datetime):
datetime = datetime.astimezone(self.ims.config.TimeZone)
return datetime.strftime("%Y-%m-%d %H:%M:%S")


@renderer
def incident_report_text(self, request, tag):
attrs_entry_system = {"class": "incident_entry_system"}
Expand All @@ -172,7 +167,7 @@ def entry_rendered(entry):
else:
attrs_entry = attrs_entry_user

when = self.formatTime(entry.created)
when = formatTime(entry.created, self.ims.config.TimeZone)

author = entry.author
if author is None:
Expand Down
19 changes: 11 additions & 8 deletions ims/element/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,17 @@ def format_date(d):

@renderer
def queue(self, request, tag):
return tag(incidents_as_table(
(
self.ims.storage.read_incident_with_number(number)
for number, etag in incidents_from_query(self.ims, request)
),
caption="Dispatch Queue",
id="dispatch_queue",
))
return tag(
incidents_as_table(
(
self.ims.storage.read_incident_with_number(number)
for number, etag in incidents_from_query(self.ims, request)
),
tz=self.ims.config.TimeZone,
caption="Dispatch Queue",
id="dispatch_queue",
)
)


@renderer
Expand Down
1 change: 1 addition & 0 deletions ims/element/report_shift.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ def activity(caption, incidents):
if incidents:
return incidents_as_table(
incidents,
tz=self.ims.config.TimeZone,
caption=caption,
id="activity:{0}:{1}".format(
hash(self.shift), hash(caption)
Expand Down
72 changes: 51 additions & 21 deletions ims/element/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def query_value(request, key, default, no_args_default=None):
return getattr(request, attr_name)


def incidents_as_table(incidents, caption=None, id=None):
def incidents_as_table(incidents, tz, caption=None, id=None):
attrs_activity = {"class": "incident_activity"}

if caption:
Expand All @@ -196,6 +196,8 @@ def incidents_as_rows(incidents):
attrs_incident = {"class": "incident"}
attrs_number = {"class": "incident_number"}
attrs_priority = {"class": "incident_priority"}
attrs_created = {"class": "incident_created"}
attrs_state = {"class": "incident_state"}
attrs_rangers = {"class": "incident_rangers"}
attrs_location = {"class": "incident_location"}
attrs_types = {"class": "incident_types"}
Expand All @@ -205,6 +207,8 @@ def incidents_as_rows(incidents):
tags.tr(
tags.th(u"#", **attrs_number),
tags.th(u"Priority", **attrs_priority),
tags.th(u"Created", **attrs_created),
tags.th(u"State", **attrs_state),
tags.th(u"Rangers", **attrs_rangers),
tags.th(u"Location", **attrs_location),
tags.th(u"Types", **attrs_types),
Expand All @@ -217,27 +221,45 @@ def incidents_as_rows(incidents):
yield tags.tbody(
tags.tr(
tags.td(
u"{0}".format(incident.number), **attrs_number
u"{0}".format(incident.number),
**attrs_number
),
tags.td(
u"{0}".format(priority_name(incident.priority)),
**attrs_priority
),
tags.td(
u"{0}".format(formatTime(
incident.created, tz=tz, format=u"%d/%H:%M"
)),
**attrs_number
),
tags.td(
u"{0}".format(IncidentState.describe(incident.state)),
**attrs_number
),
tags.td(
u"{0}".format(
priority_name(incident.priority), **attrs_priority
)
u", ".join(
ranger.handle for ranger in incident.rangers
)
),
**attrs_rangers
),
tags.td(
u"{0}".format(str(incident.location).decode("utf-8")),
**attrs_location
),
tags.td(
u"{0}".format(u", ".join(incident.incident_types)),
**attrs_types
),
tags.td(
u"{0}".format(incident.summaryFromReport()),
**attrs_summary
),
tags.td(u"{0}".format(
u", ".join(ranger.handle for ranger in incident.rangers)
), **attrs_rangers),
tags.td(u"{0}".format(
str(incident.location).decode("utf-8")
), **attrs_location),
tags.td(u"{0}".format(
u", ".join(incident.incident_types)
), **attrs_types),
tags.td(u"{0}".format(
incident.summaryFromReport()
), **attrs_summary),
onclick=(
'window.open("/queue/incidents/{0}");'
u'window.open("/queue/incidents/{0}");'
.format(incident.number)
),
**attrs_incident
Expand All @@ -247,7 +269,7 @@ def incidents_as_rows(incidents):

attrs_table = dict(attrs_activity)
if id is not None:
attrs_table["id"] = id
attrs_table[u"id"] = id

return tags.table(
captionElement,
Expand All @@ -274,7 +296,15 @@ def priority_name(priority):
Return a string label for a priority.
"""
return {
1: "High",
3: "Normal",
5: "Low",
1: u"High",
3: u"Normal",
5: u"Low",
}[normalize_priority(priority)]


def formatTime(datetime, tz, format=u"%Y-%m-%d %H:%M:%S"):
if datetime is None:
return u""

datetime = datetime.astimezone(tz)
return datetime.strftime(format)
7 changes: 4 additions & 3 deletions resources/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ tbody.incident_activity { border: 1px solid black; }

tr.incident:hover { background-color: #FFFF00; }

th.incident_number { width: 4em; }
th.incident_priority { width: 4em; }
th.incident_state { width: 4em; }
th.incident_number { width: 2em; }
th.incident_priority { width: 3em; }
th.incident_created { width: 4em; }
th.incident_state { width: 5em; }
th.incident_rangers { width: 8em; }
th.incident_location { width: 16em; }
th.incident_types { width: 8em; }
Expand Down

0 comments on commit b7776c5

Please sign in to comment.