summaryrefslogtreecommitdiffhomepage
path: root/apioforum/templates
diff options
context:
space:
mode:
authorcitrons <citrons>2021-08-06 03:31:07 +0000
committercitrons <citrons>2021-08-06 03:31:07 +0000
commit5cf3eaebb1db20d61b88f044dfb2a34512aecd61 (patch)
tree945a270e59bb6d691e6f20686f2f9c8ec3d6e8b4 /apioforum/templates
parent52c63cddb3f7860862af6a2185a728baf7593cc7 (diff)
parent74a992ca018a69cc1de6225a681ca17c19c74ffa (diff)
merge the things; poll permissions
Diffstat (limited to 'apioforum/templates')
-rw-r--r--apioforum/templates/base.html3
-rw-r--r--apioforum/templates/common.html49
-rw-r--r--apioforum/templates/config_thread.html25
-rw-r--r--apioforum/templates/view_forum.html43
-rw-r--r--apioforum/templates/view_post.html12
-rw-r--r--apioforum/templates/view_thread.html71
6 files changed, 185 insertions, 18 deletions
diff --git a/apioforum/templates/base.html b/apioforum/templates/base.html
index f462df2..ca1dd87 100644
--- a/apioforum/templates/base.html
+++ b/apioforum/templates/base.html
@@ -6,12 +6,13 @@
<title>{%block title %}{% endblock %}</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="/static/style.css">
+ <link rel="stylesheet" href="/static/md-colors.css">
<link rel="icon" href="//gh0.pw/favicon.ico">
</head>
<body>
<nav id="navbar">
<p style="font-family: monospace;"><b>apio</b><i>forum</i>&trade;</p>
- <form class="search-form" action="/search">
+ <form class="inline-form" action="/search">
<input type="search" placeholder="query" name="q">
<input type="submit" value="search">
</form>
diff --git a/apioforum/templates/common.html b/apioforum/templates/common.html
index 7144667..f6b6f29 100644
--- a/apioforum/templates/common.html
+++ b/apioforum/templates/common.html
@@ -6,7 +6,7 @@
{{url_for('thread.view_thread', thread_id=post.thread)}}#post_{{post.id}}
{%- endmacro %}
-{% macro disp_post(post, buttons=False, forum=None) %}
+{% macro disp_post(post, buttons=False, forum=None, footer=None) %}
<div class="post {% if post.deleted %}deleted-post{% endif %}" id="post_{{post.id}}">
<div class="post-heading">
<span class="post-heading-a">
@@ -45,17 +45,25 @@
<a class="actionbutton"
href="{{url_for('thread.delete_post',post_id=post.id)}}">delete</a>
{% endif %}
+ <a class="actionbutton"
+ href="{{url_for('thread.view_post',post_id=post.id)}}">src</a>
{% endif %}
+
<a class="post-anchor-link" href="{{post_url(post)}}">#{{post.id}}</a>
</span>
</div>
- <div class="post-content">
+ <div class="post-content md">
{% if not post.deleted %}
{{ post.content|md|safe }}
{% else %}
this post never existed.
{% endif %}
</div>
+ {% if footer %}
+ <div class="post-footer">
+ {{ footer }}
+ </div>
+ {% endif %}
</div>
{% endmacro %}
@@ -97,3 +105,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.index|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/config_thread.html b/apioforum/templates/config_thread.html
index b26a73d..7403614 100644
--- a/apioforum/templates/config_thread.html
+++ b/apioforum/templates/config_thread.html
@@ -2,6 +2,7 @@
{% from 'common.html' import tag %}
{% block header %}<h1>{% block title %}configure thread '{{thread.title}}'{% endblock %}</h1>{% endblock %}
{% block content %}
+<h2>thread options</h2>
<form method="post">
<fieldset>
<legend>title</legend>
@@ -27,4 +28,28 @@
<input type="submit" value="confirm">
<a href="{{url_for('thread.view_thread',thread_id=thread.id)}}">cancel</a>
</form>
+
+{% if thread.poll is none and has_permission(thread.forum, g.user, "p_create_polls" %}
+<h2>create poll</h2>
+<form method="post" action="{{url_for('thread.create_poll',thread_id=thread.id)}}">
+ <fieldset>
+ <legend>create poll</legend>
+ <label for="polltitle">question title</label>
+ <input type="title" id="polltitle" name="polltitle">
+ <br>
+ <label for="polloptions">options (one per line)</label>
+ <textarea name="polloptions" id="polloptions"></textarea>
+ </fieldset>
+ <p>important: once a poll is created, you will not be able to modify it except to delete it entirely</p>
+ <input type="submit" value="create">
+</form>
+{% else %}
+<h2>delete poll</h2>
+<p>there is already a poll attached to this thread. you can delete it, which will allow you to create a new one, but this will erase all existing votes and data for the current poll.</p>
+<form action="{{url_for('thread.delete_poll',thread_id=thread.id)}}" method="post">
+ <input type="submit" value="confirm: delete poll">
+</form>
+
+{% endif %}
+
{% endblock %}
diff --git a/apioforum/templates/view_forum.html b/apioforum/templates/view_forum.html
index 863f91c..ff1af9b 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, ab %}
+{% from 'common.html' import ts, tag, disp_user, post_url, forum_breadcrumb, ab, vote_meter %}
{% block header %}
<h1>{% block title %}{{forum.name}}{% endblock %} <span class="thing-id">#{{forum.id}}</span></h1>
{% if forum.id != 1 %}
@@ -8,15 +8,28 @@
{%endblock%}
{%block content%}
-{{forum.description|md|safe}}
-{% if bureaucrats|length > 0 %}
- <p>
- bureaucrats in this forum:
- {% for b in bureaucrats %}
- {{disp_user(b)}}
- {% endfor %}
+{{forum.description|md|safe}}
+
+<hr/>
+<div class="forum-info">
+ {% if bureaucrats|length > 0 %}
+ <p>
+ bureaucrats in this forum:
+ {% for b in bureaucrats %}
+ {{disp_user(b)}}
+ {% endfor %}
+ </p>
+ {% endif %}
+
+ <p>available tags:
+ {% for the_tag in avail_tags %}
+ {{tag(the_tag)}}
+ {% else %}
+ <em>(none available)</em>
+ {% endfor %}
</p>
-{% endif %}
+</div>
+
<p>
{% if is_bureaucrat(forum.id, g.user) %}
{{ab("forum settings",url_for('forum.edit_forum',forum_id=forum.id))}}
@@ -30,6 +43,7 @@
{{ab("approve users",url_for('forum.view_user_role',forum_id=forum.id))}}
{% endif %}
</p>
+
{% if subforums %}
<h2>subforæ</h2>
<div class="forum-list">
@@ -55,10 +69,11 @@
{% endif %}
<h2>threads</h2>
+<p>
{% if g.user %}
-<p><a class="actionbutton" href="{{url_for('forum.create_thread',forum_id=forum.id)}}">create new thread</a></p>
+<a class="actionbutton" href="{{url_for('forum.create_thread',forum_id=forum.id)}}">create new thread</a>
{% else %}
-<p>please log in to create a new thread</p>
+please log in to create a new thread
{% endif %}
{% if has_permission(forum.id, g.user, "p_view_threads") %}
@@ -103,11 +118,15 @@
</a>
</div>
{% endif %}
+ {% if thread_polls[thread.id] %}
+ <div class="thread-vote-summary">
+ {{ vote_meter(thread_polls[thread.id]) }}
+ </div>
+ {% endif %}
</div>
{%endfor%}
</div>
{% else %}
<p>you do not have permission to view threads in this forum</p>
{% endif %}
-
{%endblock%}
diff --git a/apioforum/templates/view_post.html b/apioforum/templates/view_post.html
new file mode 100644
index 0000000..993c005
--- /dev/null
+++ b/apioforum/templates/view_post.html
@@ -0,0 +1,12 @@
+{% from 'common.html' import disp_post %}
+{% extends 'base.html' %}
+{% block header %}
+<h1>{%block title%}viewing post{%endblock%}</h1>
+{% endblock %}
+
+{% block content %}
+{{disp_post(post,False)}}
+<p>post source:</p>
+<textarea readonly class="new-post-box" name="newcontent">{{post.content}}</textarea>
+<a href="{{url_for('thread.view_thread',thread_id=post.thread)}}">i am satisfied</a>
+{% endblock %}
diff --git a/apioforum/templates/view_thread.html b/apioforum/templates/view_thread.html
index da8df74..132fd44 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 %} <span class="thing-id">#{{thread.id}}</span></h1>
@@ -6,6 +6,15 @@
{% endblock %}
{%block content%}
+{% if poll %}
+<p>{{poll.title}}</p>
+<ol>
+ {%for opt in poll.options%}
+ <li value="{{opt.option_idx}}"><i>{{opt.text}}</i>: {{opt.num or 0}} votes</li>
+ {%endfor%}
+</ol>
+{{ vote_meter(poll) }}
+{% endif %}
<div class="thread-top-bar">
<span class="thread-top-bar-a">
{% if g.user == thread.creator or has_permission(thread.forum, g.user, "p_manage_threads") %}
@@ -25,14 +34,70 @@
<div class="posts">
{% for post in posts %}
- {{ disp_post(post, buttons=True, forum=thread.forum) }}
+ {% if votes[post.id] %}
+
+ {% set vote = votes[post.id] %}
+ {% set option_idx = vote.option_idx %}
+
+ {# this is bad but it's going to get refactored anyway #}
+ {% set footer %}
+ {% if vote.is_retraction %}
+ {% if not post.deleted %}
+ {{post.author}} retracted their vote
+ {% else %}
+ this post retracted a vote
+ {% endif %}
+ {% else %}
+ {% set option = poll.options[option_idx-1] %}
+ {% if vote.current %}
+ {{post.author}} votes for {{option_idx}}: {{option.text}}
+ {% else %}
+ {% if not post.deleted %}
+ {{post.author}} voted for {{option_idx}}: {{option.text}}, but later changed their vote
+ {% else %}
+ this post presented a vote that was later changed
+ {% endif %}
+ {% endif %}
+ {% endif %}
+
+ {% endset %}
+
+ {{ disp_post(post, forum=thread.forum, buttons=True, footer=footer) }}
+
+ {% else %}
+ {{ disp_post(post, forum=thread.forum, buttons=True) }}
+ {% endif %}
{% endfor %}
</div>
-{% if g.user %}
+{% if g.user and has_permission(thread.forum, g.user, "p_reply_threads") %}
<form class="new-post" action="{{url_for('thread.create_post',thread_id=thread.id)}}" method="POST">
<textarea class="new-post-box" placeholder="your post here..." name="content"></textarea>
+ {% if poll and has_permission(thread.forum, g.user, "p_vote") %}
+ <fieldset>
+ <legend>poll: {{poll.title}}</legend>
+ <p>if you want, you can submit a vote along with this post. if you have previously voted
+ on this poll, your previous vote will be changed</p>
+
+ <input type="radio" id="dontvote" name="poll" value="dontvote" checked>
+ <label for="dontvote">do not submit any vote at the moment</label>
+
+ {% if has_voted %}
+ <br>
+ <input type="radio" id="retractvote" name="poll" value="retractvote">
+ <label for="retractvote">clear current vote</label>
+ {% endif %}
+
+ {% for opt in poll.options %}
+ <br>
+ <input type="radio" id="option_{{opt.option_idx}}" name="poll" value="{{opt.option_idx}}">
+ <label for="option_{{opt.option_idx}}">#{{opt.option_idx}} - {{opt.text}}</label>
+ {% endfor %}
+ </fieldset>
+ {% endif %}
<input type="submit" value="yes">
</form>
+{% elif g.user %}
+<p>you do not have permission to reply to this thread</p>
{% else %}
<p>please log in to reply to this thread</p>
{% endif %}