| 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@422
 | 
    39 ui.container{ attr = { class = "issues events" }, content = function()
 | 
| 
bsw@414
 | 
    40 
 | 
| 
bsw@422
 | 
    41   local last_event_date
 | 
| 
bsw@422
 | 
    42   for i, event in ipairs(event_selector:exec()) do
 | 
| 
bsw@422
 | 
    43     last_event_id = event.id
 | 
| 
bsw@414
 | 
    44 
 | 
| 
bsw@422
 | 
    45     if event.occurrence.date ~= last_event_date then
 | 
| 
bsw@437
 | 
    46       local days_ago_text
 | 
| 
bsw@437
 | 
    47       if event.time_ago == 0 then
 | 
| 
bsw@437
 | 
    48         days_ago_text = _"Today"
 | 
| 
bsw@437
 | 
    49       elseif event.time_ago == 1 then
 | 
| 
bsw@437
 | 
    50         days_ago_text = _"Yesterday"
 | 
| 
bsw@437
 | 
    51       else
 | 
| 
bsw@437
 | 
    52         days_ago_text = _("#{count} days ago", { count = event.time_ago })
 | 
| 
bsw@437
 | 
    53       end
 | 
| 
bsw@437
 | 
    54       ui.container{ attr = { class = "date" }, content = function()
 | 
| 
bsw@437
 | 
    55         ui.tag{ content = format.date(event.occurrence.date) }
 | 
| 
bsw@437
 | 
    56         slot.put(" · ")
 | 
| 
bsw@437
 | 
    57         ui.tag{ content = days_ago_text }
 | 
| 
bsw@437
 | 
    58       end }
 | 
| 
bsw@437
 | 
    59       
 | 
| 
bsw@422
 | 
    60       last_event_date = event.occurrence.date
 | 
| 
bsw@422
 | 
    61     end
 | 
| 
bsw@422
 | 
    62     local class = "issue"
 | 
| 
bsw@422
 | 
    63     if event.is_interested then
 | 
| 
bsw@422
 | 
    64       class = class .. " interested"
 | 
| 
bsw@422
 | 
    65     elseif event.is_interested_by_delegation_to_member_id then
 | 
| 
bsw@422
 | 
    66       class = class .. " interested_by_delegation"
 | 
| 
bsw@422
 | 
    67     end
 | 
| 
bsw@422
 | 
    68     ui.container{ attr = { class = class }, content = function()
 | 
| 
bsw@414
 | 
    69 
 | 
| 
bsw@422
 | 
    70       ui.container { attr = { class = "issue_info" }, content = function()
 | 
| 
bsw@422
 | 
    71       
 | 
| 
bsw@422
 | 
    72         ui.container{ content = function()
 | 
| 
bsw@422
 | 
    73           ui.link{
 | 
| 
bsw@422
 | 
    74             attr = { class = "issue_id" },
 | 
| 
bsw@422
 | 
    75             text = _("Issue ##{id}", { id = tostring(event.issue_id) }),
 | 
| 
bsw@422
 | 
    76             module = "issue",
 | 
| 
bsw@422
 | 
    77             view = "show",
 | 
| 
bsw@422
 | 
    78             id = event.issue_id
 | 
| 
bsw@422
 | 
    79           }
 | 
| 
bsw@414
 | 
    80 
 | 
| 
bsw@422
 | 
    81           slot.put(" · ")
 | 
| 
bsw@471
 | 
    82           ui.tag{ content = event.issue.policy.name }
 | 
| 
bsw@471
 | 
    83           slot.put(" · ")
 | 
| 
bsw@422
 | 
    84           ui.tag{ content = event.issue.area.name }
 | 
| 
bsw@422
 | 
    85           slot.put(" · ")
 | 
| 
bsw@422
 | 
    86           ui.tag{ content = event.issue.area.unit.name }
 | 
| 
bsw@414
 | 
    87         end }
 | 
| 
bsw@414
 | 
    88 
 | 
| 
bsw@422
 | 
    89         ui.container{ attr = { class = "issue_policy_info" }, content = function()
 | 
| 
bsw@456
 | 
    90           if (app.session.member_id or config.public_access == "pseudonym") and event.member_id then
 | 
| 
bsw@456
 | 
    91             if app.session.member_id then
 | 
| 
bsw@456
 | 
    92               ui.link{
 | 
| 
bsw@456
 | 
    93                 content = function()
 | 
| 
bsw@456
 | 
    94                   execute.view{
 | 
| 
bsw@456
 | 
    95                     module = "member_image",
 | 
| 
bsw@456
 | 
    96                     view = "_show",
 | 
| 
bsw@456
 | 
    97                     params = {
 | 
| 
bsw@456
 | 
    98                       member = event.member,
 | 
| 
bsw@456
 | 
    99                       image_type = "avatar",
 | 
| 
bsw@456
 | 
   100                       show_dummy = true,
 | 
| 
bsw@456
 | 
   101                       class = "micro_avatar",
 | 
| 
bsw@456
 | 
   102                       popup_text = text
 | 
| 
bsw@456
 | 
   103                     }
 | 
| 
bsw@422
 | 
   104                   }
 | 
| 
bsw@456
 | 
   105                 end,
 | 
| 
bsw@456
 | 
   106                 module = "member", view = "show", id = event.member_id
 | 
| 
bsw@456
 | 
   107               }
 | 
| 
bsw@456
 | 
   108               slot.put(" ")
 | 
| 
bsw@456
 | 
   109             end
 | 
| 
bsw@422
 | 
   110             ui.link{
 | 
| 
bsw@422
 | 
   111               text = event.member.name,
 | 
| 
bsw@422
 | 
   112               module = "member", view = "show", id = event.member_id
 | 
| 
bsw@422
 | 
   113             }
 | 
| 
bsw@422
 | 
   114             slot.put(" · ") 
 | 
| 
bsw@422
 | 
   115           end
 | 
| 
bsw@422
 | 
   116           local event_name = event.event_name
 | 
| 
bsw@422
 | 
   117           local event_image
 | 
| 
bsw@422
 | 
   118           if event.event == "issue_state_changed" then
 | 
| 
bsw@422
 | 
   119             if event.state == "discussion" then
 | 
| 
bsw@422
 | 
   120               event_name = _"Discussion started"
 | 
| 
bsw@422
 | 
   121               event_image = "comments.png"
 | 
| 
bsw@422
 | 
   122             elseif event.state == "verification" then
 | 
| 
bsw@422
 | 
   123               event_name = _"Verification started"
 | 
| 
bsw@422
 | 
   124               event_image = "lock.png"
 | 
| 
bsw@422
 | 
   125             elseif event.state == "voting" then
 | 
| 
bsw@422
 | 
   126               event_name = _"Voting started"
 | 
| 
bsw@422
 | 
   127               event_image = "email_open.png"
 | 
| 
bsw@422
 | 
   128             else
 | 
| 
bsw@422
 | 
   129               event_name = event.state_name
 | 
| 
bsw@422
 | 
   130             end
 | 
| 
bsw@422
 | 
   131             if event_image then
 | 
| 
bsw@422
 | 
   132               ui.image{ static = "icons/16/" .. event_image }
 | 
| 
bsw@422
 | 
   133               slot.put(" ")
 | 
| 
bsw@422
 | 
   134             end
 | 
| 
bsw@422
 | 
   135           end
 | 
| 
bsw@422
 | 
   136           ui.tag{ attr = { class = "event_name" }, content = event_name }
 | 
| 
bsw@422
 | 
   137           slot.put(" · ") 
 | 
| 
bsw@422
 | 
   138           ui.tag{ attr = { class = "time" }, content = format.time(event.occurrence) }
 | 
| 
bsw@422
 | 
   139         end }
 | 
| 
bsw@422
 | 
   140 
 | 
| 
bsw@422
 | 
   141       end }
 | 
| 
bsw@422
 | 
   142       
 | 
| 
bsw@422
 | 
   143       if event.suggestion_id then
 | 
| 
bsw@422
 | 
   144         ui.container{ attr = { class = "suggestion" }, content = function()
 | 
| 
bsw@422
 | 
   145           ui.link{
 | 
| 
bsw@422
 | 
   146             text = event.suggestion.name,
 | 
| 
bsw@422
 | 
   147             module = "suggestion", view = "show", id = event.suggestion_id
 | 
| 
bsw@422
 | 
   148           }
 | 
| 
bsw@422
 | 
   149         end }   
 | 
| 
bsw@422
 | 
   150       end
 | 
| 
bsw@422
 | 
   151 
 | 
| 
bsw@422
 | 
   152       ui.container{ attr = { class = "initiative_list" }, content = function()
 | 
| 
bsw@422
 | 
   153         if not event.initiative_id then
 | 
| 
bsw@422
 | 
   154           local initiatives_selector = Initiative:new_selector()
 | 
| 
bsw@422
 | 
   155             :add_where{ "initiative.issue_id = ?", event.issue_id }
 | 
| 
bsw@422
 | 
   156             :add_order_by("initiative.rank, initiative.supporter_count")
 | 
| 
bsw@422
 | 
   157           execute.view{ module = "initiative", view = "_list", params = { 
 | 
| 
bsw@422
 | 
   158             issue = event.issue,
 | 
| 
bsw@422
 | 
   159             initiatives_selector = initiatives_selector,
 | 
| 
bsw@422
 | 
   160             no_sort = true,
 | 
| 
bsw@422
 | 
   161             limit = 3
 | 
| 
bsw@422
 | 
   162           } }
 | 
| 
bsw@422
 | 
   163         else
 | 
| 
bsw@422
 | 
   164         local initiatives_selector = Initiative:new_selector()
 | 
| 
bsw@422
 | 
   165           :add_where{ "initiative.id = ?", event.initiative_id }
 | 
| 
bsw@422
 | 
   166           execute.view{ module = "initiative", view = "_list", params = { 
 | 
| 
bsw@422
 | 
   167             issue = event.issue,
 | 
| 
bsw@422
 | 
   168             initiatives_selector = initiatives_selector,
 | 
| 
bsw@422
 | 
   169             no_sort = true,
 | 
| 
bsw@422
 | 
   170             limit = 1
 | 
| 
bsw@422
 | 
   171           } }
 | 
| 
bsw@414
 | 
   172         end
 | 
| 
bsw@414
 | 
   173       end }
 | 
| 
bsw@414
 | 
   174 
 | 
| 
bsw@422
 | 
   175       --[[      
 | 
| 
bsw@422
 | 
   176       if event.initiative_id then
 | 
| 
bsw@422
 | 
   177         ui.container{ attr = { class = "initiative_id" }, content = event.initiative_id }
 | 
| 
bsw@422
 | 
   178       end
 | 
| 
bsw@422
 | 
   179       if event.draft_id then
 | 
| 
bsw@422
 | 
   180         ui.container{ attr = { class = "draft_id" }, content = event.draft_id }
 | 
| 
bsw@422
 | 
   181       end
 | 
| 
bsw@422
 | 
   182       if event.suggestion_id then
 | 
| 
bsw@422
 | 
   183         ui.container{ attr = { class = "suggestion_id" }, content = event.suggestion_id }
 | 
| 
bsw@422
 | 
   184       end
 | 
| 
bsw@422
 | 
   185 --]]
 | 
| 
bsw@422
 | 
   186       
 | 
| 
bsw@422
 | 
   187     end }
 | 
| 
bsw@422
 | 
   188   end
 | 
| 
bsw@414
 | 
   189 
 | 
| 
bsw@422
 | 
   190 end }
 | 
| 
bsw@422
 | 
   191 
 | 
| 
bsw@422
 | 
   192 ui.link{
 | 
| 
bsw@423
 | 
   193   text = _"Show older events",
 | 
| 
bsw@422
 | 
   194   module = request.get_module(),
 | 
| 
bsw@422
 | 
   195   view = request.get_view(),
 | 
| 
bsw@422
 | 
   196   id = param.get_id(),
 | 
| 
bsw@422
 | 
   197   params = { 
 | 
| 
bsw@422
 | 
   198     tab = param.get_all_cgi()["tab"],
 | 
| 
bsw@422
 | 
   199     events = param.get_all_cgi()["events"],
 | 
| 
bsw@422
 | 
   200     event_max_id = last_event_id
 | 
| 
bsw@422
 | 
   201   }
 | 
| 
bsw@422
 | 
   202 }
 | 
| 
bsw@456
 | 
   203 
 | 
| 
bsw@456
 | 
   204 
 | 
| 
bsw@456
 | 
   205 slot.put("<br />")
 | 
| 
bsw@456
 | 
   206 slot.put("<br />")
 |