liquid_feedback_frontend
view app/main/initiative/_battles.lua @ 145:90520c9fca44
implement area filter in timeline
allows the user to ignore any area in the timeline filter.
better display in javascript off
allows the user to ignore any area in the timeline filter.
better display in javascript off
| author | Daniel Poelzleithner <poelzi@poelzi.org> |
|---|---|
| date | Thu Oct 07 00:35:48 2010 +0200 (2010-10-07) |
| parents | a6caaff47205 |
| children | cc64a4fc6ab6 |
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.container{
23 attr = { class = "heading first" },
24 content = _"This initiative compared to alternative initiatives"
25 }
27 ui.list{
28 records = battled_initiatives,
29 columns = {
30 {
31 content = function()
32 slot.put(_"This initiative")
33 end
34 },
35 {
36 content = function(record)
37 local population = initiative.issue.voter_count
38 local value = record.winning_count
39 ui.bargraph{
40 class = "bargraph bargraph50",
41 max_value = population,
42 width = 50,
43 bars = {
44 { color = "#aaa", value = population - value },
45 { color = "#444", value = value },
46 }
47 }
48 end
49 },
50 {
51 content = function(record)
52 slot.put(record.winning_count)
53 end
54 },
55 {
56 content = function(record)
57 if record.winning_count == record.losing_count then
58 ui.image{ static = "icons/16/bullet_blue.png" }
59 elseif record.winning_count > record.losing_count then
60 ui.image{ static = "icons/16/resultset_previous.png" }
61 else
62 ui.image{ static = "icons/16/resultset_next.png" }
63 end
64 end
65 },
66 {
67 field_attr = { style = "text-align: right;" },
68 content = function(record)
69 slot.put(record.losing_count)
70 end
71 },
72 {
73 content = function(record)
74 local population = initiative.issue.voter_count
75 local value = record.losing_count
76 ui.bargraph{
77 class = "bargraph bargraph50",
78 max_value = population,
79 width = 50,
80 bars = {
81 { color = "#444", value = value },
82 { color = "#aaa", value = population - value },
83 }
84 }
85 end
86 },
87 {
88 content = function(record)
89 ui.link{
90 module = "initiative",
91 view = "show",
92 id = record.id,
93 text = record.name
94 }
95 end
96 }
97 }
98 }
99 end
