liquid_feedback_frontend

view app/main/timeline/index.lua @ 11:77d58efe99fd

Version beta7

Important security fixes:
- Added missing HTML encoding to postal address of member
- Link to discussion URL only if it starts with http(s)://

Other bugfixes:
- Fixed wrong display of 2nd level delegating voters for an initiative
- Do not display invited initiators as initiators while voting
- Added missing translation

New features:
- Public message of the day
- Both direct and indirect supporter count is shown in tab heads
- Support shown in initiative lists

Language chooser at the login page has been added (again)
author bsw
date Fri Jan 22 12:00:00 2010 +0100 (2010-01-22)
parents 72c5e0ee7c98
children 00d1004545f1
line source
1 execute.view{
2 module = "timeline",
3 view = "_constants"
4 }
6 local options_box_count = param.get("options_box_count", atom.number) or 1
7 if options_box_count > 10 then
8 options_box_count = 10
9 end
11 local function format_dow(dow)
12 local dows = {
13 _"Monday",
14 _"Tuesday",
15 _"Wednesday",
16 _"Thursday",
17 _"Friday",
18 _"Saturday",
19 _"Sunday"
20 }
21 return dows[dow+1]
22 end
23 slot.put_into("title", _"Timeline")
25 slot.select("actions", function()
26 local setting_key = "liquidfeedback_frontend_timeline_current_options"
27 local setting = Setting:by_pk(app.session.member.id, setting_key)
28 local current_options = ""
29 if setting then
30 current_options = setting.value
31 end
32 local setting_maps = app.session.member:get_setting_maps_by_key("timeline_filters")
33 for i, setting_map in ipairs(setting_maps) do
34 local active
35 local options_string = setting_map.value
36 local name = setting_map.subkey
37 if options_string == current_options then
38 active = true
39 end
40 timeline_params.date = param.get("date")
41 ui.link{
42 attr = { class = active and "action_active" or nil },
43 content = function()
44 ui.image{ static = "icons/16/time.png" }
45 slot.put(encode.html(name))
46 end,
47 module = 'timeline',
48 action = 'update',
49 params = {
50 options_string = options_string
51 },
52 }
53 end
54 if #setting_maps > 0 then
55 ui.link{
56 content = function()
57 ui.image{ static = "icons/16/wrench.png" }
58 slot.put(_"Manage filter")
59 end,
60 module = "timeline",
61 view = "list_filter",
62 }
63 end
64 ui.link{
65 content = function()
66 ui.image{ static = "icons/16/bullet_disk.png" }
67 slot.put(_"Save current filter")
68 end,
69 module = "timeline",
70 view = "save_filter",
71 attr = {
72 onclick = "el=document.getElementById('timeline_save');el.checked=true;el.form.submit();return(false);"
73 }
74 }
75 end)
77 util.help("timeline.index", _"Timeline")
79 ui.form{
80 module = "timeline",
81 action = "update",
82 content = function()
85 ui.tag{
86 tag = "label",
87 attr = { style = "font-size: 130%;" },
88 content = _"Date" .. ":"
89 }
90 slot.put(" ")
91 local date = param.get("date")
92 if not date or #date == 0 then
93 date = tostring(db:query("select now()::date as date")[1].date)
94 end
95 ui.tag{
96 tag = "input",
97 attr = {
98 type = "text",
99 id = "timeline_search_date",
100 style = "width: 10em;",
101 onchange = "this.form.submit();",
102 name = "date",
103 value = date
104 },
105 content = function() end
106 }
108 ui.script{ static = "gregor.js/gregor.js" }
109 util.gregor("timeline_search_date", "document.getElementById('timeline_search_date').form.submit();")
112 ui.link{
113 attr = { style = "margin-left: 1em; font-size: 130%; font-weight: bold;", onclick = "document.getElementById('timeline_search_date').form.submit();return(false);" },
114 content = function()
115 ui.image{
116 attr = { style = "margin-right: 0.25em;" },
117 static = "icons/16/magnifier.png"
118 }
119 slot.put(_"Search")
120 end,
121 external = "#",
122 }
123 local show_options = param.get("show_options", atom.boolean)
124 ui.link{
125 attr = { style = "margin-left: 1em; font-size: 130%;", onclick = "el=document.getElementById('timeline_show_options');el.checked=" .. tostring(not show_options) .. ";el.form.submit();return(false);" },
126 content = function()
127 ui.image{
128 attr = { style = "margin-right: 0.25em;" },
129 static = "icons/16/text_list_bullets.png"
130 }
131 slot.put(not show_options and _"Show filter details" or _"Hide filter details")
132 end,
133 external = "#",
134 }
136 ui.field.boolean{
137 attr = { id = "timeline_show_options", style = "display: none;", onchange="this.form.submit();" },
138 name = "show_options",
139 value = param.get("show_options", atom.boolean)
140 }
142 ui.field.boolean{
143 attr = { id = "timeline_save", style = "display: none;", onchange="this.form.submit();" },
144 name = "save",
145 value = false
146 }
148 ui.container{
149 attr = {
150 id = "timeline_options_boxes",
151 class = "vertical",
152 style = not param.get("show_options", atom.boolean) and "display: none;" or nil
153 },
154 content = function()
156 local function option_field(event_ident, filter_ident)
157 local param_name
158 if not filter_ident then
159 param_name = "option_" .. event_ident
160 else
161 param_name = "option_" .. event_ident .. "_" .. filter_ident
162 end
163 local value = param.get(param_name, atom.boolean)
164 ui.field.boolean{
165 attr = { id = param_name },
166 name = param_name,
167 value = value,
168 }
169 end
171 local function filter_option_fields(event_ident, filter_idents)
173 for i, filter_ident in ipairs(filter_idents) do
174 slot.put("<td>")
175 option_field(event_ident, filter_ident)
176 slot.put("</td><td><div class='ui_field_label label_right'>")
177 ui.tag{
178 attr = { ["for"] = "option_" .. event_ident .. "_" .. filter_ident },
179 tag = "label",
180 content = filter_names[filter_ident]
181 }
182 slot.put("</div></td>")
183 end
185 end
187 local event_groups = {
188 {
189 title = _"Issue events",
190 event_idents = {
191 "issue_created",
192 "issue_canceled",
193 "issue_accepted",
194 "issue_half_frozen",
195 "issue_finished_without_voting",
196 "issue_voting_started",
197 "issue_finished_after_voting",
198 },
199 filter_idents = {
200 "membership",
201 "interested"
202 }
203 },
204 {
205 title = _"Initiative events",
206 event_idents = {
207 "initiative_created",
208 "initiative_revoked",
209 "draft_created",
210 "suggestion_created",
211 },
212 filter_idents = {
213 "membership",
214 "interested",
215 "supporter",
216 "potential_supporter",
217 "initiator"
218 }
219 }
220 }
222 slot.put("<br />")
224 slot.put("<table>")
226 for i_event_group, event_group in ipairs(event_groups) do
227 slot.put("<tr>")
228 slot.put("<th colspan='2'>")
229 slot.put(event_group.title)
230 slot.put("</th><th colspan='10'>")
231 slot.put(_"Show only events which match... (or associtated)")
232 slot.put("</th>")
233 slot.put("</tr>")
234 local event_idents = event_group.event_idents
235 for i, event_ident in ipairs(event_idents) do
236 slot.put("<tr><td>")
237 option_field(event_ident)
238 slot.put("</td><td><div class='ui_field_label label_right'>")
239 ui.tag{
240 attr = { ["for"] = "option_" .. event_ident },
241 tag = "label",
242 content = event_names[event_ident]
243 }
244 slot.put("</div></td>")
245 filter_option_fields(event_ident, event_group.filter_idents)
246 slot.put("</tr>")
247 end
248 end
250 slot.put("</table>")
252 end
253 }
254 end
255 }
257 local date = param.get("date")
258 if not date or #date == 0 then
259 date = "today"
260 end
262 local timeline_selector
264 for event, event_name in pairs(event_names) do
266 if param.get("option_" .. event, atom.boolean) then
268 local tmp = Timeline:new_selector()
269 :add_where{ "occurrence::date = ?", date }
271 :left_join("draft", nil, "draft.id = timeline.draft_id")
272 :left_join("suggestion", nil, "suggestion.id = timeline.suggestion_id")
273 :left_join("initiative", nil, "initiative.id = timeline.initiative_id or initiative.id = draft.initiative_id or initiative.id = suggestion.initiative_id")
274 :left_join("issue", nil, "issue.id = timeline.issue_id or issue.id = initiative.issue_id")
275 :left_join("area", nil, "area.id = issue.area_id")
277 :left_join("interest", "_interest", { "_interest.issue_id = issue.id AND _interest.member_id = ?", app.session.member.id} )
278 :left_join("membership", "_membership", { "_membership.area_id = area.id AND _membership.member_id = ?", app.session.member.id} )
279 :left_join("initiator", "_initiator", { "_initiator.initiative_id = initiative.id AND _initiator.member_id = ?", app.session.member.id} )
280 :left_join("supporter", "_supporter", { "_supporter.initiative_id = initiative.id AND _supporter.member_id = ?", app.session.member.id} )
282 :add_field("(_interest.member_id NOTNULL)", "is_interested")
283 :add_field("(_initiator.member_id NOTNULL)", "is_initiator")
284 :add_field({"(_supporter.member_id NOTNULL) AND NOT EXISTS(SELECT NULL 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)) LIMIT 1)", app.session.member.id }, "is_supporter")
285 :add_field({"EXISTS(SELECT NULL 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)) LIMIT 1)", app.session.member.id }, "is_potential_supporter")
286 -- :left_join("member", nil, "member.id = timeline.member_id")
288 tmp:add_where{ "event = ?", event }
290 local filters = {}
291 if param.get("option_" .. event .. "_membership", atom.boolean) then
292 filters[#filters+1] = "(timeline.initiative_id ISNULL AND timeline.issue_id ISNULL AND timeline.draft_id ISNULL AND timeline.suggestion_id ISNULL) OR _membership.member_id NOTNULL"
293 end
295 if param.get("option_" .. event .. "_supporter", atom.boolean) then
296 filters[#filters+1] = "(timeline.initiative_id ISNULL AND timeline.issue_id ISNULL AND timeline.draft_id ISNULL AND timeline.suggestion_id ISNULL) OR ((_supporter.member_id NOTNULL) AND NOT EXISTS(SELECT NULL 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)) LIMIT 1))"
297 end
299 if param.get("option_" .. event .. "_potential_supporter", atom.boolean) then
300 filters[#filters+1] = "(timeline.initiative_id ISNULL AND timeline.issue_id ISNULL AND timeline.draft_id ISNULL AND timeline.suggestion_id ISNULL) OR ((_supporter.member_id NOTNULL) AND EXISTS(SELECT NULL 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)) LIMIT 1))"
301 end
303 if param.get("option_" .. event .. "_interested", atom.boolean) then
304 filters[#filters+1] = "(timeline.initiative_id ISNULL AND timeline.issue_id ISNULL AND timeline.draft_id ISNULL AND timeline.suggestion_id ISNULL) OR _interest.member_id NOTNULL"
305 end
307 if param.get("option_" .. event .. "_initiator", atom.boolean) then
308 filters[#filters+1] = "(timeline.initiative_id ISNULL AND timeline.issue_id ISNULL AND timeline.draft_id ISNULL AND timeline.suggestion_id ISNULL) OR _initiator.member_id NOTNULL"
309 end
311 if #filters > 0 then
312 local filter_string = "(" .. table.concat(filters, ") OR (") .. ")"
313 tmp:add_where{ filter_string, app.session.member.id }
314 end
316 if not timeline_selector then
317 timeline_selector = tmp
318 else
319 timeline_selector:union_all(tmp)
320 end
321 end
322 end
324 if timeline_selector then
326 local initiatives_per_page = param.get("initiatives_per_page", atom.number)
328 local outer_timeline_selector = db:new_selector()
329 outer_timeline_selector._class = Timeline
330 outer_timeline_selector:add_field{ "timeline.*" }
331 outer_timeline_selector:from({"($)", { timeline_selector }}, "timeline" )
332 outer_timeline_selector:add_order_by("occurrence DESC")
334 slot.put("<br />")
335 execute.view{
336 module = "timeline",
337 view = "_list",
338 params = {
339 timeline_selector = outer_timeline_selector,
340 per_page = param.get("per_page", atom.number),
341 event_names = event_names,
342 initiatives_per_page = initiatives_per_page
343 }
344 }
346 else
348 slot.put(_"No events selected to list")
350 end

Impressum / About Us