Implement organization filtering, fixing #12
This commit is contained in:
parent
f6bdd54fec
commit
054b791e28
3 changed files with 37 additions and 12 deletions
|
@ -25,6 +25,10 @@ def directUserOrgas(user):
|
||||||
def directOrgaString(user):
|
def directOrgaString(user):
|
||||||
return ", ".join(str(orga) for orga in directUserOrgas(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)
|
@register.simple_tag(takes_context=True)
|
||||||
def userOrgas(context):
|
def userOrgas(context):
|
||||||
return directUserOrgas(context.request.user)
|
return directUserOrgas(context.request.user)
|
||||||
|
@ -52,3 +56,7 @@ def userNets(context):
|
||||||
@register.simple_tag
|
@register.simple_tag
|
||||||
def netOrgaString(network):
|
def netOrgaString(network):
|
||||||
return ", ".join(str(orga) for orga in network.organization.all())
|
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()) + "]"
|
||||||
|
|
|
@ -188,6 +188,16 @@ function showorgas() {
|
||||||
window.history.pushState("", "", "/organizations/");
|
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('/'));
|
var page = document.location.pathname.substring(1, document.location.pathname.lastIndexOf('/'));
|
||||||
if (page == "users") showusers();
|
if (page == "users") showusers();
|
||||||
else if (page == "wifi") showwifi();
|
else if (page == "wifi") showwifi();
|
||||||
|
@ -195,8 +205,14 @@ else if (page == "networks") shownets();
|
||||||
else if (page == "organizations") showorgas();
|
else if (page == "organizations") showorgas();
|
||||||
else showdevices();
|
else showdevices();
|
||||||
|
|
||||||
|
filtertables();
|
||||||
|
|
||||||
$("div[id$='-indicator']").each(function() {
|
$("div[id$='-indicator']").each(function() {
|
||||||
device_id = this.id.split("-")[0];
|
device_id = this.id.split("-")[0];
|
||||||
updateStatus(device_id);
|
updateStatus(device_id);
|
||||||
setInterval(updateStatus, 10000, device_id);
|
setInterval(updateStatus, 10000, device_id);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$("#orgaselect").on('change', function() {
|
||||||
|
filtertables();
|
||||||
|
});
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
{% load manager %}
|
{% load manager %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
<p><b>Organization:</b> {% orgaString %}</p>
|
<p><b>Organization:</b> {% userOrgas as orgas %}{% if orgas|length > 1 %}<select id="orgaselect">{% for orga in orgas %}<option value="{{ orga.id }}">{{ orga }}</option>{% endfor %}</select>{% else %}{% orgaString %}{% endif %}</p>
|
||||||
<p><b>User:</b> {{ user.first_name }} {{ user.last_name }} ({{ user.username }}) <a href="/users/{{ user.id }}/edit"><i class="fas fa-edit" title="Edit User"></i></a></p>
|
<p><b>User:</b> {{ user.first_name }} {{ user.last_name }} ({{ user.username }}) <a href="/users/{{ user.id }}/edit"><i class="fas fa-edit" title="Edit User"></i></a></p>
|
||||||
|
|
||||||
<div align="center"><b>Manage:</b>
|
<div align="center"><b>Manage:</b>
|
||||||
|
@ -32,10 +32,10 @@
|
||||||
<th>Options {% if user.is_superuser %}<a href="/makedevice/" style="font-weight:bold;color:green;"><i class="fas fa-plus" title="Add Device"></i></a>{% endif %}</th>
|
<th>Options {% if user.is_superuser %}<a href="/makedevice/" style="font-weight:bold;color:green;"><i class="fas fa-plus" title="Add Device"></i></a>{% endif %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
<tbody>
|
||||||
{% userDevices as devices %}
|
{% userDevices as devices %}
|
||||||
{% for device in devices %}
|
{% for device in devices %}
|
||||||
<tr>
|
<tr data-orga="[{{ device.organization.id }}]">
|
||||||
<td><div style="display: inline; color: grey; font-weight: bold;" title="No information available" id="{{ device.id }}-indicator">⬤</div> <div style="display: inline;" {% if user.is_superuser %}title="{{ device.organization.name }}"{% endif %} id="{{ device.id }}-id">{{ device.serial }}</div></td>
|
<td><div style="display: inline; color: grey; font-weight: bold;" title="No information available" id="{{ device.id }}-indicator">⬤</div> <div style="display: inline;" {% if user.is_superuser %}title="{{ device.organization.name }}"{% endif %} id="{{ device.id }}-id">{{ device.serial }}</div></td>
|
||||||
<td id="{{ device.id }}-name">{% if device.name %}{{ device.name }}{% endif %}</td>
|
<td id="{{ device.id }}-name">{% if device.name %}{{ device.name }}{% endif %}</td>
|
||||||
<td id="{{ device.id }}-network">{{ device.network }}</td>
|
<td id="{{ device.id }}-network">{{ device.network }}</td>
|
||||||
|
@ -43,7 +43,7 @@
|
||||||
<td><a href="/devices/{{ device.id }}/edit"><i class="fas fa-edit" title="Edit Device"></i></a> <a href="#"><i style="color: green;" onclick="askreboot({{ device.id }});" class="fas fa-sync" title="Reboot Device"></i></a>{% if user.is_staff %} <i onclick="downloadnotice({{ device.id }});" class="fas fa-download" title="Download Configuration"></i></a>{% endif %}{% if user.is_superuser %} <a href="#"><i style="color: darkred;" onclick="askdelete({{ device.id }});" class="fas fa-trash-alt" title="Delete Device"></i></a>{% endif %}</td>
|
<td><a href="/devices/{{ device.id }}/edit"><i class="fas fa-edit" title="Edit Device"></i></a> <a href="#"><i style="color: green;" onclick="askreboot({{ device.id }});" class="fas fa-sync" title="Reboot Device"></i></a>{% if user.is_staff %} <i onclick="downloadnotice({{ device.id }});" class="fas fa-download" title="Download Configuration"></i></a>{% endif %}{% if user.is_superuser %} <a href="#"><i style="color: darkred;" onclick="askdelete({{ device.id }});" class="fas fa-trash-alt" title="Delete Device"></i></a>{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -60,16 +60,16 @@
|
||||||
<th>Options {% if user.is_staff %}<a href="/makewifi/" style="font-weight:bold;color:green;"><i class="fas fa-plus" title="Add WiFi"></i></a>{% endif %}</th>
|
<th>Options {% if user.is_staff %}<a href="/makewifi/" style="font-weight:bold;color:green;"><i class="fas fa-plus" title="Add WiFi"></i></a>{% endif %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
<tbody>
|
||||||
{% userWifis as wifis %}
|
{% userWifis as wifis %}
|
||||||
{% for wifi in wifis %}
|
{% for wifi in wifis %}
|
||||||
<tr>
|
<tr data-orga="[{{ wifi.organization.id }}]">
|
||||||
<td><div style="display:inline;" {% if user.is_superuser %}title="{{ wifi.organization.name }}"{% endif %}>{{ wifi.serial }}</div></td>
|
<td><div style="display:inline;" {% if user.is_superuser %}title="{{ wifi.organization.name }}"{% endif %}>{{ wifi.serial }}</div></td>
|
||||||
<td>{{ wifi.ssid }}</td>
|
<td>{{ wifi.ssid }}</td>
|
||||||
<td><a href="/wifi/{{ wifi.id }}/edit"><i class="fas fa-edit" title="Edit WiFi"></i></a>{% if user.is_staff %} <a href="#"><i style="color: darkred;" onclick="askdeletewifi({{ wifi.id }});" class="fas fa-trash-alt" title="Delete WiFi"></i></a>{% endif %}</td>
|
<td><a href="/wifi/{{ wifi.id }}/edit"><i class="fas fa-edit" title="Edit WiFi"></i></a>{% if user.is_staff %} <a href="#"><i style="color: darkred;" onclick="askdeletewifi({{ wifi.id }});" class="fas fa-trash-alt" title="Delete WiFi"></i></a>{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -88,17 +88,17 @@
|
||||||
<th>Options {% if user.is_superuser %}<a href="/makeuser/" style="font-weight:bold;color:green;"><i class="fas fa-plus" title="Add User"></i></a>{% endif %}</th>
|
<th>Options {% if user.is_superuser %}<a href="/makeuser/" style="font-weight:bold;color:green;"><i class="fas fa-plus" title="Add User"></i></a>{% endif %}</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
<tbody>
|
||||||
{% userUsers as users %}
|
{% userUsers as users %}
|
||||||
{% for auser in users %}
|
{% for auser in users %}
|
||||||
<tr>
|
<tr data-orga="{% directOrgaAjax auser %}">
|
||||||
<td><div style="display:inline;" {% if user.is_superuser %}title="{% directOrgaString auser %}"{% endif %}>{% if auser.is_staff %}<b>{% endif %}{{ auser.username }}{% if auser.is_staff %}</b>{% endif %}</div></td>
|
<td><div style="display:inline;" {% if user.is_superuser %}title="{% directOrgaString auser %}"{% endif %}>{% if auser.is_staff %}<b>{% endif %}{{ auser.username }}{% if auser.is_staff %}</b>{% endif %}</div></td>
|
||||||
<td>{% if auser.is_staff %}<b>{% endif %}{{ auser.first_name }} {{ auser.last_name }}{% if auser.is_staff %}</b>{% endif %}</td>
|
<td>{% if auser.is_staff %}<b>{% endif %}{{ auser.first_name }} {{ auser.last_name }}{% if auser.is_staff %}</b>{% endif %}</td>
|
||||||
<td>{{ auser.userstatus.last_action }}</td>
|
<td>{{ auser.userstatus.last_action }}</td>
|
||||||
<td><a href="/users/{{ auser.id }}/edit"><i class="fas fa-edit" title="Edit User"></i></a> {% if auser.email %}<a href="mailto:{{ auser.email }}"><i class="fas fa-envelope" title="Send Email"></i></a>{% endif %}{% if user.is_superuser %} <a href="#"><i style="color: darkred;" onclick="askdeleteuser({{ auser.id }});" class="fas fa-trash-alt" title="Delete User"></i></a>{% endif %}</td>
|
<td><a href="/users/{{ auser.id }}/edit"><i class="fas fa-edit" title="Edit User"></i></a> {% if auser.email %}<a href="mailto:{{ auser.email }}"><i class="fas fa-envelope" title="Send Email"></i></a>{% endif %}{% if user.is_superuser %} <a href="#"><i style="color: darkred;" onclick="askdeleteuser({{ auser.id }});" class="fas fa-trash-alt" title="Delete User"></i></a>{% endif %}</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -117,16 +117,17 @@
|
||||||
<th>Options <a href="/makenet/" style="font-weight:bold;color:green;"><i class="fas fa-plus" title="Add User"></i></a></th>
|
<th>Options <a href="/makenet/" style="font-weight:bold;color:green;"><i class="fas fa-plus" title="Add User"></i></a></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
|
<tbody>
|
||||||
{% userNets as networks %}
|
{% userNets as networks %}
|
||||||
{% for network in networks %}
|
{% for network in networks %}
|
||||||
<tr>
|
<tr data-orga="{% netOrgaAjax network %}">
|
||||||
<td><div style="display:inline;" title="{% netOrgaString network %}">{{ network.name }}</div></td>
|
<td><div style="display:inline;" title="{% netOrgaString network %}">{{ network.name }}</div></td>
|
||||||
<td>{{ network.intip }}</td>
|
<td>{{ network.intip }}</td>
|
||||||
<td>{{ network.extip }}</td>
|
<td>{{ network.extip }}</td>
|
||||||
<td><a href="#"><i style="color: darkred;" onclick="askdeletenet({{ network.id }});" class="fas fa-trash-alt" title="Delete Network"></i></a></td>
|
<td><a href="#"><i style="color: darkred;" onclick="askdeletenet({{ network.id }});" class="fas fa-trash-alt" title="Delete Network"></i></a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue