liquid_feedback_frontend

view app/main/index/_sidebar_notifications.lua @ 1248:c0fd12b97d65

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

Impressum / About Us