liquid_feedback_frontend

view app/main/initiative/_battles.lua @ 1858:3d1f0464a3ea

Handle missing ldap.member.allowed function
author bsw
date Tue Sep 20 17:35:29 2022 +0200 (20 months ago)
parents dcbe505ddf24
children
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.heading { level = 1, content = _"Preference comparison" }
23 ui.list{
24 records = battled_initiatives,
25 columns = {
26 {
27 content = function()
28 slot.put(_"This initiative")
29 end
30 },
31 {
32 content = function(record)
33 local population = initiative.issue.voter_count
34 local value = record.winning_count
35 ui.bargraph{
36 class = "bargraph bargraph50",
37 max_value = population,
38 width = 50,
39 bars = {
40 { color = "#aaa", value = population - value },
41 { color = "#444", value = value },
42 }
43 }
44 end
45 },
46 {
47 content = function(record)
48 slot.put(record.winning_count)
49 end
50 },
51 {
52 content = function(record)
53 if record.winning_count == record.losing_count then
54 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "fiber_manual_record" }
55 elseif record.winning_count > record.losing_count then
56 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "arrow_left" }
57 else
58 ui.tag{ tag = "i", attr = { class = "material-icons" }, content = "arrow_right" }
59 end
60 end
61 },
62 {
63 field_attr = { style = "text-align: right;" },
64 content = function(record)
65 slot.put(record.losing_count)
66 end
67 },
68 {
69 content = function(record)
70 local population = initiative.issue.voter_count
71 local value = record.losing_count
72 ui.bargraph{
73 class = "bargraph bargraph50",
74 max_value = population,
75 width = 50,
76 bars = {
77 { color = "#444", value = value },
78 { color = "#aaa", value = population - value },
79 }
80 }
81 end
82 },
83 {
84 content = function(record)
85 ui.link{
86 module = "initiative",
87 view = "show",
88 id = record.id,
89 text = record.name
90 }
91 end
92 }
93 }
94 }
95 end

Impressum / About Us