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