Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a toggle all/none incident types button #1583

Merged
merged 1 commit into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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