From 054b791e28d133eb996d96371bca0291c9c54762 Mon Sep 17 00:00:00 2001 From: Klaus-Uwe Mitterer Date: Tue, 19 Feb 2019 13:19:43 +0000 Subject: [PATCH] Implement organization filtering, fixing #12 --- manager/templatetags/manager.py | 8 ++++++++ static/js/devices.js | 16 ++++++++++++++++ templates/manager/index.html | 25 +++++++++++++------------ 3 files changed, 37 insertions(+), 12 deletions(-) diff --git a/manager/templatetags/manager.py b/manager/templatetags/manager.py index 4c8edd9..df45343 100644 --- a/manager/templatetags/manager.py +++ b/manager/templatetags/manager.py @@ -25,6 +25,10 @@ def directUserOrgas(user): def directOrgaString(user): return ", ".join(str(orga) for orga in directUserOrgas(user)) +@register.simple_tag +def directOrgaAjax(user): + return "[" + ",".join(str(orga.id) for orga in directUserOrgas(user)) + "]" + @register.simple_tag(takes_context=True) def userOrgas(context): return directUserOrgas(context.request.user) @@ -52,3 +56,7 @@ def userNets(context): @register.simple_tag def netOrgaString(network): return ", ".join(str(orga) for orga in network.organization.all()) + +@register.simple_tag +def netOrgaAjax(network): + return "[" + ",".join(str(orga.id) for orga in network.organization.all()) + "]" diff --git a/static/js/devices.js b/static/js/devices.js index 16729b9..717ce7e 100644 --- a/static/js/devices.js +++ b/static/js/devices.js @@ -188,6 +188,16 @@ function showorgas() { window.history.pushState("", "", "/organizations/"); }; +function filtertables() { + orga_id = $("#orgaselect option:selected").val(); + $("tbody tr").each(function(i, row) + { + if ($.inArray(parseInt(orga_id, "10"), $(row).data('orga')) !== -1) $(row).show(); + else $(row).hide(); + }); + +}; + var page = document.location.pathname.substring(1, document.location.pathname.lastIndexOf('/')); if (page == "users") showusers(); else if (page == "wifi") showwifi(); @@ -195,8 +205,14 @@ else if (page == "networks") shownets(); else if (page == "organizations") showorgas(); else showdevices(); +filtertables(); + $("div[id$='-indicator']").each(function() { device_id = this.id.split("-")[0]; updateStatus(device_id); setInterval(updateStatus, 10000, device_id); }); + +$("#orgaselect").on('change', function() { + filtertables(); +}); diff --git a/templates/manager/index.html b/templates/manager/index.html index 30e5110..9697691 100644 --- a/templates/manager/index.html +++ b/templates/manager/index.html @@ -3,7 +3,7 @@ {% load manager %} {% block content %} -

Organization: {% orgaString %}

+

Organization: {% userOrgas as orgas %}{% if orgas|length > 1 %}{% else %}{% orgaString %}{% endif %}

User: {{ user.first_name }} {{ user.last_name }} ({{ user.username }})

Manage: @@ -32,10 +32,10 @@ Options {% if user.is_superuser %}{% endif %} - + {% userDevices as devices %} {% for device in devices %} - +
 
{{ device.serial }}
{% if device.name %}{{ device.name }}{% endif %} {{ device.network }} @@ -43,7 +43,7 @@ {% if user.is_staff %} {% endif %}{% if user.is_superuser %} {% endif %} {% endfor %} - +
@@ -60,16 +60,16 @@ Options {% if user.is_staff %}{% endif %} - + {% userWifis as wifis %} {% for wifi in wifis %} - +
{{ wifi.serial }}
{{ wifi.ssid }} {% if user.is_staff %} {% endif %} {% endfor %} - + @@ -88,17 +88,17 @@ Options {% if user.is_superuser %}{% endif %} - + {% userUsers as users %} {% for auser in users %} - +
{% if auser.is_staff %}{% endif %}{{ auser.username }}{% if auser.is_staff %}{% endif %}
{% if auser.is_staff %}{% endif %}{{ auser.first_name }} {{ auser.last_name }}{% if auser.is_staff %}{% endif %} {{ auser.userstatus.last_action }} {% if auser.email %}{% endif %}{% if user.is_superuser %} {% endif %} {% endfor %} - + @@ -117,16 +117,17 @@ Options + {% userNets as networks %} {% for network in networks %} - +
{{ network.name }}
{{ network.intip }} {{ network.extip }} {% endfor %} - +