liquid_feedback_frontend
view app/main/index/_sidebar_notifications.lua @ 1208:24f4c23f76ff
Moved code from draft add action to Draft model
| author | bsw | 
|---|---|
| date | Sat Jul 18 15:58:39 2015 +0200 (2015-07-18) | 
| parents | baa99640ad69 | 
| children | c0fd12b97d65 | 
 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 if app.session.member.notify_level == nil then
    11   notification_links[#notification_links+1] = {
    12     module = "member", view = "settings_notification",
    13     text = _"Select a notification level"
    14   }
    15 end
    17 if config.check_delegations_interval_soft then
    18   local member = Member:new_selector()
    19     :add_where({ "id = ?", app.session.member_id })
    20     :add_field({ "now() > COALESCE(last_delegation_check, activated) + ?::interval", config.check_delegations_interval_soft }, "needs_delegation_check_soft")
    21     :single_object_mode()
    22     :exec()
    25   if member.needs_delegation_check_soft then
    27     local delegations = Delegation:delegations_to_check_for_member_id(member.id)
    29     if #delegations > 0 then
    30       notification_links[#notification_links+1] = {
    31         module = "index", view = "check_delegations", 
    32         text = _"Check your outgoing delegations"
    33       }
    34     end
    36   end
    37 end
    39 local broken_delegations = Delegation:selector_for_broken(app.session.member_id):exec()
    41 for i, delegation in ipairs(broken_delegations) do
    42   local scope
    43   local context
    44   local id
    45   if delegation.scope == "unit" then
    46     scope = _"unit"
    47     id = delegation.unit_id
    48     context = delegation.unit.name
    49   elseif delegation.scope == "area" then
    50     scope = _"area"
    51     id = delegation.area_id
    52     context = delegation.area.name
    53   elseif delegation.scope == "issue" then
    54     scope = _"issue"
    55     id = delegation.issue_id
    56     context = delegation.issue.name
    57   end
    59   notification_links[#notification_links+1] = {
    60     module = delegation.scope, view = "show", id = id,
    61     text = _("Check your #{scope} delegation to '#{trustee_name}' for '#{context}'", {
    62       trustee_name = delegation.trustee.name,
    63       scope = scope,
    64       context = context
    65     })
    66   }
    67 end
    69 local selector = Issue:new_selector()
    70   :join("area", nil, "area.id = issue.area_id")
    71   :join("privilege", nil, { "privilege.unit_id = area.unit_id AND privilege.member_id = ? AND privilege.voting_right", app.session.member_id })
    72   :left_join("direct_voter", nil, { "direct_voter.issue_id = issue.id AND direct_voter.member_id = ?", app.session.member.id })
    73   :left_join("non_voter", nil, { "non_voter.issue_id = issue.id AND non_voter.member_id = ?", app.session.member.id })
    74   :left_join("interest", nil, { "interest.issue_id = issue.id AND interest.member_id = ?", app.session.member.id })
    75   :add_where{ "direct_voter.member_id ISNULL" }
    76   :add_where{ "non_voter.member_id ISNULL" }
    77   :add_where{ "interest.member_id NOTNULL" }
    78   :add_where{ "issue.fully_frozen NOTNULL" }
    79   :add_where{ "issue.closed ISNULL" }
    80   :add_order_by{ "issue.fully_frozen + issue.voting_time ASC" }
    82 local issues_to_vote = selector:exec()
    84 for i, issue in ipairs(issues_to_vote) do
    85   notification_links[#notification_links+1] = {
    86     module = "issue", view = "show", id = issue.id,
    87     text = _("#{issue} is in voting", { issue = issue.name })
    88   }
    89 end
    91 local initiator_invites = Initiator:selector_for_invites(app.session.member_id):exec()
    93 for i, initiative in ipairs(initiator_invites) do
    94   notification_links[#notification_links+1] = {
    95     module = "initiative", view = "show", id = initiative.id,
    96     text = _("You are invited to become initiator of '#{initiative_name}'", { initiative_name = initiative.display_name })
    97   }
    98 end
   100 local updated_drafts = Initiative:selector_for_updated_drafts(app.session.member_id):exec()
   102 for i, initiative in ipairs(updated_drafts) do
   103   notification_links[#notification_links+1] = {
   104     module = "initiative", view = "show", id = initiative.id,
   105     text = _("New draft for initiative '#{initiative_name}'", { initiative_name = initiative.display_name })
   106   }
   107 end
   109 local mode = param.get("mode") or "view"
   111 if #notification_links > 0 then
   112   if mode == "link" then
   113     slot.select("notification", function ()
   114       local text = _"notifications"
   115       ui.link {
   116         attr = { class = "notifications", title = text },
   117         module = "index", view = "notifications",
   118         content = function ()
   119           ui.image { attr = { class = "icon", alt = text }, static = "icons/48/bell.png" }
   120           ui.tag { attr = { class = "count" }, content = #notification_links }
   121         end
   122       }
   123     end )
   124   elseif mode == "view" then
   125     ui.tag{ tag = "ul", attr = { class = "ul" }, content = function()
   126       for i, notification_link in ipairs(notification_links) do
   127         ui.tag{ tag = "li", content = function()
   128           ui.link(notification_link)
   129         end }
   130       end
   131     end }
   132   end
   133 end
