liquid_feedback_frontend

annotate app/main/index/_sidebar_notifications.lua @ 1302:9ff5b868760d

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

Impressum / About Us