liquid_feedback_frontend
diff app/main/issue/_sidebar_state.lua @ 1045:701a5cf6b067
Imported LiquidFeedback Frontend 3.0 branch
author | bsw |
---|---|
date | Thu Jul 10 01:19:48 2014 +0200 (2014-07-10) |
parents | |
children | d6ab5f231178 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/app/main/issue/_sidebar_state.lua Thu Jul 10 01:19:48 2014 +0200 1.3 @@ -0,0 +1,171 @@ 1.4 +local issue = param.get("issue", "table") 1.5 +local initiative = param.get("initiative", "table") 1.6 + 1.7 +local view_module 1.8 +local view_id 1.9 + 1.10 +if initiative then 1.11 + issue = initiative.issue 1.12 + view_module = "initiative" 1.13 + view_id = initiative.id 1.14 +else 1.15 + view_module = "issue" 1.16 + view_id = issue.id 1.17 +end 1.18 + 1.19 +ui.sidebar( "tab-whatcanido", function() 1.20 + 1.21 + ui.sidebarHead( function() 1.22 + ui.heading{ level = 2, content = function() 1.23 + ui.link{ 1.24 + content = issue.name, 1.25 + module = "issue", view = "show", id = issue.id 1.26 + } 1.27 + end } 1.28 + end ) 1.29 + 1.30 + local current_occured = false 1.31 + local failed = false 1.32 + 1.33 + for i, state in ipairs{ "admission", "discussion", "verification", "voting" } do 1.34 + local current = state == issue.state 1.35 + 1.36 + if current then 1.37 + current_occured = true 1.38 + end 1.39 + 1.40 + local phase_success = ( 1.41 + (state == "admission" and issue.accepted) 1.42 + or (state == "discussion" and issue.half_frozen) 1.43 + or (state == "verification" and issue.fully_frozen and issue.state ~= "canceled_no_initiative_admitted") 1.44 + or (state == "voting" and issue.closed and issue.state ~= "canceled_no_initiative_admitted" and issue.state ~= "canceled_by_admin") 1.45 + ) 1.46 + 1.47 + if not failed then 1.48 + ui.sidebarSection( "sidebarRowNarrow" .. (current and " highlightedx" or ""), function() 1.49 + 1.50 + local state_names = { 1.51 + admission = _"Admission", 1.52 + discussion = _"Discussion", 1.53 + verification = _"Verification", 1.54 + voting = _"Voting" 1.55 + } 1.56 + 1.57 + local state_name = "(" .. i .. ") " .. state_names[state] or state 1.58 + 1.59 + local function quorum_text(policy, quorum) 1.60 + local num 1.61 + local den 1.62 + 1.63 + if quorum == 1 then 1.64 + num = policy.issue_quorum_num 1.65 + den = policy.issue_quorum_den 1.66 + elseif quorum == 2 then 1.67 + num = policy.initiative_quorum_num 1.68 + den = policy.initiative_quorum_den 1.69 + end 1.70 + 1.71 + if den == 100 then 1.72 + return _("#{percentage}%", { percentage = num }) 1.73 + else 1.74 + return num .. "/" .. den 1.75 + end 1.76 + 1.77 + end 1.78 + 1.79 + local quorum 1.80 + if state == "admission" then 1.81 + quorum = quorum_text(issue.policy, 1) 1.82 + elseif state == "verification" then 1.83 + quorum = quorum_text(issue.policy, 2) 1.84 + end 1.85 + 1.86 + if current then 1.87 + local time_left 1.88 + if issue.state_time_left:sub(1,1) ~= "-" then 1.89 + time_left = format.interval_text(issue.state_time_left, { mode = "time_left" }) 1.90 + else 1.91 + time_left = "phase ends soon" 1.92 + end 1.93 + 1.94 + ui.tag{ attr = { class = "right" }, 1.95 + content = time_left 1.96 + } 1.97 + elseif current_occured then 1.98 + local phase_duration = issue[state .. "_time"] 1.99 + ui.tag{ attr = { class = "right" }, 1.100 + content = _("#{duration}", { 1.101 + duration = format.interval_text(phase_duration) 1.102 + } ) 1.103 + } 1.104 + else 1.105 + local text = "failed" 1.106 + if quorum then 1.107 + text = _("failed #{quorum}", { quorum = quorum }) 1.108 + end 1.109 + if phase_success then 1.110 + if quorum then 1.111 + text = _("reached #{quorum}", { quorum = quorum }) 1.112 + else 1.113 + text = _"finished" 1.114 + end 1.115 + elseif issue.state == "canceled_revoked_before_accepted" or 1.116 + issue.state == "canceled_after_revocation_during_discussion" or 1.117 + issue.state == "canceled_after_revocation_during_verification" 1.118 + then 1.119 + text = _"revoked" 1.120 + elseif issue.state == "canceled_by_admin" then 1.121 + text = _"canceled" 1.122 + end 1.123 + 1.124 + ui.tag{ attr = { class = "right" }, 1.125 + content = text 1.126 + } 1.127 + end 1.128 + 1.129 + ui.heading{ level = 3, content = function() 1.130 + if current then 1.131 + ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_current.png" } 1.132 + elseif not current_occured and not phase_success then 1.133 + ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_failed.png" } 1.134 + elseif current_occured then 1.135 + ui.image{ attr = { class = "icon16" }, static = "icons/32/empty.png" } 1.136 + else 1.137 + ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_finished.png" } 1.138 + end 1.139 + slot.put(" ") 1.140 + ui.tag{ content = state_name } 1.141 + end } 1.142 + 1.143 + local help_texts = { 1.144 + admission = _"As soon as one initiative of this issue reaches #{quorum} support, the issue will go into discussion phase.", 1.145 + discussion = _"During the discussion phase the issue is debated between initiators while the initiatives are improved by suggestions from the supporters.", 1.146 + verification = _"During the verification phase the initiative drafts cannot be changed anymore.", 1.147 + voting = _"On this issue can be voted now." 1.148 + } 1.149 + if current then 1.150 + -- ui.container { content = help_texts[state] } 1.151 + end 1.152 + 1.153 + 1.154 + end ) 1.155 + end 1.156 + 1.157 + if not phase_success and not current and not current_occured then 1.158 + failed = true 1.159 + end 1.160 + end 1.161 + 1.162 + if issue.closed then 1.163 + ui.sidebarSection( function() 1.164 + ui.heading { level = 1, content = issue.state_name } 1.165 + end ) 1.166 + if issue.admin_notice then 1.167 + ui.sidebarSection( function() 1.168 + ui.heading { level = 3, content = _"Administrative notice:" } 1.169 + slot.put(encode.html_newlines(issue.admin_notice)) 1.170 + end ) 1.171 + end 1.172 + end 1.173 + 1.174 +end ) 1.175 \ No newline at end of file