bsw@1045: local issue = param.get("issue", "table") bsw@1045: local initiative = param.get("initiative", "table") bsw@1045: bsw@1045: local view_module bsw@1045: local view_id bsw@1045: bsw@1045: if initiative then bsw@1045: issue = initiative.issue bsw@1045: view_module = "initiative" bsw@1045: view_id = initiative.id bsw@1045: else bsw@1045: view_module = "issue" bsw@1045: view_id = issue.id bsw@1045: end bsw@1045: bsw@1045: ui.sidebar( "tab-whatcanido", function() bsw@1045: bsw@1045: ui.sidebarHead( function() bsw@1045: ui.heading{ level = 2, content = function() bsw@1045: ui.link{ bsw@1045: content = issue.name, bsw@1045: module = "issue", view = "show", id = issue.id bsw@1045: } bsw@1045: end } bsw@1045: end ) bsw@1045: bsw@1045: local current_occured = false bsw@1045: local failed = false bsw@1045: bsw@1045: for i, state in ipairs{ "admission", "discussion", "verification", "voting" } do bsw@1045: local current = state == issue.state bsw@1045: bsw@1045: if current then bsw@1045: current_occured = true bsw@1045: end bsw@1045: bsw@1045: local phase_success = ( bsw@1045: (state == "admission" and issue.accepted) bsw@1045: or (state == "discussion" and issue.half_frozen) bsw@1045: or (state == "verification" and issue.fully_frozen and issue.state ~= "canceled_no_initiative_admitted") bsw@1045: or (state == "voting" and issue.closed and issue.state ~= "canceled_no_initiative_admitted" and issue.state ~= "canceled_by_admin") bsw@1045: ) bsw@1045: bsw@1045: if not failed then bsw@1045: ui.sidebarSection( "sidebarRowNarrow" .. (current and " highlightedx" or ""), function() bsw@1045: bsw@1045: local state_names = { bsw@1045: admission = _"Admission", bsw@1045: discussion = _"Discussion", bsw@1045: verification = _"Verification", bsw@1045: voting = _"Voting" bsw@1045: } bsw@1045: bsw@1045: local state_name = "(" .. i .. ") " .. state_names[state] or state bsw@1045: bsw@1045: local function quorum_text(policy, quorum) bsw@1045: local num bsw@1045: local den bsw@1045: bsw@1045: if quorum == 1 then bsw@1045: num = policy.issue_quorum_num bsw@1045: den = policy.issue_quorum_den bsw@1045: elseif quorum == 2 then bsw@1045: num = policy.initiative_quorum_num bsw@1045: den = policy.initiative_quorum_den bsw@1045: end bsw@1045: bsw@1045: if den == 100 then bsw@1045: return _("#{percentage}%", { percentage = num }) bsw@1045: else bsw@1045: return num .. "/" .. den bsw@1045: end bsw@1045: bsw@1045: end bsw@1045: bsw@1045: local quorum bsw@1045: if state == "admission" then bsw@1045: quorum = quorum_text(issue.policy, 1) bsw@1045: elseif state == "verification" then bsw@1045: quorum = quorum_text(issue.policy, 2) bsw@1045: end bsw@1045: bsw@1045: if current then bsw@1045: local time_left bsw@1045: if issue.state_time_left:sub(1,1) ~= "-" then bsw@1045: time_left = format.interval_text(issue.state_time_left, { mode = "time_left" }) bsw@1045: else bsw@1045: time_left = "phase ends soon" bsw@1045: end bsw@1045: bsw@1045: ui.tag{ attr = { class = "right" }, bsw@1045: content = time_left bsw@1045: } bsw@1045: elseif current_occured then bsw@1045: local phase_duration = issue[state .. "_time"] bsw@1045: ui.tag{ attr = { class = "right" }, bsw@1045: content = _("#{duration}", { bsw@1045: duration = format.interval_text(phase_duration) bsw@1045: } ) bsw@1045: } bsw@1045: else bsw@1045: local text = "failed" bsw@1045: if quorum then bsw@1045: text = _("failed #{quorum}", { quorum = quorum }) bsw@1045: end bsw@1045: if phase_success then bsw@1045: if quorum then bsw@1045: text = _("reached #{quorum}", { quorum = quorum }) bsw@1045: else bsw@1045: text = _"finished" bsw@1045: end bsw@1045: elseif issue.state == "canceled_revoked_before_accepted" or bsw@1045: issue.state == "canceled_after_revocation_during_discussion" or bsw@1045: issue.state == "canceled_after_revocation_during_verification" bsw@1045: then bsw@1045: text = _"revoked" bsw@1045: elseif issue.state == "canceled_by_admin" then bsw@1045: text = _"canceled" bsw@1045: end bsw@1045: bsw@1045: ui.tag{ attr = { class = "right" }, bsw@1045: content = text bsw@1045: } bsw@1045: end bsw@1045: bsw@1045: ui.heading{ level = 3, content = function() bsw@1045: if current then bsw@1045: ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_current.png" } bsw@1045: elseif not current_occured and not phase_success then bsw@1045: ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_failed.png" } bsw@1045: elseif current_occured then bsw@1045: ui.image{ attr = { class = "icon16" }, static = "icons/32/empty.png" } bsw@1045: else bsw@1045: ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_finished.png" } bsw@1045: end bsw@1045: slot.put(" ") bsw@1045: ui.tag{ content = state_name } bsw@1045: end } bsw@1045: bsw@1045: local help_texts = { bsw@1045: admission = _"As soon as one initiative of this issue reaches #{quorum} support, the issue will go into discussion phase.", bsw@1045: discussion = _"During the discussion phase the issue is debated between initiators while the initiatives are improved by suggestions from the supporters.", bsw@1045: verification = _"During the verification phase the initiative drafts cannot be changed anymore.", bsw@1045: voting = _"On this issue can be voted now." bsw@1045: } bsw@1045: if current then bsw@1045: -- ui.container { content = help_texts[state] } bsw@1045: end bsw@1045: bsw@1045: bsw@1045: end ) bsw@1045: end bsw@1045: bsw@1045: if not phase_success and not current and not current_occured then bsw@1045: failed = true bsw@1045: end bsw@1045: end bsw@1045: bsw@1045: if issue.closed then bsw@1045: ui.sidebarSection( function() bsw@1045: ui.heading { level = 1, content = issue.state_name } bsw@1045: end ) bsw@1045: if issue.admin_notice then bsw@1045: ui.sidebarSection( function() bsw@1045: ui.heading { level = 3, content = _"Administrative notice:" } bsw@1045: slot.put(encode.html_newlines(issue.admin_notice)) bsw@1045: end ) bsw@1045: end bsw@1045: end bsw@1045: bsw@1045: end )