liquid_feedback_frontend
view app/main/initiative/_battles.lua @ 981:a54d75e313d1
Sort suggestions by proportional order
| author | bsw | 
|---|---|
| date | Sun Mar 17 15:55:30 2013 +0100 (2013-03-17) | 
| parents | cc64a4fc6ab6 | 
| children | 701a5cf6b067 | 
 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.list{
    23     records = battled_initiatives,
    24     columns = {
    25       {
    26         content = function()
    27           slot.put(_"This initiative")
    28         end
    29       },
    30       {
    31         content = function(record)
    32           local population = initiative.issue.voter_count
    33           local value = record.winning_count
    34           ui.bargraph{
    35             class = "bargraph bargraph50",
    36             max_value = population,
    37             width = 50,
    38             bars = {
    39               { color = "#aaa", value = population - value },
    40               { color = "#444", value = value },
    41             }
    42           }
    43         end
    44       },
    45       {
    46         content = function(record)
    47           slot.put(record.winning_count)
    48         end
    49       },
    50       {
    51         content = function(record)
    52           if record.winning_count == record.losing_count then
    53             ui.image{ static = "icons/16/bullet_blue.png" }
    54           elseif record.winning_count > record.losing_count then
    55             ui.image{ static = "icons/16/resultset_previous.png" }
    56           else
    57             ui.image{ static = "icons/16/resultset_next.png" }
    58           end
    59         end
    60       },
    61       {
    62         field_attr = { style = "text-align: right;" },
    63         content = function(record)
    64           slot.put(record.losing_count)
    65         end
    66       },
    67       {
    68         content = function(record)
    69           local population = initiative.issue.voter_count
    70           local value = record.losing_count
    71           ui.bargraph{
    72             class = "bargraph bargraph50",
    73             max_value = population,
    74             width = 50,
    75             bars = {
    76               { color = "#444", value = value },
    77               { color = "#aaa", value = population - value },
    78             }
    79           }
    80         end
    81       },
    82       {
    83         content = function(record)
    84           ui.link{
    85             module = "initiative",
    86             view = "show",
    87             id = record.id,
    88             text = record.name
    89           }
    90         end
    91       }
    92     }
    93   }
    94 end
