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