Implement Network display tab
This commit is contained in:
parent
22d0726175
commit
21014a6894
4 changed files with 60 additions and 4 deletions
|
@ -16,7 +16,7 @@ class Network(models.Model):
|
|||
name = models.CharField("Common Name", max_length=64, blank=True, null=True)
|
||||
extip = models.CharField("External/Public IP", max_length=15)
|
||||
intip = models.CharField("Internal/Private IP", max_length=15)
|
||||
organizations = models.ManyToManyField(Organization)
|
||||
organization = models.ManyToManyField(Organization)
|
||||
|
||||
def __str__(self):
|
||||
return ("%s" % self.intip + (" (%s)" % self.name if self.name else ""))
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from django import template
|
||||
from manager.models import Organization, Device, Wifi
|
||||
from manager.models import Organization, Device, Wifi, Network
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
register = template.Library()
|
||||
|
@ -11,6 +11,10 @@ def abcSort(inlist):
|
|||
def allOrgas():
|
||||
return abcSort(Organization.objects.all())
|
||||
|
||||
@register.simple_tag
|
||||
def allNets():
|
||||
return abcSort(Network.objects.all())
|
||||
|
||||
def orgaObjects(cls, orga):
|
||||
return abcSort(set(cls.objects.filter(organization__in=orga)))
|
||||
|
||||
|
@ -41,3 +45,6 @@ def userWifis(context):
|
|||
def userUsers(context):
|
||||
return orgaObjects(User, userOrgas(context))
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def userNets(context):
|
||||
return orgaObjects(Network, userOrgas(context))
|
||||
|
|
|
@ -74,10 +74,12 @@ function showdevices() {
|
|||
$("#devicespart").show();
|
||||
$("#wifipart").hide();
|
||||
$("#userpart").hide();
|
||||
$("#netpart").hide();
|
||||
|
||||
$("#linkdevices").css("font-weight", "bold");
|
||||
$("#linkwifi").css("font-weight", "normal");
|
||||
$("#linkusers").css("font-weight", "normal");
|
||||
$("#linknets").css("font-weight", "normal");
|
||||
|
||||
window.history.pushState("", "", "/devices/");
|
||||
};
|
||||
|
@ -86,10 +88,12 @@ function showwifi() {
|
|||
$("#devicespart").hide();
|
||||
$("#wifipart").show();
|
||||
$("#userpart").hide();
|
||||
$("#netpart").hide();
|
||||
|
||||
$("#linkdevices").css("font-weight", "normal");
|
||||
$("#linkwifi").css("font-weight", "bold");
|
||||
$("#linkusers").css("font-weight", "normal");
|
||||
$("#linknets").css("font-weight", "normal");
|
||||
|
||||
window.history.pushState("", "", "/wifi/");
|
||||
};
|
||||
|
@ -98,10 +102,26 @@ function showusers() {
|
|||
$("#devicespart").hide();
|
||||
$("#wifipart").hide();
|
||||
$("#userpart").show();
|
||||
$("#netpart").hide();
|
||||
|
||||
$("#linkdevices").css("font-weight", "normal");
|
||||
$("#linkwifi").css("font-weight", "normal");
|
||||
$("#linkusers").css("font-weight", "bold");
|
||||
$("#linknets").css("font-weight", "normal");
|
||||
|
||||
window.history.pushState("", "", "/users/");
|
||||
};
|
||||
|
||||
function shownets() {
|
||||
$("#devicespart").hide();
|
||||
$("#wifipart").hide();
|
||||
$("#userpart").hide();
|
||||
$("#netpart").show();
|
||||
|
||||
$("#linkdevices").css("font-weight", "normal");
|
||||
$("#linkwifi").css("font-weight", "normal");
|
||||
$("#linkusers").css("font-weight", "normal");
|
||||
$("#linknets").css("font-weight", "bold");
|
||||
|
||||
window.history.pushState("", "", "/users/");
|
||||
};
|
||||
|
@ -109,6 +129,7 @@ function showusers() {
|
|||
var page = document.location.pathname.substring(1, document.location.pathname.lastIndexOf('/'));
|
||||
if (page == "users") showusers();
|
||||
else if (page == "wifi") showwifi();
|
||||
else if (page == "networks") shownets();
|
||||
else showdevices();
|
||||
|
||||
$("div[id$='-indicator']").each(function() {
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<p><b>Organization:</b> {% orgaString %}</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> <a id="linkdevices" href="#" onclick="showdevices();">Devices</a> ‐ <a id="linkwifi" href="#" onclick="showwifi();">WiFi</a>{% if user.is_staff %} ‐ <a id="linkusers" href="#" onclick="showusers();">Users</a>{% endif %}</div>
|
||||
<div align="center"><b>Manage:</b> <a id="linkdevices" href="#" onclick="showdevices();">Devices</a> ‐ <a id="linkwifi" href="#" onclick="showwifi();">WiFi</a>{% if user.is_staff %} ‐ <a id="linkusers" href="#" onclick="showusers();">Users</a>{% endif %}{% if user.is_superuser %} ‐ <a id="linknets" href="#" onclick="shownets();">Networks</a>{% endif %}</div>
|
||||
|
||||
{% getNotifications %}
|
||||
|
||||
|
@ -95,7 +95,35 @@
|
|||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if request.user.is_superuser %}
|
||||
<div name ="netpart" id="netpart">
|
||||
<h2>Networks</h2>
|
||||
|
||||
<div class="table-responsive">
|
||||
<table id="networks" name="networks" class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Common Name</th>
|
||||
<th>Internal IP</th>
|
||||
<th>External IP</th>
|
||||
<th>Options</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
{% userNets as networks %}
|
||||
{% for network in networks %}
|
||||
<tr>
|
||||
<td><div style="display:inline;" title="{% directOrgaString auser %}">{{ network.name }}</div></td>
|
||||
<td>{{ network.intip }}</td>
|
||||
<td>{{ network.extip }}</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
{% endif %}
|
||||
<script src="/js/devices.js"></script>
|
||||
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in a new issue