liquid_feedback_frontend
annotate app/main/initiative/_battles.lua @ 148:034f96181e59
gui part for autosupport
autosupport lets you automaticly support any new draft of an initiative
autosupport lets you automaticly support any new draft of an initiative
author | Daniel Poelzleithner <poelzi@poelzi.org> |
---|---|
date | Fri Oct 08 02:49:53 2010 +0200 (2010-10-08) |
parents | a6caaff47205 |
children | cc64a4fc6ab6 |
rev | line source |
---|---|
bsw@31 | 1 local initiative = param.get("initiative", "table") |
bsw@31 | 2 |
bsw@31 | 3 if not initiative.issue.closed then |
bsw@31 | 4 return |
bsw@31 | 5 end |
bsw@31 | 6 |
bsw@31 | 7 local battled_initiatives = Initiative:new_selector() |
bsw@31 | 8 :add_field("winning_battle.count", "winning_count") |
bsw@31 | 9 :add_field("losing_battle.count", "losing_count") |
bsw@31 | 10 :join("battle", "winning_battle", { "winning_battle.winning_initiative_id = ? AND winning_battle.losing_initiative_id = initiative.id", initiative.id }) |
bsw@31 | 11 :join("battle", "losing_battle", { "losing_battle.losing_initiative_id = ? AND losing_battle.winning_initiative_id = initiative.id", initiative.id }) |
bsw@31 | 12 :add_order_by("rank") |
bsw@31 | 13 :exec() |
bsw@31 | 14 |
bsw@31 | 15 |
bsw@31 | 16 local number_of_initiatives = Initiative:new_selector() |
bsw@31 | 17 :add_where{ "issue_id = ?", initiative.issue_id } |
bsw@31 | 18 :add_where("admitted") |
bsw@31 | 19 :count() |
bsw@31 | 20 |
bsw@31 | 21 if number_of_initiatives > 1 then |
bsw@31 | 22 ui.container{ |
bsw@31 | 23 attr = { class = "heading first" }, |
bsw@31 | 24 content = _"This initiative compared to alternative initiatives" |
bsw@31 | 25 } |
bsw@31 | 26 |
bsw@31 | 27 ui.list{ |
bsw@31 | 28 records = battled_initiatives, |
bsw@31 | 29 columns = { |
bsw@31 | 30 { |
bsw@31 | 31 content = function() |
bsw@31 | 32 slot.put(_"This initiative") |
bsw@31 | 33 end |
bsw@31 | 34 }, |
bsw@31 | 35 { |
bsw@31 | 36 content = function(record) |
bsw@31 | 37 local population = initiative.issue.voter_count |
bsw@31 | 38 local value = record.winning_count |
bsw@31 | 39 ui.bargraph{ |
bsw@31 | 40 class = "bargraph bargraph50", |
bsw@31 | 41 max_value = population, |
bsw@31 | 42 width = 50, |
bsw@31 | 43 bars = { |
bsw@31 | 44 { color = "#aaa", value = population - value }, |
bsw@31 | 45 { color = "#444", value = value }, |
bsw@31 | 46 } |
bsw@31 | 47 } |
bsw@31 | 48 end |
bsw@31 | 49 }, |
bsw@31 | 50 { |
bsw@31 | 51 content = function(record) |
bsw@31 | 52 slot.put(record.winning_count) |
bsw@31 | 53 end |
bsw@31 | 54 }, |
bsw@31 | 55 { |
bsw@31 | 56 content = function(record) |
bsw@31 | 57 if record.winning_count == record.losing_count then |
bsw@31 | 58 ui.image{ static = "icons/16/bullet_blue.png" } |
bsw@31 | 59 elseif record.winning_count > record.losing_count then |
bsw@31 | 60 ui.image{ static = "icons/16/resultset_previous.png" } |
bsw@31 | 61 else |
bsw@31 | 62 ui.image{ static = "icons/16/resultset_next.png" } |
bsw@31 | 63 end |
bsw@31 | 64 end |
bsw@31 | 65 }, |
bsw@31 | 66 { |
bsw@31 | 67 field_attr = { style = "text-align: right;" }, |
bsw@31 | 68 content = function(record) |
bsw@31 | 69 slot.put(record.losing_count) |
bsw@31 | 70 end |
bsw@31 | 71 }, |
bsw@31 | 72 { |
bsw@31 | 73 content = function(record) |
bsw@31 | 74 local population = initiative.issue.voter_count |
bsw@31 | 75 local value = record.losing_count |
bsw@31 | 76 ui.bargraph{ |
bsw@31 | 77 class = "bargraph bargraph50", |
bsw@31 | 78 max_value = population, |
bsw@31 | 79 width = 50, |
bsw@31 | 80 bars = { |
bsw@31 | 81 { color = "#444", value = value }, |
bsw@31 | 82 { color = "#aaa", value = population - value }, |
bsw@31 | 83 } |
bsw@31 | 84 } |
bsw@31 | 85 end |
bsw@31 | 86 }, |
bsw@31 | 87 { |
bsw@31 | 88 content = function(record) |
bsw@31 | 89 ui.link{ |
bsw@31 | 90 module = "initiative", |
bsw@31 | 91 view = "show", |
bsw@31 | 92 id = record.id, |
bsw@31 | 93 text = record.name |
bsw@31 | 94 } |
bsw@31 | 95 end |
bsw@31 | 96 } |
bsw@31 | 97 } |
bsw@31 | 98 } |
bsw@31 | 99 end |