liquid_feedback_frontend
view app/main/initiative/show_tab.lua @ 272:65a1f7a01e7b
More optical enhancements and repositioning of elements
author | bsw |
---|---|
date | Wed Feb 08 00:55:17 2012 +0100 (2012-02-08) |
parents | 0849be391140 |
children | 808269b7f41c |
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 = "initiative",
27 view = "_current_draft",
28 params = {
29 initiative = initiative,
30 initiator = initiator
31 }
32 }
33 }
35 if app.session.member_id then
36 if initiative.issue.ranks_available then
37 tabs[#tabs+1] = {
38 name = "voting",
39 label = _"Voting details",
40 icon = { static = "icons/16/email_open.png" },
41 module = "initiative",
42 view = "_show_voting",
43 params = {
44 initiative = initiative
45 }
46 }
47 end
48 end
50 local suggestion_count = initiative:get_reference_selector("suggestions"):count()
52 tabs[#tabs+1] = {
53 name = "suggestions",
54 label = _"Suggestions" .. " (" .. tostring(suggestion_count) .. ")",
55 icon = { static = "icons/16/comments.png" },
56 module = "initiative",
57 view = "_suggestions",
58 params = {
59 initiative = initiative
60 }
61 }
63 if app.session.member_id then
64 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
65 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
66 :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")
67 :add_field("direct_interest_snapshot.weight")
68 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
69 :add_where("direct_supporter_snapshot.satisfied")
70 :add_field("direct_supporter_snapshot.informed", "is_informed")
72 local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
73 local direct_satisfied_supporter_count = tmp.count
74 local indirect_satisfied_supporter_count = (tmp.weight or 0) - tmp.count
76 local count_string
77 if indirect_satisfied_supporter_count > 0 then
78 count_string = "(" .. tostring(direct_satisfied_supporter_count) .. "+" .. tostring(indirect_satisfied_supporter_count) .. ")"
79 else
80 count_string = "(" .. tostring(direct_satisfied_supporter_count) .. ")"
81 end
83 tabs[#tabs+1] = {
84 name = "satisfied_supporter",
85 label = _"Supporter" .. " " .. count_string,
86 icon = { static = "icons/16/thumb_up_green.png" },
87 module = "member",
88 view = "_list",
89 params = {
90 initiative = initiative,
91 members_selector = members_selector
92 }
93 }
95 local members_selector = initiative:get_reference_selector("supporting_members_snapshot")
96 :join("issue", nil, "issue.id = direct_supporter_snapshot.issue_id")
97 :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")
98 :add_field("direct_interest_snapshot.weight")
99 :add_where("direct_supporter_snapshot.event = issue.latest_snapshot_event")
100 :add_where("NOT direct_supporter_snapshot.satisfied")
101 :add_field("direct_supporter_snapshot.informed", "is_informed")
103 local tmp = db:query("SELECT count(1) AS count, sum(weight) AS weight FROM (" .. tostring(members_selector) .. ") as subquery", "object")
104 local direct_potential_supporter_count = tmp.count
105 local indirect_potential_supporter_count = (tmp.weight or 0) - tmp.count
107 local count_string
108 if indirect_potential_supporter_count > 0 then
109 count_string = "(" .. tostring(direct_potential_supporter_count) .. "+" .. tostring(indirect_potential_supporter_count) .. ")"
110 else
111 count_string = "(" .. tostring(direct_potential_supporter_count) .. ")"
112 end
114 tabs[#tabs+1] = {
115 name = "supporter",
116 label = _"Potential supporter" .. " " .. count_string,
117 icon = { static = "icons/16/thumb_up.png" },
118 module = "member",
119 view = "_list",
120 params = {
121 initiative = initiative,
122 members_selector = members_selector
123 }
124 }
126 end
128 local drafts_count = initiative:get_reference_selector("drafts"):count()
130 tabs[#tabs+1] = {
131 name = "drafts",
132 label = _"Draft history" .. " (" .. tostring(drafts_count) .. ")",
133 icon = { static = "icons/16/script.png" },
134 module = "draft",
135 view = "_list",
136 params = { drafts = initiative.drafts }
137 }
139 tabs[#tabs+1] = {
140 name = "details",
141 label = _"Details",
142 icon = { static = "icons/16/magnifier.png" },
143 module = "initiative",
144 view = "_details",
145 params = {
146 initiative = initiative,
147 members_selector = members_selector
148 }
149 }
151 tabs.module = "initiative"
152 tabs.view = "show_tab"
153 tabs.static_params = {
154 initiative_id = initiative.id
155 }
157 ui.tabs(tabs)