| 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@1045 | 44   if delegation.scope == "unit" then | 
| bsw@1045 | 45     scope = _"unit" | 
| bsw@1045 | 46     id = delegation.unit_id | 
| bsw@1045 | 47     context = delegation.unit.name | 
| bsw@1045 | 48   elseif delegation.scope == "area" then | 
| bsw@1045 | 49     scope = _"area" | 
| bsw@1045 | 50     id = delegation.area_id | 
| bsw@1045 | 51     context = delegation.area.name | 
| bsw@1045 | 52   elseif delegation.scope == "issue" then | 
| bsw@1045 | 53     scope = _"issue" | 
| bsw@1045 | 54     id = delegation.issue_id | 
| bsw@1045 | 55     context = delegation.issue.name | 
| bsw@1045 | 56   end | 
| bsw@1045 | 57 | 
| bsw@1045 | 58   notification_links[#notification_links+1] = { | 
| bsw@1045 | 59     module = delegation.scope, view = "show", id = id, | 
| bsw@1045 | 60     text = _("Check your #{scope} delegation to '#{trustee_name}' for '#{context}'", { | 
| bsw@1045 | 61       trustee_name = delegation.trustee.name, | 
| bsw@1045 | 62       scope = scope, | 
| bsw@1045 | 63       context = context | 
| bsw@1045 | 64     }) | 
| bsw@1045 | 65   } | 
| bsw@1045 | 66 end | 
| bsw@1045 | 67 | 
| bsw@1045 | 68 local selector = Issue:new_selector() | 
| bsw@1045 | 69   :join("area", nil, "area.id = issue.area_id") | 
| bsw@1045 | 70   :join("privilege", nil, { "privilege.unit_id = area.unit_id AND privilege.member_id = ? AND privilege.voting_right", app.session.member_id }) | 
| bsw@1045 | 71   :left_join("direct_voter", nil, { "direct_voter.issue_id = issue.id AND direct_voter.member_id = ?", app.session.member.id }) | 
| bsw@1045 | 72   :left_join("non_voter", nil, { "non_voter.issue_id = issue.id AND non_voter.member_id = ?", app.session.member.id }) | 
| bsw@1045 | 73   :left_join("interest", nil, { "interest.issue_id = issue.id AND interest.member_id = ?", app.session.member.id }) | 
| bsw@1045 | 74   :add_where{ "direct_voter.member_id ISNULL" } | 
| bsw@1045 | 75   :add_where{ "non_voter.member_id ISNULL" } | 
| bsw@1045 | 76   :add_where{ "interest.member_id NOTNULL" } | 
| bsw@1045 | 77   :add_where{ "issue.fully_frozen NOTNULL" } | 
| bsw@1045 | 78   :add_where{ "issue.closed ISNULL" } | 
| bsw@1045 | 79   :add_order_by{ "issue.fully_frozen + issue.voting_time ASC" } | 
| bsw@1045 | 80 | 
| bsw@1045 | 81 local issues_to_vote = selector:exec() | 
| bsw@1045 | 82 | 
| bsw@1045 | 83 for i, issue in ipairs(issues_to_vote) do | 
| bsw@1045 | 84   notification_links[#notification_links+1] = { | 
| bsw@1045 | 85     module = "issue", view = "show", id = issue.id, | 
| bsw@1045 | 86     text = _("#{issue} is in voting", { issue = issue.name }) | 
| bsw@1045 | 87   } | 
| bsw@1045 | 88 end | 
| bsw@1045 | 89 | 
| bsw@1045 | 90 local initiator_invites = Initiator:selector_for_invites(app.session.member_id):exec() | 
| bsw@1045 | 91 | 
| bsw@1045 | 92 for i, initiative in ipairs(initiator_invites) do | 
| bsw@1045 | 93   notification_links[#notification_links+1] = { | 
| bsw@1045 | 94     module = "initiative", view = "show", id = initiative.id, | 
| bsw@1045 | 95     text = _("You are invited to become initiator of '#{initiative_name}'", { initiative_name = initiative.display_name }) | 
| bsw@1045 | 96   } | 
| bsw@1045 | 97 end | 
| bsw@1045 | 98 | 
| bsw@1045 | 99 updated_drafts = Initiative:selector_for_updated_drafts(app.session.member_id):exec() | 
| bsw@1045 | 100 | 
| bsw@1045 | 101 for i, initiative in ipairs(updated_drafts) do | 
| bsw@1045 | 102   notification_links[#notification_links+1] = { | 
| bsw@1045 | 103     module = "initiative", view = "show", id = initiative.id, | 
| bsw@1045 | 104     text = _("New draft for initiative '#{initiative_name}'", { initiative_name = initiative.display_name }) | 
| bsw@1045 | 105   } | 
| bsw@1045 | 106 end | 
| bsw@1045 | 107 | 
| bsw@1045 | 108 local mode = param.get("mode") or "view" | 
| bsw@1045 | 109 | 
| bsw@1045 | 110 if #notification_links > 0 then | 
| bsw@1045 | 111   if mode == "link" then | 
| bsw@1045 | 112     slot.select("notification", function () | 
| bsw@1045 | 113       local text = _"notifications" | 
| bsw@1045 | 114       ui.link { | 
| bsw@1045 | 115         attr = { class = "notifications", title = text }, | 
| bsw@1045 | 116         module = "index", view = "notifications", | 
| bsw@1045 | 117         content = function () | 
| bsw@1045 | 118           ui.image { attr = { class = "icon", alt = text }, static = "icons/48/bell.png" } | 
| bsw@1045 | 119           ui.tag { attr = { class = "count" }, content = #notification_links } | 
| bsw@1045 | 120         end | 
| bsw@1045 | 121       } | 
| bsw@1045 | 122     end ) | 
| bsw@1045 | 123   elseif mode == "view" then | 
| bsw@1045 | 124     ui.tag{ tag = "ul", attr = { class = "ul" }, content = function() | 
| bsw@1045 | 125       for i, notification_link in ipairs(notification_links) do | 
| bsw@1045 | 126         ui.tag{ tag = "li", content = function() | 
| bsw@1045 | 127           ui.link(notification_link) | 
| bsw@1045 | 128         end } | 
| bsw@1045 | 129       end | 
| bsw@1045 | 130     end } | 
| bsw@1045 | 131   end | 
| bsw@1045 | 132 end |