Add a search box in the "My Checks" page.

This commit is contained in:
Pēteris Caune 2018-10-29 14:01:03 +02:00
parent c57a9dcbc4
commit 40c83e3cba
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
5 changed files with 58 additions and 14 deletions

View File

@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file.
- Load settings from environment variables - Load settings from environment variables
- Add "List-Unsubscribe" header to alert and report emails - Add "List-Unsubscribe" header to alert and report emails
- Don't send monthly reports to inactive accounts (no pings in 6 months) - Don't send monthly reports to inactive accounts (no pings in 6 months)
- Add search box in the "My Checks" page
### Bug Fixes ### Bug Fixes
- During DST transition, handle ambiguous dates as pre-transition - During DST transition, handle ambiguous dates as pre-transition

View File

@ -76,12 +76,21 @@ def my_checks(request):
channels = list(channels.order_by("created")) channels = list(channels.order_by("created"))
hidden_checks = set() hidden_checks = set()
# Hide checks that don't match selected tags:
selected_tags = set(request.GET.getlist("tag", [])) selected_tags = set(request.GET.getlist("tag", []))
if selected_tags: if selected_tags:
for check in checks: for check in checks:
if not selected_tags.issubset(check.tags_list()): if not selected_tags.issubset(check.tags_list()):
hidden_checks.add(check) hidden_checks.add(check)
# Hide checks that don't match the search string:
search = request.GET.get("search", "")
if search:
for check in checks:
search_key = "%s\n%s" % (check.name.lower(), check.code)
if search not in search_key:
hidden_checks.add(check)
ctx = { ctx = {
"page": "checks", "page": "checks",
"checks": checks, "checks": checks,
@ -94,6 +103,8 @@ def my_checks(request):
"num_available": request.team.check_limit - len(checks), "num_available": request.team.check_limit - len(checks),
"sort": request.profile.sort, "sort": request.profile.sort,
"selected_tags": selected_tags, "selected_tags": selected_tags,
"show_search": True,
"search": search,
"hidden_checks": hidden_checks "hidden_checks": hidden_checks
} }

View File

@ -27,6 +27,11 @@
border-color: #000; border-color: #000;
} }
#search {
padding-left: 15px;
border-radius: 16px;
}
@media (min-width: 992px) { @media (min-width: 992px) {
#update-timeout-modal .modal-dialog, #ping-details-modal .modal-dialog { #update-timeout-modal .modal-dialog, #ping-details-modal .modal-dialog {
width: 800px; width: 800px;

View File

@ -63,11 +63,7 @@ $(function () {
return false; return false;
}); });
function applyFilters() {
// Filtering by tags
$("#my-checks-tags div").click(function() {
$(this).toggleClass('checked');
// Make a list of currently checked tags: // Make a list of currently checked tags:
var checked = []; var checked = [];
var qs = []; var qs = [];
@ -76,6 +72,11 @@ $(function () {
qs.push({"name": "tag", "value": el.textContent}); qs.push({"name": "tag", "value": el.textContent});
}); });
var search = $("#search").val().toLowerCase();
if (search) {
qs.push({"name": "search", "value": search});
}
// Update hash // Update hash
if (window.history && window.history.replaceState) { if (window.history && window.history.replaceState) {
var url = "/checks/"; var url = "/checks/";
@ -85,30 +86,50 @@ $(function () {
window.history.replaceState({}, "", url); window.history.replaceState({}, "", url);
} }
// No checked tags: show all // No checked tags and no search string: show all
if (checked.length == 0) { if (checked.length == 0 && !search) {
$("#checks-table tr.checks-row").show(); $("#checks-table tr.checks-row").show();
return; return;
} }
function applyFilters(index, element) { function applySingle(index, element) {
// use attr(), as data() tries converting strings to JS types: if (search) {
// (e.g., "123" -> 123) var code = element.getAttribute("id");
var tags = $(".my-checks-name", element).attr("data-tags").split(" "); var name = $(".my-checks-name", element).attr("data-name").toLowerCase();
for (var i=0, tag; tag=checked[i]; i++) { if (name.indexOf(search) == -1 && code.indexOf(search) == -1) {
if (tags.indexOf(tag) == -1) {
$(element).hide(); $(element).hide();
return; return;
} }
} }
if (checked.length) {
// use attr(), as data() tries converting strings to JS types:
// (e.g., "123" -> 123)
var tags = $(".my-checks-name", element).attr("data-tags").split(" ");
for (var i=0, tag; tag=checked[i]; i++) {
if (tags.indexOf(tag) == -1) {
$(element).hide();
return;
}
}
}
$(element).show(); $(element).show();
} }
// For each row, see if it needs to be shown or hidden // For each row, see if it needs to be shown or hidden
$("#checks-table tr.checks-row").each(applyFilters); $("#checks-table tr.checks-row").each(applySingle);
}
// User clicks on tags: apply filters
$("#my-checks-tags div").click(function() {
$(this).toggleClass('checked');
applyFilters();
}); });
// User changes the search string: apply filters
$("#search").keyup(applyFilters);
$(".show-log").click(function(e) { $(".show-log").click(function(e) {
var code = $(this).closest("tr.checks-row").attr("id"); var code = $(this).closest("tr.checks-row").attr("id");
var url = "/checks/" + code + "/details/"; var url = "/checks/" + code + "/details/";

View File

@ -146,6 +146,12 @@
<li><a href="{% url 'hc-login' %}">Sign In</a></li> <li><a href="{% url 'hc-login' %}">Sign In</a></li>
</ul> </ul>
{% endif %} {% endif %}
{% if show_search %}
<form class="navbar-form navbar-right">
<input id="search" type="text" placeholder="Search checks&hellip;" class="form-control" value="{{ search }}">
</form>
{% endif %}
</div> </div>
</div> </div>