liquid_feedback_frontend

view app/main/suggestion/_list_element.lua @ 959:1d9e48ecd254

Ordering of suggestions by harmonic weight
author bsw
date Sat Feb 02 22:16:10 2013 +0100 (2013-02-02)
parents cc64a4fc6ab6
children f03fbffc1800
line source
2 local initiative = param.get("initiative", "table")
3 local suggestions_selector = param.get("suggestions_selector", "table")
5 suggestions_selector:add_order_by("plus2_unfulfilled_count + plus1_unfulfilled_count DESC, id")
7 local tab_id = param.get("tab_id")
8 local show_name = param.get("show_name", atom.boolean)
9 if show_name == nil then
10 show_name = true
11 end
12 local show_filter = param.get("show_filter", atom.boolean)
13 if show_filter == nil then
14 show_filter = true
15 end
17 local partial = {
18 routing = {
19 default = {
20 mode = "redirect",
21 module = "initiative",
22 view = "show_tab",
23 params = {
24 initiative_id = initiative.id,
25 tab = "suggestions",
26 tab_id = tab_id
27 },
28 }
29 }
30 }
32 local ui_filters = ui.filters
33 if true or not show_filter then
34 ui_filters = function(args) args.content() end
35 end
37 ui.container{ attr = { class = "box" },
38 content = function()
39 ui.paginate{
40 selector = suggestions_selector,
41 content = function()
42 ui.list{
43 attr = { style = "table-layout: fixed;" },
44 records = suggestions_selector:exec(),
45 columns = {
46 {
47 label = show_name and _"Suggestion" or nil,
48 content = function(record)
49 if show_name then
50 ui.link{
51 text = record.name,
52 module = "suggestion",
53 view = "show",
54 id = record.id
55 }
56 end
57 end
58 },
59 {
60 label = _"Collective opinion of supporters",
61 label_attr = { style = "width: 101px;" },
62 content = function(record)
63 if record.minus2_unfulfilled_count then
64 local max_value = record.initiative.supporter_count
65 ui.bargraph{
66 max_value = max_value,
67 width = 100,
68 bars = {
69 { color = "#0a0", value = record.plus2_unfulfilled_count + record.plus2_fulfilled_count },
70 { color = "#8f8", value = record.plus1_unfulfilled_count + record.plus1_fulfilled_count },
71 { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count},
72 { color = "#f88", value = record.minus1_unfulfilled_count + record.minus1_fulfilled_count },
73 { color = "#a00", value = record.minus2_unfulfilled_count + record.minus2_fulfilled_count },
74 }
75 }
76 end
77 end
78 },
79 {
80 label = _"My opinion",
81 label_attr = { style = "width: 130px; font-style: italic;" },
82 content = function(record)
83 local degree
84 local opinion
85 if app.session.member_id then
86 opinion = Opinion:by_pk(app.session.member.id, record.id)
87 end
88 if opinion then
89 degree = opinion.degree
90 end
91 ui.container{
92 attr = { class = "suggestion_my_opinion" },
93 content = function()
94 local has_voting_right = app.session.member and app.session.member:has_voting_right_for_unit_id(initiative.issue.area.unit_id)
95 if app.session.member_id and has_voting_right then
96 if initiative.issue.state == "voting" or initiative.issue.state == "closed" then
97 if degree == -2 then
98 ui.tag{
99 tag = "span",
100 attr = {
101 class = "action" .. (degree == -2 and " active_red2" or "")
102 },
103 content = _"must not"
104 }
105 end
106 if degree == -1 then
107 ui.tag{
108 tag = "span",
109 attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
110 content = _"should not"
111 }
112 end
113 if degree == nil then
114 ui.tag{
115 tag = "span",
116 attr = { class = "action" .. (degree == nil and " active" or "") },
117 content = _"neutral"
118 }
119 end
120 if degree == 1 then
121 ui.tag{
122 tag = "span",
123 attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
124 content = _"should"
125 }
126 end
127 if degree == 2 then
128 ui.tag{
129 tag = "span",
130 attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
131 content = _"must"
132 }
133 end
134 else
135 -- we need to put initiative_id into the parameters to have a redirect target in case the suggestion is gone after the action
136 params = param.get_all_cgi()
137 params['initiative_id'] = initiative.id
139 ui.link{
140 attr = { class = "action" .. (degree == 2 and " active_green2" or "") },
141 text = _"must",
142 module = "opinion",
143 action = "update",
144 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
145 params = {
146 suggestion_id = record.id,
147 degree = 2
148 },
149 partial = partial
150 }
151 slot.put(" ")
152 ui.link{
153 attr = { class = "action" .. (degree == 1 and " active_green1" or "") },
154 text = _"should",
155 module = "opinion",
156 action = "update",
157 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params} },
158 params = {
159 suggestion_id = record.id,
160 degree = 1
161 },
162 partial = partial
163 }
164 slot.put(" ")
165 ui.link{
166 attr = { class = "action" .. (degree == nil and " active" or "") },
167 text = _"neutral",
168 module = "opinion",
169 action = "update",
170 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
171 params = {
172 suggestion_id = record.id,
173 delete = true
174 },
175 partial = partial
176 }
177 slot.put(" ")
178 ui.link{
179 attr = { class = "action" .. (degree == -1 and " active_red1" or "") },
180 text = _"should not",
181 module = "opinion",
182 action = "update",
183 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
184 params = {
185 suggestion_id = record.id,
186 degree = -1
187 },
188 partial = partial
189 }
190 slot.put(" ")
191 ui.link{
192 attr = { class = "action" .. (degree == -2 and " active_red2" or "") },
193 text = _"must not",
194 module = "opinion",
195 action = "update",
196 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = params } },
197 params = {
198 suggestion_id = record.id,
199 degree = -2
200 },
201 partial = partial
202 }
203 end
204 elseif app.session.member_id then
205 ui.field.text{ value = _"[No voting privilege]" }
206 else
207 ui.field.text{ value = _"[Registered members only]" }
208 end
209 end
210 }
211 end
212 },
213 {
214 label = _"Suggestion currently not implemented",
215 label_attr = { style = "width: 101px;" },
216 content = function(record)
217 if record.minus2_unfulfilled_count then
218 local max_value = record.initiative.supporter_count
219 ui.bargraph{
220 max_value = max_value,
221 width = 100,
222 bars = {
223 { color = "#0a0", value = record.plus2_unfulfilled_count },
224 { color = "#8f8", value = record.plus1_unfulfilled_count },
225 { color = "#eee", value = max_value - record.minus2_unfulfilled_count - record.minus1_unfulfilled_count - record.plus1_unfulfilled_count - record.plus2_unfulfilled_count },
226 { color = "#f88", value = record.minus1_unfulfilled_count },
227 { color = "#a00", value = record.minus2_unfulfilled_count },
228 }
229 }
230 end
231 end
232 },
233 {
234 label = _"Suggestion currently implemented",
235 label_attr = { style = "width: 101px;" },
236 content = function(record)
237 if record.minus2_fulfilled_count then
238 local max_value = record.initiative.supporter_count
239 ui.bargraph{
240 max_value = max_value,
241 width = 100,
242 bars = {
243 { color = "#0a0", value = record.plus2_fulfilled_count },
244 { color = "#8f8", value = record.plus1_fulfilled_count },
245 { color = "#eee", value = max_value - record.minus2_fulfilled_count - record.minus1_fulfilled_count - record.plus1_fulfilled_count - record.plus2_fulfilled_count},
246 { color = "#f88", value = record.minus1_fulfilled_count },
247 { color = "#a00", value = record.minus2_fulfilled_count },
248 }
249 }
250 end
251 end
252 },
253 {
254 label = app.session.member_id and _"I consider suggestion as" or nil,
255 label_attr = { style = "width: 100px; font-style: italic;" },
256 content = function(record)
257 local degree
258 local opinion
259 if app.session.member_id then
260 opinion = Opinion:by_pk(app.session.member.id, record.id)
261 end
262 if opinion then
263 degree = opinion.degree
264 end
265 if opinion then
267 ui.link{
268 attr = { class = opinion.fulfilled and "action active" or "action" },
269 text = _"implemented",
270 module = "opinion",
271 action = "update",
272 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
273 params = {
274 suggestion_id = record.id,
275 fulfilled = true
276 },
277 partial = partial
278 }
279 slot.put("<br />")
280 ui.link{
281 attr = { class = not opinion.fulfilled and "action active" or "action" },
282 text = _"not implemented",
283 module = "opinion",
284 action = "update",
285 routing = { default = { mode = "redirect", module = request.get_module(), view = request.get_view(), id = param.get_id_cgi(), params = param.get_all_cgi() } },
286 params = {
287 suggestion_id = record.id,
288 fulfilled = false
289 },
290 partial = partial
291 }
293 end
294 end
295 },
296 {
297 label = app.session.member_id and _"So I'm" or nil,
298 content = function(record)
299 local opinion
300 if app.session.member_id then
301 opinion = Opinion:by_pk(app.session.member.id, record.id)
302 end
303 if opinion then
304 if (opinion.fulfilled and opinion.degree > 0) or (not opinion.fulfilled and opinion.degree < 0) then
305 local title = _"satisfied"
306 ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_happy.png" }
307 elseif opinion.degree == 1 or opinion.degree == -1 then
308 local title = _"a bit unsatisfied"
309 ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy.png" }
310 else
311 local title = _"more unsatisfied"
312 ui.image{ attr = { alt = title, title = title }, static = "icons/emoticon_unhappy_red.png" }
313 end
314 end
315 end
316 },
317 }
318 }
319 end
320 }
321 end
322 }

Impressum / About Us