liquid_feedback_frontend

annotate app/main/timeline/_action/update.lua @ 144:7c3e8a1678fc

fix timeline saved filters

add Members:set_setting_map code
check for empty name
update settings when saved under same name
fixes bug #305
author Daniel Poelzleithner <poelzi@poelzi.org>
date Wed Oct 06 18:15:23 2010 +0200 (2010-10-06)
parents 00d1004545f1
children 90520c9fca44
rev   line source
bsw@11 1 execute.view{
bsw@11 2 module = "timeline",
bsw@11 3 view = "_constants"
bsw@11 4 }
bsw@11 5
bsw@11 6 local options_string = param.get("options_string")
bsw@11 7
bsw@11 8 if not options_string then
bsw@11 9 local active_options = ""
bsw@11 10 for event_ident, event_name in pairs(event_names) do
bsw@11 11 if param.get("option_" .. event_ident, atom.boolean) then
bsw@11 12 active_options = active_options .. event_ident .. ":"
bsw@11 13 local filter_idents = {}
bsw@11 14 for filter_ident, filter_name in pairs(filter_names) do
bsw@11 15 if param.get("option_" .. event_ident .. "_" .. filter_ident, atom.boolean) then
bsw@11 16 filter_idents[#filter_idents+1] = filter_ident
bsw@11 17 end
bsw@11 18 end
bsw@11 19 if #filter_idents > 0 then
bsw@11 20 active_options = active_options .. table.concat(filter_idents, "|") .. " "
bsw@11 21 else
bsw@11 22 active_options = active_options .. "* "
bsw@11 23 end
bsw@11 24 end
bsw@11 25 end
bsw@11 26 if #active_options > 0 then
bsw@11 27 options_string = active_options
bsw@11 28 end
bsw@11 29 end
bsw@11 30
bsw@11 31 if not options_string then
bsw@11 32 options_string = "issue_created:* issue_finished_after_voting:* issue_accepted:* issue_voting_started:* suggestion_created:* issue_canceled:* initiative_created:* issue_finished_without_voting:* draft_created:* initiative_revoked:* issue_half_frozen:* "
bsw@11 33 end
bsw@11 34
bsw@11 35 local setting_key = "liquidfeedback_frontend_timeline_current_options"
bsw@11 36 local setting = Setting:by_pk(app.session.member.id, setting_key)
bsw@11 37
bsw@11 38 if not setting or setting.value ~= options_string then
bsw@11 39 if not setting then
bsw@11 40 setting = Setting:new()
bsw@11 41 setting.member_id = app.session.member_id
bsw@11 42 setting.key = setting_key
bsw@11 43 end
bsw@11 44 if options_string then
bsw@11 45 setting.value = options_string
bsw@11 46 setting:save()
bsw@11 47 end
bsw@11 48 end
bsw@11 49
bsw@11 50 local date = param.get("date")
bsw/jbe@19 51
bsw/jbe@19 52 if param.get("search_from") == "last_24h" then
bsw/jbe@19 53 date = "last_24h"
bsw/jbe@19 54 end
bsw@11 55
bsw@11 56 if date and #date > 0 then
bsw@11 57 local setting_key = "liquidfeedback_frontend_timeline_current_date"
bsw@11 58 local setting = Setting:by_pk(app.session.member.id, setting_key)
bsw@11 59 if not setting or setting.value ~= date then
bsw@11 60 if not setting then
bsw@11 61 setting = Setting:new()
bsw@11 62 setting.member_id = app.session.member.id
bsw@11 63 setting.key = setting_key
bsw@11 64 end
bsw@11 65 setting.value = date
bsw@11 66 setting:save()
bsw@11 67 end
bsw@11 68 end
bsw@11 69
bsw@11 70 local setting_key = "liquidfeedback_frontend_timeline_current_options"
bsw@11 71 local setting = Setting:by_pk(app.session.member.id, setting_key)
bsw@11 72
bsw@11 73 local timeline_params = {}
bsw@11 74 if setting and setting.value then
bsw@11 75 for event_ident, filter_idents in setting.value:gmatch("(%S+):(%S+)") do
bsw@11 76 timeline_params["option_" .. event_ident] = true
bsw@11 77 if filter_idents ~= "*" then
bsw@11 78 for filter_ident in filter_idents:gmatch("([^\|]+)") do
bsw@11 79 timeline_params["option_" .. event_ident .. "_" .. filter_ident] = true
bsw@11 80 end
bsw@11 81 end
bsw@11 82 end
bsw@11 83 end
bsw@11 84
bsw@11 85 local setting_key = "liquidfeedback_frontend_timeline_current_date"
bsw@11 86 local setting = Setting:by_pk(app.session.member.id, setting_key)
bsw@11 87
bsw@11 88 if setting then
bsw@11 89 timeline_params.date = setting.value
bsw@11 90 end
bsw@11 91
bsw@11 92 timeline_params.show_options = param.get("show_options", atom.boolean)
bsw@11 93
bsw@11 94 if param.get("save", atom.boolean) then
bsw@11 95 request.redirect{
bsw@11 96 module = "timeline",
poelzi@144 97 view = "save_filter",
poelzi@144 98 params = {
poelzi@144 99 current_name = param.get("current_name")
poelzi@144 100 }
bsw@11 101 }
bsw@11 102 else
bsw@11 103 request.redirect{
bsw@11 104 module = "timeline",
bsw@11 105 view = "index",
bsw@11 106 params = timeline_params
bsw@11 107 }
bsw@11 108 end

Impressum / About Us