Fix tag population and date formatting

This commit is contained in:
Mark Veidemanis 2022-08-11 07:22:22 +01:00
parent 54f82f772b
commit 86ec95ab6c
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
4 changed files with 189 additions and 179 deletions

View File

@ -1,5 +1,6 @@
{% load static %} {% load static %}
{% load index %} {% load index %}
{% load joinsep %}
{% include 'partials/notify.html' %} {% include 'partials/notify.html' %}
{% if table %} {% if table %}
<div style="display: none" id="jsonData" data-json="{{ data }}"> <div style="display: none" id="jsonData" data-json="{{ data }}">
@ -35,4 +36,24 @@
{% include 'ui/drilldown/table_results_partial.html' %} {% include 'ui/drilldown/table_results_partial.html' %}
</div> </div>
</div> </div>
{% endif %} {% endif %}
{# Update the tags in case the user changed the query #}
{# Check for focus and refocus #}
<script>
var inputTags = document.getElementsByClassName('tags-input');
var inputBox = document.querySelector("[placeholder='Add query']");
var isFocused = (document.activeElement === inputBox);
for (index = 0; index < inputTags.length; index++) {
if (index == 0) {
inputTags[0].outerHTML = '<input id="tags" class="input" type="tags" placeholder="Add query" value="{{ tags|joinsep:',' }}">';
} else {
inputTags[index].remove();
}
}
// inputTags[0].outerHTML = '<input id="tags" class="input" type="tags" placeholder="Add query" value="{{ tags|joinsep:',' }}">';
setupTags();
var inputBox = document.querySelector("[placeholder='Add query']");
if (isFocused) {
inputBox.focus();
}
</script>

View File

@ -1,7 +1,6 @@
{% load django_tables2 %} {% load django_tables2 %}
{% load i18n %} {% load i18n %}
{% load django_tables2_bulma_template %} {% load django_tables2_bulma_template %}
{% load joinsep %}
{% block table-wrapper %} {% block table-wrapper %}
<div class="container"> <div class="container">
@ -13,34 +12,38 @@
{% block table.thead.row %} {% block table.thead.row %}
<tr> <tr>
{% for column in table.columns %} {% for column in table.columns %}
{% block table.thead.th %}
<th {% render_attrs column.attrs.th class="" %}> {% if column.name not in hide %}
{% if column.orderable %} {% block table.thead.th %}
{% if column.is_ordered %} <th {% render_attrs column.attrs.th class="" %}>
{% is_descending column.order_by as descending %} {% if column.orderable %}
{% if descending %} {% if column.is_ordered %}
<span class="icon" aria-hidden="true">{% block table.desc_icon %}<i class="fa-solid fa-sort-down"></i>{% endblock table.desc_icon %}</span> {% is_descending column.order_by as descending %}
{% if descending %}
<span class="icon" aria-hidden="true">{% block table.desc_icon %}<i class="fa-solid fa-sort-down"></i>{% endblock table.desc_icon %}</span>
{% else %}
<span class="icon" aria-hidden="true">{% block table.asc_icon %}<i class="fa-solid fa-sort-up"></i>{% endblock table.asc_icon %}</span>
{% endif %}
{% else %} {% else %}
<span class="icon" aria-hidden="true">{% block table.asc_icon %}<i class="fa-solid fa-sort-up"></i>{% endblock table.asc_icon %}</span> <span class="icon" aria-hidden="true">{% block table.orderable_icon %}<i class="fa-solid fa-sort"></i>{% endblock table.orderable_icon %}</span>
{% endif %} {% endif %}
<a
hx-get="search/{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}&{{ uri }}"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-trigger="click"
hx-target="#results"
hx-swap="innerHTML"
hx-indicator=".progress"
style="cursor: pointer;">
{{ column.header }}
</a>
{% else %} {% else %}
<span class="icon" aria-hidden="true">{% block table.orderable_icon %}<i class="fa-solid fa-sort"></i>{% endblock table.orderable_icon %}</span>
{% endif %}
<a
hx-get="search/{% querystring table.prefixed_order_by_field=column.order_by_alias.next %}&{{ uri }}"
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-trigger="click"
hx-target="#results"
hx-swap="innerHTML"
hx-indicator=".progress"
style="cursor: pointer;">
{{ column.header }} {{ column.header }}
</a> {% endif %}
{% else %} </th>
{{ column.header }} {% endblock table.thead.th %}
{% endif %} {% endif %}
</th>
{% endblock table.thead.th %}
{% endfor %} {% endfor %}
</tr> </tr>
{% endblock table.thead.row %} {% endblock table.thead.row %}
@ -65,144 +68,151 @@
has-background-info-light has-background-info-light
{% endif %}"> {% endif %}">
{% for column, cell in row.items %} {% for column, cell in row.items %}
{% block table.tbody.td %} {% if column.name not in hide %}
{% if column.name == 'src' %} {% block table.tbody.td %}
<td> {% if column.name == 'src' %}
<a class="has-text-link is-underlined" <td>
onclick="populateSearch('src', '{{ cell|escapejs }}')"> <a class="has-text-link is-underlined"
{% if row.cells.src == 'irc' %} onclick="populateSearch('src', '{{ cell|escapejs }}')">
<span class="icon" data-tooltip="IRC"> {% if row.cells.src == 'irc' %}
<i class="fa-solid fa-hashtag" aria-hidden="true"></i> <span class="icon" data-tooltip="IRC">
</span> <i class="fa-solid fa-hashtag" aria-hidden="true"></i>
{% elif row.cells.src == 'dis' %}
<span class="icon" data-tooltip="Discord">
<i class="fa-brands fa-discord" aria-hidden="true"></i>
</span>
{% endif %}
</a>
</td>
{% elif column.name == 'type' %}
<td>
<a class="has-text-link is-underlined"
onclick="populateSearch('type', '{{ cell|escapejs }}')">
{% if row.cells.type == 'msg' %}
<span class="icon" data-tooltip="Message">
<i class="fa-solid fa-message"></i>
</span>
{% elif row.cells.type == 'join' %}
<span class="icon" data-tooltip="Join">
<i class="fa-solid fa-person-to-portal"></i>
</span>
{% elif row.cells.type == 'part' %}
<span class="icon" data-tooltip="Part">
<i class="fa-solid fa-person-from-portal"></i>
</span>
{% elif row.cells.type == 'quit' %}
<span class="icon" data-tooltip="Quit">
<i class="fa-solid fa-circle-xmark"></i>
</span>
{% elif row.cells.type == 'kick' %}
<span class="icon" data-tooltip="Kick">
<i class="fa-solid fa-user-slash"></i>
</span>
{% elif row.cells.type == 'nick' %}
<span class="icon" data-tooltip="Nick">
<i class="fa-solid fa-signature"></i>
</span>
{% elif row.cells.type == 'mode' %}
<span class="icon" data-tooltip="Mode">
<i class="fa-solid fa-gear"></i>
</span>
{% elif row.cells.type == 'action' %}
<span class="icon" data-tooltip="Action">
<i class="fa-solid fa-exclamation"></i>
</span>
{% else %}
{{ row.cells.type }}
{% endif %}
</a>
</td>
{% elif column.name == 'msg' %}
<td style="max-width: 10em" class="wrap">{{ row.cells.msg }}</td>
{% elif column.name == 'host' %}
<td>
<a class="has-text-link is-underlined"
onclick="populateSearch('host', '{{ cell|escapejs }}')">
{{ cell }}
</a>
</td>
{% elif column.name == 'nick' %}
<td>
<div class="nowrap-parent">
<div class="nowrap-child">
{% if row.cells.online is True %}
<span class="icon has-text-success has-tooltip-success" data-tooltip="Online">
<i class="fa-solid fa-circle"></i>
</span> </span>
{% elif row.cells.online is False %} {% elif row.cells.src == 'dis' %}
<span class="icon has-text-danger has-tooltip-danger" data-tooltip="Offline"> <span class="icon" data-tooltip="Discord">
<i class="fa-solid fa-circle"></i> <i class="fa-brands fa-discord" aria-hidden="true"></i>
</span>
{% endif %}
</a>
</td>
{% elif column.name == 'ts' %}
<td>
<p>{{ row.cells.date }}</p>
<p>{{ row.cells.time }}</p>
</td>
{% elif column.name == 'type' %}
<td>
<a class="has-text-link is-underlined"
onclick="populateSearch('type', '{{ cell|escapejs }}')">
{% if row.cells.type == 'msg' %}
<span class="icon" data-tooltip="Message">
<i class="fa-solid fa-message"></i>
</span>
{% elif row.cells.type == 'join' %}
<span class="icon" data-tooltip="Join">
<i class="fa-solid fa-person-to-portal"></i>
</span>
{% elif row.cells.type == 'part' %}
<span class="icon" data-tooltip="Part">
<i class="fa-solid fa-person-from-portal"></i>
</span>
{% elif row.cells.type == 'quit' %}
<span class="icon" data-tooltip="Quit">
<i class="fa-solid fa-circle-xmark"></i>
</span>
{% elif row.cells.type == 'kick' %}
<span class="icon" data-tooltip="Kick">
<i class="fa-solid fa-user-slash"></i>
</span>
{% elif row.cells.type == 'nick' %}
<span class="icon" data-tooltip="Nick">
<i class="fa-solid fa-signature"></i>
</span>
{% elif row.cells.type == 'mode' %}
<span class="icon" data-tooltip="Mode">
<i class="fa-solid fa-gear"></i>
</span>
{% elif row.cells.type == 'action' %}
<span class="icon" data-tooltip="Action">
<i class="fa-solid fa-exclamation"></i>
</span> </span>
{% else %} {% else %}
<span class="icon has-text-warning has-tooltip-warning" data-tooltip="Unknown"> {{ row.cells.type }}
<i class="fa-solid fa-circle"></i>
</span>
{% endif %} {% endif %}
</div> </a>
<a class="nowrap-child has-text-link is-underlined" onclick="populateSearch('nick', '{{ cell|escapejs }}')"> </td>
{% elif column.name == 'msg' %}
<td style="max-width: 10em" class="wrap">{{ row.cells.msg }}</td>
{% elif column.name == 'host' %}
<td>
<a class="has-text-link is-underlined"
onclick="populateSearch('host', '{{ cell|escapejs }}')">
{{ cell }} {{ cell }}
</a> </a>
<div class="nowrap-child"> </td>
{% if row.cells.src == 'irc' %} {% elif column.name == 'nick' %}
<button <td>
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}' <div class="nowrap-parent">
hx-post="{% url 'modal_drilldown' %}" <div class="nowrap-child">
hx-vals='{"net": "{{ row.cells.net }}", "nick": "{{ row.cells.nick }}", "channel": "{{ row.cells.channel }}"}' {% if row.cells.online is True %}
hx-target="#modals-here" <span class="icon has-text-success has-tooltip-success" data-tooltip="Online">
hx-trigger="click" <i class="fa-solid fa-circle"></i>
class="button is-small"> </span>
Information {% elif row.cells.online is False %}
</button> <span class="icon has-text-danger has-tooltip-danger" data-tooltip="Offline">
<i class="fa-solid fa-circle"></i>
</span>
{% else %}
<span class="icon has-text-warning has-tooltip-warning" data-tooltip="Unknown">
<i class="fa-solid fa-circle"></i>
</span>
{% endif %}
</div>
<a class="nowrap-child has-text-link is-underlined" onclick="populateSearch('nick', '{{ cell|escapejs }}')">
{{ cell }}
</a>
<div class="nowrap-child">
{% if row.cells.src == 'irc' %}
<button
hx-headers='{"X-CSRFToken": "{{ csrf_token }}"}'
hx-post="{% url 'modal_drilldown' %}"
hx-vals='{"net": "{{ row.cells.net }}", "nick": "{{ row.cells.nick }}", "channel": "{{ row.cells.channel }}"}'
hx-target="#modals-here"
hx-trigger="click"
class="button is-small">
Information
</button>
{% endif %}
</div>
{% if row.cells.num_chans is not None %}
<div class="nowrap-child">
<span class="tag">
{{ row.cells.num_chans }}
</span>
</div>
{% endif %} {% endif %}
</div> </div>
{% if row.cells.num_chans is not None %} </td>
<div class="nowrap-child"> {% elif column.name == 'channel' %}
<span class="tag"> <td>
{{ row.cells.num_chans }} <div class="nowrap-parent">
</span> <a class="nowrap-child has-text-link is-underlined"
</div> onclick="populateSearch('channel', '{{ cell|escapejs }}')">
{% endif %} {{ cell }}
</div> </a>
</td> {% if row.cells.num_users is not None %}
{% elif column.name == 'channel' %} <div class="nowrap-child">
<td> <span class="tag">
<div class="nowrap-parent"> {{ row.cells.num_users }}
<a class="nowrap-child has-text-link is-underlined" </span>
onclick="populateSearch('channel', '{{ cell|escapejs }}')"> </div>
{% endif %}
</div>
</td>
{% elif column.name == 'net' %}
<td>
<a class="has-text-link is-underlined"
onclick="populateSearch('net', '{{ cell|escapejs }}')">
{{ cell }} {{ cell }}
</a> </a>
{% if row.cells.num_users is not None %} </td>
<div class="nowrap-child"> {% else %}
<span class="tag"> <td>
{{ row.cells.num_users }}
</span>
</div>
{% endif %}
</div>
</td>
{% elif column.name == 'net' %}
<td>
<a class="has-text-link is-underlined"
onclick="populateSearch('net', '{{ cell|escapejs }}')">
{{ cell }} {{ cell }}
</a> </td>
</td> {% endif %}
{% else %} {% endblock table.tbody.td %}
<td> {% endif %}
{{ cell }}
</td>
{% endif %}
{% endblock table.tbody.td %}
{% endfor %} {% endfor %}
</tr> </tr>
{% endblock table.tbody.row %} {% endblock table.tbody.row %}
@ -309,24 +319,4 @@
{% endif %} {% endif %}
{% endblock pagination %} {% endblock pagination %}
</div> </div>
{# Update the tags in case the user changed the query #}
{# Check for focus and refocus #}
<script>
var inputTags = document.getElementsByClassName('tags-input');
var inputBox = document.querySelector("[placeholder='Add query']");
var isFocused = (document.activeElement === inputBox);
for (index = 0; index < inputTags.length; index++) {
if (index == 0) {
inputTags[0].outerHTML = '<input id="tags" class="input" type="tags" placeholder="Add query" value="{{ tags|joinsep:',' }}">';
} else {
inputTags[index].remove();
}
}
// inputTags[0].outerHTML = '<input id="tags" class="input" type="tags" placeholder="Add query" value="{{ tags|joinsep:',' }}">';
setupTags();
var inputBox = document.querySelector("[placeholder='Add query']");
if (isFocused) {
inputBox.focus();
}
</script>
{% endblock table-wrapper %} {% endblock table-wrapper %}

View File

@ -190,6 +190,7 @@ class DrilldownTableView(SingleTableView):
for k, v in self.context.items(): for k, v in self.context.items():
if k not in context: if k not in context:
context[k] = v context[k] = v
context["hide"] = ["date", "time", "id", "num", "channel_nsfw", "num_users", "num_chans", "exemption", "version_sentiment"]
if request.method == "GET": if request.method == "GET":
if not request.htmx: if not request.htmx:

View File

@ -5,9 +5,8 @@ from django_tables2.columns.base import BoundColumn
# Make the table column headings lowercase # Make the table column headings lowercase
orig_Column_header = BoundColumn.header orig_Column_header = BoundColumn.header
@property @property
def lower_header(self): def format_header(self):
header = orig_Column_header.__get__(self) header = orig_Column_header.__get__(self)
header = header.lower() header = header.lower()
header = header.title() header = header.title()
@ -20,8 +19,7 @@ def lower_header(self):
return header return header
BoundColumn.header = format_header
BoundColumn.header = lower_header
class DrilldownTable(Table): class DrilldownTable(Table):
@ -38,8 +36,8 @@ class DrilldownTable(Table):
num = Column() num = Column()
src = Column() src = Column()
ts = Column() ts = Column()
# date = Column() date = Column()
# time = Column() time = Column()
type = Column() type = Column()
bot = Column() bot = Column()
channel = Column() channel = Column()