bsw@1045: local notification_links = {} bsw@1045: bsw@1045: if app.session.member.notify_email_unconfirmed then bsw@1045: notification_links[#notification_links+1] = { bsw@1045: module = "index", view = "email_unconfirmed", bsw@1045: text = _"Confirm your email address" bsw@1045: } bsw@1045: end bsw@1045: bsw@1045: if app.session.member.notify_level == nil then bsw@1045: notification_links[#notification_links+1] = { bsw@1045: module = "member", view = "settings_notification", bsw@1045: text = _"Select a notification level" bsw@1045: } bsw@1045: end bsw@1045: bsw@1045: if config.check_delegations_interval_soft then bsw@1045: local member = Member:new_selector() bsw@1045: :add_where({ "id = ?", app.session.member_id }) bsw@1045: :add_field({ "now() > COALESCE(last_delegation_check, activated) + ?::interval", config.check_delegations_interval_soft }, "needs_delegation_check_soft") bsw@1045: :single_object_mode() bsw@1045: :exec() bsw@1045: bsw@1045: bsw@1045: if member.needs_delegation_check_soft then bsw@1045: bsw@1045: local delegations = Delegation:delegations_to_check_for_member_id(member.id) bsw@1045: bsw@1045: if #delegations > 0 then bsw@1045: notification_links[#notification_links+1] = { bsw@1045: module = "index", view = "check_delegations", bsw@1045: text = _"Check your outgoing delegations" bsw@1045: } bsw@1045: end bsw@1045: bsw@1045: end bsw@1045: end bsw@1045: bsw@1045: local broken_delegations = Delegation:selector_for_broken(app.session.member_id):exec() bsw@1045: bsw@1045: for i, delegation in ipairs(broken_delegations) do bsw@1045: local scope bsw@1045: local context bsw@1045: if delegation.scope == "unit" then bsw@1045: scope = _"unit" bsw@1045: id = delegation.unit_id bsw@1045: context = delegation.unit.name bsw@1045: elseif delegation.scope == "area" then bsw@1045: scope = _"area" bsw@1045: id = delegation.area_id bsw@1045: context = delegation.area.name bsw@1045: elseif delegation.scope == "issue" then bsw@1045: scope = _"issue" bsw@1045: id = delegation.issue_id bsw@1045: context = delegation.issue.name bsw@1045: end bsw@1045: bsw@1045: notification_links[#notification_links+1] = { bsw@1045: module = delegation.scope, view = "show", id = id, bsw@1045: text = _("Check your #{scope} delegation to '#{trustee_name}' for '#{context}'", { bsw@1045: trustee_name = delegation.trustee.name, bsw@1045: scope = scope, bsw@1045: context = context bsw@1045: }) bsw@1045: } bsw@1045: end bsw@1045: bsw@1045: local selector = Issue:new_selector() bsw@1045: :join("area", nil, "area.id = issue.area_id") bsw@1045: :join("privilege", nil, { "privilege.unit_id = area.unit_id AND privilege.member_id = ? AND privilege.voting_right", app.session.member_id }) bsw@1045: :left_join("direct_voter", nil, { "direct_voter.issue_id = issue.id AND direct_voter.member_id = ?", app.session.member.id }) bsw@1045: :left_join("non_voter", nil, { "non_voter.issue_id = issue.id AND non_voter.member_id = ?", app.session.member.id }) bsw@1045: :left_join("interest", nil, { "interest.issue_id = issue.id AND interest.member_id = ?", app.session.member.id }) bsw@1045: :add_where{ "direct_voter.member_id ISNULL" } bsw@1045: :add_where{ "non_voter.member_id ISNULL" } bsw@1045: :add_where{ "interest.member_id NOTNULL" } bsw@1045: :add_where{ "issue.fully_frozen NOTNULL" } bsw@1045: :add_where{ "issue.closed ISNULL" } bsw@1045: :add_order_by{ "issue.fully_frozen + issue.voting_time ASC" } bsw@1045: bsw@1045: local issues_to_vote = selector:exec() bsw@1045: bsw@1045: for i, issue in ipairs(issues_to_vote) do bsw@1045: notification_links[#notification_links+1] = { bsw@1045: module = "issue", view = "show", id = issue.id, bsw@1045: text = _("#{issue} is in voting", { issue = issue.name }) bsw@1045: } bsw@1045: end bsw@1045: bsw@1045: local initiator_invites = Initiator:selector_for_invites(app.session.member_id):exec() bsw@1045: bsw@1045: for i, initiative in ipairs(initiator_invites) do bsw@1045: notification_links[#notification_links+1] = { bsw@1045: module = "initiative", view = "show", id = initiative.id, bsw@1045: text = _("You are invited to become initiator of '#{initiative_name}'", { initiative_name = initiative.display_name }) bsw@1045: } bsw@1045: end bsw@1045: bsw@1145: local updated_drafts = Initiative:selector_for_updated_drafts(app.session.member_id):exec() bsw@1045: bsw@1045: for i, initiative in ipairs(updated_drafts) do bsw@1045: notification_links[#notification_links+1] = { bsw@1045: module = "initiative", view = "show", id = initiative.id, bsw@1045: text = _("New draft for initiative '#{initiative_name}'", { initiative_name = initiative.display_name }) bsw@1045: } bsw@1045: end bsw@1045: bsw@1045: local mode = param.get("mode") or "view" bsw@1045: bsw@1045: if #notification_links > 0 then bsw@1045: if mode == "link" then bsw@1045: slot.select("notification", function () bsw@1045: local text = _"notifications" bsw@1045: ui.link { bsw@1045: attr = { class = "notifications", title = text }, bsw@1045: module = "index", view = "notifications", bsw@1045: content = function () bsw@1045: ui.image { attr = { class = "icon", alt = text }, static = "icons/48/bell.png" } bsw@1045: ui.tag { attr = { class = "count" }, content = #notification_links } bsw@1045: end bsw@1045: } bsw@1045: end ) bsw@1045: elseif mode == "view" then bsw@1045: ui.tag{ tag = "ul", attr = { class = "ul" }, content = function() bsw@1045: for i, notification_link in ipairs(notification_links) do bsw@1045: ui.tag{ tag = "li", content = function() bsw@1045: ui.link(notification_link) bsw@1045: end } bsw@1045: end bsw@1045: end } bsw@1045: end bsw@1045: end