rev |
line source |
bsw/jbe@19
|
1 local initiative = param.get("initiative", "table")
|
bsw/jbe@19
|
2
|
bsw/jbe@19
|
3
|
bsw/jbe@19
|
4 local battled_initiatives = Initiative:new_selector()
|
bsw/jbe@19
|
5 :add_field("winning_battle.count", "winning_count")
|
bsw/jbe@19
|
6 :add_field("losing_battle.count", "losing_count")
|
bsw/jbe@19
|
7 :join("battle", "winning_battle", { "winning_battle.winning_initiative_id = ? AND winning_battle.losing_initiative_id = initiative.id", initiative.id })
|
bsw/jbe@19
|
8 :join("battle", "losing_battle", { "losing_battle.losing_initiative_id = ? AND losing_battle.winning_initiative_id = initiative.id", initiative.id })
|
bsw/jbe@19
|
9 :add_order_by("rank")
|
bsw/jbe@19
|
10 :exec()
|
bsw/jbe@19
|
11
|
bsw/jbe@19
|
12 local number_of_initiatives = Initiative:new_selector()
|
bsw/jbe@19
|
13 :add_where{ "issue_id = ?", initiative.issue_id }
|
bsw/jbe@19
|
14 :add_where("admitted")
|
bsw/jbe@19
|
15 :count()
|
bsw/jbe@19
|
16
|
bsw/jbe@19
|
17 if initiative.revoked then
|
bsw/jbe@19
|
18 slot.put(_"Not voted (revoked from initiator)")
|
bsw/jbe@19
|
19 elseif initiative.admitted == false then
|
bsw/jbe@19
|
20 slot.put(_"Not voted (not admitted)")
|
bsw/jbe@19
|
21 else
|
bsw/jbe@19
|
22 if number_of_initiatives > 1 then
|
bsw/jbe@19
|
23 ui.container{
|
bsw/jbe@19
|
24 attr = { class = "heading first" },
|
bsw/jbe@19
|
25 content = _"This initiative compared to alternative initiatives"
|
bsw/jbe@19
|
26 }
|
bsw/jbe@19
|
27
|
bsw/jbe@19
|
28 ui.list{
|
bsw/jbe@19
|
29 records = battled_initiatives,
|
bsw/jbe@19
|
30 columns = {
|
bsw/jbe@19
|
31 {
|
bsw/jbe@19
|
32 content = function()
|
bsw/jbe@19
|
33 slot.put(_"This initiative")
|
bsw/jbe@19
|
34 end
|
bsw/jbe@19
|
35 },
|
bsw/jbe@19
|
36 {
|
bsw/jbe@19
|
37 content = function(record)
|
bsw/jbe@19
|
38 local population = initiative.issue.voter_count
|
bsw/jbe@19
|
39 local value = record.winning_count
|
bsw/jbe@19
|
40 ui.bargraph{
|
bsw/jbe@19
|
41 class = "bargraph bargraph50",
|
bsw/jbe@19
|
42 max_value = population,
|
bsw/jbe@19
|
43 width = 50,
|
bsw/jbe@19
|
44 bars = {
|
bsw/jbe@19
|
45 { color = "#aaa", value = population - value },
|
bsw/jbe@19
|
46 { color = "#444", value = value },
|
bsw/jbe@19
|
47 }
|
bsw/jbe@19
|
48 }
|
bsw/jbe@19
|
49 end
|
bsw/jbe@19
|
50 },
|
bsw/jbe@19
|
51 {
|
bsw/jbe@19
|
52 content = function(record)
|
bsw/jbe@19
|
53 slot.put(record.winning_count)
|
bsw/jbe@19
|
54 end
|
bsw/jbe@19
|
55 },
|
bsw/jbe@19
|
56 {
|
bsw/jbe@19
|
57 content = function(record)
|
bsw/jbe@19
|
58 if record.winning_count == record.losing_count then
|
bsw/jbe@19
|
59 ui.image{ static = "icons/16/bullet_blue.png" }
|
bsw/jbe@19
|
60 elseif record.winning_count > record.losing_count then
|
bsw/jbe@19
|
61 ui.image{ static = "icons/16/resultset_previous.png" }
|
bsw/jbe@19
|
62 else
|
bsw/jbe@19
|
63 ui.image{ static = "icons/16/resultset_next.png" }
|
bsw/jbe@19
|
64 end
|
bsw/jbe@19
|
65 end
|
bsw/jbe@19
|
66 },
|
bsw/jbe@19
|
67 {
|
bsw/jbe@19
|
68 field_attr = { style = "text-align: right;" },
|
bsw/jbe@19
|
69 content = function(record)
|
bsw/jbe@19
|
70 slot.put(record.losing_count)
|
bsw/jbe@19
|
71 end
|
bsw/jbe@19
|
72 },
|
bsw/jbe@19
|
73 {
|
bsw/jbe@19
|
74 content = function(record)
|
bsw/jbe@19
|
75 local population = initiative.issue.voter_count
|
bsw/jbe@19
|
76 local value = record.losing_count
|
bsw/jbe@19
|
77 ui.bargraph{
|
bsw/jbe@19
|
78 class = "bargraph bargraph50",
|
bsw/jbe@19
|
79 max_value = population,
|
bsw/jbe@19
|
80 width = 50,
|
bsw/jbe@19
|
81 bars = {
|
bsw/jbe@19
|
82 { color = "#444", value = value },
|
bsw/jbe@19
|
83 { color = "#aaa", value = population - value },
|
bsw/jbe@19
|
84 }
|
bsw/jbe@19
|
85 }
|
bsw/jbe@19
|
86 end
|
bsw/jbe@19
|
87 },
|
bsw/jbe@19
|
88 {
|
bsw/jbe@19
|
89 name = "name"
|
bsw/jbe@19
|
90 }
|
bsw/jbe@19
|
91 }
|
bsw/jbe@19
|
92 }
|
bsw/jbe@19
|
93 end
|
bsw/jbe@19
|
94
|
bsw/jbe@19
|
95 ui.container{
|
bsw/jbe@19
|
96 attr = { class = "heading" },
|
bsw/jbe@19
|
97 content = _"Member voting"
|
bsw/jbe@19
|
98 }
|
bsw/jbe@19
|
99
|
bsw/jbe@19
|
100 execute.view{
|
bsw/jbe@19
|
101 module = "member",
|
bsw/jbe@19
|
102 view = "_list",
|
bsw/jbe@19
|
103 params = {
|
bsw/jbe@19
|
104 initiative = initiative,
|
bsw/jbe@19
|
105 members_selector = initiative.issue:get_reference_selector("direct_voters")
|
bsw/jbe@19
|
106 :left_join("vote", nil, { "vote.initiative_id = ? AND vote.member_id = member.id", initiative.id })
|
bsw/jbe@19
|
107 :add_field("direct_voter.weight as voter_weight")
|
bsw/jbe@19
|
108 :add_field("coalesce(vote.grade, 0) as grade")
|
bsw/jbe@19
|
109 }
|
bsw/jbe@19
|
110 }
|
bsw/jbe@19
|
111
|
bsw/jbe@19
|
112 end
|