rev |
line source |
bsw/jbe@19
|
1 ui.script{ script = "lf_initiative_expanded = {};" }
|
bsw@11
|
2
|
bsw/jbe@0
|
3 local issue = param.get("issue", "table")
|
bsw/jbe@0
|
4
|
bsw/jbe@19
|
5 local initiatives_selector = param.get("initiatives_selector", "table")
|
bsw@51
|
6
|
bsw@274
|
7 local highlight_initiative = param.get("highlight_initiative", "table")
|
bsw@274
|
8
|
bsw@11
|
9 initiatives_selector
|
bsw/jbe@19
|
10 :join("issue", nil, "issue.id = initiative.issue_id")
|
bsw@11
|
11
|
bsw@51
|
12 if app.session.member_id then
|
bsw@51
|
13 initiatives_selector
|
bsw@57
|
14 :left_join("initiator", "_initiator", { "_initiator.initiative_id = initiative.id AND _initiator.member_id = ? AND _initiator.accepted", app.session.member.id} )
|
bsw@51
|
15 :left_join("supporter", "_supporter", { "_supporter.initiative_id = initiative.id AND _supporter.member_id = ?", app.session.member.id} )
|
bsw@51
|
16
|
bsw@51
|
17 :add_field("(_initiator.member_id NOTNULL)", "is_initiator")
|
bsw@51
|
18 :add_field({"(_supporter.member_id NOTNULL) AND NOT EXISTS(SELECT 1 FROM opinion WHERE opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)))", app.session.member.id }, "is_supporter")
|
bsw@51
|
19 :add_field({"EXISTS(SELECT 1 FROM opinion WHERE opinion.initiative_id = initiative.id AND opinion.member_id = ? AND ((opinion.degree = 2 AND NOT fulfilled) OR (opinion.degree = -2 AND fulfilled)))", app.session.member.id }, "is_potential_supporter")
|
bsw@51
|
20 end
|
bsw@11
|
21
|
bsw/jbe@19
|
22 local initiatives_count = initiatives_selector:count()
|
bsw@11
|
23
|
bsw/jbe@19
|
24 local limit = param.get("limit", atom.number)
|
bsw/jbe@19
|
25 local no_sort = param.get("no_sort", atom.boolean)
|
bsw/jbe@19
|
26
|
bsw/jbe@19
|
27 local show_for_issue = param.get("show_for_issue", atom.boolean)
|
bsw/jbe@19
|
28
|
bsw/jbe@19
|
29 local show_for_initiative
|
bsw/jbe@19
|
30
|
bsw/jbe@19
|
31 local show_for_initiative_id = param.get("for_initiative_id", atom.number)
|
bsw/jbe@19
|
32
|
bsw/jbe@19
|
33 if show_for_initiative_id then
|
bsw/jbe@19
|
34 show_for_initiative = Initiative:by_id(show_for_initiative_id)
|
bsw/jbe@19
|
35
|
bsw/jbe@19
|
36 elseif not show_for_initiative_id and show_for_issue and issue and issue.ranks_available then
|
bsw/jbe@19
|
37 winning_initiative = Initiative:new_selector()
|
bsw/jbe@19
|
38 :add_where{ "issue_id = ?", issue.id }
|
bsw/jbe@19
|
39 :add_where("rank = 1")
|
bsw@24
|
40 :optional_object_mode()
|
bsw/jbe@19
|
41 :exec()
|
bsw/jbe@19
|
42 if winning_initiative then
|
bsw/jbe@19
|
43 show_for_initiative = winning_initiative
|
bsw/jbe@19
|
44 ui.container{
|
bsw/jbe@19
|
45 attr = { class = "admitted_info" },
|
bsw/jbe@19
|
46 content = _"This issue has been finished with the following winning initiative:"
|
bsw/jbe@19
|
47 }
|
bsw/jbe@19
|
48 else
|
bsw/jbe@19
|
49 ui.container{
|
bsw/jbe@19
|
50 attr = { class = "not_admitted_info" },
|
bsw/jbe@19
|
51 content = _"This issue has been finished without any winning initiative."
|
bsw/jbe@19
|
52 }
|
bsw/jbe@19
|
53 end
|
bsw/jbe@19
|
54 end
|
bsw/jbe@19
|
55
|
bsw/jbe@19
|
56
|
bsw/jbe@19
|
57 if show_for_initiative then
|
bsw/jbe@19
|
58 ui.script{ script = "lf_initiative_expanded['initiative_content_" .. tostring(show_for_initiative.id) .. "'] = true;" }
|
bsw/jbe@19
|
59 initiatives_selector:add_where{ "initiative.id != ?", show_for_initiative.id }
|
bsw/jbe@19
|
60
|
bsw/jbe@19
|
61 execute.view{
|
bsw/jbe@19
|
62 module = "initiative",
|
bsw/jbe@19
|
63 view = "_list_element",
|
bsw/jbe@19
|
64 params = {
|
bsw/jbe@19
|
65 initiative = show_for_initiative,
|
bsw/jbe@19
|
66 expanded = true,
|
bsw/jbe@19
|
67 expandable = true
|
bsw/jbe@19
|
68 }
|
bsw/jbe@19
|
69 }
|
bsw/jbe@19
|
70 if show_for_issue then
|
bsw/jbe@19
|
71 slot.put("<br />")
|
bsw/jbe@19
|
72 ui.container{
|
bsw/jbe@19
|
73 attr = { style = "font-weight: bold;" },
|
bsw/jbe@0
|
74 content = function()
|
bsw/jbe@19
|
75 slot.put(_"Alternative initiatives")
|
bsw/jbe@0
|
76 end
|
bsw/jbe@0
|
77 }
|
bsw/jbe@0
|
78 end
|
bsw/jbe@19
|
79 elseif show_for_issue then
|
bsw/jbe@19
|
80 ui.container{
|
bsw/jbe@19
|
81 attr = { style = "font-weight: bold;" },
|
bsw/jbe@19
|
82 content = function()
|
bsw/jbe@19
|
83 slot.put(_"Alternative initiatives")
|
bsw/jbe@19
|
84 end
|
bsw@11
|
85 }
|
bsw@11
|
86 end
|
bsw/jbe@19
|
87
|
bsw/jbe@19
|
88 if not show_for_initiative or initiatives_count > 1 then
|
bsw/jbe@19
|
89
|
bsw/jbe@19
|
90
|
bsw/jbe@19
|
91 local more_initiatives_count
|
bsw/jbe@19
|
92 if limit then
|
bsw/jbe@19
|
93 limit = limit - (show_for_initiative and 1 or 0)
|
bsw/jbe@19
|
94 if initiatives_count > limit then
|
bsw/jbe@19
|
95 more_initiatives_count = initiatives_count - limit
|
bsw/jbe@19
|
96 end
|
bsw/jbe@19
|
97 initiatives_selector:limit(limit)
|
bsw/jbe@19
|
98 end
|
bsw/jbe@19
|
99
|
bsw/jbe@19
|
100 local expandable = param.get("expandable", atom.boolean)
|
bsw/jbe@19
|
101
|
bsw/jbe@19
|
102 local issue = param.get("issue", "table")
|
bsw/jbe@19
|
103
|
bsw/jbe@19
|
104 local name = "initiative_list"
|
bsw/jbe@19
|
105 if issue then
|
bsw/jbe@19
|
106 name = "issue_" .. tostring(issue.id) .. "_initiative_list"
|
bsw/jbe@19
|
107 end
|
bsw/jbe@19
|
108
|
bsw/jbe@19
|
109 ui.add_partial_param_names{ name }
|
bsw/jbe@19
|
110
|
bsw/jbe@19
|
111 local order_filter = {
|
bsw/jbe@19
|
112 name = name,
|
bsw/jbe@19
|
113 label = _"Order by"
|
bsw/jbe@19
|
114 }
|
bsw/jbe@19
|
115
|
bsw/jbe@19
|
116 if issue and issue.ranks_available then
|
bsw/jbe@19
|
117 order_filter[#order_filter+1] = {
|
bsw/jbe@19
|
118 name = "rank",
|
bsw/jbe@19
|
119 label = _"Rank",
|
bsw/jbe@19
|
120 selector_modifier = function(selector) selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id") end
|
bsw/jbe@19
|
121 }
|
bsw/jbe@19
|
122 end
|
bsw/jbe@19
|
123
|
bsw/jbe@19
|
124 order_filter[#order_filter+1] = {
|
bsw/jbe@19
|
125 name = "potential_support",
|
bsw/jbe@19
|
126 label = _"Potential support",
|
bsw@270
|
127 selector_modifier = function(selector) selector:add_order_by("CASE WHEN issue.population = 0 THEN 0 ELSE initiative.supporter_count::float / issue.population::float END DESC, initiative.id") end
|
bsw/jbe@19
|
128 }
|
bsw/jbe@19
|
129
|
bsw/jbe@19
|
130 order_filter[#order_filter+1] = {
|
bsw/jbe@19
|
131 name = "support",
|
bsw/jbe@19
|
132 label = _"Support",
|
bsw/jbe@19
|
133 selector_modifier = function(selector) selector:add_order_by("initiative.satisfied_supporter_count::float / issue.population::float DESC, initiative.id") end
|
bsw/jbe@19
|
134 }
|
bsw/jbe@19
|
135
|
bsw/jbe@19
|
136 order_filter[#order_filter+1] = {
|
bsw/jbe@19
|
137 name = "newest",
|
bsw/jbe@19
|
138 label = _"Newest",
|
bsw/jbe@19
|
139 selector_modifier = function(selector) selector:add_order_by("initiative.created DESC, initiative.id") end
|
bsw/jbe@19
|
140 }
|
bsw/jbe@19
|
141
|
bsw/jbe@19
|
142 order_filter[#order_filter+1] = {
|
bsw/jbe@19
|
143 name = "oldest",
|
bsw/jbe@19
|
144 label = _"Oldest",
|
bsw/jbe@19
|
145 selector_modifier = function(selector) selector:add_order_by("initiative.created, initiative.id") end
|
bsw/jbe@19
|
146 }
|
bsw/jbe@19
|
147
|
bsw/jbe@19
|
148 ui_filters = ui.filters
|
bsw/jbe@19
|
149
|
bsw/jbe@19
|
150 if no_sort then
|
bsw/jbe@19
|
151 ui_filters = function(args) args.content() end
|
bsw/jbe@19
|
152 if issue.ranks_available then
|
bsw/jbe@19
|
153 initiatives_selector:add_order_by("initiative.rank, initiative.admitted DESC, vote_ratio(initiative.positive_votes, initiative.negative_votes) DESC, initiative.id")
|
bsw/jbe@19
|
154 else
|
bsw@274
|
155 initiatives_selector:add_order_by("CASE WHEN issue.population = 0 OR initiative.supporter_count = 0 OR initiative.supporter_count ISNULL THEN 0 ELSE initiative.supporter_count::float / issue.population::float END DESC, initiative.id")
|
bsw/jbe@19
|
156 end
|
bsw/jbe@19
|
157 end
|
bsw/jbe@19
|
158
|
bsw/jbe@19
|
159 ui_filters{
|
bsw/jbe@19
|
160 label = _"Change order",
|
bsw/jbe@19
|
161 order_filter,
|
bsw/jbe@19
|
162 selector = initiatives_selector,
|
bsw/jbe@19
|
163 content = function()
|
bsw/jbe@19
|
164 ui.paginate{
|
bsw/jbe@19
|
165 name = issue and "issue_" .. tostring(issue.id) .. "_page" or nil,
|
bsw/jbe@19
|
166 selector = initiatives_selector,
|
bsw@274
|
167 per_page = param.get("per_page", atom.number) or limit,
|
bsw/jbe@19
|
168 content = function()
|
bsw/jbe@19
|
169 local initiatives = initiatives_selector:exec()
|
bsw@274
|
170 if highlight_initiative then
|
bsw@274
|
171 local highlight_initiative_found
|
bsw@274
|
172 for i, initiative in ipairs(initiatives) do
|
bsw@274
|
173 if initiative.id == highlight_initiative.id then
|
bsw@274
|
174 highhighlight_initiative_found = true
|
bsw@274
|
175 end
|
bsw@274
|
176 end
|
bsw@274
|
177 if not highhighlight_initiative_found then
|
bsw@274
|
178 initiatives[#initiatives+1] = highlight_initiative
|
bsw@274
|
179 if more_initiatives_count then
|
bsw@274
|
180 more_initiatives_count = more_initiatives_count - 1
|
bsw@274
|
181 end
|
bsw@274
|
182 end
|
bsw@274
|
183 end
|
bsw/jbe@19
|
184 for i, initiative in ipairs(initiatives) do
|
bsw/jbe@19
|
185 local expanded = config.user_tab_mode == "accordeon_all_expanded" and expandable or
|
bsw/jbe@19
|
186 show_for_initiative and initiative.id == show_for_initiative.id
|
bsw/jbe@19
|
187 if expanded then
|
bsw/jbe@19
|
188 ui.script{ script = "lf_initiative_expanded['initiative_content_" .. tostring(initiative.id) .. "'] = true;" }
|
bsw/jbe@19
|
189 end
|
bsw/jbe@19
|
190 execute.view{
|
bsw/jbe@19
|
191 module = "initiative",
|
bsw/jbe@19
|
192 view = "_list_element",
|
bsw/jbe@19
|
193 params = {
|
bsw/jbe@19
|
194 initiative = initiative,
|
bsw@274
|
195 selected = highlight_initiative and highlight_initiative.id == initiative.id or nil,
|
bsw/jbe@19
|
196 expanded = expanded,
|
bsw/jbe@19
|
197 expandable = expandable
|
bsw/jbe@19
|
198 }
|
bsw/jbe@19
|
199 }
|
bsw/jbe@19
|
200 end
|
bsw/jbe@19
|
201 end
|
bsw/jbe@19
|
202 }
|
bsw/jbe@19
|
203 end
|
bsw/jbe@19
|
204 }
|
bsw/jbe@19
|
205
|
bsw/jbe@19
|
206 if more_initiatives_count then
|
bsw@274
|
207 local text
|
bsw@274
|
208 if more_initiatives_count == 1 then
|
bsw@274
|
209 text = _("and one more initiative")
|
bsw@274
|
210 else
|
bsw@274
|
211 text = _("and #{count} more initiatives", { count = more_initiatives_count })
|
bsw@274
|
212 end
|
bsw/jbe@19
|
213 ui.link{
|
bsw@274
|
214 attr = { class = "more_initiatives_link" },
|
bsw@274
|
215 content = text,
|
bsw/jbe@19
|
216 module = "issue",
|
bsw/jbe@19
|
217 view = "show",
|
bsw/jbe@19
|
218 id = issue.id,
|
bsw/jbe@19
|
219 }
|
bsw/jbe@19
|
220 end
|
bsw/jbe@19
|
221
|
bsw/jbe@19
|
222 end
|
bsw/jbe@19
|
223
|
bsw/jbe@19
|
224 if show_for_issue then
|
bsw/jbe@19
|
225 slot.put("<br />")
|
bsw/jbe@19
|
226
|
bsw/jbe@19
|
227 if issue and initiatives_count == 1 then
|
bsw/jbe@19
|
228 ui.container{
|
bsw/jbe@19
|
229 content = function()
|
bsw/jbe@19
|
230 if issue.fully_frozen or issue.closed then
|
bsw/jbe@19
|
231 slot.put(_"There were no more alternative initiatives.")
|
bsw/jbe@19
|
232 else
|
bsw/jbe@19
|
233 slot.put(_"There are no more alternative initiatives currently.")
|
bsw/jbe@19
|
234 end
|
bsw/jbe@19
|
235 end
|
bsw/jbe@19
|
236 }
|
bsw/jbe@19
|
237 end
|
bsw/jbe@19
|
238
|
bsw/jbe@19
|
239 end
|