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

View File

@ -12,20 +12,15 @@ from files.__main__ import app, limiter
def hats(v:User): def hats(v:User):
owned_hat_ids = [x.hat_id for x in v.owned_hats] owned_hat_ids = [x.hat_id for x in v.owned_hats]
if request.values.get("sort") == 'author_asc': if v.equipped_hat_ids:
hats = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None).order_by(User.username).all() 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()
elif request.values.get("sort") == 'author_desc': 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()
hats = g.db.query(HatDef, User).join(HatDef.author).filter(HatDef.submitter_id == None).order_by(User.username.desc()).all() owned = equipped + not_equipped
else: else:
if v.equipped_hat_ids: 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()
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()
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() 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 hats = owned + not_owned
sales = g.db.query(func.sum(User.coins_spent_on_hats)).scalar() 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() 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"> <div class="overflow-x-auto"><table class="table table-striped">
<thead class="bg-primary text-white"> <thead class="bg-primary text-white">
<tr> <tr>
<th scope="col">Select</th> <th>Select</th>
<th scope="col">Image</th> <th>Image</th>
<th scope="col">Name</th> <th>Name</th>
<th scope="col">Default Description</th> <th>Default Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

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

View File

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

View File

@ -77,25 +77,16 @@
<table class="table table-striped shop"> <table class="table table-striped shop">
<thead class="bg-primary text-white"> <thead class="bg-primary text-white">
<tr> <tr>
<th scope="col">Hat</th> <th>Hat</th>
<th scope="col">Name</th> <th>Name</th>
<th scope="col">Description</th> <th>Description</th>
{% if SITE == 'rdrama.net' %} {% if SITE == 'rdrama.net' %}
{% if request.values.get("sort") == 'author_asc' %} <th onclick="sort_table(this)">Author</a></th>
<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>
{% endif %} {% 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> </tr>
</thead> </thead>

View File

@ -5,14 +5,14 @@
<div class="overflow-x-auto mt-3"><table class="table table-striped mb-5"> <div class="overflow-x-auto mt-3"><table class="table table-striped mb-5">
<thead class="bg-primary text-white"> <thead class="bg-primary text-white">
<tr> <tr>
<th onclick="sort_table(0)">#</th> <th onclick="sort_table(this)">#</th>
<th onclick="sort_table(1)">Name</th> <th onclick="sort_table(this)">Name</th>
<th>Marsey</th> <th>Marsey</th>
<th onclick="sort_table(3)">Usage</th> <th onclick="sort_table(this)">Usage</th>
{% if FEATURES['ASSET_SUBMISSIONS'] %} {% if FEATURES['ASSET_SUBMISSIONS'] %}
<th onclick="sort_table(4)">Author</th> <th onclick="sort_table(this)">Author</th>
{% endif %} {% endif %}
<th onclick="sort_table(5)">Added on</th> <th onclick="sort_table(this)">Added on</th>
{% if FEATURES['ASSET_SUBMISSIONS'] %} {% if FEATURES['ASSET_SUBMISSIONS'] %}
<th>Original File</th> <th>Original File</th>
{% endif %} {% endif %}
@ -22,7 +22,7 @@
{% for marsey in marseys %} {% for marsey in marseys %}
<tr> <tr>
<td>{{loop.index}}</td> <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><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> <td>{{marsey.count}}</td>
{% if FEATURES['ASSET_SUBMISSIONS'] %} {% if FEATURES['ASSET_SUBMISSIONS'] %}

View File

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

View File

@ -165,8 +165,8 @@
<div class="overflow-x-auto"><table class="table table-hover rounded mb-0"> <div class="overflow-x-auto"><table class="table table-hover rounded mb-0">
<thead class="thead-dark"> <thead class="thead-dark">
<tr> <tr>
<th scope="col">User</th> <th>User</th>
<th scope="col">Unblock</th> <th>Unblock</th>
</tr> </tr>
</thead> </thead>
<tbody class="text-muted"> <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"> <div class="overflow-x-auto mt-1 mb-5"><table class="table table-striped shop">
<thead class="bg-primary text-white"> <thead class="bg-primary text-white">
<tr> <tr>
<th scope="col">Icon</th> <th>Icon</th>
<th scope="col">Title</th> <th>Title</th>
<th scope="col">Price</th> <th>Price</th>
<th scope="col" onclick="sort_table(3)">Owned</th> <th onclick="sort_table(this)">Owned</th>
<th scope="col">Buy</th> <th>Buy</th>
<th scope="col">Description</th> <th>Description</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>

View File

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

View File

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

View File

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