liquid_feedback_frontend
diff app/main/index/_sidebar_notifications.lua @ 1045:701a5cf6b067
Imported LiquidFeedback Frontend 3.0 branch
author | bsw |
---|---|
date | Thu Jul 10 01:19:48 2014 +0200 (2014-07-10) |
parents | |
children | 904f6807f7fa |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/app/main/index/_sidebar_notifications.lua Thu Jul 10 01:19:48 2014 +0200 1.3 @@ -0,0 +1,132 @@ 1.4 +local notification_links = {} 1.5 + 1.6 +if app.session.member.notify_email_unconfirmed then 1.7 + notification_links[#notification_links+1] = { 1.8 + module = "index", view = "email_unconfirmed", 1.9 + text = _"Confirm your email address" 1.10 + } 1.11 +end 1.12 + 1.13 +if app.session.member.notify_level == nil then 1.14 + notification_links[#notification_links+1] = { 1.15 + module = "member", view = "settings_notification", 1.16 + text = _"Select a notification level" 1.17 + } 1.18 +end 1.19 + 1.20 +if config.check_delegations_interval_soft then 1.21 + local member = Member:new_selector() 1.22 + :add_where({ "id = ?", app.session.member_id }) 1.23 + :add_field({ "now() > COALESCE(last_delegation_check, activated) + ?::interval", config.check_delegations_interval_soft }, "needs_delegation_check_soft") 1.24 + :single_object_mode() 1.25 + :exec() 1.26 + 1.27 + 1.28 + if member.needs_delegation_check_soft then 1.29 + 1.30 + local delegations = Delegation:delegations_to_check_for_member_id(member.id) 1.31 + 1.32 + if #delegations > 0 then 1.33 + notification_links[#notification_links+1] = { 1.34 + module = "index", view = "check_delegations", 1.35 + text = _"Check your outgoing delegations" 1.36 + } 1.37 + end 1.38 + 1.39 + end 1.40 +end 1.41 + 1.42 +local broken_delegations = Delegation:selector_for_broken(app.session.member_id):exec() 1.43 + 1.44 +for i, delegation in ipairs(broken_delegations) do 1.45 + local scope 1.46 + local context 1.47 + if delegation.scope == "unit" then 1.48 + scope = _"unit" 1.49 + id = delegation.unit_id 1.50 + context = delegation.unit.name 1.51 + elseif delegation.scope == "area" then 1.52 + scope = _"area" 1.53 + id = delegation.area_id 1.54 + context = delegation.area.name 1.55 + elseif delegation.scope == "issue" then 1.56 + scope = _"issue" 1.57 + id = delegation.issue_id 1.58 + context = delegation.issue.name 1.59 + end 1.60 + 1.61 + notification_links[#notification_links+1] = { 1.62 + module = delegation.scope, view = "show", id = id, 1.63 + text = _("Check your #{scope} delegation to '#{trustee_name}' for '#{context}'", { 1.64 + trustee_name = delegation.trustee.name, 1.65 + scope = scope, 1.66 + context = context 1.67 + }) 1.68 + } 1.69 +end 1.70 + 1.71 +local selector = Issue:new_selector() 1.72 + :join("area", nil, "area.id = issue.area_id") 1.73 + :join("privilege", nil, { "privilege.unit_id = area.unit_id AND privilege.member_id = ? AND privilege.voting_right", app.session.member_id }) 1.74 + :left_join("direct_voter", nil, { "direct_voter.issue_id = issue.id AND direct_voter.member_id = ?", app.session.member.id }) 1.75 + :left_join("non_voter", nil, { "non_voter.issue_id = issue.id AND non_voter.member_id = ?", app.session.member.id }) 1.76 + :left_join("interest", nil, { "interest.issue_id = issue.id AND interest.member_id = ?", app.session.member.id }) 1.77 + :add_where{ "direct_voter.member_id ISNULL" } 1.78 + :add_where{ "non_voter.member_id ISNULL" } 1.79 + :add_where{ "interest.member_id NOTNULL" } 1.80 + :add_where{ "issue.fully_frozen NOTNULL" } 1.81 + :add_where{ "issue.closed ISNULL" } 1.82 + :add_order_by{ "issue.fully_frozen + issue.voting_time ASC" } 1.83 + 1.84 +local issues_to_vote = selector:exec() 1.85 + 1.86 +for i, issue in ipairs(issues_to_vote) do 1.87 + notification_links[#notification_links+1] = { 1.88 + module = "issue", view = "show", id = issue.id, 1.89 + text = _("#{issue} is in voting", { issue = issue.name }) 1.90 + } 1.91 +end 1.92 + 1.93 +local initiator_invites = Initiator:selector_for_invites(app.session.member_id):exec() 1.94 + 1.95 +for i, initiative in ipairs(initiator_invites) do 1.96 + notification_links[#notification_links+1] = { 1.97 + module = "initiative", view = "show", id = initiative.id, 1.98 + text = _("You are invited to become initiator of '#{initiative_name}'", { initiative_name = initiative.display_name }) 1.99 + } 1.100 +end 1.101 + 1.102 +updated_drafts = Initiative:selector_for_updated_drafts(app.session.member_id):exec() 1.103 + 1.104 +for i, initiative in ipairs(updated_drafts) do 1.105 + notification_links[#notification_links+1] = { 1.106 + module = "initiative", view = "show", id = initiative.id, 1.107 + text = _("New draft for initiative '#{initiative_name}'", { initiative_name = initiative.display_name }) 1.108 + } 1.109 +end 1.110 + 1.111 +local mode = param.get("mode") or "view" 1.112 + 1.113 +if #notification_links > 0 then 1.114 + if mode == "link" then 1.115 + slot.select("notification", function () 1.116 + local text = _"notifications" 1.117 + ui.link { 1.118 + attr = { class = "notifications", title = text }, 1.119 + module = "index", view = "notifications", 1.120 + content = function () 1.121 + ui.image { attr = { class = "icon", alt = text }, static = "icons/48/bell.png" } 1.122 + ui.tag { attr = { class = "count" }, content = #notification_links } 1.123 + end 1.124 + } 1.125 + end ) 1.126 + elseif mode == "view" then 1.127 + ui.tag{ tag = "ul", attr = { class = "ul" }, content = function() 1.128 + for i, notification_link in ipairs(notification_links) do 1.129 + ui.tag{ tag = "li", content = function() 1.130 + ui.link(notification_link) 1.131 + end } 1.132 + end 1.133 + end } 1.134 + end 1.135 +end