liquid_feedback_frontend
diff app/main/initiative/_list_element.lua @ 1045:701a5cf6b067
Imported LiquidFeedback Frontend 3.0 branch
| author | bsw |
|---|---|
| date | Thu Jul 10 01:19:48 2014 +0200 (2014-07-10) |
| parents | c7215c18168b |
| children | 904f6807f7fa |
line diff
1.1 --- a/app/main/initiative/_list_element.lua Thu Jul 10 01:02:43 2014 +0200 1.2 +++ b/app/main/initiative/_list_element.lua Thu Jul 10 01:19:48 2014 +0200 1.3 @@ -1,152 +1,110 @@ 1.4 local initiative = param.get("initiative", "table") 1.5 -local selected = param.get("selected", atom.boolean) 1.6 -local for_member = param.get("for_member", "table") or app.session.member 1.7 +local for_event = param.get("for_event", atom.boolean) 1.8 + 1.9 +local issue = initiative.issue 1.10 1.11 local class = "initiative" 1.12 1.13 -if selected then 1.14 - class = class .. " selected" 1.15 +if initiative.rank == 1 then 1.16 + class = class .. " rank1" 1.17 end 1.18 1.19 -if initiative.polling then 1.20 - class = class .. " polling" 1.21 +if initiative.revoked then 1.22 + class = class .. " revoked" 1.23 end 1.24 1.25 -ui.container{ attr = { class = class }, content = function() 1.26 - 1.27 - ui.container{ attr = { class = "rank" }, content = function() 1.28 - if initiative.issue.fully_frozen and initiative.issue.closed 1.29 - or initiative.admitted == false 1.30 - then 1.31 - ui.field.rank{ attr = { class = "rank" }, value = initiative.rank, eligible = initiative.eligible } 1.32 - elseif not initiative.issue.closed then 1.33 - ui.image{ static = "icons/16/script.png" } 1.34 - else 1.35 - ui.image{ static = "icons/16/cross.png" } 1.36 - end 1.37 - end } 1.38 - 1.39 - ui.container{ attr = { class = "bar" }, content = function() 1.40 - if initiative.issue.fully_frozen and initiative.issue.closed then 1.41 - if initiative.negative_votes and initiative.positive_votes then 1.42 - local max_value = initiative.issue.voter_count 1.43 - ui.bargraph{ 1.44 - max_value = max_value, 1.45 - width = 100, 1.46 - bars = { 1.47 - { color = "#0a5", value = initiative.positive_votes }, 1.48 - { color = "#aaa", value = max_value - initiative.negative_votes - initiative.positive_votes }, 1.49 - { color = "#a00", value = initiative.negative_votes }, 1.50 - } 1.51 - } 1.52 - else 1.53 - slot.put(" ") 1.54 - end 1.55 - else 1.56 - local max_value = initiative.issue.population or 0 1.57 - local quorum 1.58 - if initiative.issue.accepted then 1.59 - quorum = initiative.issue.policy.initiative_quorum_num / initiative.issue.policy.initiative_quorum_den 1.60 - else 1.61 - quorum = initiative.issue.policy.issue_quorum_num / initiative.issue.policy.issue_quorum_den 1.62 - end 1.63 - ui.bargraph{ 1.64 - max_value = max_value, 1.65 - width = 100, 1.66 - quorum = max_value * quorum, 1.67 - quorum_color = "#00F", 1.68 - bars = { 1.69 - { color = "#0a5", value = (initiative.satisfied_supporter_count or 0) }, 1.70 - { color = "#aaa", value = (initiative.supporter_count or 0) - (initiative.satisfied_supporter_count or 0) }, 1.71 - { color = "#fff", value = max_value - (initiative.supporter_count or 0) }, 1.72 +ui.container{ 1.73 + attr = { class = class }, 1.74 + content = function () 1.75 + if initiative.rank ~= 1 and not for_event then 1.76 + execute.view { 1.77 + module = "initiative", view = "_bargraph", params = { 1.78 + initiative = initiative, 1.79 + battled_initiative = issue.initiatives[1] 1.80 } 1.81 } 1.82 + slot.put(" ") 1.83 end 1.84 - end } 1.85 - 1.86 - if app.session.member_id then 1.87 - ui.container{ attr = { class = "interest" }, content = function() 1.88 - if initiative.member_info.initiated then 1.89 - local label 1.90 - if for_member and for_member.id ~= app.session.member_id then 1.91 - label = _"This member is initiator of this initiative" 1.92 - else 1.93 - label = _"You are initiator of this initiative" 1.94 - end 1.95 - ui.image{ 1.96 - attr = { alt = label, title = label }, 1.97 - static = "icons/16/user_edit.png" 1.98 + ui.tag { 1.99 + attr = { class = "initiative_name" }, 1.100 + content = function() 1.101 + ui.link { 1.102 + text = initiative.display_name, 1.103 + module = "initiative", view = "show", id = initiative.id 1.104 } 1.105 - elseif initiative.member_info.directly_supported then 1.106 - if initiative.member_info.satisfied then 1.107 - if for_member and for_member.id ~= app.session.member_id then 1.108 - label = _"This member is supporter of this initiative" 1.109 - else 1.110 - local label = _"You are supporter of this initiative" 1.111 + slot.put(" ") 1.112 + if initiative.vote_grade ~= nil then 1.113 + if initiative.vote_grade > 0 then 1.114 + local text = _"voted yes" 1.115 + ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/support_satisfied.png" } 1.116 + elseif initiative.vote_grade == 0 then 1.117 + elseif initiative.vote_grade < 0 then 1.118 + local text = _"voted no" 1.119 + ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/voted_no.png" } 1.120 end 1.121 - ui.image{ 1.122 - attr = { alt = label, title = label }, 1.123 - static = "icons/16/thumb_up_green.png" 1.124 - } 1.125 - else 1.126 - if for_member and for_member.id ~= app.session.member_id then 1.127 - label = _"This member is potential supporter of this initiative" 1.128 - else 1.129 - local label = _"You are potential supporter of this initiative" 1.130 + elseif app.session.member then 1.131 + if initiative.member_info.supported then 1.132 + if initiative.member_info.satisfied then 1.133 + local text = _"supporter" 1.134 + ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/support_satisfied.png" } 1.135 + else 1.136 + local text = _"supporter with restricting suggestions" 1.137 + ui.image { attr = { class = "icon16", title = text, alt = text }, static = "icons/32/support_unsatisfied.png" } 1.138 + end 1.139 end 1.140 - ui.image{ 1.141 - attr = { alt = label, title = label }, 1.142 - static = "icons/16/thumb_up.png" 1.143 - } 1.144 - end 1.145 - elseif initiative.member_info.supported then 1.146 - if initiative.member_info.satisfied then 1.147 - if for_member and for_member.id ~= app.session.member_id then 1.148 - label = _"This member is supporter of this initiative via delegation" 1.149 - else 1.150 - local label = _"You are supporter of this initiative via delegation" 1.151 - end 1.152 - ui.image{ 1.153 - attr = { alt = label, title = label }, 1.154 - static = "icons/16/thumb_up_green_arrow.png" 1.155 - } 1.156 - else 1.157 - if for_member and for_member.id ~= app.session.member_id then 1.158 - label = _"This member is potential supporter of this initiative via delegation" 1.159 - else 1.160 - local label = _"You are potential supporter of this initiative via delegation" 1.161 - end 1.162 - ui.image{ 1.163 - attr = { alt = label, title = label }, 1.164 - static = "icons/16/thumb_up_arrow.png" 1.165 - } 1.166 end 1.167 end 1.168 - end } 1.169 + } 1.170 + 1.171 end 1.172 - 1.173 - ui.container{ attr = { class = "name" }, content = function() 1.174 - local link_class = "initiative_link" 1.175 - if initiative.revoked then 1.176 - link_class = "revoked" 1.177 +} 1.178 + 1.179 +if initiative.rank == 1 1.180 + and issue.voter_count 1.181 + and initiative.positive_votes ~= nil 1.182 + and initiative.negative_votes ~= nil 1.183 + and not for_event 1.184 +then 1.185 + function percent(p, q) 1.186 + if q > 0 then 1.187 + return math.floor(p / q * 100) .. "%" 1.188 + else 1.189 + return "0%" 1.190 end 1.191 - ui.link{ 1.192 - attr = { class = link_class }, 1.193 - content = function() 1.194 - local name 1.195 - if initiative.name_highlighted then 1.196 - name = encode.highlight(initiative.name_highlighted) 1.197 - else 1.198 - name = encode.html(initiative.shortened_name) 1.199 - end 1.200 - ui.tag{ content = "i" .. initiative.id .. ": " } 1.201 - slot.put(name) 1.202 - end, 1.203 - module = "initiative", 1.204 - view = "show", 1.205 - id = initiative.id 1.206 - } 1.207 - 1.208 - end } 1.209 + end 1.210 + local result = "" 1.211 + if initiative.eligible then 1.212 + result = _("Reached #{sign}#{num}/#{den}", { 1.213 + sign = issue.policy.direct_majority_strict and ">" or "≥", 1.214 + num = issue.policy.direct_majority_num, 1.215 + den = issue.policy.direct_majority_den 1.216 + }) 1.217 + else 1.218 + result = _("Failed #{sign}#{num}/#{den}", { 1.219 + sign = issue.policy.direct_majority_strict and ">" or "≥", 1.220 + num = issue.policy.direct_majority_num, 1.221 + den = issue.policy.direct_majority_den 1.222 + }) 1.223 + end 1.224 + local neutral_count = issue.voter_count - initiative.positive_votes - initiative.negative_votes 1.225 + 1.226 + local result_text 1.227 + 1.228 + if issue.voter_count > 0 then 1.229 + result_text = _("#{result}: #{yes_count} Yes (#{yes_percent}), #{no_count} No (#{no_percent}), #{neutral_count} Abstention (#{neutral_percent})", { 1.230 + result = result, 1.231 + yes_count = initiative.positive_votes, 1.232 + yes_percent = percent(initiative.positive_votes, issue.voter_count), 1.233 + neutral_count = neutral_count, 1.234 + neutral_percent = percent(neutral_count, issue.voter_count), 1.235 + no_count = initiative.negative_votes, 1.236 + no_percent = percent(initiative.negative_votes, issue.voter_count) 1.237 + }) 1.238 + else 1.239 + result_text = _("#{result}: No votes (0)", { result = result }) 1.240 + end 1.241 + 1.242 + ui.container { attr = { class = "result" }, content = result_text } 1.243 1.244 -end } 1.245 +end 1.246 +