liquid_feedback_frontend
view app/main/index/_sidebar_notifications.lua @ 1426:a964cf74e02f
Link to unit member list when showing a unit
| author | bsw | 
|---|---|
| date | Fri Oct 05 18:57:52 2018 +0200 (2018-10-05) | 
| parents | 32cc544d5a5b | 
| children | 
 line source
     1 local notification_links = {}
     3 if app.session.member.notify_email_unconfirmed then
     4   notification_links[#notification_links+1] = {
     5     module = "index", view = "email_unconfirmed",
     6     text = _"Confirm your email address"
     7   }
     8 end
    10 local agents = Agent:new_selector()
    11   :add_where{ "controller_id = ?", app.session.member_id }
    12   :add_where{ "accepted ISNULL" }
    13   :exec()
    14 for i, agent in ipairs(agents) do
    15   local member = Member:by_id(agent.controlled_id)
    16   notification_links[#notification_links+1] = {
    17     module = "agent", view = "show", params = { controlled_id = agent.controlled_id },
    18     text = _("Account access invitation from '#{member_name}'", { member_name = member.name })
    19   }
    20 end
    22 if config.check_delegations_interval_soft then
    23   local member = Member:new_selector()
    24     :add_where({ "id = ?", app.session.member_id })
    25     :add_field({ "now() > COALESCE(last_delegation_check, activated) + ?::interval", config.check_delegations_interval_soft }, "needs_delegation_check_soft")
    26     :single_object_mode()
    27     :exec()
    30   if member.needs_delegation_check_soft then
    32     local delegations = Delegation:delegations_to_check_for_member_id(member.id)
    34     if #delegations > 0 then
    35       notification_links[#notification_links+1] = {
    36         module = "index", view = "check_delegations", 
    37         text = _"Check your outgoing delegations"
    38       }
    39     end
    41   end
    42 end
    44 local broken_delegations = Delegation:selector_for_broken(app.session.member_id):exec()
    46 for i, delegation in ipairs(broken_delegations) do
    47   local scope
    48   local context
    49   local id
    50   if delegation.scope == "unit" then
    51     scope = _"unit"
    52     id = delegation.unit_id
    53     context = delegation.unit.name
    54   elseif delegation.scope == "area" then
    55     scope = _"area"
    56     id = delegation.area_id
    57     context = delegation.area.name
    58   elseif delegation.scope == "issue" then
    59     scope = _"issue"
    60     id = delegation.issue_id
    61     context = delegation.issue.name
    62   end
    64   notification_links[#notification_links+1] = {
    65     module = delegation.scope, view = "show", id = id,
    66     text = _("Check your #{scope} delegation to '#{trustee_name}' for '#{context}'", {
    67       trustee_name = delegation.trustee.name,
    68       scope = scope,
    69       context = context
    70     })
    71   }
    72 end
    74 local selector = Issue:new_selector()
    75   :join("area", nil, "area.id = issue.area_id")
    76   :join("privilege", nil, { "privilege.unit_id = area.unit_id AND privilege.member_id = ? AND privilege.voting_right", app.session.member_id })
    77   :left_join("direct_voter", nil, { "direct_voter.issue_id = issue.id AND direct_voter.member_id = ?", app.session.member.id })
    78   :left_join("non_voter", nil, { "non_voter.issue_id = issue.id AND non_voter.member_id = ?", app.session.member.id })
    79   :left_join("interest", nil, { "interest.issue_id = issue.id AND interest.member_id = ?", app.session.member.id })
    80   :add_where{ "direct_voter.member_id ISNULL" }
    81   :add_where{ "non_voter.member_id ISNULL" }
    82   :add_where{ "interest.member_id NOTNULL" }
    83   :add_where{ "issue.fully_frozen NOTNULL" }
    84   :add_where{ "issue.closed ISNULL" }
    85   :add_order_by{ "issue.fully_frozen + issue.voting_time ASC" }
    87 local issues_to_vote = selector:exec()
    89 for i, issue in ipairs(issues_to_vote) do
    90   notification_links[#notification_links+1] = {
    91     module = "issue", view = "show", id = issue.id,
    92     text = _("#{issue} is in voting", { issue = issue.name })
    93   }
    94 end
    96 local initiator_invites = Initiator:selector_for_invites(app.session.member_id):exec()
    98 for i, initiative in ipairs(initiator_invites) do
    99   notification_links[#notification_links+1] = {
   100     module = "initiative", view = "show", id = initiative.id,
   101     text = _("You are invited to become initiator of '#{initiative_name}'", { initiative_name = initiative.display_name })
   102   }
   103 end
   105 local updated_drafts = Initiative:selector_for_updated_drafts(app.session.member_id):exec()
   107 for i, initiative in ipairs(updated_drafts) do
   108   notification_links[#notification_links+1] = {
   109     module = "initiative", view = "show", id = initiative.id,
   110     text = _("New draft for initiative '#{initiative_name}'", { initiative_name = initiative.display_name })
   111   }
   112 end
   114 if #notification_links > 0 then
   115   ui.container{ attr = { class = "mdl-card mdl-card__fullwidth mdl-shadow--2dp" }, content = function()
   116     ui.container{ attr = { class = "mdl-card__title mdl-card--border" }, content = function()
   117       ui.heading { attr = { class = "mdl-card__title-text" }, level = 2, content = _"Notifications" }
   118     end }
   119     ui.container{ attr = { class = "mdl-card__content what-can-i-do-here" }, content = function()
   120       ui.tag{ tag = "ul", attr = { class = "ul" }, content = function()
   121         for i, notification_link in ipairs(notification_links) do
   122           ui.tag{ tag = "li", content = function()
   123             ui.link(notification_link)
   124           end }
   125         end
   126       end }
   127     end }
   128   end }
   129 end
