liquid_feedback_frontend

view app/main/initiative/show_tab.lua @ 593:6ccab8039935

Added plural-"s" to (potential) supporters tab, closes #1235
author bsw
date Fri Jun 22 17:40:59 2012 +0200 (2012-06-22)
parents 4cee33ad5e16
children
line source
1 local initiative = param.get("initiative", "table")
2 local initiator = param.get("initiator", "table")
4 if not initiative then
5 initiative = Initiative:by_id(param.get("initiative_id", atom.number))
6 end
8 if not initiator and app.session.member_id then
9 initiator = Initiator:by_pk(initiative.id, app.session.member.id)
10 end
12 local current_draft_name = _"Current draft"
13 if initiative.issue.half_frozen then
14 current_draft_name = _"Voting proposal"
15 end
17 if initiative.issue.state == "finished" then
18 current_draft_name = _"Voted proposal"
19 end
21 local tabs = {
22 {
23 name = "current_draft",
24 label = current_draft_name,
25 icon = { static = "icons/16/script.png" },
26 module = "draft",
27 view = "_show",
28 params = {
29 draft = initiative.current_draft
30 }
31 }
32 }
34 if config.public_access == "full" or app.session.member_id then
35 if initiative.issue.ranks_available then
36 tabs[#tabs+1] = {
37 name = "voting",
38 label = _"Voting details",
39 icon = { static = "icons/16/email_open.png" },
40 module = "initiative",
41 view = "_show_voting",
42 params = {
43 initiative = initiative
44 }
45 }
46 end
47 end
49 local suggestion_count = initiative:get_reference_selector("suggestions"):count()
51 tabs[#tabs+1] = {
52 name = "suggestions",
53 label = _"Suggestions" .. " (" .. tostring(suggestion_count) .. ")",
54 icon = { static = "icons/16/comments.png" },
55 module = "suggestion",
56 view = "_list",
57 params = {
58 initiative = initiative,
59 suggestions_selector = initiative:get_reference_selector("suggestions"),
60 tab_id = param.get("tab_id")
61 }
62 }
64 if config.public_access == "full" or app.session.member_id then
65 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
66 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
67 :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
68 :add_field("direct_interest_snapshot.weight")
69 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
70 :add_where("direct_supporter_snapshot.satisfied")
71 :add_field("direct_supporter_snapshot.informed", "is_informed")
73 local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
74 local direct_satisfied_supporter_count = tmp.count
75 local indirect_satisfied_supporter_count = (tmp.weight or 0) - tmp.count
77 local count_string
78 if indirect_satisfied_supporter_count > 0 then
79 count_string = "(" .. tostring(direct_satisfied_supporter_count) .. "+" .. tostring(indirect_satisfied_supporter_count) .. ")"
80 else
81 count_string = "(" .. tostring(direct_satisfied_supporter_count) .. ")"
82 end
84 tabs[#tabs+1] = {
85 name = "satisfied_supporter",
86 label = _"Supporters" .. " " .. count_string,
87 icon = { static = "icons/16/thumb_up_green.png" },
88 module = "member",
89 view = "_list",
90 params = {
91 initiative = initiative,
92 members_selector = members_selector
93 }
94 }
96 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
97 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
98 :join("direct_interest_snapshot", nil, "direct_interest_snapshot.event = issue.latest_snapshot_event AND direct_interest_snapshot.issue_id = issue.id AND direct_interest_snapshot.member_id = member.id")
99 :add_field("direct_interest_snapshot.weight")
100 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
101 :add_where("NOT direct_supporter_snapshot.satisfied")
102 :add_field("direct_supporter_snapshot.informed", "is_informed")
104 local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
105 local direct_potential_supporter_count = tmp.count
106 local indirect_potential_supporter_count = (tmp.weight or 0) - tmp.count
108 local count_string
109 if indirect_potential_supporter_count > 0 then
110 count_string = "(" .. tostring(direct_potential_supporter_count) .. "+" .. tostring(indirect_potential_supporter_count) .. ")"
111 else
112 count_string = "(" .. tostring(direct_potential_supporter_count) .. ")"
113 end
115 tabs[#tabs+1] = {
116 name = "supporter",
117 label = _"Potential supporters" .. " " .. count_string,
118 icon = { static = "icons/16/thumb_up.png" },
119 module = "member",
120 view = "_list",
121 params = {
122 initiative = initiative,
123 members_selector = members_selector
124 }
125 }
127 end
129 local drafts_count = initiative:get_reference_selector("drafts"):count()
131 tabs[#tabs+1] = {
132 name = "drafts",
133 label = _"Draft history" .. " (" .. tostring(drafts_count) .. ")",
134 icon = { static = "icons/16/script.png" },
135 module = "draft",
136 view = "_list",
137 params = { drafts = initiative.drafts }
138 }
140 tabs[#tabs+1] = {
141 name = "details",
142 label = _"Details",
143 icon = { static = "icons/16/magnifier.png" },
144 module = "initiative",
145 view = "_details",
146 params = {
147 initiative = initiative,
148 members_selector = members_selector
149 }
150 }
152 tabs.module = "initiative"
153 tabs.view = "show_tab"
154 tabs.static_params = {
155 initiative_id = initiative.id
156 }
158 ui.tabs(tabs)

Impressum / About Us