liquid_feedback_frontend

diff app/main/issue/_sidebar_state.lua @ 1309:32cc544d5a5b

Cumulative patch for upcoming frontend version 4
author bsw/jbe
date Sun Jul 15 14:07:29 2018 +0200 (2018-07-15)
parents 9578cef4018a
children 4f4a42bb84ec
line diff
     1.1 --- a/app/main/issue/_sidebar_state.lua	Thu Jun 23 03:30:57 2016 +0200
     1.2 +++ b/app/main/issue/_sidebar_state.lua	Sun Jul 15 14:07:29 2018 +0200
     1.3 @@ -13,165 +13,164 @@
     1.4    view_id = issue.id
     1.5  end
     1.6  
     1.7 -ui.sidebar( "tab-whatcanido", function()
     1.8 +local current_occured = false
     1.9 +local failed = false
    1.10 +
    1.11 +ui.tag{ tag = "table", content = function()
    1.12  
    1.13 -  ui.sidebarHead( function()
    1.14 -    ui.heading{ level = 2, content = function()
    1.15 -      ui.link{ 
    1.16 -        content = issue.name,
    1.17 -        module = "issue", view = "show", id = issue.id
    1.18 -      }
    1.19 -    end }
    1.20 -  end )
    1.21 +local function quorum_text(policy, quorum)
    1.22 +  local num
    1.23 +  local den
    1.24 +  
    1.25 +  if quorum == 1 then
    1.26 +    return math.max(policy.issue_quorum or 0, issue.issue_quorum or 0)
    1.27 +  elseif quorum == 2 then
    1.28 +    num = policy.initiative_quorum_num
    1.29 +    den = policy.initiative_quorum_den
    1.30 +  end
    1.31 +  
    1.32 +  if num == nil or den == nil then
    1.33 +    return 0
    1.34 +  end
    1.35 +  
    1.36 +  if den == 100 or den == 10 then
    1.37 +    return _("#{percentage}%", { percentage = num * 100 / den })
    1.38 +  else
    1.39 +    return num .. "/" .. den
    1.40 +  end
    1.41 +  
    1.42 +end
    1.43  
    1.44 -  local current_occured = false
    1.45 -  local failed = false
    1.46 +local phases = { "admission", "discussion", "verification", "voting" }
    1.47 +
    1.48 +for i, state in ipairs(phases) do
    1.49 +  local current = state == issue.state
    1.50 +  
    1.51 +  if current then
    1.52 +    current_occured = true
    1.53 +  end
    1.54    
    1.55 -  for i, state in ipairs{ "admission", "discussion", "verification", "voting" } do
    1.56 -    local current = state == issue.state
    1.57 +  local phase_success = (
    1.58 +    (state == "admission" and issue.accepted)
    1.59 +      or (state == "discussion" and issue.half_frozen)
    1.60 +      or (state == "verification" and issue.fully_frozen and issue.state ~= "canceled_no_initiative_admitted")
    1.61 +      or (state == "voting" and issue.closed and issue.state ~= "canceled_no_initiative_admitted" and issue.state ~= "canceled_by_admin")
    1.62 +  )
    1.63 +  
    1.64 +  if not failed then
    1.65 +    ui.container{ tag = "div", attr = { id = "phase-" .. state, class = current and "phase-current" or nil }, content = function()
    1.66      
    1.67 -    if current then
    1.68 -      current_occured = true
    1.69 -    end
    1.70 -    
    1.71 -    local phase_success = (
    1.72 -      (state == "admission" and issue.accepted)
    1.73 -        or (state == "discussion" and issue.half_frozen)
    1.74 -        or (state == "verification" and issue.fully_frozen and issue.state ~= "canceled_no_initiative_admitted")
    1.75 -        or (state == "voting" and issue.closed and issue.state ~= "canceled_no_initiative_admitted" and issue.state ~= "canceled_by_admin")
    1.76 -    )
    1.77 -    
    1.78 -    if not failed then
    1.79 -      ui.link{ attr = {
    1.80 -        onclick = "$('#phase-help-" .. state .. "').toggle();return false;",
    1.81 -        class = "sidebarRow sidebarRowNarrow",
    1.82 -      }, content = function()
    1.83 +      local state_names = {
    1.84 +        admission = _"Admission",
    1.85 +        discussion = _"Discussion",
    1.86 +        verification = _"Verification",
    1.87 +        voting = _"Voting"
    1.88 +      }
    1.89        
    1.90 -        local state_names = {
    1.91 -          admission = _"Admission",
    1.92 -          discussion = _"Discussion",
    1.93 -          verification = _"Verification",
    1.94 -          voting = _"Voting"
    1.95 -        }
    1.96 -        
    1.97 -        local state_name = "(" .. i .. ") " .. state_names[state] or state
    1.98 +      local state_name = state_names[state] or state
    1.99 +      
   1.100 +      local quorum
   1.101 +      if state == "admission" then
   1.102 +        quorum = quorum_text(issue.policy, 1)
   1.103 +      elseif state == "verification" then
   1.104 +        quorum = quorum_text(issue.policy, 2)
   1.105 +      end
   1.106 +      
   1.107 +      local time_text
   1.108 +      if current then
   1.109 +        local time_left
   1.110 +        if issue.state_time_left:sub(1,1) ~= "-" then
   1.111 +          time_text = format.interval_text(issue.state_time_left, { mode = "time_left" })
   1.112 +        else
   1.113 +          time_text = "phase ends soon"
   1.114 +        end
   1.115 +      elseif current_occured then
   1.116 +        local phase_duration = issue[state .. "_time_text"]
   1.117 +        time_text = _("#{duration}", { duration = format.interval_text(phase_duration) } )
   1.118 +      else
   1.119 +        local text = "failed"
   1.120 +        if quorum then
   1.121 +          text = _("failed #{quorum}", { quorum = quorum })
   1.122 +        end
   1.123 +        if phase_success then
   1.124 +          if quorum == 0 then
   1.125 +            text = _"without quorum"
   1.126 +          elseif quorum then
   1.127 +            text = _("reached #{quorum}", { quorum = quorum })
   1.128 +          else
   1.129 +            text = _"finished"
   1.130 +          end
   1.131 +        elseif issue.state == "canceled_revoked_before_accepted" or
   1.132 +            issue.state == "canceled_after_revocation_during_discussion" or
   1.133 +            issue.state == "canceled_after_revocation_during_verification"
   1.134 +        then
   1.135 +          text = _"revoked"
   1.136 +        elseif issue.state == "canceled_by_admin" then
   1.137 +          text = _"canceled"
   1.138 +        end
   1.139 +        time_text = text
   1.140 +      end
   1.141  
   1.142 -        local function quorum_text(policy, quorum)
   1.143 -          local num
   1.144 -          local den
   1.145 -          
   1.146 -          if quorum == 1 then
   1.147 -            num = policy.issue_quorum_num
   1.148 -            den = policy.issue_quorum_den
   1.149 -          elseif quorum == 2 then
   1.150 -            num = policy.initiative_quorum_num
   1.151 -            den = policy.initiative_quorum_den
   1.152 -          end
   1.153 -          
   1.154 -          if num == nil or den == nil then
   1.155 -            return 0
   1.156 -          end
   1.157 -          
   1.158 -          if den == 100 or den == 10 then
   1.159 -            return _("#{percentage}%", { percentage = num * 100 / den })
   1.160 -          else
   1.161 -            return num .. "/" .. den
   1.162 -          end
   1.163 -          
   1.164 -        end
   1.165 -        
   1.166 -        local quorum
   1.167 -        if state == "admission" then
   1.168 -          quorum = quorum_text(issue.policy, 1)
   1.169 -        elseif state == "verification" then
   1.170 -          quorum = quorum_text(issue.policy, 2)
   1.171 +      if not config.voting_only or state == "voting" then
   1.172 +        if current then
   1.173 +          ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "play_arrow" }
   1.174 +        elseif not current_occured and not phase_success then
   1.175 +          ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "clear" }
   1.176 +        elseif current_occured and issue.accepted then
   1.177 +          ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "schedule" }
   1.178 +        elseif current_occured then
   1.179 +          ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "lock" }
   1.180 +        else
   1.181 +          ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "check" }
   1.182          end
   1.183  
   1.184 -        if current then
   1.185 -          local time_left
   1.186 -          if issue.state_time_left:sub(1,1) ~= "-" then
   1.187 -            time_left = format.interval_text(issue.state_time_left, { mode = "time_left" })
   1.188 -          else
   1.189 -            time_left = "phase ends soon"
   1.190 -          end
   1.191 -          
   1.192 -          ui.tag{ attr = { class = "right" },
   1.193 -            content = time_left
   1.194 -          }
   1.195 -        elseif current_occured then
   1.196 -          local phase_duration = issue[state .. "_time_text"]
   1.197 -          ui.tag{ attr = { class = "right" },
   1.198 -            content = _("#{duration}", {
   1.199 -              duration = format.interval_text(phase_duration)
   1.200 -            } )
   1.201 -          }
   1.202 -        else
   1.203 -          local text = "failed"
   1.204 -          if quorum then
   1.205 -            text = _("failed #{quorum}", { quorum = quorum })
   1.206 -          end
   1.207 -          if phase_success then
   1.208 -            if quorum == 0 then
   1.209 -              text = _"without quorum"
   1.210 -            elseif quorum then
   1.211 -              text = _("reached #{quorum}", { quorum = quorum })
   1.212 -            else
   1.213 -              text = _"finished"
   1.214 -            end
   1.215 -          elseif issue.state == "canceled_revoked_before_accepted" or
   1.216 -              issue.state == "canceled_after_revocation_during_discussion" or
   1.217 -              issue.state == "canceled_after_revocation_during_verification"
   1.218 -          then
   1.219 -            text = _"revoked"
   1.220 -          elseif issue.state == "canceled_by_admin" then
   1.221 -            text = _"canceled"
   1.222 -          end
   1.223 -          
   1.224 -          ui.tag{ attr = { class = "right" },
   1.225 -            content = text
   1.226 -          }
   1.227 +        if not config.voting_only then
   1.228 +          slot.put(" ")
   1.229          end
   1.230  
   1.231 -        ui.heading{ level = 3, content = function()
   1.232 -          if current then
   1.233 -            ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_current.png" }
   1.234 -          elseif not current_occured and not phase_success then
   1.235 -            ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_failed.png" }
   1.236 -          elseif current_occured then
   1.237 -            ui.image{ attr = { class = "icon16" }, static = "icons/32/empty.png" }
   1.238 -          else
   1.239 -            ui.image{ attr = { class = "icon16" }, static = "icons/32/phase_finished.png" }
   1.240 +        ui.tag{ attr = { class = "mdl-data-table__cell--non-numeric" }, content = function()
   1.241 +          if not config.voting_only then
   1.242 +            ui.tag{ content = i .. "." }
   1.243            end
   1.244            slot.put(" ")
   1.245 -          ui.tag{ content = state_name }
   1.246 -        end }
   1.247 +          ui.tag{ content = state_name  }
   1.248 +        end}
   1.249 +        ui.tag{ content = " (" .. time_text .. ")"}
   1.250 +      
   1.251 +        slot.put(" ")
   1.252 +          
   1.253 +        if not current then
   1.254 +          ui.tag{ tag = "i", attr = { onclick = "document.getElementById('phase-info-" .. i .. "').classList.toggle('hidden');", class = "material-icons material-icons-small clickable" }, content = "info_outline" }
   1.255 +        end
   1.256 +      end
   1.257 +      
   1.258 +    end }
   1.259 +    
   1.260 +    local help_texts = {
   1.261 +      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) }),
   1.262 +      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.",
   1.263 +      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) }),
   1.264 +      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."
   1.265 +    }
   1.266 +    
   1.267 +    local class = "phase-info"
   1.268 +    if not current then
   1.269 +      class = class .. " hidden"
   1.270 +    end
   1.271  
   1.272 -        local help_texts = {
   1.273 -          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) }),
   1.274 -          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.",
   1.275 -          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) }),
   1.276 -          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."
   1.277 -        }
   1.278 -        ui.container { attr = { id = "phase-help-" .. state, style = "display: none;" }, content = help_texts[state] }
   1.279 -
   1.280 -      end }
   1.281 +    if not config.voting_only then
   1.282 +      ui.container { attr = { id = "phase-info-" .. i, class = class }, content = help_texts[state] }
   1.283      end
   1.284      
   1.285 -    if not phase_success and not current and not current_occured then
   1.286 -      failed = true
   1.287 -    end
   1.288 +  end
   1.289 +  
   1.290 +  if not phase_success and not current and not current_occured then
   1.291 +    failed = true
   1.292    end
   1.293 -    
   1.294 -  if issue.closed then
   1.295 -    ui.sidebarSection( function()
   1.296 -      ui.heading { level = 1, content = issue.state_name }
   1.297 -    end )
   1.298 -  end
   1.299 -      
   1.300 -  if issue.admin_notice then
   1.301 -    ui.sidebarSection( function()
   1.302 -      ui.heading { level = 3, content = _"Administrative notice:" }
   1.303 -      slot.put(encode.html_newlines(issue.admin_notice)) 
   1.304 -    end )
   1.305 -  end
   1.306 -end )
   1.307 +end
   1.308 +
   1.309 +end }
   1.310 +
   1.311 +if issue.closed then
   1.312 +  ui.tag{ content = issue.state_name }
   1.313 +end

Impressum / About Us