move sort_table.js to core.js

master
Aevann1 2022-12-10 12:40:34 +02:00
parent b2591daa2b
commit 1886dd986e
16 changed files with 116 additions and 150 deletions

View File

@ -5096,7 +5096,7 @@ code {
.noshadow {
box-shadow: none !important;
}
[role="button"], :not(textarea)[onclick] {
[role="button"], :not(textarea)[onclick], th {
cursor: pointer !important;
}

View File

@ -233,12 +233,6 @@ function expandDesktopImage(url) {
bootstrap.Modal.getOrCreateInstance(document.getElementById('expandImageModal')).show();
};
document.addEventListener("click", function(e){
const element = e.target
if (element instanceof HTMLImageElement && element.alt.startsWith('![]('))
expandDesktopImage()
});
function bs_trigger(e) {
let tooltipTriggerList = [].slice.call(e.querySelectorAll('[data-bs-toggle="tooltip"]'));
tooltipTriggerList.map(function(element){
@ -404,3 +398,51 @@ function sendFormXHRSwitch(e) {
}
)
}
let sortAscending = {};
function sort_table(t) {
const n = Array.prototype.indexOf.call(t.parentElement.children, t);
const table = this.event.target.parentElement.parentElement.parentElement
const rows = table.rows;
let items = [];
for (let i = 1; i < rows.length; i++) {
const ele = rows[i];
let x = rows[i].getElementsByTagName("TD")[n];
if (!('sortKey' in x.dataset)) {
x = x.getElementsByTagName('a')[0] || x;
}
let attr;
if ('sortKey' in x.dataset) {
attr = x.dataset.sortKey;
} else if ('time' in x.dataset) {
attr = parseInt(x.dataset.time);
} else {
attr = x.innerText
if (/^[\d-,]+$/.test(attr)) {
attr = parseInt(attr.replace(/,/g, ''))
}
}
items.push({ele, attr});
}
if (sortAscending[n]) {
items.sort((a, b) => a.attr > b.attr ? 1 : -1);
sortAscending[n] = false;
} else {
items.sort((a, b) => a.attr < b.attr ? 1 : -1);
sortAscending[n] = true;
}
for (let i = items.length - 1; i--;) {
items[i].ele.parentNode.insertBefore(items[i].ele, items[i + 1].ele);
}
}
document.addEventListener("click", function(e){
const element = e.target
if (element instanceof HTMLImageElement && element.alt.startsWith('![]('))
expandDesktopImage()
else if (element.tagName == "TH")
sort_table(element)
});

View File

@ -1,40 +0,0 @@
let sortAscending = {};
function sort_table(t) {
const n = Array.prototype.indexOf.call(t.parentElement.children, t);
const table = this.event.target.parentElement.parentElement.parentElement
const rows = table.rows;
let items = [];
for (let i = 1; i < rows.length; i++) {
const ele = rows[i];
let x = rows[i].getElementsByTagName("TD")[n];
if (!('sortKey' in x.dataset)) {
x = x.getElementsByTagName('a')[0] || x;
}
let attr;
if ('sortKey' in x.dataset) {
attr = x.dataset.sortKey;
} else if ('time' in x.dataset) {
attr = parseInt(x.dataset.time);
} else {
attr = x.innerHTML
try {
attr = parseInt(attr.replace(/,/g, ''));
}
catch(e) {
}
}
items.push({ ele, attr });
}
if (sortAscending[n]) {
items.sort((a, b) => a.attr > b.attr ? 1 : -1);
sortAscending[n] = false;
} else {
items.sort((a, b) => a.attr < b.attr ? 1 : -1);
sortAscending[n] = true;
}
for (let i = items.length - 1; i--;) {
items[i].ele.parentNode.insertBefore(items[i].ele, items[i + 1].ele);
}
}

View File

@ -519,9 +519,9 @@ class User(Base):
@property
@lazy
def unban_in(self):
def unban_string(self):
if self.unban_utc == 0:
return "never"
return "permanently banned"
wait = self.unban_utc - int(time.time())
@ -538,43 +538,9 @@ class User(Base):
text = f"{days}d {hours:02d}h {mins:02d}m"
return text
@property
@lazy
def unban_string(self):
text = self.unban_in
if text == "never": return "permanently banned"
return f"Unban in {text}"
@property
@lazy
def unchud_in(self):
if self.agendaposter == 1:
return "never"
wait = self.agendaposter - int(time.time())
if wait < 60:
text = f"{wait}s"
else:
days = wait//(24*60*60)
wait -= days*24*60*60
hours = wait//(60*60)
wait -= hours*60*60
mins = wait//60
text = f"{days}d {hours:02d}h {mins:02d}m"
return text
@property
@lazy
def received_awards(self):

View File

@ -6,26 +6,26 @@
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th onclick="sort_table(this)">#</th>
<th onclick="sort_table(this)">Name</th>
<th onclick="sort_table(this)">Last Active</th>
<th onclick="sort_table(this)">Truescore</th>
<th onclick="sort_table(this)">Shadowbanned by</th>
<th onclick="sort_table(this)">Shadowban reason</th>
<th>#</th>
<th>Name</th>
<th>Last Active</th>
<th>Truescore</th>
<th>Shadowbanned by</th>
<th>Shadowban reason</th>
</tr>
</thead>
{% for user in users %}
<tr>
<td>{{loop.index}}</td>
<td data-sort-key="{{user.username.lower() if user else ''}}">{%- include 'user_in_table.html' -%}</td>
<td data-time="{{user.last_active}}"></td>
<td {% if user.last_active %}data-time="{{user.last_active}}"{% endif %}></td>
<td>{{user.truescore}}</td>
<td>{{user.shadowbanned}}</td>
<td>{{user.ban_reason}}</td>
<td>{% if user.ban_reason %}{{user.ban_reason}}{% endif %}</td>
</tr>
{% endfor %}
</table>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %}

View File

@ -12,8 +12,8 @@
<tr>
<th>#</th>
<th>Name</th>
<th onclick="sort_table(this)" style="text-align:right;">Truescore</th>
<th onclick="sort_table(this)" style="text-align:right;">Mod actions</th>
<th style="text-align:right;">Truescore</th>
<th style="text-align:right;">Mod actions</th>
</tr>
</thead>
@ -28,6 +28,6 @@
</table>
</div>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %}

View File

@ -7,12 +7,12 @@
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th onclick="sort_table(this)">#</th>
<th>#</th>
<th>Name</th>
<th>Image</th>
<th>Description</th>
<th onclick="sort_table(this)">#</th>
<th onclick="sort_table(this)">Rarity</th>
<th>#</th>
<th>Rarity</th>
</tr>
</thead>
@ -32,6 +32,6 @@
</table>
</div>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %}

View File

@ -6,14 +6,14 @@
<div class="overflow-x-auto"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th onclick="sort_table(this)">#</th>
<th onclick="sort_table(this)">Name</th>
<th>#</th>
<th>Name</th>
{% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%}
<th onclick="sort_table(this)">Last Active</th>
<th>Last Active</th>
{%- endif %}
<td onclick="sort_table(this)">Truescore</td>
<th onclick="sort_table(this)">Ban reason</th>
<th onclick="sort_table(this)">Banned by</th>
<th>Truescore</th>
<th>Ban reason</th>
<th>Banned by</th>
<th>Unban in</th>
</tr>
</thead>
@ -22,7 +22,7 @@
<td>{{loop.index}}</td>
<td data-sort-key="{{user.username.lower() if user else ''}}">{% include "user_in_table.html" %}</td>
{% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%}
<td data-time="{{user.last_active}}"></td>
<td {% if user.last_active %}data-time="{{user.last_active}}"{% endif %}></td>
{%- endif %}
<td>{{user.truescore}}</td>
<td>{% if user.ban_reason %}{{user.ban_reason}}{% endif %}</td>
@ -31,13 +31,11 @@
{% include "user_in_table.html" %}
</td>
{% endwith %}
<td>
{{user.unban_in}}
</td>
<td {% if user.unban_utc %}data-time="{{user.unban_utc}}"{% endif %}></td>
</tr>
{% endfor %}
</table>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %}

View File

@ -6,12 +6,12 @@
<div class="overflow-x-auto"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th onclick="sort_table(this)">#</th>
<th onclick="sort_table(this)">Name</th>
<th>#</th>
<th>Name</th>
{% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%}
<th onclick="sort_table(this)">Last Active</th>
<th>Last Active</th>
{%- endif %}
<td onclick="sort_table(this)">Truescore</td>
<th>Truescore</th>
<th>Unchud in</th>
</tr>
</thead>
@ -20,14 +20,14 @@
<td>{{loop.index}}</td>
<td data-sort-key="{{user.username.lower() if user else ''}}">{% include "user_in_table.html" %}</td>
{% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%}
<td data-time="{{user.last_active}}"></td>
<td {% if user.last_active %}data-time="{{user.last_active}}"{% endif %}></td>
{%- endif %}
<td>{{user.truescore}}</td>
<td>{{user.unchud_in}}</td>
<td {% if user.agendaposter != 1 %}data-time="{{user.agendaposter}}"{% endif %}></td>
</tr>
{% endfor %}
</table>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %}

View File

@ -81,12 +81,12 @@
<th>Name</th>
<th>Description</th>
{% if SITE == 'rdrama.net' %}
<th onclick="sort_table(this)">Author</a></th>
<th>Author</a></th>
{% endif %}
<th onclick="sort_table(this)">Owners</th>
<th onclick="sort_table(this)">Price</th>
<th>Owners</th>
<th>Price</th>
<th>Actions</th>
<th onclick="sort_table(this)">Added on</th>
<th>Added on</th>
</tr>
</thead>
@ -129,5 +129,5 @@
{% endfor %}
</tbody>
</table>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %}

View File

@ -5,14 +5,14 @@
<div class="overflow-x-auto mt-3"><table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th onclick="sort_table(this)">#</th>
<th onclick="sort_table(this)">Name</th>
<th>#</th>
<th>Name</th>
<th>Marsey</th>
<th onclick="sort_table(this)">Usage</th>
<th>Usage</th>
{% if FEATURES['ASSET_SUBMISSIONS'] %}
<th onclick="sort_table(this)">Author</th>
<th>Author</th>
{% endif %}
<th onclick="sort_table(this)">Added on</th>
<th>Added on</th>
{% if FEATURES['ASSET_SUBMISSIONS'] %}
<th>Original File</th>
{% endif %}
@ -41,5 +41,5 @@
{% endfor %}
</tbody>
</table>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %}

View File

@ -9,8 +9,8 @@
<tr>
<th>#</th>
<th>User</th>
<th onclick="sort_table(this)">User Truescore</th>
<th onclick="sort_table(this)">Vote Time</th>
<th>User Truescore</th>
<th>Vote Time</th>
</tr>
</thead>
@ -28,6 +28,6 @@
{% endfor %}
</table>
</div>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endif %}
{% endblock %}

View File

@ -73,7 +73,7 @@
<th>Icon</th>
<th>Title</th>
<th>Price</th>
<th onclick="sort_table(this)">Owned</th>
<th>Owned</th>
<th>Buy</th>
<th>Description</th>
</tr>
@ -107,5 +107,5 @@
{% endfor %}
</table>
</div>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %}

View File

@ -6,12 +6,12 @@
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th onclick="sort_table(this)">#</th>
<th onclick="sort_table(this)">Name</th>
<th onclick="sort_table(this)">Wins</th>
<th onclick="sort_table(this)">Bets</th>
<th onclick="sort_table(this)">Win rate</th>
<th onclick="sort_table(this)">Winnings</th>
<th>#</th>
<th>Name</th>
<th>Wins</th>
<th>Bets</th>
<th>Win rate</th>
<th>Winnings</th>
</tr>
</thead>
<tbody>
@ -31,5 +31,5 @@
</tbody>
</table>
</div>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %}

View File

@ -8,10 +8,10 @@
<tr>
<th>#</th>
<th>Name</th>
<th onclick="sort_table(this)">Posts</th>
<th onclick="sort_table(this)">Followers</th>
<th onclick="sort_table(this)">Blockers</th>
<th onclick="sort_table(this)">Created on</th>
<th>Posts</th>
<th>Followers</th>
<th>Blockers</th>
<th>Created on</th>
</tr>
</thead>
@ -32,6 +32,6 @@
</table>
</div>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endblock %}

View File

@ -17,8 +17,8 @@
<tr>
<th>#</th>
<th>User</th>
<th onclick="sort_table(this)">User Truescore</th>
<th onclick="sort_table(this)">Vote Time</th>
<th>User Truescore</th>
<th>Vote Time</th>
</tr>
</thead>
@ -44,8 +44,8 @@
<tr>
<th>#</th>
<th>User</th>
<th onclick="sort_table(this)">User Truescore</th>
<th onclick="sort_table(this)">Vote Time</th>
<th>User Truescore</th>
<th>Vote Time</th>
</tr>
</thead>
@ -64,7 +64,7 @@
</table>
</div>
<script defer src="{{'js/sort_table.js' | asset}}"></script>
{% endif %}