liquid_feedback_frontend

view app/main/delegation/_info.lua @ 1853:9c298b5832e7

Correctly determine own voting weight
author bsw
date Tue Mar 22 13:52:26 2022 +0100 (2022-03-22)
parents 4b74a177884b
children 220653575083
line source
1 if not app.session.member_id then
2 return
3 end
5 local member = param.get("member", "table") or app.session.member
7 local unit = param.get("unit", "table")
8 local area = param.get("area", "table")
9 local issue = param.get("issue", "table")
11 local for_title = param.get("for_title", "boolean")
13 local unit_id = unit and unit.id or nil
14 local area_id = area and area.id or nil
15 local issue_id = issue and issue.id or nil
17 local info
18 local delegation_text
20 if unit then
21 info = unit.delegation_info
22 delegation_text = _"Delegate unit"
23 end
25 if area then
26 info = area.delegation_info
27 delegation_text = _"Delegate area"
28 end
30 if issue then
31 info = issue.member_info
32 delegation_text = _"Delegate issue"
33 end
35 if not info then
36 --return
37 end
39 local function print_delegation_info()
40 local participant_occured = info.own_participation
42 if not (issue and issue.state == "voting" and info.own_participation) then
44 if info.first_trustee_id then
46 local text = _"delegates to"
47 ui.image{
48 attr = { class = "delegation_arrow", alt = text, title = text },
49 static = "delegation_arrow_24_horizontal.png"
50 }
52 local class = "micro_avatar"
53 if not participant_occured and info.first_trustee_participation then
54 participant_occured = true
55 class = class .. " highlighted"
56 end
58 execute.view{ module = "member_image", view = "_show", params = {
59 member_id = info.first_trustee_id, class = class, popup_text = info.first_trustee_name,
60 image_type = "avatar", show_dummy = true,
61 } }
63 end
65 if info.first_trustee_ellipsis then
67 local text = _"delegates to"
68 ui.image{
69 attr = { class = "delegation_arrow", alt = text, title = text },
70 static = "delegation_arrow_24_horizontal.png"
71 }
73 slot.put("...")
75 end
77 if info.other_trustee_id then
79 local text = _"delegates to"
80 ui.image{
81 attr = { class = "delegation_arrow", alt = text, title = text },
82 static = "delegation_arrow_24_horizontal.png"
83 }
85 local class = "micro_avatar"
86 if not participant_occured and info.other_trustee_participation then
87 participant_occured = true
88 class = class .. " highlighted"
89 end
91 execute.view{ module = "member_image", view = "_show", params = {
92 member_id = info.other_trustee_id, class = class, popup_text = info.other_trustee_name,
93 image_type = "avatar", show_dummy = true,
94 } }
96 end
98 if info.other_trustee_ellipsis then
100 local text = _"delegates to"
101 ui.image{
102 attr = { class = "delegation_arrow", alt = text, title = text },
103 static = "delegation_arrow_24_horizontal.png"
104 }
106 slot.put("...")
108 end
110 local trailing_ellipsis = info.other_trustee_ellipsis or
111 (info.first_trustee_ellipsis and not info.other_trustee_id)
113 if info.delegation_loop == "own" then
115 local text = _"delegates to"
116 ui.image{
117 attr = { class = "delegation_arrow", alt = text, title = text },
118 static = "delegation_arrow_24_horizontal.png"
119 }
121 execute.view{ module = "member_image", view = "_show", params = {
122 member = member, class = "micro_avatar", popup_text = member.name,
123 image_type = "avatar", show_dummy = true,
124 } }
126 elseif info.delegation_loop == "first" then
127 if info.first_trustee_ellipsis then
128 if not trailing_ellipsis then
130 local text = _"delegates to"
131 ui.image{
132 attr = { class = "delegation_arrow", alt = text, title = text },
133 static = "delegation_arrow_24_horizontal.png"
134 }
136 slot.put("...")
137 end
139 else
141 local text = _"delegates to"
142 ui.image{
143 attr = { class = "delegation_arrow", alt = text, title = text },
144 static = "delegation_arrow_24_horizontal.png"
145 }
147 execute.view{
148 module = "member_image", view = "_show", params = {
149 member_id = info.first_trustee_id,
150 class = "micro_avatar",
151 popup_text = info.first_trustee_name,
152 image_type = "avatar",
153 show_dummy = true,
154 }
155 }
156 end
159 elseif info.delegation_loop and not trailing_ellipsis then
160 local text = _"delegates to"
161 ui.image{
162 attr = { class = "delegation_arrow", alt = text, title = text },
163 static = "delegation_arrow_24_horizontal.png"
164 }
166 slot.put("...")
167 end
169 end
170 end
172 if not param.get("no_star", "boolean") and issue then
173 local redirect_unit = request.get_param{ name = "unit" }
174 local redirect_area = request.get_param{ name = "area" }
176 if issue.fully_frozen and info.own_participation then
177 ui.link{
178 attr = { class = "mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--underlined" },
179 module = "vote", view = "list", params = {
180 issue_id = issue.id
181 },
182 content = function ()
183 ui.tag { content = _"you voted" }
184 end
185 }
186 elseif not issue.half_frozen and not issue.closed and not info.own_participation then
187 ui.link{
188 attr = {
189 id = "issue_" .. issue.id .. "_interest_link",
190 class = "float-right mdl-button mdl-js-button mdl-button--icon mdl-button--feature-off",
191 },
192 form_attr = {
193 onsubmit = "toggleInterest(" .. issue.id .. ", 'issue_" .. issue.id .. "_interest_icon'); return false;"
194 },
195 module = "interest", action = "update", params = { issue_id = issue.id, interested = true },
196 routing = { default = {
197 mode = "redirect", module = "index", view = "index", params = {
198 unit = redirect_unit, area = redirect_area
199 },
200 anchor = "issue_" .. issue.id
201 } },
202 content = function()
203 ui.tag{ tag = "i", attr = { id = "issue_" .. issue.id .. "_interest_icon", class = "material-icons" }, content = "star_outline" }
204 end
205 }
206 elseif not issue.half_frozen and not issue.closed and info.own_participation then
207 ui.link{
208 attr = {
209 id = "issue_" .. issue.id .. "_interest_link",
210 class = "float-right mdl-button mdl-js-button mdl-button--icon mdl-button--accent"
211 },
212 form_attr = {
213 onsubmit = "toggleInterest(" .. issue.id .. ", 'issue_" .. issue.id .. "_interest_icon'); return false;"
214 },
215 module = "interest", action = "update", params = { issue_id = issue.id, interested = false },
216 routing = { default = {
217 mode = "redirect", module = "index", view = "index", params = {
218 unit = redirect_unit, area = redirect_area
219 },
220 anchor = "issue_" .. issue.id
221 } },
222 content = function()
223 ui.tag{ tag = "i", attr = { id = "issue_" .. issue.id .. "_interest_icon", class = "material-icons" }, content = "star" }
224 end
225 }
227 local privilege = Privilege:new_selector()
228 :add_where{ "member_id = ?", member.id }
229 :add_where{ "unit_id = ?", issue.area.unit_id }
230 :optional_object_mode()
231 :exec()
233 local own_weight = privilege and privilege.weight or 0
235 if not issue.closed and info.own_participation and info.weight and info.weight > own_weight then
236 slot.put(" ")
237 ui.link {
238 attr = { class = "right" }, content = "+" .. (info.weight - own_weight),
239 module = "interest", view = "show_incoming", params = {
240 issue_id = issue.id, member_id = member.id
241 }
242 }
243 end
244 slot.put(" ")
245 end
246 end
249 if info.own_participation or info.first_trustee_id then
250 local class = "delegation_info"
251 if info.own_participation then
252 class = class .. " suspended"
253 end
255 local voting_member_id
256 local voting_member_name
257 if issue and issue.fully_frozen and issue.closed then
258 if issue.member_info.first_trustee_participation then
259 voting_member_id = issue.member_info.first_trustee_id
260 voting_member_name = issue.member_info.first_trustee_name
261 elseif issue.member_info.other_trustee_participation then
262 voting_member_id = issue.member_info.other_trustee_id
263 voting_member_name = issue.member_info.other_trustee_name
264 end
265 end
267 if app.session.member_id == member.id then
269 if voting_member_id then
270 ui.link{
271 module = "vote", view = "list", params = {
272 issue_id = issue.id,
273 member_id = voting_member_id
274 },
275 attr = { class = class }, content = function()
276 print_delegation_info()
277 end
278 }
280 else
281 ui.link{
282 module = "delegation", view = "show", params = {
283 unit_id = unit_id,
284 area_id = area_id,
285 issue_id = issue_id
286 },
287 attr = { class = class }, content = function()
288 print_delegation_info()
289 end
290 }
291 end
292 else
293 ui.container{
294 attr = { class = class }, content = function()
295 print_delegation_info()
296 end
297 }
298 end
299 end
301 if issue and app.session.member and issue.fully_frozen and not issue.closed and not issue.member_info.direct_voted and app.session.member:has_voting_right_for_unit_id(issue.area.unit_id) then
302 ui.link{
303 attr = { class = "mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--underlined" },
304 module = "vote", view = "list", params = {
305 issue_id = issue.id
306 },
307 content = function ()
308 ui.tag { content = _"vote now" }
309 end
310 }
311 else
312 end

Impressum / About Us