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

nicer algorithm, permalink support

parent 039b7753
No related branches found
No related tags found
1 merge request!1Test release
Pipeline #11268 failed
......@@ -6,6 +6,7 @@
"dependencies": {
"css-loader": "^6.7.3",
"jquery": "^3.6.3",
"js-cookie": "^3.0.1",
"select2": "^4.1.0-rc.0",
"style-loader": "^3.3.1",
"tailwindcss": "^3.2.4",
......
Django==4.1.5
django-database-url==1.0.3
django-environ==0.9.0
psycopg2-binary==2.9.5
django-webpack-loader==1.8.0
nodeenv==1.7.0
django-http-exceptions==1.4.0
gql[requests]==3.4.0
nodeenv==1.7.0
psycopg2-binary==2.9.5
requests==2.28.2
......@@ -2,32 +2,36 @@
<ul class="flex flex-col gap-2">
{% for option_key, option in options.items %}
{% if option.has_support or show_has_support %}
<h3 class="flex gap-2 items-end text-xl font-semibold">
{{ option_key }}
<span class="text-sm text-gray-600">
{{ option.ticket_count }} lístků, {{ option.vote_count }} hlasů
</span>
{% if show_has_support and not option.has_support %}
<span class="text-sm text-red-600">(Nemá nadpoloviční podporu)</span>
{% endif %}
</h3>
{% if not option.marked_for_deletion or show_marked_for_deletion %}
{% if option.has_support or show_has_support %}
<h3 class="flex gap-2 items-end text-xl font-semibold {% if option.marked_for_deletion or not option.has_support %}text-red-600{% endif %}">
{{ option_key }}
<span class="text-sm {% if option.marked_for_deletion or not option.has_support %}text-red-600{% else %}text-gray-600{% endif %}">
{{ option.ticket_count }} lístků, {{ option.vote_count }} hlasů
</span>
{% if show_has_support and not option.has_support %}
<span class="text-sm text-red-600">(Nemá nadpoloviční podporu)</span>
{% endif %}
</h3>
{% if option.votes|length != 0 %}
<ul class="flex gap-3 mt-1 flex-wrap">
{% for vote in option.votes %}
<li class="flex">
<div class="px-4 py-2 bg-gray-300">
{{ rv_members|index:vote.member|index:"displayName" }}
</div>
<ul class="px-4 py-2 flex gap-1 bg-gray-200">
{% for option in options_by_member|index:vote.member %}
<li>{{ option }}{% if not forloop.last %}, {% endif %}</li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
{% if option.ticket_votes|length != 0 %}
<ul class="flex gap-3 mt-1 flex-wrap">
{% for vote in option.ticket_votes %}
{% if not vote.hidden %}
<li class="flex">
<div class="px-4 py-2 {% if not option.marked_for_deletion and option.has_support %}bg-gray-300{% else %}bg-red-300{% endif %}">
{{ rv_members|index:vote.member|index:"displayName" }}
</div>
<ul class="px-4 py-2 flex gap-1 {% if not option.marked_for_deletion and option.has_support %}bg-gray-200{% else %}bg-red-200{% endif %}">
{% for option in options_by_member|index:vote.member %}
<li>{{ option }}{% if not forloop.last %}, {% endif %}</li>
{% endfor %}
</ul>
</li>
{% endif %}
{% endfor %}
</ul>
{% endif %}
{% endif %}
{% endif %}
{% endfor %}
......
......@@ -43,12 +43,21 @@
{% endfor %}
</ul>
<ul
class="flex flex-col gap-5"
id="result"
>
</ul>
<div>
<ul
class="flex flex-col gap-5"
id="result"
>
</ul>
<div class="mt-3">
<a
class="hidden underline"
id="permalink"
href=""
>Permalink</a>
</div>
</div>
</div>
</main>
......@@ -56,5 +65,21 @@
<script>
const VOTE_CALCULATION_ENDPOINT = "{% url "rv_voting_calc:get_calculated_votes" %}"
{% if options_by_member %}
{% for member, selected_options in options_by_member.items %}
{% for selected_option in selected_options %}
$(`#${$.escapeSelector("{{ member}}")}-selection`).append(
new Option(
"{{ selected_option }}",
"{{ selected_option }}",
true,
true,
)
);
{% endfor %}
$(`#${$.escapeSelector("{{ member}}")}-selection`).trigger("change");
{% endfor %}
{% endif %}
</script>
{% endblock %}
{% load index %}
<li class="bg-gray-100 drop-shadow-md p-4">
<div class="pb-2 mb-2 border-b border-gray-300">
<div class="pb-2 mb-3 border-b border-gray-300">
<h2 class="text-2xl font-semibold font-bebas">{{ iteration|add:1 }}. vyřazovací kolo</h2>
</div>
<p>Odstraněna {% if randomly %}(losováním){% else %}nepopulární{% endif %} možnost {{ option_key }}</p>
<p class="mb-2 text-red-600 font-semibold">
Možnost {{ option_key }} bude {% if randomly %}losováním{% else %}kvůli nepopularitě{% endif %} odstraněna
</p>
{% include "rv_voting_calc/includes/option_list.html" with options=options options_by_member=options_by_member show_proposers=True show_marked_for_deletion=True %}
</li>
This diff is collapsed.
......@@ -57,6 +57,9 @@ MIDDLEWARE = [
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django_http_exceptions.middleware.ExceptionHandlerMiddleware",
"django_http_exceptions.middleware.ThreadLocalRequestMiddleware",
]
ROOT_URLCONF = "rybicka.urls"
......
......@@ -2,6 +2,8 @@ import jQuery from "jquery";
Object.assign(window, { $: jQuery, jQuery });
import Cookies from "js-cookie";
require("select2/dist/js/i18n/cs");
import "select2/dist/js/select2.full";
import "select2/dist/css/select2.min.css";
......@@ -134,8 +136,21 @@ $(window).ready(
}
}
const urlParams = new URL(window.location).searchParams;
const rvGid = urlParams.get("rv_gid");
const seed = urlParams.get("seed");
let response = await fetch(
`${VOTE_CALCULATION_ENDPOINT}?votes=${encodeURIComponent(JSON.stringify(votes))}`
VOTE_CALCULATION_ENDPOINT
+ `?votes=${encodeURIComponent(JSON.stringify(votes))}`
+ (
(rvGid !== null) ?
`&rv_gid=${rvGid}` : ""
)
+ (
(seed !== null) ?
`&seed=${seed}` : ""
)
);
if (!response.ok) {
......@@ -144,6 +159,18 @@ $(window).ready(
}
$("#result").html(await response.text());
$("#permalink").show();
$("#permalink").attr(
"href",
(
// Base URL
window.location.href.split('?')[0]
+ `?votes=${encodeURIComponent(JSON.stringify(votes))}`
+ `&rv_gid=${Cookies.get("rv_gid")}`
+ `&seed=${Cookies.get("seed")}`
)
);
}
);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment