| rev |
line source |
|
bsw/jbe@0
|
1 local initiatives_selector = param.get("initiatives_selector", "table")
|
|
bsw/jbe@0
|
2 initiatives_selector:join("issue", nil, "issue.id = initiative.issue_id")
|
|
bsw/jbe@0
|
3
|
|
bsw@11
|
4 local limit = param.get("limit", atom.number)
|
|
bsw@11
|
5
|
|
bsw@11
|
6 local more_initiatives_count
|
|
bsw@11
|
7 if limit then
|
|
bsw@11
|
8 local initiatives_count = initiatives_selector:count()
|
|
bsw@11
|
9 if initiatives_count > limit then
|
|
bsw@11
|
10 more_initiatives_count = initiatives_count - limit
|
|
bsw@11
|
11 end
|
|
bsw@11
|
12 initiatives_selector:limit(limit)
|
|
bsw@11
|
13 end
|
|
bsw@11
|
14
|
|
bsw@11
|
15
|
|
bsw/jbe@0
|
16 local issue = param.get("issue", "table")
|
|
bsw/jbe@0
|
17
|
|
bsw/jbe@0
|
18 local order_options = {}
|
|
bsw/jbe@0
|
19
|
|
bsw/jbe@0
|
20 if issue and issue.ranks_available then
|
|
bsw/jbe@0
|
21 order_options[#order_options+1] = {
|
|
bsw/jbe@0
|
22 name = "rank",
|
|
bsw/jbe@0
|
23 label = _"Rank",
|
|
bsw/jbe@5
|
24 order_by = "initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id"
|
|
bsw/jbe@0
|
25 }
|
|
bsw/jbe@0
|
26 end
|
|
bsw/jbe@0
|
27
|
|
bsw/jbe@0
|
28 order_options[#order_options+1] = {
|
|
bsw/jbe@5
|
29 name = "potential_support",
|
|
bsw/jbe@5
|
30 label = _"Potential support",
|
|
bsw/jbe@5
|
31 order_by = "initiative.supporter_count::float / issue.population::float DESC, initiative.id"
|
|
bsw/jbe@5
|
32 }
|
|
bsw/jbe@5
|
33
|
|
bsw/jbe@5
|
34 order_options[#order_options+1] = {
|
|
bsw/jbe@0
|
35 name = "support",
|
|
bsw/jbe@0
|
36 label = _"Support",
|
|
bsw/jbe@5
|
37 order_by = "initiative.satisfied_supporter_count::float / issue.population::float DESC, initiative.id"
|
|
bsw/jbe@0
|
38 }
|
|
bsw/jbe@0
|
39
|
|
bsw/jbe@0
|
40 order_options[#order_options+1] = {
|
|
bsw/jbe@0
|
41 name = "newest",
|
|
bsw/jbe@0
|
42 label = _"Newest",
|
|
bsw/jbe@5
|
43 order_by = "initiative.created DESC, initiative.id"
|
|
bsw/jbe@0
|
44 }
|
|
bsw/jbe@0
|
45
|
|
bsw/jbe@0
|
46 order_options[#order_options+1] = {
|
|
bsw/jbe@0
|
47 name = "oldest",
|
|
bsw/jbe@0
|
48 label = _"Oldest",
|
|
bsw/jbe@5
|
49 order_by = "initiative.created, initiative.id"
|
|
bsw/jbe@0
|
50 }
|
|
bsw/jbe@0
|
51
|
|
bsw/jbe@0
|
52 local name = "initiative_list"
|
|
bsw/jbe@0
|
53 if issue then
|
|
bsw/jbe@0
|
54 name = "issue_" .. tostring(issue.id) .. "_initiative_list"
|
|
bsw/jbe@0
|
55 end
|
|
bsw/jbe@0
|
56
|
|
bsw@10
|
57 ui_order = ui.order
|
|
bsw@10
|
58
|
|
bsw@10
|
59 if param.get("no_sort", atom.boolean) then
|
|
bsw@10
|
60 ui_order = function(args) args.content() end
|
|
bsw@10
|
61 if issue.ranks_available then
|
|
bsw@10
|
62 initiatives_selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id")
|
|
bsw@10
|
63 else
|
|
bsw@10
|
64 initiatives_selector:add_order_by("initiative.supporter_count::float / issue.population::float DESC, initiative.id")
|
|
bsw@10
|
65 end
|
|
bsw@10
|
66 end
|
|
bsw@10
|
67
|
|
bsw@11
|
68 initiatives_selector
|
|
bsw@11
|
69 :left_join("initiator", "_initiator", { "_initiator.initiative_id = initiative.id AND _initiator.member_id = ?", app.session.member.id} )
|
|
bsw@11
|
70 :left_join("supporter", "_supporter", { "_supporter.initiative_id = initiative.id AND _supporter.member_id = ?", app.session.member.id} )
|
|
bsw@11
|
71
|
|
bsw@11
|
72 :add_field("(_initiator.member_id NOTNULL)", "is_initiator")
|
|
bsw@11
|
73 :add_field({"(_supporter.member_id NOTNULL) AND NOT EXISTS(SELECT 1 FROM opinion WHERE opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)))", app.session.member.id }, "is_supporter")
|
|
bsw@11
|
74 :add_field({"EXISTS(SELECT 1 FROM opinion WHERE opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)))", app.session.member.id }, "is_potential_supporter")
|
|
bsw@11
|
75
|
|
bsw@11
|
76
|
|
bsw@10
|
77 ui_order{
|
|
bsw/jbe@0
|
78 name = name,
|
|
bsw/jbe@0
|
79 selector = initiatives_selector,
|
|
bsw/jbe@0
|
80 options = order_options,
|
|
bsw/jbe@0
|
81 content = function()
|
|
bsw/jbe@0
|
82 ui.paginate{
|
|
bsw@11
|
83 name = issue and "issue_" .. tostring(issue.id) .. "_page" or nil,
|
|
bsw/jbe@0
|
84 selector = initiatives_selector,
|
|
bsw@10
|
85 per_page = param.get("per_page", atom.number),
|
|
bsw/jbe@0
|
86 content = function()
|
|
bsw/jbe@0
|
87 local initiatives = initiatives_selector:exec()
|
|
bsw/jbe@0
|
88 local columns = {}
|
|
bsw@2
|
89 columns[#columns+1] = {
|
|
bsw@2
|
90 content = function(record)
|
|
bsw@2
|
91 if record.issue.accepted and record.issue.closed and record.issue.ranks_available then
|
|
bsw@3
|
92 ui.field.rank{ attr = { class = "rank" }, value = record.rank }
|
|
bsw@3
|
93 end
|
|
bsw@3
|
94 end
|
|
bsw@3
|
95 }
|
|
bsw@3
|
96 columns[#columns+1] = {
|
|
bsw@3
|
97 content = function(record)
|
|
bsw/jbe@5
|
98 if record.issue.accepted and record.issue.closed then
|
|
bsw/jbe@5
|
99 if record.issue.ranks_available then
|
|
bsw/jbe@5
|
100 if record.negative_votes and record.positive_votes then
|
|
bsw/jbe@5
|
101 local max_value = record.issue.voter_count
|
|
bsw/jbe@5
|
102 ui.bargraph{
|
|
bsw/jbe@5
|
103 max_value = max_value,
|
|
bsw/jbe@5
|
104 width = 100,
|
|
bsw/jbe@5
|
105 bars = {
|
|
bsw/jbe@5
|
106 { color = "#0a0", value = record.positive_votes },
|
|
bsw/jbe@5
|
107 { color = "#aaa", value = max_value - record.negative_votes - record.positive_votes },
|
|
bsw/jbe@5
|
108 { color = "#a00", value = record.negative_votes },
|
|
bsw/jbe@5
|
109 }
|
|
bsw/jbe@0
|
110 }
|
|
bsw/jbe@5
|
111 end
|
|
bsw/jbe@5
|
112 else
|
|
bsw/jbe@5
|
113 slot.put(_"Counting of votes")
|
|
bsw/jbe@0
|
114 end
|
|
bsw@2
|
115 else
|
|
bsw/jbe@0
|
116 local max_value = (record.issue.population or 0)
|
|
bsw/jbe@0
|
117 ui.bargraph{
|
|
bsw/jbe@0
|
118 max_value = max_value,
|
|
bsw/jbe@4
|
119 width = 100,
|
|
bsw/jbe@0
|
120 bars = {
|
|
bsw@2
|
121 { color = "#0a0", value = (record.satisfied_supporter_count or 0) },
|
|
bsw/jbe@5
|
122 { color = "#777", value = (record.supporter_count or 0) - (record.satisfied_supporter_count or 0) },
|
|
bsw/jbe@0
|
123 { color = "#ddd", value = max_value - (record.supporter_count or 0) },
|
|
bsw/jbe@0
|
124 }
|
|
bsw/jbe@0
|
125 }
|
|
bsw/jbe@0
|
126 end
|
|
bsw@2
|
127 end
|
|
bsw@2
|
128 }
|
|
bsw/jbe@0
|
129 columns[#columns+1] = {
|
|
bsw/jbe@0
|
130 content = function(record)
|
|
bsw@10
|
131 local link_class
|
|
bsw@10
|
132 if record.revoked then
|
|
bsw@10
|
133 link_class = "revoked"
|
|
bsw@10
|
134 end
|
|
bsw/jbe@0
|
135 ui.link{
|
|
bsw@10
|
136 attr = { class = link_class },
|
|
bsw/jbe@0
|
137 content = function()
|
|
bsw@2
|
138 local name
|
|
bsw@2
|
139 if record.name_highlighted then
|
|
bsw@2
|
140 name = encode.highlight(record.name_highlighted)
|
|
bsw@2
|
141 else
|
|
bsw@2
|
142 name = encode.html(record.name)
|
|
bsw@2
|
143 end
|
|
bsw@2
|
144 slot.put(name)
|
|
bsw/jbe@0
|
145 end,
|
|
bsw/jbe@0
|
146 module = "initiative",
|
|
bsw/jbe@0
|
147 view = "show",
|
|
bsw/jbe@0
|
148 id = record.id
|
|
bsw/jbe@0
|
149 }
|
|
bsw@2
|
150 if record.issue.state == "new" then
|
|
bsw@2
|
151 ui.image{
|
|
bsw@2
|
152 static = "icons/16/new.png"
|
|
bsw@2
|
153 }
|
|
bsw@2
|
154 end
|
|
bsw@11
|
155 if record.is_supporter then
|
|
bsw@11
|
156 slot.put(" ")
|
|
bsw@11
|
157 local label = _"You are supporting this initiative"
|
|
bsw@11
|
158 ui.image{
|
|
bsw@11
|
159 attr = { alt = label, title = label },
|
|
bsw@11
|
160 static = "icons/16/thumb_up_green.png"
|
|
bsw@11
|
161 }
|
|
bsw@11
|
162 end
|
|
bsw@11
|
163 if record.is_potential_supporter then
|
|
bsw@11
|
164 slot.put(" ")
|
|
bsw@11
|
165 local label = _"You are potential supporter of this initiative"
|
|
bsw@11
|
166 ui.image{
|
|
bsw@11
|
167 attr = { alt = label, title = label },
|
|
bsw@11
|
168 static = "icons/16/thumb_up.png"
|
|
bsw@11
|
169 }
|
|
bsw@11
|
170 end
|
|
bsw@11
|
171 if record.is_initiator then
|
|
bsw@11
|
172 slot.put(" ")
|
|
bsw@11
|
173 local label = _"You are iniator of this initiative"
|
|
bsw@11
|
174 ui.image{
|
|
bsw@11
|
175 attr = { alt = label, title = label },
|
|
bsw@11
|
176 static = "icons/16/user_edit.png"
|
|
bsw@11
|
177 }
|
|
bsw@11
|
178 end
|
|
bsw/jbe@0
|
179 end
|
|
bsw/jbe@0
|
180 }
|
|
bsw/jbe@0
|
181
|
|
bsw/jbe@0
|
182 ui.list{
|
|
bsw/jbe@0
|
183 attr = { class = "initiatives" },
|
|
bsw/jbe@0
|
184 records = initiatives,
|
|
bsw/jbe@0
|
185 columns = columns
|
|
bsw/jbe@0
|
186 }
|
|
bsw/jbe@0
|
187 end
|
|
bsw/jbe@0
|
188 }
|
|
bsw/jbe@0
|
189 end
|
|
bsw@11
|
190 }
|
|
bsw@11
|
191
|
|
bsw@11
|
192 if more_initiatives_count then
|
|
bsw@11
|
193 ui.link{
|
|
bsw@11
|
194 attr = { style = "font-size: 75%; font-style: italic;" },
|
|
bsw@11
|
195 content = _("#{count} more initiatives", { count = more_initiatives_count }),
|
|
bsw@11
|
196 module = "issue",
|
|
bsw@11
|
197 view = "show",
|
|
bsw@11
|
198 id = issue.id,
|
|
bsw@11
|
199 }
|
|
bsw@11
|
200 end
|