liquid_feedback_frontend
view app/main/issue/_sidebar_state.lua @ 1455:24dc7bd75d0a
New layout for admin member edit view
author | bsw |
---|---|
date | Thu Oct 18 17:23:45 2018 +0200 (2018-10-18) |
parents | 32cc544d5a5b |
children | 4f4a42bb84ec |
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 local current_occured = false
17 local failed = false
19 ui.tag{ tag = "table", content = function()
21 local function quorum_text(policy, quorum)
22 local num
23 local den
25 if quorum == 1 then
26 return math.max(policy.issue_quorum or 0, issue.issue_quorum or 0)
27 elseif quorum == 2 then
28 num = policy.initiative_quorum_num
29 den = policy.initiative_quorum_den
30 end
32 if num == nil or den == nil then
33 return 0
34 end
36 if den == 100 or den == 10 then
37 return _("#{percentage}%", { percentage = num * 100 / den })
38 else
39 return num .. "/" .. den
40 end
42 end
44 local phases = { "admission", "discussion", "verification", "voting" }
46 for i, state in ipairs(phases) do
47 local current = state == issue.state
49 if current then
50 current_occured = true
51 end
53 local phase_success = (
54 (state == "admission" and issue.accepted)
55 or (state == "discussion" and issue.half_frozen)
56 or (state == "verification" and issue.fully_frozen and issue.state ~= "canceled_no_initiative_admitted")
57 or (state == "voting" and issue.closed and issue.state ~= "canceled_no_initiative_admitted" and issue.state ~= "canceled_by_admin")
58 )
60 if not failed then
61 ui.container{ tag = "div", attr = { id = "phase-" .. state, class = current and "phase-current" or nil }, content = function()
63 local state_names = {
64 admission = _"Admission",
65 discussion = _"Discussion",
66 verification = _"Verification",
67 voting = _"Voting"
68 }
70 local state_name = state_names[state] or state
72 local quorum
73 if state == "admission" then
74 quorum = quorum_text(issue.policy, 1)
75 elseif state == "verification" then
76 quorum = quorum_text(issue.policy, 2)
77 end
79 local time_text
80 if current then
81 local time_left
82 if issue.state_time_left:sub(1,1) ~= "-" then
83 time_text = format.interval_text(issue.state_time_left, { mode = "time_left" })
84 else
85 time_text = "phase ends soon"
86 end
87 elseif current_occured then
88 local phase_duration = issue[state .. "_time_text"]
89 time_text = _("#{duration}", { duration = format.interval_text(phase_duration) } )
90 else
91 local text = "failed"
92 if quorum then
93 text = _("failed #{quorum}", { quorum = quorum })
94 end
95 if phase_success then
96 if quorum == 0 then
97 text = _"without quorum"
98 elseif quorum then
99 text = _("reached #{quorum}", { quorum = quorum })
100 else
101 text = _"finished"
102 end
103 elseif issue.state == "canceled_revoked_before_accepted" or
104 issue.state == "canceled_after_revocation_during_discussion" or
105 issue.state == "canceled_after_revocation_during_verification"
106 then
107 text = _"revoked"
108 elseif issue.state == "canceled_by_admin" then
109 text = _"canceled"
110 end
111 time_text = text
112 end
114 if not config.voting_only or state == "voting" then
115 if current then
116 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "play_arrow" }
117 elseif not current_occured and not phase_success then
118 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "clear" }
119 elseif current_occured and issue.accepted then
120 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "schedule" }
121 elseif current_occured then
122 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "lock" }
123 else
124 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "check" }
125 end
127 if not config.voting_only then
128 slot.put(" ")
129 end
131 ui.tag{ attr = { class = "mdl-data-table__cell--non-numeric" }, content = function()
132 if not config.voting_only then
133 ui.tag{ content = i .. "." }
134 end
135 slot.put(" ")
136 ui.tag{ content = state_name }
137 end}
138 ui.tag{ content = " (" .. time_text .. ")"}
140 slot.put(" ")
142 if not current then
143 ui.tag{ tag = "i", attr = { onclick = "document.getElementById('phase-info-" .. i .. "').classList.toggle('hidden');", class = "material-icons material-icons-small clickable" }, content = "info_outline" }
144 end
145 end
147 end }
149 local help_texts = {
150 admission = _("As soon as one initiative of this issue reaches the 1st quorum of #{quorum} support, the issue will proceed to discussion phase.", { quorum = quorum_text(issue.policy, 1) }),
151 discussion = _"During the discussion phase, the issue is debated on while the initiators improve the proposals and reasons in their initiatives. Supporters of initiatives can write and rate suggestions for improvement.",
152 verification = _("During the verification phase, existing initiatives cannot be changed anymore. Initiatives need to pass the 2nd quorum of #{quorum} at end of verification phase to become admitted for voting.", { quorum = quorum_text(issue.policy, 2) }),
153 voting = _"During the voting phase, votes for all admitted initiatives in this issue can be cast. The final result will be calculated as soon as this phase ends."
154 }
156 local class = "phase-info"
157 if not current then
158 class = class .. " hidden"
159 end
161 if not config.voting_only then
162 ui.container { attr = { id = "phase-info-" .. i, class = class }, content = help_texts[state] }
163 end
165 end
167 if not phase_success and not current and not current_occured then
168 failed = true
169 end
170 end
172 end }
174 if issue.closed then
175 ui.tag{ content = issue.state_name }
176 end