Skip to content

Commit

Permalink
migrate the web client further toward "field report"
Browse files Browse the repository at this point in the history
  • Loading branch information
srabraham committed Dec 20, 2024
1 parent dac91c5 commit c5f258f
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/ims/element/incident/incident_template/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@
</div>
<div class="card-footer">
<textarea
id="incident_report_add"
id="report_entry_add"
class="form-control no-print"
rows="3"
placeholder="Additional report text..."
Expand Down
4 changes: 2 additions & 2 deletions src/ims/element/incident/report/_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ def event_id(self, request: IRequest, tag: Tag) -> KleinRenderable:
return jsonTextFromObject(self.event.id)

@renderer
def incident_report_number(self, request: IRequest, tag: Tag) -> KleinRenderable:
def field_report_number(self, request: IRequest, tag: Tag) -> KleinRenderable:
"""
JSON integer: incident report number.
JSON integer: field report number.
"""
return jsonTextFromObject(self.number)

Expand Down
4 changes: 2 additions & 2 deletions src/ims/element/incident/report/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<!-- FIXME: figure out how to move this to / include from report.js -->
var editingAllowed = <json t:render="editing_allowed"/>;
var eventID = <json t:render="event_id"/>;
var incidentReportNumber = <json t:render="incident_report_number"/>;
var fieldReportNumber = <json t:render="field_report_number"/>;
var canWriteIncidents = <json t:render="can_write_incidents"/>;
var pageTemplateURL = url_viewFieldReportTemplate;

initIncidentReportPage();
initFieldReportPage();
</script>

</html>
10 changes: 5 additions & 5 deletions src/ims/element/incident/report_template/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<div class="row">
<div class="col-sm-4">
<div class="py-1 input-group">
<label for="incident_report_number" class="control-label input-group-text">FR #</label>
<span id="incident_report_number" class="form-control form-control-static"/>
<label for="field_report_number" class="control-label input-group-text">FR #</label>
<span id="field_report_number" class="form-control form-control-static"/>
</div>
</div>
<div class="col-sm-8">
Expand Down Expand Up @@ -39,9 +39,9 @@
<div class="row">
<div class="col-sm-12">
<div class="py-1 input-group">
<label for="incident_report_summary" class="control-label input-group-text">Summary</label>
<label for="field_report_summary" class="control-label input-group-text">Summary</label>
<input
id="incident_report_summary" class="form-control input-sm"
id="field_report_summary" class="form-control input-sm"
type="text" inputmode="latin-prose"
placeholder="e.g. Someone did a thing at Camp ABC. IMS#123"
onchange="editSummary()"
Expand Down Expand Up @@ -121,7 +121,7 @@
<div id="report_entries"/>
<div class="card-footer">
<textarea
id="incident_report_add"
id="report_entry_add"
class="form-control no-print input-sm"
rows="12"
placeholder="Additional report text..."
Expand Down
8 changes: 4 additions & 4 deletions src/ims/element/incident/reports_template/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

<div class="row">
<div id="button_container" class="col-sm-7">
<div class="btn-group new_incident_report no-print">
<div class="btn-group new_field_report no-print">
<a href="./new" target="_blank">
<button
id="new_incident_report"
id="new_field_report"
type="button"
class="btn btn-sm btn-default btn-primary"
>
Expand Down Expand Up @@ -87,13 +87,13 @@
placeholder="Search"
inputmode="latin"
autocomplete="off"
aria-controls="incident_reports_table"
aria-controls="field_reports_table"
/>
</div>
</div>
</div>

<table id="incident_reports_table" class="table table-striped table-hover">
<table id="field_reports_table" class="table table-striped table-hover">
<thead>
<tr>
<th>#</th>
Expand Down
94 changes: 47 additions & 47 deletions src/ims/element/static/field_report.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@

//
// Initialize UI
let incidentReport = null;
let fieldReport = null;

function initIncidentReportPage() {
function loadedIncidentReport() {
function initFieldReportPage() {
function loadedFieldReport() {
// for a new incident report
if (incidentReport.number == null) {
$("#incident_report_summary").focus();
if (fieldReport.number == null) {
$("#field_report_summary").focus();
} else {
// Scroll to incident_report_add field
$("html, body").animate({scrollTop: $("#incident_report_add").offset().top}, 500);
$("#incident_report_add").focus();
$("html, body").animate({scrollTop: $("#report_entry_add").offset().top}, 500);
$("#report_entry_add").focus();
}

// Warn the user if they're about to navigate away with unsaved text.
window.addEventListener('beforeunload', function (e) {
if (document.getElementById("incident_report_add").value !== '') {
if (document.getElementById("report_entry_add").value !== '') {
e.preventDefault();
}
});
}

function loadedBody() {
disableEditing();
loadAndDisplayIncidentReport(loadedIncidentReport);
loadAndDisplayFieldReport(loadedFieldReport);

let command = false;

Expand Down Expand Up @@ -69,8 +69,8 @@ function initIncidentReportPage() {
}
}

$("#incident_report_add")[0].onkeydown = addFieldKeyDown;
$("#incident_report_add")[0].onkeyup = addFieldKeyUp;
$("#report_entry_add")[0].onkeydown = addFieldKeyDown;
$("#report_entry_add")[0].onkeyup = addFieldKeyUp;
}

loadBody(loadedBody);
Expand All @@ -93,18 +93,18 @@ function clearErrorMessage() {
// Load incident report
//

function loadIncidentReport(success) {
function loadFieldReport(success) {
let number = null;
if (incidentReport == null) {
if (fieldReport == null) {
// First time here. Use page JavaScript initial value.
number = incidentReportNumber;
number = fieldReportNumber;
} else {
// We have an incident already. Use that number.
number = incidentReport.number;
number = fieldReport.number;
}

function ok(data, status, xhr) {
incidentReport = data;
fieldReport = data;

if (success) {
success();
Expand All @@ -130,9 +130,9 @@ function loadIncidentReport(success) {
}


function loadAndDisplayIncidentReport(success) {
function loadAndDisplayFieldReport(success) {
function loaded() {
if (incidentReport == null) {
if (fieldReport == null) {
const message = "Field report failed to load";
console.log(message);
setErrorMessage(message);
Expand All @@ -143,10 +143,10 @@ function loadAndDisplayIncidentReport(success) {
drawNumber();
drawIncident();
drawSummary();
drawReportEntries(incidentReport.report_entries);
drawReportEntries(fieldReport.report_entries);
clearErrorMessage();

$("#incident_report_add").on("input", reportEntryEdited);
$("#report_entry_add").on("input", reportEntryEdited);

if (editingAllowed) {
enableEditing();
Expand All @@ -157,7 +157,7 @@ function loadAndDisplayIncidentReport(success) {
}
}

loadIncidentReport(loaded);
loadFieldReport(loaded);
}


Expand All @@ -166,7 +166,7 @@ function loadAndDisplayIncidentReport(success) {
//

function drawTitle() {
document.title = fieldReportAsString(incidentReport);
document.title = fieldReportAsString(fieldReport);
}


Expand All @@ -175,11 +175,11 @@ function drawTitle() {
//

function drawNumber() {
let number = incidentReport.number;
let number = fieldReport.number;
if (number == null) {
number = "(new)";
}
$("#incident_report_number").text(number);
$("#field_report_number").text(number);
}

//
Expand All @@ -189,19 +189,19 @@ function drawNumber() {
function drawIncident() {
$("#incident_number").text("Please include in Summary");
// New Incident Report. There can be no Incident
if (incidentReport.number === null) {
if (fieldReport.number == null) {
return;
}
// If there's an attached Incident, then show a link to it
if (incidentReport.incident !== null) {
const incidentURL = urlReplace(url_viewIncidentNumber).replace("<number>", incidentReport.incident);
if (fieldReport.incident != null) {
const incidentURL = urlReplace(url_viewIncidentNumber).replace("<number>", fieldReport.incident);
const $a = $("<a>", {href: incidentURL});
$a.text(incidentReport.incident);
$a.text(fieldReport.incident);
$("#incident_number").text("").append($a);
}
// If there's no attached Incident, show a button for making
// a new Incident
if (incidentReport.incident == null && canWriteIncidents) {
if (fieldReport.incident == null && canWriteIncidents) {
$("#create_incident").removeClass("hidden");
} else {
$("#create_incident").addClass("hidden");
Expand All @@ -214,17 +214,17 @@ function drawIncident() {
//

function drawSummary() {
if (incidentReport.summary) {
$("#incident_report_summary").val(incidentReport.summary);
$("#incident_report_summary").attr("placeholder", "");
if (fieldReport.summary) {
$("#field_report_summary").val(fieldReport.summary);
$("#field_report_summary").attr("placeholder", "");
return;
}

$("#incident_report_summary")[0].removeAttribute("value");
const summarized = summarizeIncident(incidentReport);
$("#field_report_summary")[0].removeAttribute("value");
const summarized = summarizeIncident(fieldReport);
if (summarized) {
// only replace the placeholder if it would be nonempty
$("#incident_report_summary").attr("placeholder", summarized);
$("#field_report_summary").attr("placeholder", summarized);
}
}

Expand All @@ -234,15 +234,15 @@ function drawSummary() {
//

function sendEdits(edits, success, error) {
const number = incidentReport.number;
const number = fieldReport.number;
let url = urlReplace(url_incidentReports);

if (number == null) {
// We're creating a new field report.
const required = [];
for (const key of required) {
if (edits[key] == null) {
edits[key] = incidentReport[key];
edits[key] = fieldReport[key];
}
}
} else {
Expand Down Expand Up @@ -279,7 +279,7 @@ function sendEdits(edits, success, error) {
}

// Store the new number in our incident object
incidentReport.number = newNumber;
fieldReport.number = newNumber;

// Update browser history to update URL
drawTitle();
Expand All @@ -290,14 +290,14 @@ function sendEdits(edits, success, error) {
}

success();
loadAndDisplayIncidentReport();
loadAndDisplayFieldReport();
}

function fail(requestError, status, xhr) {
const message = "Failed to apply edit";
console.log(message + ": " + requestError);
error();
loadAndDisplayIncidentReport();
loadAndDisplayFieldReport();
setErrorMessage(message);
}

Expand All @@ -306,7 +306,7 @@ function sendEdits(edits, success, error) {


function editSummary() {
editFromElement($("#incident_report_summary"), "summary");
editFromElement($("#field_report_summary"), "summary");
}

//
Expand All @@ -318,16 +318,16 @@ function makeIncident() {

function createOk(data, status, xhr) {
const newIncident = xhr.getResponseHeader("X-IMS-Incident-Number");
incidentReport.incident = parseInt(newIncident);
fieldReport.incident = parseInt(newIncident);

const url = (
urlReplace(url_incidentReports) + incidentReport.number +
urlReplace(url_incidentReports) + fieldReport.number +
"?action=attach;incident=" + newIncident
);

function attachOk(data, status, xhr) {
console.log("Created and attached to new incident " + newIncident);
loadAndDisplayIncidentReport();
loadAndDisplayFieldReport();
}

function attachFail(error, status, xhr) {
Expand All @@ -348,12 +348,12 @@ function makeIncident() {
}

const authors = [];
if (incidentReport.report_entries?.length > 0) {
authors.push(incidentReport.report_entries[0].author);
if (fieldReport.report_entries?.length > 0) {
authors.push(fieldReport.report_entries[0].author);
}

jsonRequest(incidentsURL, {
"summary": incidentReport.summary,
"summary": fieldReport.summary,
"ranger_handles": authors,
}, createOk, createFail,
);
Expand Down
Loading

0 comments on commit c5f258f

Please sign in to comment.