liquid_feedback_frontend

view app/main/index/_sidebar_notifications.lua @ 1145:904f6807f7fa

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

Impressum / About Us