liquid_feedback_frontend
view app/main/initiative/_list.lua @ 0:3bfb2fcf7ab9
Version alpha1
author | bsw/jbe |
---|---|
date | Wed Nov 18 12:00:00 2009 +0100 (2009-11-18) |
parents | |
children | 5c601807d397 |
line source
1 local initiatives_selector = param.get("initiatives_selector", "table")
2 initiatives_selector:join("issue", nil, "issue.id = initiative.issue_id")
4 local issue = param.get("issue", "table")
6 local order_options = {}
8 if issue and issue.ranks_available then
9 order_options[#order_options+1] = {
10 name = "rank",
11 label = _"Rank",
12 order_by = "initiative.rank"
13 }
14 end
16 order_options[#order_options+1] = {
17 name = "support",
18 label = _"Support",
19 order_by = "initiative.supporter_count::float / issue.population::float DESC"
20 }
22 order_options[#order_options+1] = {
23 name = "support_si",
24 label = _"Support S+I",
25 order_by = "initiative.satisfied_informed_supporter_count::float / issue.population::float DESC"
26 }
28 order_options[#order_options+1] = {
29 name = "newest",
30 label = _"Newest",
31 order_by = "initiative.created DESC"
32 }
34 order_options[#order_options+1] = {
35 name = "oldest",
36 label = _"Oldest",
37 order_by = "initiative.created"
38 }
40 local name = "initiative_list"
41 if issue then
42 name = "issue_" .. tostring(issue.id) .. "_initiative_list"
43 end
45 ui.order{
46 name = name,
47 selector = initiatives_selector,
48 options = order_options,
49 content = function()
50 ui.paginate{
51 selector = initiatives_selector,
52 content = function()
53 local initiatives = initiatives_selector:exec()
54 local columns = {}
55 local issue = initiatives[1] and initiatives[1].issue or {}
56 if issue.accepted and issue.closed and issue.ranks_available then
57 columns[#columns+1] = {
58 content = function(record)
59 ui.field.rank{ value = record.rank }
60 end
61 }
62 columns[#columns+1] = {
63 content = function(record)
64 if record.negative_votes and record.positive_votes then
65 local max_value = record.issue.voter_count
66 trace.debug(record.issue.voter_count)
67 ui.bargraph{
68 max_value = max_value,
69 width = 100,
70 bars = {
71 { color = "#0a0", value = record.positive_votes },
72 { color = "#aaa", value = max_value - record.negative_votes - record.positive_votes },
73 { color = "#a00", value = record.negative_votes },
74 }
75 }
76 end
77 end
78 }
79 else
80 columns[#columns+1] = {
81 content = function(record)
82 local max_value = (record.issue.population or 0)
83 ui.bargraph{
84 max_value = max_value,
85 width = 100,
86 bars = {
87 { color = "#0a0", value = (record.satisfied_informed_supporter_count or 0) },
88 { color = "#8f8", value = (record.supporter_count or 0) - (record.satisfied_informed_supporter_count or 0) },
89 { color = "#ddd", value = max_value - (record.supporter_count or 0) },
90 }
91 }
92 end
93 }
94 end
95 columns[#columns+1] = {
96 content = function(record)
97 ui.link{
98 content = function()
99 util.put_highlighted_string(record.shortened_name)
100 end,
101 module = "initiative",
102 view = "show",
103 id = record.id
104 }
105 end
106 }
108 ui.list{
109 attr = { class = "initiatives" },
110 records = initiatives,
111 columns = columns
112 }
113 end
114 }
115 end
116 }