-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dynamic HTML output for monitoring (#2062)
Co-authored-by: Klaus Zimmermann <klaus.zimmermann@smhi.se>
- Loading branch information
Showing
7 changed files
with
339 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,72 @@ | ||
|
||
<!-- Tab links --> | ||
<ul class="nav nav-tabs sticky-top bg-light" id="tabDiagnostics" role="tablist"> | ||
<li class="nav-item"> | ||
<!-- Filter --> | ||
<div class="dropdown" style="position: static"> | ||
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown" aria-expanded="false" data-bs-auto-close="outside"> | ||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-filter" viewBox="0 0 16 16"> | ||
<path d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/> | ||
</svg> | ||
Filters | ||
</button> | ||
<div class="dropdown-menu w-100"> | ||
<div class="container div_filter"> | ||
<div class="row justify-content-center"> | ||
{% for filter_name, filter_values in filters.items() %} | ||
{% set filter_loop = loop %} | ||
<div class="col-xl-3 col-lg-4 col-sm-6 col-12 filter_category" id="filter_{{ filter_name|replace(' ', '_') }}"> | ||
<h4>{{ filter_name|replace('_', ' ')|title }}</h4> | ||
{% for value in filter_values %} | ||
<div class="form-check"> | ||
<input class="form-check-input filter_cb" type="checkbox" value="" id="cb_{{ filter_loop.index }}_{{ loop.index }}" rel="f_{{ filter_name|replace(' ', '_') }}_{{ value|replace(' ', '_') }}"> | ||
<label class="form-check-label" for="cb_{{ filter_loop.index }}_{{ loop.index }}"> | ||
{{ value|replace('_', ' ')|title }} | ||
</label> | ||
</div> | ||
{% endfor %} | ||
</div> | ||
{% endfor %} | ||
</div> | ||
<div class="d-flex justify-content-center align-items-center gap-3"> | ||
<div class="d-inline-block"> | ||
<button class="btn btn-primary" id="b_deleteFilters" disabled>Delete Filters</button> | ||
</div> | ||
<div class="form-check form-switch d-inline-block"> | ||
<input class="form-check-input" type="checkbox" value="" id="cb_hideEmptyDiagnostics" rel="" checked> | ||
<label class="form-check-label" for="cb_hideEmptyDiagnostics"> | ||
Hide empty diagnostics | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</li> | ||
<li class="nav-item" role="presentation"> | ||
<button class="nav-link active diagnostics-tab" id="tabAll" data-bs-toggle="tab" data-bs-target="#" type="button" role="tab" aria-controls="" aria-selected="true">All</button> | ||
</li> | ||
{% for diagnostic in diagnostics %} | ||
<li class="nav-item" role="presentation"> | ||
<button class="nav-link diagnostics-tab" id="tab_{{ loop.index }}" data-bs-toggle="tab" data-bs-target="#tabPane_{{ loop.index }}" type="button" role="tab" aria-controls="tabPane_{{ loop.index }}" aria-selected="true">{{ diagnostic.title }}</button> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
|
||
<div class="tab-content" id="tabContentDiagnostics"> | ||
{% for diagnostic in diagnostics %} | ||
|
||
<h2>{{ diagnostic.title }}</h2> | ||
<p>{{ diagnostic.description }}</p> | ||
<div id="tabPane_{{ loop.index }}" class="tab-pane show active diagnostics-tab-pane" role="tabpanel" aria-labelledby="tab_{{ loop.index }}"> | ||
<h2>{{ diagnostic.title }}</h2> | ||
<p>{{ diagnostic.description }}</p> | ||
|
||
{% for task in diagnostic.task_output %} | ||
{% set diagnostic_loop = loop %} | ||
{% for task in diagnostic.task_output %} | ||
|
||
{% include 'TaskOutput.j2' %} | ||
{% include 'TaskOutput.j2' %} | ||
|
||
{% endfor %} | ||
{% endfor %} | ||
</div> | ||
|
||
{% endfor %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
function filterFigures(){ | ||
/** | ||
* Update visibility of filtered figures. | ||
*/ | ||
let allFigures = $(".div_figure"); | ||
let selectedFigures = allFigures; | ||
$(".filter_category").each(function() { | ||
let selection = $(this).find(":checked").map(function() { | ||
// Returns the figures that the checkbox relates to. | ||
return $("."+$(this).attr("rel")).get(); | ||
}); | ||
if (selection.length !== 0){ | ||
selectedFigures = selectedFigures.filter(selection); | ||
} | ||
}); | ||
selectedFigures.addClass("selected") // affects the div | ||
.find("figure").show(); // affects figure inside the div | ||
allFigures.not(selectedFigures).removeClass("selected") // affects the div | ||
.find("figure").hide(); // affects figure inside the div | ||
} | ||
|
||
function filterTabs(){ | ||
/** | ||
* Disable tab buttons for empty diagnostics and | ||
* mark empty tabPanes. | ||
*/ | ||
$(".diagnostics-tab").not("#tabAll").each(function() { | ||
let tabPane = $($(this).attr("data-bs-target")); | ||
if (tabPane.find(".div_figure.selected").length === 0){ | ||
$(this).addClass("disabled"); | ||
tabPane.addClass("filtered"); | ||
} else { | ||
$(this).removeClass("disabled"); | ||
tabPane.removeClass("filtered"); | ||
} | ||
|
||
// If the active tab is disabled, change to "All" | ||
if($(".diagnostics-tab.active").hasClass("disabled")){ | ||
$("#tabAll").click(); | ||
} | ||
}); | ||
} | ||
|
||
function hideEmptyTabPanes(){ | ||
/** | ||
* Hide empty tab panes. It's separated from "filterTabs()" | ||
* to reuse on the "Hide empty diagnostics" checkbox | ||
*/ | ||
if($("#tabAll").hasClass("active")){ | ||
let panes = $(".diagnostics-tab-pane"); | ||
panes.addClass("active").addClass("show"); | ||
if ($("#cb_hideEmptyDiagnostics").prop("checked")){ | ||
panes.filter(".filtered").removeClass("active").removeClass("show"); | ||
} | ||
} | ||
} | ||
|
||
function applyFilters(){ | ||
/** | ||
* Updates visibility according to filters. | ||
*/ | ||
filterFigures(); | ||
filterTabs(); | ||
hideEmptyTabPanes(); | ||
} | ||
|
||
// Set up events with jQuery | ||
// Specific events are defined as anonymous functions | ||
$(document).ready(function() { | ||
|
||
$("#tabAll").on("click", function() { | ||
/** | ||
* Functionality for tab "All", as it is not supported | ||
* by Bootstrap. | ||
*/ | ||
|
||
// Both activate this tab | ||
$(this).addClass("active") | ||
// and deactivate other tabs | ||
.parent("li").siblings().find("button").removeClass("active"); | ||
|
||
// Show all non-filtered tab panes | ||
let tabPanes = $(".diagnostics-tab-pane"); | ||
if ($("#cb_hideEmptyDiagnostics").prop("checked")){ | ||
tabPanes = tabPanes.not(".filtered"); | ||
} | ||
tabPanes.addClass("active").addClass("show"); | ||
}); | ||
|
||
$(".diagnostics-tab").not("#tabAll").on("click", function() { | ||
/** | ||
* Upgrades Bootstrap tab functionality to deactivate | ||
* tab "All" by hiding all non-selected panes, as | ||
* Bootstrap hides only one pane. | ||
*/ | ||
$(".diagnostics-tab-pane").not($(this).attr("data-bs-target")) | ||
.removeClass("active").removeClass("show"); | ||
}); | ||
|
||
// Checkbox "Hide empty diagnostics" | ||
$("#cb_hideEmptyDiagnostics").on("click", hideEmptyTabPanes); | ||
|
||
$("#b_deleteFilters").on("click", function(){ | ||
/** | ||
* Unchecks all filters and disables "Delete filters" button. | ||
*/ | ||
$(".filter_cb").prop("checked", false); | ||
applyFilters(); | ||
$(this).prop("disabled", true); | ||
}); | ||
|
||
$(".filter_cb").on("click", function(){ | ||
/** | ||
* Update visibility of figures and panes when filters | ||
* are applied, and set up disable filters button. | ||
*/ | ||
applyFilters(); | ||
|
||
let areFiltersClear = $(".filter_cb:checked").length === 0; | ||
$("#b_deleteFilters").prop("disabled", areFiltersClear); | ||
}); | ||
}); |
Oops, something went wrong.