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