Skip to content

Commit

Permalink
feat: run formatter on html files, create pagination component
Browse files Browse the repository at this point in the history
  • Loading branch information
lenforiee committed Dec 25, 2022
1 parent 965d0a8 commit 2795c51
Show file tree
Hide file tree
Showing 36 changed files with 3,119 additions and 2,276 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ rpusers.json
test.py
static/servers.json
config.json.save
venv/
node_modules/
.vscode/
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
overrides: [
{
files: ["*.html"],
options: {
parser: "jinja-template"
},
},
],
}
52 changes: 52 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"devDependencies": {
"prettier": "^2.8.1",
"prettier-plugin-jinja-template": "^0.0.4"
}
}
47 changes: 22 additions & 25 deletions panel/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2155,38 +2155,16 @@ def UserPageCount():
mycursor.execute("SELECT count(*) FROM users")
TheNumber = mycursor.fetchone()[0]
# working with page number (this is a mess...)
TheNumber /= 50
# if not single digit, round up
if len(str(TheNumber)) != 0:
NewNumber = round(TheNumber)
# if number was rounded down
if NewNumber == round(int(str(TheNumber).split(".")[0])):
NewNumber += 1
TheNumber = NewNumber
return TheNumber
return math.ceil(TheNumber / PAGE_SIZE)


def RapLogCount():
"""Gets the amount of pages for rap logs."""
# i made it separate, fite me
mycursor.execute("SELECT count(*) FROM rap_logs")
TheNumber = mycursor.fetchone()[0]
# working with page number (this is a mess...)
TheNumber /= 50
# if not single digit, round up
if len(str(TheNumber)) != 0:
NewNumber = round(TheNumber)
# if number was rounded down
if NewNumber == round(int(str(TheNumber).split(".")[0])):
NewNumber += 1
TheNumber = NewNumber
# makign page dict
Pages = []
while TheNumber != 0:
Pages.append(TheNumber)
TheNumber -= 1
Pages.reverse()
return Pages

return math.ceil(TheNumber / PAGE_SIZE)


def GetClans(Page: int = 1):
Expand Down Expand Up @@ -2630,6 +2608,19 @@ def ban_pages() -> int:
return math.ceil(ban_count() / PAGE_SIZE)


def request_count() -> int:
"""Returns the total number of requests."""

mycursor.execute("SELECT COUNT(*) FROM rank_requests WHERE blacklisted = 0")
return mycursor.fetchone()[0]


def request_pages() -> int:
"""Returns the number of pages in the request."""

return math.ceil(request_count() / PAGE_SIZE)


def fetch_user_banlogs(user_id: int) -> list[BanLog]:
"""Fetches all ban logs targetting a specific user.
Expand Down Expand Up @@ -2819,6 +2810,12 @@ def get_hwid_count(user_id: int) -> int:
return mycursor.fetchone()[0]


def hwid_pages(user_id: int) -> int:
"""Returns the number of pages in the ban log."""

return math.ceil(get_hwid_count(user_id) / PAGE_SIZE)


class HWIDResult(TypedDict):
result: HWIDLog
exact_matches: list[HWIDLog]
Expand Down
4 changes: 3 additions & 1 deletion panel/init_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ def panel_search_users(page_str: str = "1"):
title="Search Users",
UserData=user_data,
page=page,
Pages=UserPageCount(),
pages=UserPageCount(),
)

@app.route("/index.php")
Expand Down Expand Up @@ -600,6 +600,7 @@ def panel_view_rank_requests(Page):
config=config,
RankRequests=GetRankRequests(int(Page)),
page=int(Page),
pages=request_pages(),
)
else:
return no_permission_response(request.path)
Expand Down Expand Up @@ -705,6 +706,7 @@ def view_user_hwid_route(user_id: int, page: int = 1):
hwid_logs=page_info["results"],
user=page_info["user"],
page=page,
pages=hwid_pages(user_id),
total_hwids=get_hwid_count(user_id),
)

Expand Down
76 changes: 41 additions & 35 deletions templates/badges.html
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
{% extends "base.html" %}
{% block content %}
<h2 class="section-title">Badges</h2>
<p class="section-lead">Modify or edit profile badges!</p>
<div class="card">
<div class="card-header">
Badges
</div>
<h2 class="section-title">Badges</h2>
<p class="section-lead">Modify or edit profile badges!</p>
<div class="card">
<div class="card-header">Badges</div>
<div class="card-body">
<table class="table table-striped">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Icon</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for badge in badges %}
<tr>
<td>{{ badge["Id"] }}</td>
<td>{{ badge["Name"] }}</td>
<td><i class="fa {{ badge['Icon'] }} fa-2x"></i></td>
<td>
<div class="buttons">
<a href="/actions/deletebadge/{{ badge['Id'] }}" class="btn btn-danger">Delete</a>
<a href="/badge/edit/{{ badge['Id'] }}" class="btn btn-primary">Edit</a>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<table class="table table-striped">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">Icon</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{% for badge in badges %}
<tr>
<td>{{ badge["Id"] }}</td>
<td>{{ badge["Name"] }}</td>
<td><i class="fa {{ badge['Icon'] }} fa-2x"></i></td>
<td>
<div class="buttons">
<a
href="/actions/deletebadge/{{ badge['Id'] }}"
class="btn btn-danger"
>Delete</a
>
<a
href="/badge/edit/{{ badge['Id'] }}"
class="btn btn-primary"
>Edit</a
>
</div>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="card-footer">
<div class="buttons">
<a href="/actions/createbadge" class="btn btn-success">Create Badge</a>
</div>
<div class="buttons">
<a href="/actions/createbadge" class="btn btn-success">Create Badge</a>
</div>
</div>
</div>
</div>
{% endblock %}
86 changes: 31 additions & 55 deletions templates/ban_logs.html
Original file line number Diff line number Diff line change
@@ -1,60 +1,36 @@
{% extends "base.html" %}
{% import "components/pagination.html" as pagination %}
{% block content %}

<h2 class="section-title">Ban Logs</h2>
<p class="section-lead">View detailed ban reasons for the entire server!</p>

{% for log in ban_logs %}

<div class= "card">
<div class="card-header">
<img alt="image" src="https://a.ussr.pl/{{ log["from_id"] }}" class="rounded-circle mr-1" style="width:100%; max-width:30px; max-height:30px;">
<h4>{{ log["from_name"] }}</h4> to
<img alt="image" src="https://a.ussr.pl/{{ log["to_id"] }}" class="rounded-circle mr-1" style="width:100%; max-width:30px; max-height:30px;margin-left: 10px;">
<h4>{{ log["to_name"] }}</h4> for {{ log["summary"] }}
</div>
<div class="card-body">
<h2 class="section-title">Ban Logs</h2>
<p class="section-lead">View detailed ban reasons for the entire server!</p>

{{ pagination.pagination('/ban-logs', page, pages) }}
{% for log in ban_logs %}
<div class="card">
<div class="card-header">
<img
alt="image"
src="https://a.ussr.pl/{{ log["from_id"] }}"
class="rounded-circle mr-1"
style="width:100%; max-width:30px; max-height:30px;"
/>
<h4>{{ log["from_name"] }}</h4>
to
<img
alt="image"
src="https://a.ussr.pl/{{ log["to_id"] }}"
class="rounded-circle mr-1"
style="width:100%; max-width:30px; max-height:30px;margin-left: 10px;"
/>
<h4>{{ log["to_name"] }}</h4>
for {{ log["summary"] }}
</div>
<div class="card-body">
{{ log["detail"] }}
</div>
<div class="card-footer">Banned {{ log["expity_timeago"] }}</div>
</div>
<div class="card-footer">
Banned {{ log["expity_timeago"] }}
</div>
</div>

{% endfor %}

<ul class="pagination">
<li class="page-item" id="page-before">
<a class="page-link" href="/users/{{ page-1 }}" aria-label="Previous">
<span aria-hidden="true">«</span>
<span class="sr-only">Previous</span>
</a>
</li>
<span id="page-items"></span>
<li class="page-item" id="page-after">
<a class="page-link" href="/users/{{ page+1 }}" aria-label="Next">
<span aria-hidden="true">»</span>
<span class="sr-only">Next</span>
</a>
</li>
</ul>
<script>
// cap = 10
const pageItems = document.querySelector("#page-items");
const pageLen = {{ pages }} + 1;
const page = {{ page }};
const plen = Math.max(page-5, 1);

for (let i = plen; i < Math.min(plen+(5*2), pageLen); i++) {
pageItems.innerHTML += `
<li class="page-item ${i == page ? "active" : ""}">
<a class="page-link" href="/users/${i}">${i}</a>
</li>
`;
}

if (page <= 1) document.getElementById("page-before").classList.add("disabled");
if (page >= pageLen-1) document.getElementById("page-after").classList.add("disabled");
</script>

{% endfor %}
{{ pagination.pagination('/ban-logs', page, pages) }}
{{ pagination.paginationJs('/ban-logs', page, pages) }}
{% endblock %}
Loading

0 comments on commit 2795c51

Please sign in to comment.