liquid_feedback_frontend

annotate app/main/event/_list.lua @ 702:0874cecb8261

Optical improvements
author bsw
date Tue Jun 26 19:44:26 2012 +0200 (2012-06-26)
parents fe76cc06e6cf
children 0daedb7c1c11
rev   line source
bsw@414 1 local global = param.get("global", atom.boolean)
bsw@414 2 local for_member = param.get("for_member", "table")
bsw@414 3 local for_unit = param.get("for_unit", "table")
bsw@414 4 local for_area = param.get("for_area", "table")
bsw@422 5 local event_max_id = param.get_all_cgi()["event_max_id"]
bsw@414 6 local event_selector = Event:new_selector()
bsw@414 7 :add_order_by("event.id DESC")
bsw@414 8 :limit(25)
bsw@414 9 :join("issue", nil, "issue.id = event.issue_id")
bsw@437 10 :add_field("now()::date - event.occurrence::date", "time_ago")
bsw@437 11
bsw@422 12 if event_max_id then
bsw@422 13 event_selector:add_where{ "event.id < ?", event_max_id }
bsw@422 14 end
bsw@422 15
bsw@414 16 if for_member then
bsw@414 17 event_selector:add_where{ "event.member_id = ?", for_member.id }
bsw@414 18 elseif for_unit then
bsw@414 19 event_selector:join("area", nil, "area.id = issue.area_id")
bsw@414 20 event_selector:add_where{ "area.unit_id = ?", for_unit.id }
bsw@414 21 elseif for_area then
bsw@414 22 event_selector:add_where{ "issue.area_id = ?", for_area.id }
bsw@414 23 elseif not global then
bsw@414 24 event_selector:join("event_seen_by_member", nil, { "event_seen_by_member.id = event.id AND event_seen_by_member.seen_by_member_id = ?", app.session.member_id })
bsw@414 25 end
bsw@414 26
bsw@414 27 if app.session.member_id then
bsw@414 28 event_selector
bsw@414 29 :left_join("interest", "_interest", { "_interest.issue_id = issue.id AND _interest.member_id = ?", app.session.member.id } )
bsw@414 30 :add_field("(_interest.member_id NOTNULL)", "is_interested")
bsw@414 31 :left_join("delegating_interest_snapshot", "_delegating_interest", { "_delegating_interest.issue_id = issue.id AND _delegating_interest.member_id = ? AND _delegating_interest.event = issue.latest_snapshot_event", app.session.member.id } )
bsw@414 32 :add_field("_delegating_interest.delegate_member_ids[1]", "is_interested_by_delegation_to_member_id")
bsw@414 33 :add_field("_delegating_interest.delegate_member_ids[array_upper(_delegating_interest.delegate_member_ids, 1)]", "is_interested_via_member_id")
bsw@414 34 :add_field("array_length(_delegating_interest.delegate_member_ids, 1)", "delegation_chain_length")
bsw@414 35 end
bsw@414 36
bsw@422 37 local last_event_id
bsw@414 38
bsw@596 39 local events = event_selector:exec()
bsw@596 40
bsw@422 41 ui.container{ attr = { class = "issues events" }, content = function()
bsw@414 42
bsw@422 43 local last_event_date
bsw@596 44 for i, event in ipairs(events) do
bsw@422 45 last_event_id = event.id
bsw@553 46 event.issue:load_everything_for_member_id(app.session.member_id)
bsw@414 47
bsw@676 48 ui.container{ attr = { class = "event_info" }, content = function()
bsw@619 49 local event_name = event.event_name
bsw@619 50 local event_image
bsw@619 51 if event.event == "issue_state_changed" then
bsw@619 52 if event.state == "discussion" then
bsw@619 53 event_name = _"Discussion started"
bsw@619 54 event_image = "comments.png"
bsw@619 55 elseif event.state == "verification" then
bsw@619 56 event_name = _"Verification started"
bsw@619 57 event_image = "lock.png"
bsw@619 58 elseif event.state == "voting" then
bsw@619 59 event_name = _"Voting started"
bsw@619 60 event_image = "email_open.png"
bsw@696 61 elseif event.state == "finished_with_winner" then
bsw@696 62 event_name = event.state_name
bsw@696 63 event_image = "award_star_gold_2.png"
bsw@696 64 elseif event.state == "finished_without_winner" then
bsw@696 65 event_name = event.state_name
bsw@696 66 event_image = "cross.png"
bsw@619 67 else
bsw@619 68 event_name = event.state_name
bsw@619 69 end
bsw@619 70 if event_image then
bsw@619 71 ui.image{ static = "icons/16/" .. event_image }
bsw@619 72 slot.put(" ")
bsw@619 73 end
bsw@619 74 end
bsw@619 75 local days_ago_text
bsw@619 76 if event.time_ago == 0 then
bsw@619 77 days_ago_text = _("Today at #{time}", { time = format.time(event.occurrence) })
bsw@619 78 elseif event.time_ago == 1 then
bsw@619 79 days_ago_text = _("Yesterday at #{time}", { time = format.time(event.occurrence) })
bsw@619 80 else
bsw@619 81 days_ago_text = _("#{date} at #{time}", { date = format.date(event.occurrence.date), time = format.time(event.occurrence) })
bsw@619 82 end
bsw@619 83 ui.tag{ attr = { class = "event_name" }, content = event_name }
bsw@686 84 slot.put("<br />")
bsw@619 85 ui.tag{ content = days_ago_text }
bsw@688 86 --[[ if event.time_ago > 1 then
bsw@686 87 slot.put("<br />(")
bsw@619 88 ui.tag{ content = _("#{count} days ago", { count = event.time_ago }) }
bsw@619 89 slot.put(")")
bsw@619 90 end
bsw@688 91 --]]
bsw@688 92 if (app.session.member_id or config.public_access == "pseudonym") and event.member_id then
bsw@688 93 slot.put("<br />")
bsw@688 94 slot.put("<br />")
bsw@688 95 if app.session.member_id then
bsw@688 96 ui.link{
bsw@688 97 content = function()
bsw@688 98 execute.view{
bsw@688 99 module = "member_image",
bsw@688 100 view = "_show",
bsw@688 101 params = {
bsw@688 102 member = event.member,
bsw@688 103 image_type = "avatar",
bsw@688 104 show_dummy = true,
bsw@688 105 class = "micro_avatar",
bsw@688 106 popup_text = text
bsw@688 107 }
bsw@688 108 }
bsw@688 109 end,
bsw@688 110 module = "member", view = "show", id = event.member_id
bsw@688 111 }
bsw@688 112 slot.put(" ")
bsw@688 113 end
bsw@688 114 ui.link{
bsw@688 115 text = event.member.name,
bsw@688 116 module = "member", view = "show", id = event.member_id
bsw@688 117 }
bsw@688 118 end
bsw@619 119 end }
bsw@525 120
bsw@635 121 ui.container{ attr = { class = "issue" }, content = function()
bsw@635 122
bsw@635 123 execute.view{ module = "delegation", view = "_info", params = { issue = event.issue } }
bsw@414 124
bsw@635 125 ui.container{ attr = { class = "content" }, content = function()
bsw@678 126 ui.link{
bsw@678 127 module = "unit", view = "show", id = event.issue.area.unit_id,
bsw@678 128 attr = { class = "unit_link" }, text = event.issue.area.unit.name
bsw@678 129 }
bsw@678 130 slot.put(" ")
bsw@678 131 ui.link{
bsw@678 132 module = "area", view = "show", id = event.issue.area_id,
bsw@678 133 attr = { class = "area_link" }, text = event.issue.area.name
bsw@678 134 }
bsw@422 135 end }
bsw@422 136
bsw@635 137 ui.container{ attr = { class = "title" }, content = function()
bsw@635 138 ui.link{
bsw@635 139 attr = { class = "issue_id" },
bsw@635 140 text = _("#{policy} ##{id}", { policy = event.issue.policy.name, id = event.issue_id }),
bsw@635 141 module = "issue",
bsw@635 142 view = "show",
bsw@635 143 id = event.issue_id
bsw@635 144 }
bsw@635 145 end }
bsw@635 146
bsw@422 147 if event.suggestion_id then
bsw@422 148 ui.container{ attr = { class = "suggestion" }, content = function()
bsw@422 149 ui.link{
bsw@422 150 text = event.suggestion.name,
bsw@422 151 module = "suggestion", view = "show", id = event.suggestion_id
bsw@422 152 }
bsw@422 153 end }
bsw@422 154 end
bsw@422 155
bsw@422 156 ui.container{ attr = { class = "initiative_list" }, content = function()
bsw@422 157 if not event.initiative_id then
bsw@422 158 local initiatives_selector = Initiative:new_selector()
bsw@422 159 :add_where{ "initiative.issue_id = ?", event.issue_id }
bsw@509 160 :add_order_by("initiative.rank, initiative.supporter_count DESC")
bsw@422 161 execute.view{ module = "initiative", view = "_list", params = {
bsw@422 162 issue = event.issue,
bsw@422 163 initiatives_selector = initiatives_selector,
bsw@422 164 no_sort = true,
bsw@422 165 limit = 3
bsw@422 166 } }
bsw@422 167 else
bsw@422 168 local initiatives_selector = Initiative:new_selector()
bsw@422 169 :add_where{ "initiative.id = ?", event.initiative_id }
bsw@422 170 execute.view{ module = "initiative", view = "_list", params = {
bsw@422 171 issue = event.issue,
bsw@422 172 initiatives_selector = initiatives_selector,
bsw@422 173 no_sort = true,
bsw@422 174 limit = 1
bsw@422 175 } }
bsw@414 176 end
bsw@414 177 end }
bsw@414 178
bsw@422 179 --[[
bsw@422 180 if event.initiative_id then
bsw@422 181 ui.container{ attr = { class = "initiative_id" }, content = event.initiative_id }
bsw@422 182 end
bsw@422 183 if event.draft_id then
bsw@422 184 ui.container{ attr = { class = "draft_id" }, content = event.draft_id }
bsw@422 185 end
bsw@422 186 if event.suggestion_id then
bsw@422 187 ui.container{ attr = { class = "suggestion_id" }, content = event.suggestion_id }
bsw@422 188 end
bsw@422 189 --]]
bsw@422 190
bsw@422 191 end }
bsw@422 192 end
bsw@414 193
bsw@422 194 end }
bsw@422 195
bsw@596 196 slot.put("<br />")
bsw@596 197
bsw@596 198 if #events > 0 then
bsw@596 199 ui.link{
bsw@596 200 text = _"Show older events",
bsw@596 201 module = request.get_module(),
bsw@596 202 view = request.get_view(),
bsw@596 203 id = param.get_id(),
bsw@596 204 params = {
bsw@596 205 tab = param.get_all_cgi()["tab"],
bsw@596 206 events = param.get_all_cgi()["events"],
bsw@596 207 event_max_id = last_event_id
bsw@596 208 }
bsw@422 209 }
bsw@596 210 else
bsw@596 211 ui.tag{ content = _"No more events available" }
bsw@596 212 end
bsw@456 213
bsw@456 214 slot.put("<br />")
bsw@456 215 slot.put("<br />")

Impressum / About Us