From 1886dd986ee2452528ca9a6cab407c2b2ef0adf9 Mon Sep 17 00:00:00 2001 From: Aevann1 Date: Sat, 10 Dec 2022 12:40:34 +0200 Subject: [PATCH] move sort_table.js to core.js --- files/assets/css/main.css | 2 +- files/assets/js/core.js | 54 ++++++++++++++++--- files/assets/js/sort_table.js | 40 -------------- files/classes/user.py | 38 +------------ files/templates/admin/shadowbanned.html | 18 +++---- files/templates/admins.html | 6 +-- files/templates/badges.html | 8 +-- files/templates/banned.html | 20 ++++--- files/templates/chuds.html | 14 ++--- files/templates/hats.html | 10 ++-- files/templates/marseys.html | 12 ++--- files/templates/poll_votes.html | 6 +-- files/templates/shop.html | 4 +- .../special/worldcup22_leaderboard.html | 14 ++--- files/templates/sub/subs.html | 10 ++-- files/templates/votes.html | 10 ++-- 16 files changed, 116 insertions(+), 150 deletions(-) delete mode 100644 files/assets/js/sort_table.js diff --git a/files/assets/css/main.css b/files/assets/css/main.css index 8594ad775..79309b319 100644 --- a/files/assets/css/main.css +++ b/files/assets/css/main.css @@ -5096,7 +5096,7 @@ code { .noshadow { box-shadow: none !important; } -[role="button"], :not(textarea)[onclick] { +[role="button"], :not(textarea)[onclick], th { cursor: pointer !important; } diff --git a/files/assets/js/core.js b/files/assets/js/core.js index cbef8ecda..1e6f07a88 100644 --- a/files/assets/js/core.js +++ b/files/assets/js/core.js @@ -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) +}); diff --git a/files/assets/js/sort_table.js b/files/assets/js/sort_table.js deleted file mode 100644 index 53d30ff29..000000000 --- a/files/assets/js/sort_table.js +++ /dev/null @@ -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); - } -} diff --git a/files/classes/user.py b/files/classes/user.py index cdf33f36b..dda195ad4 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -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): diff --git a/files/templates/admin/shadowbanned.html b/files/templates/admin/shadowbanned.html index a29cdf73f..3a7652c7c 100644 --- a/files/templates/admin/shadowbanned.html +++ b/files/templates/admin/shadowbanned.html @@ -6,26 +6,26 @@ - - - - - - + + + + + + {% for user in users %} - + - + {% endfor %}
#NameLast ActiveTruescoreShadowbanned byShadowban reason#NameLast ActiveTruescoreShadowbanned byShadowban reason
{{loop.index}} {%- include 'user_in_table.html' -%} {{user.truescore}} {{user.shadowbanned}}{{user.ban_reason}}{% if user.ban_reason %}{{user.ban_reason}}{% endif %}
- + {% endblock %} diff --git a/files/templates/admins.html b/files/templates/admins.html index 71c868f9a..be12a30b5 100644 --- a/files/templates/admins.html +++ b/files/templates/admins.html @@ -12,8 +12,8 @@ # Name - Truescore - Mod actions + Truescore + Mod actions @@ -28,6 +28,6 @@ - + {% endblock %} diff --git a/files/templates/badges.html b/files/templates/badges.html index 0388f1968..b5bd3fa3f 100644 --- a/files/templates/badges.html +++ b/files/templates/badges.html @@ -7,12 +7,12 @@ - + - - + + @@ -32,6 +32,6 @@
## Name Image Description#Rarity#Rarity
- + {% endblock %} diff --git a/files/templates/banned.html b/files/templates/banned.html index fa90b080e..611d1b0d4 100644 --- a/files/templates/banned.html +++ b/files/templates/banned.html @@ -6,14 +6,14 @@
- - + + {% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} - + {%- endif %} - - - + + + @@ -22,7 +22,7 @@ {% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} - + {%- endif %} @@ -31,13 +31,11 @@ {% include "user_in_table.html" %} {% endwith %} - + {% endfor %}
#Name#NameLast ActiveLast ActiveTruescoreBan reasonBanned byTruescoreBan reasonBanned by Unban in
{{loop.index}} {% include "user_in_table.html" %}{{user.truescore}} {% if user.ban_reason %}{{user.ban_reason}}{% endif %} - {{user.unban_in}} -
- + {% endblock %} diff --git a/files/templates/chuds.html b/files/templates/chuds.html index eddd80480..f40015edd 100644 --- a/files/templates/chuds.html +++ b/files/templates/chuds.html @@ -6,12 +6,12 @@
- - + + {% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} - + {%- endif %} - + @@ -20,14 +20,14 @@ {% if v and v.admin_level >= PERMS['VIEW_LAST_ACTIVE'] -%} - + {%- endif %} - + {% endfor %}
#Name#NameLast ActiveLast ActiveTruescoreTruescore Unchud in
{{loop.index}} {% include "user_in_table.html" %}{{user.truescore}}{{user.unchud_in}}
- + {% endblock %} diff --git a/files/templates/hats.html b/files/templates/hats.html index bbbc9660a..ca1f24f3d 100644 --- a/files/templates/hats.html +++ b/files/templates/hats.html @@ -81,12 +81,12 @@ Name Description {% if SITE == 'rdrama.net' %} - Author + Author {% endif %} - Owners - Price + Owners + Price Actions - Added on + Added on @@ -129,5 +129,5 @@ {% endfor %} - + {% endblock %} diff --git a/files/templates/marseys.html b/files/templates/marseys.html index cd17ba009..e51f368cf 100644 --- a/files/templates/marseys.html +++ b/files/templates/marseys.html @@ -5,14 +5,14 @@
- - + + - + {% if FEATURES['ASSET_SUBMISSIONS'] %} - + {% endif %} - + {% if FEATURES['ASSET_SUBMISSIONS'] %} {% endif %} @@ -41,5 +41,5 @@ {% endfor %}
#Name#Name MarseyUsageUsageAuthorAuthorAdded onAdded onOriginal File
- + {% endblock %} diff --git a/files/templates/poll_votes.html b/files/templates/poll_votes.html index 53d909512..7f720a5f1 100644 --- a/files/templates/poll_votes.html +++ b/files/templates/poll_votes.html @@ -9,8 +9,8 @@ # User - User Truescore - Vote Time + User Truescore + Vote Time @@ -28,6 +28,6 @@ {% endfor %}
- + {% endif %} {% endblock %} diff --git a/files/templates/shop.html b/files/templates/shop.html index 6423bc2b6..b6c98e509 100644 --- a/files/templates/shop.html +++ b/files/templates/shop.html @@ -73,7 +73,7 @@ Icon Title Price - Owned + Owned Buy Description @@ -107,5 +107,5 @@ {% endfor %}
- + {% endblock %} diff --git a/files/templates/special/worldcup22_leaderboard.html b/files/templates/special/worldcup22_leaderboard.html index 3507c0b5d..828f866c8 100644 --- a/files/templates/special/worldcup22_leaderboard.html +++ b/files/templates/special/worldcup22_leaderboard.html @@ -6,12 +6,12 @@ - - - - - - + + + + + + @@ -31,5 +31,5 @@
#NameWinsBetsWin rateWinnings#NameWinsBetsWin rateWinnings
- + {% endblock %} diff --git a/files/templates/sub/subs.html b/files/templates/sub/subs.html index 26663e89e..5c5fb833c 100644 --- a/files/templates/sub/subs.html +++ b/files/templates/sub/subs.html @@ -8,10 +8,10 @@ # Name - Posts - Followers - Blockers - Created on + Posts + Followers + Blockers + Created on @@ -32,6 +32,6 @@ - + {% endblock %} diff --git a/files/templates/votes.html b/files/templates/votes.html index 7a449a6ad..b4fdd1a59 100644 --- a/files/templates/votes.html +++ b/files/templates/votes.html @@ -17,8 +17,8 @@ # User - User Truescore - Vote Time + User Truescore + Vote Time @@ -44,8 +44,8 @@ # User - User Truescore - Vote Time + User Truescore + Vote Time @@ -64,7 +64,7 @@ - + {% endif %}