Skip to content
Snippets Groups Projects
Commit b71027dd authored by Tomáš's avatar Tomáš
Browse files

nicer UI, loading info & disabling button when calculating

parent e599315a
No related branches found
No related tags found
1 merge request!1Test release
Pipeline #11274 failed
...@@ -8,6 +8,17 @@ ...@@ -8,6 +8,17 @@
{% block head %} {% block head %}
{% render_bundle "rv_voting_calc" %} {% render_bundle "rv_voting_calc" %}
<link
href="https://styleguide.pirati.cz/2.11.x/css/styles.css"
rel="stylesheet"
media="all"
>
<link
href="https://styleguide.pirati.cz/2.11.x/css/pattern-scaffolding.css"
rel="stylesheet"
media="all"
>
{% endblock %} {% endblock %}
{% block content %} {% block content %}
...@@ -20,9 +31,14 @@ ...@@ -20,9 +31,14 @@
<div class="flex items-center gap-3 justify-between"> <div class="flex items-center gap-3 justify-between">
<h2 class="text-2xl font-bebas">Výsledky</h2> <h2 class="text-2xl font-bebas">Výsledky</h2>
<button <button
class="bg-black text-white px-5 py-3 duration-100 hover:bg-gray-800" class="btn disabled:cursor-progress"
id="count-votes" id="count-votes"
>Vypočítat</button> disabled
>
<div class="btn__body">
Vypočítat
</div>
</button>
</div> </div>
</div> </div>
......
...@@ -22,7 +22,8 @@ def get_options_by_member(source, rv_members) -> dict: ...@@ -22,7 +22,8 @@ def get_options_by_member(source, rv_members) -> dict:
try: try:
options_by_member = json.loads(source) options_by_member = json.loads(source)
if not isinstance(options_by_member, dict): # The provided votes must be a dictionary with at least 1 key.
if not isinstance(options_by_member, dict) or len(options_by_member) == 0:
raise ValueError raise ValueError
except ValueError: except ValueError:
raise HTTPExceptions.BAD_REQUEST raise HTTPExceptions.BAD_REQUEST
......
...@@ -38,39 +38,7 @@ $(window).ready( ...@@ -38,39 +38,7 @@ $(window).ready(
$(".__vote-selection").on( $(".__vote-selection").on(
"select2:select", "select2:select",
event => { event => {
// //// Sync the tag option with other selectors. $("#count-votes").prop("disabled", false);
//
// // If the tag isn't new for this selection, do nothing.
// if (!event.params.data.isNew) {
// return;
// }
//
// const tagName = event.params.data.id;
//
// const addedTag = new Option(
// tagName,
// tagName,
// false,
// false
// );
//
// // Get all other selections.
// const unfilteredSelections = $(".__vote-selection").not(event.target);
// let filteredSelections = [];
//
// // Check if they contain the tag. If they do, ignore them.
// for (const selection of unfilteredSelections) {
// if (
// $(selection).
// children(`option[value=${$.escapeSelector(tagName)}]`).
// length === 0
// ) {
// filteredSelections.push(selection);
// }
// }
//
// // Add the new tag to all selections that don't have it yet.
// $(filteredSelections).append(addedTag).trigger("change");
// Keep user-defined ordering. This is imperative! // Keep user-defined ordering. This is imperative!
// http://github.com/select2/select2/issues/3106 - Thanks to kevin-brown! // http://github.com/select2/select2/issues/3106 - Thanks to kevin-brown!
...@@ -85,41 +53,21 @@ $(window).ready( ...@@ -85,41 +53,21 @@ $(window).ready(
$(".__vote-selection").on( $(".__vote-selection").on(
"select2:unselect", "select2:unselect",
event => { event => {
//// Remove the tag option if it's not selected anywhere. for (const selection of $(".__vote-selection")) {
if ($(selection).select2("data").length !== 0) {
// const tagName = event.params.data.id; return;
// }
// // Get all other selections. }
// const selections = $(".__vote-selection");
// $("#count-votes").prop("disabled", true);
// // Check if any of them have the tag selected. If they do, end the function.
// for (const selection of selections) {
// for (const data of $(selection).select2("data")) {
// if (data.id == tagName) {
// // TODO - Don't remove the tag from this select.
// // I'm not sure select2 has a good way of doing this.
//
// return;
// }
// }
// }
//
// // If the function has not ended by now, we can remove the tag.
// for (const selection of selections) {
// (
// $(selection).
// children(`option[value=${$.escapeSelector(tagName)}]`).
// remove()
// );
//
// $(selection).trigger("change");
// }
} }
); );
$("#count-votes").on( $("#count-votes").on(
"click", "click",
async (event) => { async (event) => {
$(event.currentTarget).addClass("btn--loading").prop("disabled", true);
let votes = {}; let votes = {};
for (const username of Object.keys(RV_MEMBERS)) { for (const username of Object.keys(RV_MEMBERS)) {
...@@ -139,7 +87,7 @@ $(window).ready( ...@@ -139,7 +87,7 @@ $(window).ready(
const urlParams = new URL(window.location).searchParams; const urlParams = new URL(window.location).searchParams;
const rvGid = urlParams.get("rv_gid"); const rvGid = urlParams.get("rv_gid");
const seed = urlParams.get("seed"); const seed = urlParams.get("seed");
let response = await fetch( let response = await fetch(
VOTE_CALCULATION_ENDPOINT VOTE_CALCULATION_ENDPOINT
+ `?votes=${encodeURIComponent(JSON.stringify(votes))}` + `?votes=${encodeURIComponent(JSON.stringify(votes))}`
...@@ -171,6 +119,8 @@ $(window).ready( ...@@ -171,6 +119,8 @@ $(window).ready(
+ `&seed=${Cookies.get("seed")}` + `&seed=${Cookies.get("seed")}`
) )
); );
$(event.currentTarget).removeClass("btn--loading").prop("disabled", false);
} }
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment