liquid_feedback_frontend
view 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 source
1 local issue = param.get("issue", "table")
2 local initiative = param.get("initiative", "table")
4 local view_module
5 local view_id
7 if initiative then
8 issue = initiative.issue
9 view_module = "initiative"
10 view_id = initiative.id
11 else
12 view_module = "issue"
13 view_id = issue.id
14 end
16 ui.sidebar( "tab-whatcanido", function()
18 ui.sidebarHead( function()
19 ui.heading{ level = 2, content = function()
20 ui.link{
21 content = issue.name,
22 module = "issue", view = "show", id = issue.id
23 }
24 end }
25 end )
27 local current_occured = false
28 local failed = false
30 for i, state in ipairs{ "admission", "discussion", "verification", "voting" } do
31 local current = state == issue.state
33 if current then
34 current_occured = true
35 end
37 local phase_success = (
38 (state == "admission" and issue.accepted)
39 or (state == "discussion" and issue.half_frozen)
40 or (state == "verification" and issue.fully_frozen and issue.state ~= "canceled_no_initiative_admitted")
41 or (state == "voting" and issue.closed and issue.state ~= "canceled_no_initiative_admitted" and issue.state ~= "canceled_by_admin")
42 )
44 if not failed then
45 ui.sidebarSection( "sidebarRowNarrow" .. (current and " highlightedx" or ""), function()
47 local state_names = {
48 admission = _"Admission",
49 discussion = _"Discussion",
50 verification = _"Verification",
51 voting = _"Voting"
52 }
54 local state_name = "(" .. i .. ") " .. state_names[state] or state
56 local function quorum_text(policy, quorum)
57 local num
58 local den
60 if quorum == 1 then
61 num = policy.issue_quorum_num
62 den = policy.issue_quorum_den
63 elseif quorum == 2 then
64 num = policy.initiative_quorum_num
65 den = policy.initiative_quorum_den
66 end
68 if den == 100 then
69 return _("#{percentage}%", { percentage = num })
70 else
71 return num .. "/" .. den
72 end
74 end
76 local quorum
77 if state == "admission" then
78 quorum = quorum_text(issue.policy, 1)
79 elseif state == "verification" then
80 quorum = quorum_text(issue.policy, 2)
81 end
83 if current then
84 local time_left
85 if issue.state_time_left:sub(1,1) ~= "-" then
86 time_left = format.interval_text(issue.state_time_left, { mode = "time_left" })
87 else
88 time_left = "phase ends soon"
89 end
91 ui.tag{ attr = { class = "right" },
92 content = time_left
93 }
94 elseif current_occured then
95 local phase_duration = issue[state .. "_time"]
96 ui.tag{ attr = { class = "right" },
97 content = _("#{duration}", {
98 duration = format.interval_text(phase_duration)
99 } )
100 }
101 else
102 local text = "failed"
103 if quorum then
104 text = _("failed #{quorum}", { quorum = quorum })
105 end
106 if phase_success then
107 if quorum then
108 text = _("reached #{quorum}", { quorum = quorum })
109 else
110 text = _"finished"
111 end
112 elseif issue.state == "canceled_revoked_before_accepted" or
113 issue.state == "canceled_after_revocation_during_discussion" or
114 issue.state == "canceled_after_revocation_during_verification"
115 then
116 text = _"revoked"
117 elseif issue.state == "canceled_by_admin" then
118 text = _"canceled"
119 end
121 ui.tag{ attr = { class = "right" },
122 content = text
123 }
124 end
126 ui.heading{ level = 3, content = function()
127 if current then
128 ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_current.png" }
129 elseif not current_occured and not phase_success then
130 ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_failed.png" }
131 elseif current_occured then
132 ui.image{ attr = { class = "icon16" }, static = "icons/32/empty.png" }
133 else
134 ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_finished.png" }
135 end
136 slot.put(" ")
137 ui.tag{ content = state_name }
138 end }
140 local help_texts = {
141 admission = _"As soon as one initiative of this issue reaches #{quorum} support, the issue will go into discussion phase.",
142 discussion = _"During the discussion phase the issue is debated between initiators while the initiatives are improved by suggestions from the supporters.",
143 verification = _"During the verification phase the initiative drafts cannot be changed anymore.",
144 voting = _"On this issue can be voted now."
145 }
146 if current then
147 -- ui.container { content = help_texts[state] }
148 end
151 end )
152 end
154 if not phase_success and not current and not current_occured then
155 failed = true
156 end
157 end
159 if issue.closed then
160 ui.sidebarSection( function()
161 ui.heading { level = 1, content = issue.state_name }
162 end )
163 if issue.admin_notice then
164 ui.sidebarSection( function()
165 ui.heading { level = 3, content = _"Administrative notice:" }
166 slot.put(encode.html_newlines(issue.admin_notice))
167 end )
168 end
169 end
171 end )