liquid_feedback_frontend

view app/main/issue/_sidebar_state.lua @ 1858:3d1f0464a3ea

Handle missing ldap.member.allowed function
author bsw
date Tue Sep 20 17:35:29 2022 +0200 (20 months ago)
parents 4f4a42bb84ec
children
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 local quorums = {}
34 if num and num > 0 and den == 100 or den == 10 then
35 table.insert(quorums, _("#{percentage}%", { percentage = num * 100 / den }))
36 elseif num and num > 0 and den and den > 0 then
37 table.insert(quorums, num .. "/" .. den)
38 end
40 if policy.initiative_quorum then
41 table.insert(quorums, policy.initiative_quorum)
42 end
44 return table.concat(quorums, " / ")
45 end
47 local phases = { "admission", "discussion", "verification", "voting" }
49 for i, state in ipairs(phases) do
50 local current = state == issue.state
52 if current then
53 current_occured = true
54 end
56 local phase_success = (
57 (state == "admission" and issue.accepted)
58 or (state == "discussion" and issue.half_frozen)
59 or (state == "verification" and issue.fully_frozen and issue.state ~= "canceled_no_initiative_admitted")
60 or (state == "voting" and issue.closed and issue.state ~= "canceled_no_initiative_admitted" and issue.state ~= "canceled_by_admin")
61 )
63 if not failed then
64 ui.container{ tag = "div", attr = { id = "phase-" .. state, class = current and "phase-current" or nil }, content = function()
66 local state_names = {
67 admission = _"Admission",
68 discussion = _"Discussion",
69 verification = _"Verification",
70 voting = _"Voting"
71 }
73 local state_name = state_names[state] or state
75 local quorum
76 if state == "admission" then
77 quorum = quorum_text(issue.policy, 1)
78 elseif state == "verification" then
79 quorum = quorum_text(issue.policy, 2)
80 end
82 local time_text
83 if current then
84 local time_left
85 if issue.state_time_left:sub(1,1) ~= "-" then
86 time_text = format.interval_text(issue.state_time_left, { mode = "time_left" })
87 else
88 time_text = "phase ends soon"
89 end
90 elseif current_occured then
91 local phase_duration = issue[state .. "_time_text"]
92 time_text = _("#{duration}", { duration = format.interval_text(phase_duration) } )
93 else
94 local text = "failed"
95 if quorum then
96 text = _("failed #{quorum}", { quorum = quorum })
97 end
98 if phase_success then
99 if quorum == 0 then
100 text = _"without quorum"
101 elseif quorum then
102 text = _("reached #{quorum}", { quorum = quorum })
103 else
104 text = _"finished"
105 end
106 elseif issue.state == "canceled_revoked_before_accepted" or
107 issue.state == "canceled_after_revocation_during_discussion" or
108 issue.state == "canceled_after_revocation_during_verification"
109 then
110 text = _"revoked"
111 elseif issue.state == "canceled_by_admin" then
112 text = _"canceled"
113 end
114 time_text = text
115 end
117 if not config.voting_only or state == "voting" then
118 if current then
119 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "play_arrow" }
120 elseif not current_occured and not phase_success then
121 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "clear" }
122 elseif current_occured and issue.accepted then
123 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "schedule" }
124 elseif current_occured then
125 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "lock" }
126 else
127 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "check" }
128 end
130 if not config.voting_only then
131 slot.put(" ")
132 end
134 ui.tag{ attr = { class = "mdl-data-table__cell--non-numeric" }, content = function()
135 if not config.voting_only then
136 ui.tag{ content = i .. "." }
137 end
138 slot.put(" ")
139 ui.tag{ content = state_name }
140 end}
141 ui.tag{ content = " (" .. time_text .. ")"}
143 slot.put(" ")
145 if not current then
146 ui.tag{ tag = "i", attr = { onclick = "document.getElementById('phase-info-" .. i .. "').classList.toggle('hidden');", class = "material-icons material-icons-small clickable" }, content = "info_outline" }
147 end
148 end
150 end }
152 local help_texts = {
153 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) }),
154 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.",
155 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) }),
156 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."
157 }
159 local class = "phase-info"
160 if not current then
161 class = class .. " hidden"
162 end
164 if not config.voting_only then
165 ui.container { attr = { id = "phase-info-" .. i, class = class }, content = help_texts[state] }
166 end
168 end
170 if not phase_success and not current and not current_occured then
171 failed = true
172 end
173 end
175 end }
177 if issue.closed then
178 ui.tag{ content = issue.state_name }
179 end

Impressum / About Us