diff options
author | ubq323 <ubq323> | 2021-07-18 15:11:59 +0000 |
---|---|---|
committer | ubq323 <ubq323> | 2021-07-18 15:11:59 +0000 |
commit | 0ff607c6aba0bde59f63e7e4d737b1eca4977c7d (patch) | |
tree | c322299799b12b947e379a737beb93ed68bed6fa /apioforum/templates | |
parent | 183061d9a17e3613db2063ccd291af3fac904f11 (diff) | |
parent | 2d92be0e223a8b54749d0b2d304a78b16b92000d (diff) |
this was a particularly horrible merge conflict but i think it all works now
Diffstat (limited to 'apioforum/templates')
-rw-r--r-- | apioforum/templates/common.html | 37 | ||||
-rw-r--r-- | apioforum/templates/view_forum.html | 7 | ||||
-rw-r--r-- | apioforum/templates/view_thread.html | 9 |
3 files changed, 48 insertions, 5 deletions
diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html index 44cfbce..286bec8 100644 --- a/apioforum/templates/common.html +++ b/apioforum/templates/common.html @@ -76,3 +76,40 @@ <li>{{ thread.title }}</li> {% endcall -%} {% endmacro %} + +{% macro vote_meter(poll) %} + {% set total_votes = poll.total_votes %} + {% set n = namespace() %} + {% set n.runningtotal = 0 %} + <svg width="100%" height="15px" xmlns="http://www.w3.org/2000/svg"> + {% if total_votes == 0 %} + <text text-anchor="middle" dominant-baseline="middle" x="11%" y="55%" fill="black" style="font-size:15px">no votes</text> + {% else %} + {% for opt in poll.options %} + {% set opt_count = opt.num or 0 %} + {% set colour = (loop.count|string + opt.text)|gen_colour %} + {% if opt_count != 0 %} + {% set percentage = 100*(opt_count/total_votes) %} + {# todo: do this in css somehow #} + {% if opt.text|length > 10 %} + {% set opt_text = opt.text[:7] + "..." %} + {% else %} + {% set opt_text = opt.text %} + {% endif %} + <rect y="0" height="100%" x="{{n.runningtotal}}%" width="{{percentage}}%" stroke="black" fill="{{colour}}" /> + <text text-anchor="middle" dominant-baseline="middle" y="55%" fill="black" style="font-size:15px" x="{{n.runningtotal+(percentage/2)}}%"> + {{opt_text}}: {{opt_count}} + </text> + {% set n.runningtotal = n.runningtotal + percentage %} + {% endif %} + {% endfor %} + {% endif %} + <desc> + poll: {{poll.title}} + {% for opt in poll.options %} + option "{{opt.text}}": {{opt.num or 0}} votes + {% endfor %} + total votes: {{total_votes}} + </desc> + </svg> +{% endmacro %} diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html index d075d85..88be22f 100644 --- a/apioforum/templates/view_forum.html +++ b/apioforum/templates/view_forum.html @@ -1,5 +1,5 @@ {% extends 'base.html' %} -{% from 'common.html' import ts, tag, disp_user, post_url, forum_breadcrumb %} +{% from 'common.html' import ts, tag, disp_user, post_url, forum_breadcrumb, vote_meter %} {% block header %} <h1>{% block title %}{{forum.name}}{%endblock%}</h1> {% if forum.id != 1 %} @@ -76,6 +76,11 @@ </span> </div> {#{% endif %}#} + {% if thread_polls[thread.id] %} + <div class="thread-vote-summary"> + {{ vote_meter(thread_polls[thread.id]) }} + </div> + {% endif %} </div> {%endfor%} </div> diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html index d4a43ef..29914e8 100644 --- a/apioforum/templates/view_thread.html +++ b/apioforum/templates/view_thread.html @@ -1,4 +1,4 @@ -{% from 'common.html' import disp_post,tag,thread_breadcrumb %} +{% from 'common.html' import disp_post,tag,thread_breadcrumb,vote_meter %} {% extends 'base.html' %} {% block header %} <h1>{%block title %}{{thread.title}}{% endblock %}</h1> @@ -8,11 +8,12 @@ {%block content%} {% if poll %} <p>{{poll.title}}</p> -<ul> +<ol> {%for opt in poll.options%} - <li>#{{opt.option_idx}} - {{opt.text}} - {{opt.num or 0}}</li> + <li value="{{opt.option_idx}}"><i>{{opt.text}}</i>: {{opt.num or 0}} votes</li> {%endfor%} -</ul> +</ol> +{{ vote_meter(poll) }} {% endif %} <div class="thread-top-bar"> <span class="thread-top-bar-a"> |