Implement network page

modern-tables
Mark Veidemanis 2 years ago
parent c993bb9c6e
commit df049f822c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F

@ -38,12 +38,15 @@ from core.views.dynamic.insights import (
InsightsSearch,
)
from core.views.dynamic.manage.threshold.irc import (
ThresholdIRCNetworkChannels,
ThresholdIRCNetworkInfo,
ThresholdIRCNetworkRelays,
ThresholdIRCNetworks,
ThresholdIRCStats,
)
# Management stuff
from core.views.manage.threshold import ThresholdIRCOverview
from core.views.manage.threshold import ThresholdIRCNetwork, ThresholdIRCOverview
urlpatterns = [
path("", Home.as_view(), name="home"),
@ -81,15 +84,35 @@ urlpatterns = [
name="threshold_irc_overview",
),
path(
"manage/threshold/irc/stats/",
"manage/threshold/irc/overview/stats/",
ThresholdIRCStats.as_view(),
name="threshold_irc_stats",
),
path(
"manage/threshold/irc/networks/",
"manage/threshold/irc/overview/networks/",
ThresholdIRCNetworks.as_view(),
name="threshold_irc_networks",
),
path(
"manage/threshold/irc/network/<str:net>/",
ThresholdIRCNetwork.as_view(),
name="threshold_irc_network",
),
path(
"manage/threshold/irc/network/<str:net>/info/",
ThresholdIRCNetworkInfo.as_view(),
name="threshold_irc_network_info",
),
path(
"manage/threshold/irc/network/<str:net>/relays/",
ThresholdIRCNetworkRelays.as_view(),
name="threshold_irc_network_relays",
),
path(
"manage/threshold/irc/network/<str:net>/channels/",
ThresholdIRCNetworkChannels.as_view(),
name="threshold_irc_network_channels",
),
##
path("api/chans/", ThresholdChans.as_view(), name="chans"),
path("api/users/", ThresholdUsers.as_view(), name="users"),

@ -17,3 +17,30 @@ def get_irc_networks():
if not networks:
return {}
return networks
def get_irc_network(net):
url = f"irc/network/{net}"
payload = {}
network = threshold_request(url, payload)
if not network:
return {}
return network
def get_irc_relays(net):
url = f"irc/network/{net}/relays"
payload = {}
relays = threshold_request(url, payload)
if not relays:
return []
return relays
def get_irc_channels(net):
url = f"irc/network/{net}/channels"
payload = {}
channels = threshold_request(url, payload)
if not channels:
return []
return channels

@ -10,7 +10,6 @@ def construct_query(net, nicks):
# Construct the query
query_nicks = [{"match": {"nick": x}} for x in nicks]
query_should = query_nicks
# print("QUERY SHOULD", query_should)
# Get the initial query
query = {
"size": settings.META_QUERY_SIZE,

@ -11,7 +11,6 @@ def construct_query(net, nicks):
query_nicks = [{"match": {"nick": x}} for x in nicks]
query_users = [{"match": {"user": x}} for x in nicks]
query_should = query_nicks + query_users
# print("QUERY SHOULD", query_should)
# Get the initial query
query = {
"size": settings.NICKTRACE_QUERY_SIZE,

@ -1,5 +1,7 @@
import logging
from json import dumps
from operator import itemgetter
from typing import OrderedDict
import requests
from django.conf import settings
@ -27,6 +29,12 @@ def sort_data(data):
for item in data:
if isinstance(data[item], list):
data[item].sort()
elif isinstance(data[item], dict):
# if all([isinstance(x, int) for k, v in
# data[item].items() for x in v.values()]):
sorted_item = sorted(data[item].items(), key=itemgetter(1), reverse=True)
data[item] = OrderedDict({k: v for k, v in sorted_item})
def threshold_request(url, data):

@ -0,0 +1,22 @@
<div id="channels">
{% if channels is not None %}
<div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container">
<table class="table is-fullwidth is-hoverable">
<tbody>
{% for channel, info in channels.items %}
<tr>
<td>
{{ channel }}
<span class="tag">
{{ info }}
</span>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</div>

@ -0,0 +1,51 @@
<div id="info">
{% if network is not None %}
<div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container">
<table class="table is-fullwidth is-hoverable">
<thead>
<th>attribute</th>
<th>value</th>
</thead>
<tbody>
{% for key, item in network.items %}
<tr>
<th>{{ key }}</th>
<td>
{% if key == 'security' %}
{% if item == 'none' %}
<span class="icon">
<i class="fa-solid fa-lock-open" aria-hidden="true"></i>
</span>
{% elif item == 'ssl' %}
<span class="icon">
<i class="fa-solid fa-lock" aria-hidden="true"></i>
</span>
{% endif %}
{% elif key == 'relays' %}
<span class="icon">
<i class="fa-brands fa-unity"></i>
</span>
{% elif key == 'channels' %}
<span class="icon">
<i class="fa-solid fa-hashtag"></i>
</span>
{% elif key == 'records' %}
<span class="icon">
<i class="fa-solid fa-album"></i>
</span>
{% elif key == 'host' %}
<span class="icon">
<i class="fa-solid fa-router"></i>
</span>
{% endif %}
{{ item }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</div>

@ -0,0 +1,59 @@
<div id="relays">
{% if relays is not None %}
<div class="content" style="max-height: 30em; overflow: auto;">
<div class="table-container">
<table class="table is-fullwidth is-hoverable">
<thead>
<th>net</th>
<th>id</th>
<th>registered</th>
<th>enabled</th>
<th>
<span class="icon">
<i class="fa-solid fa-hashtag"></i>
</span>
</th>
<th>nick</th>
</thead>
<tbody>
{% for relay in relays %}
<tr>
<th>{{ relay.net }}</th>
<td>{{ relay.id }}</td>
<td>
{% if relay.registered %}
<span class="icon">
<i class="fa-solid fa-check" aria-hidden="true"></i>
</span>
{% else %}
<span class="icon">
<i class="fa-solid fa-xmark" aria-hidden="true"></i>
</span>
{% endif %}
</td>
<td>
{% if relay.enabled %}
<span class="icon">
<i class="fa-solid fa-check" aria-hidden="true"></i>
</span>
{% else %}
<span class="icon">
<i class="fa-solid fa-xmark" aria-hidden="true"></i>
</span>
{% endif %}
</td>
<td>
{{ relay.chans }}
</td>
<td>
{{ relay.nick }}
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% endif %}
</div>

@ -9,21 +9,21 @@
</thead>
{% for key, net in networks.items %}
<tr>
<th>{{ key }}</th>
<th><a href="{% url 'threshold_irc_network' key %}">{{ key }}</a></th>
<td>
<span class="icon has-text-info has-tooltip-info">
<span class="icon">
<i class="fa-brands fa-unity"></i>
</span>
{{ net.relays }}
</td>
<td>
<span class="icon has-text-info has-tooltip-info">
<span class="icon">
<i class="fa-solid fa-hashtag"></i>
</span>
{{ net.channels }}
</td>
<td>
<span class="icon has-text-info has-tooltip-info">
<span class="icon">
<i class="fa-solid fa-album"></i>
</span>
{{ net.records }}

@ -0,0 +1,60 @@
{% extends "base.html" %}
{% block content %}
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_network_info' net %}"
hx-trigger="load"
hx-target="#info"
hx-swap="outerHTML">
</div>
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_network_relays' net %}"
hx-trigger="load"
hx-target="#relays"
hx-swap="outerHTML">
</div>
<div
style="display: none;"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'threshold_irc_network_channels' net %}"
hx-trigger="load"
hx-target="#channels"
hx-swap="outerHTML">
</div>
<div class="columns">
<div class="column">
<div class="box">
<div id="info">
</div>
</div>
</div>
<div class="column">
<div class="box">
<div id="relays">
</div>
</div>
</div>
</div>
<div class="columns">
<div class="column">
<div class="box">
<div id="channels">
</div>
</div>
</div>
<div class="column">
<div class="box">
<div id="alerts">
</div>
</div>
</div>
</div>
{% endblock %}

@ -1,12 +1,18 @@
from django.shortcuts import render
from django.views import View
from core.lib.manage.threshold import get_irc_networks, get_irc_stats
from core.lib.manage.threshold import (
get_irc_channels,
get_irc_network,
get_irc_networks,
get_irc_relays,
get_irc_stats,
)
from core.views.manage.permissions import SuperUserRequiredMixin
class ThresholdIRCStats(SuperUserRequiredMixin, View):
stats_template = "dynamic/manage/threshold/irc/stats.html"
stats_template = "dynamic/manage/threshold/irc/overview/stats.html"
def post(self, request):
stats = get_irc_stats()
@ -15,9 +21,36 @@ class ThresholdIRCStats(SuperUserRequiredMixin, View):
class ThresholdIRCNetworks(SuperUserRequiredMixin, View):
stats_template = "dynamic/manage/threshold/irc/networks.html"
template_name = "dynamic/manage/threshold/irc/overview/networks.html"
def post(self, request):
stats = get_irc_networks()
context = {"networks": stats}
return render(request, self.stats_template, context)
networks = get_irc_networks()
context = {"networks": networks}
return render(request, self.template_name, context)
class ThresholdIRCNetworkInfo(SuperUserRequiredMixin, View):
template_name = "dynamic/manage/threshold/irc/network/info.html"
def post(self, request, net):
network = get_irc_network(net)
context = {"network": network}
return render(request, self.template_name, context)
class ThresholdIRCNetworkRelays(SuperUserRequiredMixin, View):
template_name = "dynamic/manage/threshold/irc/network/relays.html"
def post(self, request, net):
relays = get_irc_relays(net)
context = {"relays": relays["relays"]}
return render(request, self.template_name, context)
class ThresholdIRCNetworkChannels(SuperUserRequiredMixin, View):
template_name = "dynamic/manage/threshold/irc/network/channels.html"
def post(self, request, net):
channels = get_irc_channels(net)
context = {"channels": channels["channels"]}
return render(request, self.template_name, context)

@ -9,3 +9,11 @@ class ThresholdIRCOverview(SuperUserRequiredMixin, View):
def get(self, request):
return render(request, self.template_name)
class ThresholdIRCNetwork(SuperUserRequiredMixin, View):
template_name = "manage/threshold/irc/network.html"
def get(self, request, net):
context = {"net": net}
return render(request, self.template_name, context)

Loading…
Cancel
Save