aboutsummaryrefslogtreecommitdiffhomepage
path: root/apioforum/templates/common.html
blob: 638c423787b3fbe244959c3ae1731a851af0444d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{% macro disp_user(username) -%} 
<a href="{{url_for('user.view_user',username=username)}}" class="username">{{username}}</a>
{%- endmacro %}

{% 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">
			{% if not post.deleted %}
				{{disp_user(post.author)}}
			{% else %}
				<span class="username">big brother</span>
			{% endif %}

			{% if forum != None %}
				{% set role = get_user_role(forum, post.author) %}
				{% if post.deleted %}
					<span class="user-role">
						(bureaucrat)
					</span>
				{% elif role != "other" %}
					<span class="user-role">
						({{ role }})
					</span>
				{% endif %}
			{% endif %}

			{{ts(post.created)}}

            {% if post.edited %}
                (edited {{ts(post.updated)}})
            {% endif %}
        </span>
        <span class="post-heading-b">
        {% if buttons and not post.deleted %}
			{% if post.author == g.user %}
				<a class="actionbutton"
				   href="{{url_for('thread.edit_post',post_id=post.id)}}">edit</a>
			{% endif %}
			{% if post.author == g.user or (forum and has_permission(forum, g.user, "p_delete_posts")) %}
				<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_jump(post.id)}}">#{{post.id}}</a>
        </span>
    </div>
    <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 %}

{% macro ts(dt) -%}
<time title="{{dt.isoformat(' ')}}" datetime="{{dt.isoformat(' ')}}">{{dt | fuzzy}}</time>
{%- endmacro %}

{% macro tag(the_tag) -%}
<span class="tag" style="color: {{the_tag.text_colour}}; background-color: {{the_tag.bg_colour}}">{{the_tag.name}}</span>
{%- endmacro %}

{% macro ab(name,href) -%}
<a class="actionbutton" href="{{href}}">{{name}}</a>
{%- endmacro %}

{% macro breadcrumb() %}
<nav aria-label="Breadcrumb">
<ol class="breadcrumbs">
	{{- caller() -}}
</ol>
</nav>
{% endmacro %}

{% macro forum_bc_entries(forum_id) -%}
	{%- for f in forum_path(forum_id) -%}
		<li><a href="{{url_for('forum.view_forum',forum_id=f.id)}}">{{ f.name }}</a></li>
	{%- endfor %}
{%- endmacro %}

{% macro forum_breadcrumb(forum) %}
	{%- call breadcrumb() %}
		{{ forum_bc_entries(forum.id) }}
	{% endcall -%}
{% endmacro %}

{% macro thread_breadcrumb(thread) %}
	{%- call breadcrumb() %}
		{{ forum_bc_entries(thread.forum) }}
		<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 %}

{% macro pagination_nav(page,max_pageno,view) %}
<nav aria-label="pagination" id="pages">
	{% if page > 1 %}
	<a href="{{url_for(view,**kwargs)}}" aria-label="first page">&lt;&lt; first</a>
	<a href="{{url_for(view,page=page-1,**kwargs)}}" aria-label="previous page">&lt; prev</a>
	{% endif %}
	page {{page}} of {{max_pageno}}
	{% if page < max_pageno %} {# > #}
	<a href="{{url_for(view,page=page+1,**kwargs)}}" aria-label="next page">next &gt;</a>
	<a href="{{url_for(view,page=max_pageno,**kwargs)}}" aria-label="last page">last &gt;&gt;</a>
	{% endif %}
</nav>
{% endmacro %}