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