liquid_feedback_frontend
view app/main/initiative/_battles.lua @ 1100:41f55e4cb905
Added translation of phase durations
| author | bsw | 
|---|---|
| date | Mon Oct 27 12:03:08 2014 +0100 (2014-10-27) | 
| parents | 701a5cf6b067 | 
| children | dcbe505ddf24 | 
 line source
     1 local initiative = param.get("initiative", "table")
     3 if not initiative.issue.closed then
     4   return
     5 end
     7 local battled_initiatives = Initiative:new_selector()
     8   :add_field("winning_battle.count", "winning_count")
     9   :add_field("losing_battle.count", "losing_count")
    10   :join("battle", "winning_battle", { "winning_battle.winning_initiative_id = ? AND winning_battle.losing_initiative_id = initiative.id", initiative.id })
    11   :join("battle", "losing_battle", { "losing_battle.losing_initiative_id = ? AND losing_battle.winning_initiative_id = initiative.id", initiative.id })
    12   :add_order_by("rank")
    13   :exec()
    16 local number_of_initiatives = Initiative:new_selector()
    17   :add_where{ "issue_id = ?", initiative.issue_id }
    18   :add_where("admitted")
    19   :count()
    21 if number_of_initiatives > 1 then
    22   ui.heading { level = 1, content = _"Preference comparison" }
    23   ui.list{
    24     records = battled_initiatives,
    25     columns = {
    26       {
    27         content = function()
    28           slot.put(_"This initiative")
    29         end
    30       },
    31       {
    32         content = function(record)
    33           local population = initiative.issue.voter_count
    34           local value = record.winning_count
    35           ui.bargraph{
    36             class = "bargraph bargraph50",
    37             max_value = population,
    38             width = 50,
    39             bars = {
    40               { color = "#aaa", value = population - value },
    41               { color = "#444", value = value },
    42             }
    43           }
    44         end
    45       },
    46       {
    47         content = function(record)
    48           slot.put(record.winning_count)
    49         end
    50       },
    51       {
    52         content = function(record)
    53           if record.winning_count == record.losing_count then
    54             ui.image{ static = "icons/16/bullet_blue.png" }
    55           elseif record.winning_count > record.losing_count then
    56             ui.image{ static = "icons/16/resultset_previous.png" }
    57           else
    58             ui.image{ static = "icons/16/resultset_next.png" }
    59           end
    60         end
    61       },
    62       {
    63         field_attr = { style = "text-align: right;" },
    64         content = function(record)
    65           slot.put(record.losing_count)
    66         end
    67       },
    68       {
    69         content = function(record)
    70           local population = initiative.issue.voter_count
    71           local value = record.losing_count
    72           ui.bargraph{
    73             class = "bargraph bargraph50",
    74             max_value = population,
    75             width = 50,
    76             bars = {
    77               { color = "#444", value = value },
    78               { color = "#aaa", value = population - value },
    79             }
    80           }
    81         end
    82       },
    83       {
    84         content = function(record)
    85           ui.link{
    86             module = "initiative",
    87             view = "show",
    88             id = record.id,
    89             text = record.name
    90           }
    91         end
    92       }
    93     }
    94   }
    95 end
