Skip to content

Commit

Permalink
add a toggle all/none incident types button (#1583)
Browse files Browse the repository at this point in the history
this also fixes a few little bugs from my last PR

#1581
  • Loading branch information
srabraham authored Feb 7, 2025
1 parent 700175b commit 1c7b028
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Each month below should look like the following, using the same ordering for the
- Started allowing searches using regular expressions on the Incidents and Field Reports pages, mostly to support "OR"-based queries. https://github.com/burningmantech/ranger-ims-server/issues/1570
- Created the ability to have a search query as part of an Incidents or Field Reports page URL. This allows bookmarking. https://github.com/burningmantech/ranger-ims-server/issues/1570
- Put all the table filters (state, type, rows, days-ago) into the URLs, making all of those bookmarkable, in addition to search. https://github.com/burningmantech/ranger-ims-server/issues/1570
- Converted the "show incident type" dropdown into a multiselect, allowing filtering the Incidents page to any number of Incident Types. https://github.com/burningmantech/ranger-ims-server/issues/1581

### Removed

Expand Down
1 change: 1 addition & 0 deletions src/ims/element/incident/incidents_template/template.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
Types
</button>
<ul id="ul_show_type" class="dropdown-menu">
<a class="dropdown-item" href="#" onclick="toggleCheckAllTypes(); return false;">All/None</a>
<!-- li will be inserted here by JQuery -->
</ul>

Expand Down
26 changes: 20 additions & 6 deletions src/ims/element/static/incidents.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,12 +337,13 @@ function initTableButtons() {
const types = fragmentParams.getAll("type");
const validTypes = [];
for (const t of types) {
console.log(`reading type ${t} checking`);
if (t && allIncidentTypes.indexOf(t) !== -1) {
validTypes.push(t);
}
}
setCheckedTypes(validTypes);
if (validTypes.length > 0) {
setCheckedTypes(validTypes);
}
showCheckedTypes(false);
showState(fragmentParams.get("state")??defaultState, false);
showDays(fragmentParams.get("days")??defaultDaysBack, false);
Expand Down Expand Up @@ -469,7 +470,9 @@ function initSearch() {
return false
}

if (_showTypes && _showTypes.length > 0) {
// don't bother with filtering, which may be computationally expensive,
// if all types seem to be selected
if (_showTypes.length !== allIncidentTypes.length) {
const intersect = Object.values(incident.incident_types).filter(t => _showTypes.includes(t)).length > 0;
if (!intersect) {
return false;
Expand Down Expand Up @@ -557,14 +560,23 @@ let _showTypes = [];

function setCheckedTypes(types) {
for (const $type of $('#ul_show_type > a')) {
if (types.length === 0 || types.includes($type.innerHTML)) {
if (types.includes($type.innerHTML)) {
$type.classList.add("dropdown-item-checked")
} else {
$type.classList.remove("dropdown-item-checked")
}
}
}

function toggleCheckAllTypes() {
if (_showTypes.length === 0 || _showTypes.length < allIncidentTypes.length) {
setCheckedTypes(allIncidentTypes);
} else {
setCheckedTypes([]);
}
showCheckedTypes(true);
}

function readCheckedTypes() {
const checkedTypes = [];
for (const $type of $('#ul_show_type > a')) {
Expand All @@ -578,8 +590,10 @@ function readCheckedTypes() {
function showCheckedTypes(replaceState) {
_showTypes = readCheckedTypes();

const numTypes = _showTypes.length === allIncidentTypes.length ? "All" : _showTypes.length;
document.getElementById("show_type").textContent = `${numTypes} Types`;
const showTypeText = _showTypes.length === allIncidentTypes.length
? "All Types"
: `Types (${_showTypes.length})`;
document.getElementById("show_type").textContent = showTypeText;

if (replaceState) {
replaceWindowState();
Expand Down

0 comments on commit 1c7b028

Please sign in to comment.