add mai2 rival management features to frontend and templates

This commit is contained in:
SoulGateKey
2025-07-27 03:06:30 +08:00
parent 2a12f84dd9
commit 1833e8abde
2 changed files with 160 additions and 1 deletions

View File

@@ -17,6 +17,10 @@
<button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#name_change">Edit</button>
</th>
</tr>
<tr>
<th>ID:</th>
<th>{{ profile.user }}</th>
</tr>
<tr>
<td>version:</td>
<td>
@@ -86,6 +90,40 @@
</tr>
</table>
</div>
<div class="col-lg-8 m-auto mt-3">
<div class="card bg-card rounded">
<table class="table-large table-rowdistinct">
<caption align="top">
RIVALS
<button type="button" class="btn btn-primary btn-sm" style="position: absolute; right: 15px;" data-bs-toggle="modal" data-bs-target="#rival_add">Add</button>
</caption>
<tr>
<th scope="col">Id</th>
<th scope="col">Name</th>
<th scope="col">Rating</th>
<th scope="col">Show</th>
<th scope="col"></th>
</tr>
{% for rival in rival_list %}
<tr>
<td>{{ rival.2 }}</td>
<td>{{ rival.0 }}</td>
<td>{{ rival.1 }}</td>
<td>
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" role="switch"
id="rivalSwitch_{{ rival.2 }}"
{% if rival.3 %}checked{% endif %}
onchange="submitShow('{{ rival.2 }}', this.checked)">
</div>
</td>
<td>
<button type="button" class="btn btn-primary btn-sm" data-bs-toggle="modal" data-bs-target="#rival_delete_{{ rival.2 }}">Delete</button>
</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
{% if error is defined %}
@@ -120,6 +158,75 @@
</div>
</div>
</div>
<div class="modal fade" id="rival_add" tabindex="-1" aria-labelledby="card_add_label" data-bs-theme="dark" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Add rival</h5>
</div>
<div class="modal-body">
<form id="rival" action="/game/mai2/rival.add" method="post" style="outline: 0;">
<label class="form-label" for="rivalUserId">Rival ID</label>
<input class="form-control" aria-describedby="rivalIdHelphelp" form="rival" id="rivalUserId" name="rivalUserId" maxlength="8" type="number" required>
<div id="rivalIdHelphelp" class="form-text">Please use the ID show next to your name in the profile page.</div>
</form>
</div>
<div class="modal-footer">
<input type=submit class="btn btn-primary" type="button" form="rival" value="Add">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{% for rival in rival_list %}
<div class="modal fade" id="rival_delete_{{ rival.2 }}" tabindex="-1" aria-labelledby="rival_delete_label" data-bs-theme="dark" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Delete rival</h5>
</div>
<div class="modal-body">
<form id="rival_delete_{{ rival.2 }}_form" action="/game/mai2/rival.delete" method="post" style="outline: 0;">
<p>Are you sure you want to delete rival {{ rival.0 }}?</p>
<input type="hidden" name="rivalUserId" value="{{ rival.2 }}">
</form>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-danger" form="rival_delete_{{ rival.2 }}_form" value="Delete">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{% endfor %}
{% for rival in rival_list %}
<div class="modal fade" id="rival_show_{{ rival.2 }}" tabindex="-1" aria-labelledby="rival_show_label" data-bs-theme="dark" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{% if rival.3 %}Hide{% else %}Show{% endif %} rival</h5>
</div>
<div class="modal-body">
<form id="rival_show_{{ rival.2 }}_form" action="/game/mai2/rival.show" method="post" style="outline: 0;">
<p>Are you sure you want to {% if rival.3 %}hide{% else %}show{% endif %} rival {{ rival.0 }}?</p>
<input type="hidden" name="rivalUserId" value="{{ rival.2 }}">
<input type="hidden" name="showRival" value="{{ "false" if rival.3 else "true" }}">
</form>
</div>
<div class="modal-footer">
<input type="submit" class="btn btn-primary" form="rival_show_{{ rival.2 }}_form" value="Confirm">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
{% endfor %}
{% for rival in rival_list %}
<form action="/game/mai2/rival.show" method="post" id="rival_show_{{ rival.2 }}_form" style="display: none;">
<input type="hidden" name="rivalUserId" value="{{ rival.2 }}">
<input type="hidden" name="showRival" id="showRival_{{ rival.2 }}" value="false">
</form>
{% endfor %}
<script>
function changeVersion(sel) {
$.post("/game/mai2/version.change", { version: sel.value })
@@ -130,5 +237,17 @@
alert("Failed to update version.");
});
}
function submitShow(rivalId, checked) {
if (checked) {
let shownCount = document.querySelectorAll('.form-check-input:checked').length;
if (shownCount > 3) {
document.getElementById('rivalSwitch_' + rivalId).checked = false;
alert('Show rival limit reached (max 3). Please unselect another rival first.');
return;
}
}
document.getElementById('showRival_' + rivalId).value = checked;
document.getElementById('rival_show_' + rivalId + '_form').submit();
}
</script>
{% endblock content %}