forked from rDrama/rDrama
1
0
Fork 0

improvement to sorting table + get rid of scope="col"

master
Aevann1 2022-12-10 10:47:15 +02:00
parent 84b1d2a7d7
commit a3c51202d1
13 changed files with 62 additions and 70 deletions

View File

@ -1,6 +1,7 @@
let sortAscending = {};
function sort_table(n) {
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 = [];
@ -16,7 +17,12 @@ function sort_table(n) {
} else if ('time' in x.dataset) {
attr = parseInt(x.dataset.time);
} else {
attr = parseInt(x.innerHTML.replace(/,/g, ''));
attr = x.innerHTML
try {
attr = parseInt(attr.replace(/,/g, ''));
}
catch(e) {
}
}
items.push({ ele, attr });
}

View File

@ -12,20 +12,15 @@ from files.__main__ import app, limiter
def hats(v:User):
owned_hat_ids = [x.hat_id for x in v.owned_hats]
if request.values.get("sort") == 'author_asc':
hats = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None).order_by(User.username).all()
elif request.values.get("sort") == 'author_desc':
hats = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None).order_by(User.username.desc()).all()
if v.equipped_hat_ids:
equipped = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None, HatDef.id.in_(owned_hat_ids), HatDef.id.in_(v.equipped_hat_ids)).order_by(HatDef.price, HatDef.name).all()
not_equipped = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None, HatDef.id.in_(owned_hat_ids), HatDef.id.notin_(v.equipped_hat_ids)).order_by(HatDef.price, HatDef.name).all()
owned = equipped + not_equipped
else:
if v.equipped_hat_ids:
equipped = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None, HatDef.id.in_(owned_hat_ids), HatDef.id.in_(v.equipped_hat_ids)).order_by(HatDef.price, HatDef.name).all()
not_equipped = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None, HatDef.id.in_(owned_hat_ids), HatDef.id.notin_(v.equipped_hat_ids)).order_by(HatDef.price, HatDef.name).all()
owned = equipped + not_equipped
else:
owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None, HatDef.id.in_(owned_hat_ids)).order_by(HatDef.price, HatDef.name).all()
owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None, HatDef.id.in_(owned_hat_ids)).order_by(HatDef.price, HatDef.name).all()
not_owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None, HatDef.id.notin_(owned_hat_ids)).order_by(HatDef.price, HatDef.name).all()
hats = owned + not_owned
not_owned = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None, HatDef.id.notin_(owned_hat_ids)).order_by(HatDef.price, HatDef.name).all()
hats = owned + not_owned
sales = g.db.query(func.sum(User.coins_spent_on_hats)).scalar()
num_of_hats = g.db.query(HatDef).filter(HatDef.submitter_id == None).count()

View File

@ -37,10 +37,10 @@
<div class="overflow-x-auto"><table class="table table-striped">
<thead class="bg-primary text-white">
<tr>
<th scope="col">Select</th>
<th scope="col">Image</th>
<th scope="col">Name</th>
<th scope="col">Default Description</th>
<th>Select</th>
<th>Image</th>
<th>Name</th>
<th>Default Description</th>
</tr>
</thead>
<tbody>

View File

@ -12,8 +12,8 @@
<tr>
<th>#</th>
<th>Name</th>
<th onclick="sort_table(2)" style="text-align:right;">Truescore</th>
<th onclick="sort_table(3)" style="text-align:right;">Mod actions</th>
<th onclick="sort_table(this)" style="text-align:right;">Truescore</th>
<th onclick="sort_table(this)" style="text-align:right;">Mod actions</th>
</tr>
</thead>

View File

@ -7,12 +7,12 @@
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th onclick="sort_table(0)">#</th>
<th onclick="sort_table(this)">#</th>
<th>Name</th>
<th>Image</th>
<th>Description</th>
<th onclick="sort_table(4)">#</th>
<th onclick="sort_table(4)">Rarity</th>
<th onclick="sort_table(this)">#</th>
<th onclick="sort_table(this)">Rarity</th>
</tr>
</thead>

View File

@ -77,25 +77,16 @@
<table class="table table-striped shop">
<thead class="bg-primary text-white">
<tr>
<th scope="col">Hat</th>
<th scope="col">Name</th>
<th scope="col">Description</th>
<th>Hat</th>
<th>Name</th>
<th>Description</th>
{% if SITE == 'rdrama.net' %}
{% if request.values.get("sort") == 'author_asc' %}
<th scope="col"><a href="?sort=author_desc">Author</a></th>
{% else %}
<th scope="col"><a href="?sort=author_asc">Author</a></th>
{% endif %}
<th scope="col" onclick="sort_table(4)">Owners</th>
<th scope="col" onclick="sort_table(5)">Price</th>
<th scope="col">Actions</th>
<th scope="col" onclick="sort_table(7)">Added on</th>
{% else %}
<th scope="col" onclick="sort_table(3)">Owners</th>
<th scope="col" onclick="sort_table(4)">Price</th>
<th scope="col">Actions</th>
<th scope="col" onclick="sort_table(6)">Added on</th>
<th onclick="sort_table(this)">Author</a></th>
{% endif %}
<th onclick="sort_table(this)">Owners</th>
<th onclick="sort_table(this)">Price</th>
<th>Actions</th>
<th onclick="sort_table(this)">Added on</th>
</tr>
</thead>

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(0)">#</th>
<th onclick="sort_table(1)">Name</th>
<th onclick="sort_table(this)">#</th>
<th onclick="sort_table(this)">Name</th>
<th>Marsey</th>
<th onclick="sort_table(3)">Usage</th>
<th onclick="sort_table(this)">Usage</th>
{% if FEATURES['ASSET_SUBMISSIONS'] %}
<th onclick="sort_table(4)">Author</th>
<th onclick="sort_table(this)">Author</th>
{% endif %}
<th onclick="sort_table(5)">Added on</th>
<th onclick="sort_table(this)">Added on</th>
{% if FEATURES['ASSET_SUBMISSIONS'] %}
<th>Original File</th>
{% endif %}
@ -22,7 +22,7 @@
{% for marsey in marseys %}
<tr>
<td>{{loop.index}}</td>
<td data-sort-key="{{marsey.name}}">{{marsey.name}}</td>
<td>{{marsey.name}}</td>
<td><img class="marsey" loading="lazy" data-bs-toggle="tooltip" alt=":#{{marsey.name}}:" title=":{{marsey.name}}:" src="/e/{{marsey.name}}.webp"></td>
<td>{{marsey.count}}</td>
{% if FEATURES['ASSET_SUBMISSIONS'] %}

View File

@ -9,8 +9,8 @@
<tr>
<th>#</th>
<th>User</th>
<th onclick="sort_table(2)">User Truescore</th>
<th onclick="sort_table(3)">Vote Time</th>
<th onclick="sort_table(this)">User Truescore</th>
<th onclick="sort_table(this)">Vote Time</th>
</tr>
</thead>

View File

@ -165,8 +165,8 @@
<div class="overflow-x-auto"><table class="table table-hover rounded mb-0">
<thead class="thead-dark">
<tr>
<th scope="col">User</th>
<th scope="col">Unblock</th>
<th>User</th>
<th>Unblock</th>
</tr>
</thead>
<tbody class="text-muted">

View File

@ -70,12 +70,12 @@
<div class="overflow-x-auto mt-1 mb-5"><table class="table table-striped shop">
<thead class="bg-primary text-white">
<tr>
<th scope="col">Icon</th>
<th scope="col">Title</th>
<th scope="col">Price</th>
<th scope="col" onclick="sort_table(3)">Owned</th>
<th scope="col">Buy</th>
<th scope="col">Description</th>
<th>Icon</th>
<th>Title</th>
<th>Price</th>
<th onclick="sort_table(this)">Owned</th>
<th>Buy</th>
<th>Description</th>
</tr>
</thead>
<tbody>

View File

@ -6,12 +6,12 @@
<table class="table table-striped mb-5">
<thead class="bg-primary text-white">
<tr>
<th onclick="sort_table(0)">#</th>
<th onclick="sort_table(1)">Name</th>
<th onclick="sort_table(2)">Wins</th>
<th onclick="sort_table(3)">Bets</th>
<th onclick="sort_table(4)">Win rate</th>
<th onclick="sort_table(5)">Winnings</th>
<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>
</tr>
</thead>
<tbody>

View File

@ -8,10 +8,10 @@
<tr>
<th>#</th>
<th>Name</th>
<th onclick="sort_table(2)">Posts</th>
<th onclick="sort_table(3)">Followers</th>
<th onclick="sort_table(4)">Blockers</th>
<th onclick="sort_table(5)">Created on</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>
</tr>
</thead>

View File

@ -17,8 +17,8 @@
<tr>
<th>#</th>
<th>User</th>
<th onclick="sort_table(2)">User Truescore</th>
<th onclick="sort_table(3)">Vote Time</th>
<th onclick="sort_table(this)">User Truescore</th>
<th onclick="sort_table(this)">Vote Time</th>
</tr>
</thead>
@ -44,8 +44,8 @@
<tr>
<th>#</th>
<th>User</th>
<th onclick="sort_table(1)">User Truescore</th>
<th onclick="sort_table(2)">Vote Time</th>
<th onclick="sort_table(this)">User Truescore</th>
<th onclick="sort_table(this)">Vote Time</th>
</tr>
</thead>