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