rev |
line source |
bsw/jbe@0
|
1 Issue = mondelefant.new_class()
|
bsw/jbe@0
|
2 Issue.table = 'issue'
|
bsw/jbe@0
|
3
|
bsw/jbe@0
|
4 Issue:add_reference{
|
bsw/jbe@0
|
5 mode = 'm1',
|
bsw/jbe@0
|
6 to = "Area",
|
bsw/jbe@0
|
7 this_key = 'area_id',
|
bsw/jbe@0
|
8 that_key = 'id',
|
bsw/jbe@0
|
9 ref = 'area',
|
bsw/jbe@0
|
10 }
|
bsw/jbe@0
|
11
|
bsw/jbe@0
|
12 Issue:add_reference{
|
bsw/jbe@0
|
13 mode = 'm1',
|
bsw/jbe@0
|
14 to = "Policy",
|
bsw/jbe@0
|
15 this_key = 'policy_id',
|
bsw/jbe@0
|
16 that_key = 'id',
|
bsw/jbe@0
|
17 ref = 'policy',
|
bsw/jbe@0
|
18 }
|
bsw/jbe@0
|
19
|
bsw/jbe@0
|
20 Issue:add_reference{
|
bsw/jbe@0
|
21 mode = '1m',
|
bsw/jbe@0
|
22 to = "Initiative",
|
bsw/jbe@0
|
23 this_key = 'id',
|
bsw/jbe@0
|
24 that_key = 'issue_id',
|
bsw/jbe@0
|
25 ref = 'initiatives',
|
bsw/jbe@0
|
26 back_ref = 'issue'
|
bsw/jbe@0
|
27 }
|
bsw/jbe@0
|
28
|
bsw/jbe@0
|
29 Issue:add_reference{
|
bsw/jbe@0
|
30 mode = '1m',
|
bsw/jbe@0
|
31 to = "Interest",
|
bsw/jbe@0
|
32 this_key = 'id',
|
bsw/jbe@0
|
33 that_key = 'issue_id',
|
bsw/jbe@0
|
34 ref = 'interests',
|
bsw/jbe@0
|
35 back_ref = 'issue',
|
bsw/jbe@0
|
36 default_order = '"id"'
|
bsw/jbe@0
|
37 }
|
bsw/jbe@0
|
38
|
bsw/jbe@0
|
39 Issue:add_reference{
|
bsw/jbe@0
|
40 mode = '1m',
|
bsw/jbe@0
|
41 to = "Supporter",
|
bsw/jbe@0
|
42 this_key = 'id',
|
bsw/jbe@0
|
43 that_key = 'issue_id',
|
bsw/jbe@0
|
44 ref = 'supporters',
|
bsw/jbe@0
|
45 back_ref = 'issue',
|
bsw/jbe@0
|
46 default_order = '"id"'
|
bsw/jbe@0
|
47 }
|
bsw/jbe@0
|
48
|
bsw/jbe@0
|
49 Issue:add_reference{
|
bsw/jbe@0
|
50 mode = '1m',
|
bsw/jbe@0
|
51 to = "DirectVoter",
|
bsw/jbe@0
|
52 this_key = 'id',
|
bsw/jbe@0
|
53 that_key = 'issue_id',
|
bsw/jbe@0
|
54 ref = 'direct_voters',
|
bsw/jbe@0
|
55 back_ref = 'issue',
|
bsw/jbe@0
|
56 default_order = '"member_id"'
|
bsw/jbe@0
|
57 }
|
bsw/jbe@0
|
58
|
bsw/jbe@0
|
59 Issue:add_reference{
|
bsw/jbe@0
|
60 mode = '1m',
|
bsw/jbe@0
|
61 to = "Vote",
|
bsw/jbe@0
|
62 this_key = 'id',
|
bsw/jbe@0
|
63 that_key = 'issue_id',
|
bsw/jbe@0
|
64 ref = 'votes',
|
bsw/jbe@0
|
65 back_ref = 'issue',
|
bsw/jbe@0
|
66 default_order = '"member_id", "initiative_id"'
|
bsw/jbe@0
|
67 }
|
bsw/jbe@0
|
68
|
bsw/jbe@0
|
69 Issue:add_reference{
|
bsw@2
|
70 mode = '1m',
|
bsw@2
|
71 to = "Delegation",
|
bsw@2
|
72 this_key = 'id',
|
bsw@2
|
73 that_key = 'issue_id',
|
bsw@2
|
74 ref = 'delegations',
|
bsw@2
|
75 back_ref = 'issue'
|
bsw@2
|
76 }
|
bsw@2
|
77
|
bsw@2
|
78 Issue:add_reference{
|
bsw/jbe@0
|
79 mode = 'mm',
|
bsw/jbe@0
|
80 to = "Member",
|
bsw/jbe@0
|
81 this_key = 'id',
|
bsw/jbe@0
|
82 that_key = 'id',
|
bsw/jbe@0
|
83 connected_by_table = 'interest',
|
bsw/jbe@0
|
84 connected_by_this_key = 'issue_id',
|
bsw/jbe@0
|
85 connected_by_that_key = 'member_id',
|
bsw/jbe@0
|
86 ref = 'members'
|
bsw/jbe@0
|
87 }
|
bsw/jbe@0
|
88
|
bsw@3
|
89 Issue:add_reference{
|
bsw@3
|
90 mode = 'mm',
|
bsw@3
|
91 to = "Member",
|
bsw@3
|
92 this_key = 'id',
|
bsw@3
|
93 that_key = 'id',
|
bsw@3
|
94 connected_by_table = 'direct_interest_snapshot',
|
bsw@3
|
95 connected_by_this_key = 'issue_id',
|
bsw@3
|
96 connected_by_that_key = 'member_id',
|
bsw@3
|
97 ref = 'interested_members_snapshot'
|
bsw@3
|
98 }
|
bsw@3
|
99
|
bsw/jbe@6
|
100 Issue:add_reference{
|
bsw/jbe@6
|
101 mode = 'mm',
|
bsw/jbe@6
|
102 to = "Member",
|
bsw/jbe@6
|
103 this_key = 'id',
|
bsw/jbe@6
|
104 that_key = 'id',
|
bsw/jbe@6
|
105 connected_by_table = 'direct_voter',
|
bsw/jbe@6
|
106 connected_by_this_key = 'issue_id',
|
bsw/jbe@6
|
107 connected_by_that_key = 'member_id',
|
bsw/jbe@6
|
108 ref = 'direct_voters'
|
bsw/jbe@6
|
109 }
|
bsw/jbe@6
|
110
|
bsw@525
|
111 Issue:add_reference{
|
bsw@525
|
112 mode = "11",
|
bsw@525
|
113 to = mondelefant.class_prototype,
|
bsw@525
|
114 this_key = "id",
|
bsw@525
|
115 that_key = "issue_id",
|
bsw@525
|
116 ref = "delegation_info",
|
bsw@525
|
117 back_ref = "issue",
|
bsw@525
|
118 selector_generator = function(list, options)
|
bsw@525
|
119 assert(options.member_id, "member_id mandatory for delegation_info")
|
bsw@525
|
120 local ids = { sep = ", " }
|
bsw@525
|
121 for i, object in ipairs(list) do
|
bsw@525
|
122 local id = object.id
|
bsw@525
|
123 if id ~= nil then
|
bsw@525
|
124 ids[#ids+1] = {"?", id}
|
bsw@525
|
125 end
|
bsw@525
|
126 end
|
bsw@525
|
127 local sub_selector = Issue:get_db_conn():new_selector()
|
bsw@525
|
128 if #ids == 0 then
|
bsw@525
|
129 return sub_selector:empty_list_mode()
|
bsw@525
|
130 end
|
bsw@525
|
131 sub_selector:from("issue")
|
bsw@525
|
132 sub_selector:add_field("issue.id", "issue_id")
|
bsw@529
|
133 sub_selector:add_field{ '(delegation_info(?, null, null, issue.id, ?)).*', options.member_id, options.trustee_id }
|
bsw@525
|
134 sub_selector:add_where{ 'issue.id IN ($)', ids }
|
bsw@525
|
135
|
bsw@525
|
136 local selector = Issue:get_db_conn():new_selector()
|
bsw@525
|
137 selector:add_from(sub_selector, "delegation_info")
|
bsw@525
|
138 selector:left_join("member", "first_trustee", "first_trustee.id = delegation_info.first_trustee_id")
|
bsw@525
|
139 selector:left_join("member", "other_trustee", "other_trustee.id = delegation_info.other_trustee_id")
|
bsw@525
|
140 selector:add_field("delegation_info.*")
|
bsw@525
|
141 selector:add_field("first_trustee.name", "first_trustee_name")
|
bsw@525
|
142 selector:add_field("other_trustee.name", "other_trustee_name")
|
bsw@525
|
143 return selector
|
bsw@525
|
144 end
|
bsw@525
|
145 }
|
bsw@525
|
146
|
bsw@529
|
147 function Issue.list:load_delegation_info_once_for_member_id(member_id, trustee_id)
|
bsw@525
|
148 if self._delegation_info_loaded_for_member_id ~= member_id then
|
bsw@529
|
149 self:load("delegation_info", { member_id = member_id, trustee_id = trustee_id })
|
bsw@525
|
150 for i, issue in ipairs(self) do
|
bsw@525
|
151 issue._delegation_info_loaded_for_member_id = member_id
|
bsw@525
|
152 end
|
bsw@525
|
153 self._delegation_info_loaded_for_member_id = member_id
|
bsw@525
|
154 end
|
bsw@525
|
155 end
|
bsw@525
|
156
|
bsw@529
|
157 function Issue.object:load_delegation_info_once_for_member_id(member_id, trustee_id)
|
bsw@525
|
158 if self._delegation_info_loaded_for_member_id ~= member_id then
|
bsw@529
|
159 self:load("delegation_info", { member_id = member_id, trustee_id = trustee_id })
|
bsw@525
|
160 self._delegation_info_loaded_for_member_id = member_id
|
bsw@525
|
161 end
|
bsw@525
|
162 end
|
bsw/jbe@6
|
163
|
bsw/jbe@6
|
164
|
bsw/jbe@0
|
165 function Issue:get_state_name_for_state(value)
|
bsw@2
|
166 local state_name_table = {
|
bsw@2
|
167 new = _"New",
|
bsw@3
|
168 accepted = _"Discussion",
|
bsw@2
|
169 frozen = _"Frozen",
|
bsw@2
|
170 voting = _"Voting",
|
bsw@2
|
171 finished = _"Finished",
|
bsw@2
|
172 cancelled = _"Cancelled"
|
bsw@2
|
173 }
|
bsw@10
|
174 return state_name_table[value] or value or ''
|
bsw/jbe@0
|
175 end
|
bsw/jbe@0
|
176
|
bsw@2
|
177 function Issue:get_search_selector(search_string)
|
bsw/jbe@0
|
178 return self:new_selector()
|
bsw/jbe@0
|
179 :join('"initiative"', nil, '"initiative"."issue_id" = "issue"."id"')
|
bsw/jbe@6
|
180 :join('"draft"', nil, '"draft"."initiative_id" = "initiative"."id"')
|
bsw/jbe@6
|
181 :add_where{ '"initiative"."text_search_data" @@ "text_search_query"(?) OR "draft"."text_search_data" @@ "text_search_query"(?)', search_string, search_string }
|
bsw/jbe@6
|
182 :add_group_by('"issue"."id"')
|
bsw@481
|
183 :add_group_by('"issue"."state"')
|
bsw/jbe@6
|
184 :add_group_by('"issue"."area_id"')
|
bsw/jbe@6
|
185 :add_group_by('"issue"."policy_id"')
|
bsw/jbe@6
|
186 :add_group_by('"issue"."created"')
|
bsw/jbe@6
|
187 :add_group_by('"issue"."accepted"')
|
bsw/jbe@6
|
188 :add_group_by('"issue"."half_frozen"')
|
bsw/jbe@6
|
189 :add_group_by('"issue"."fully_frozen"')
|
bsw/jbe@6
|
190 :add_group_by('"issue"."closed"')
|
bsw/jbe@6
|
191 :add_group_by('"issue"."ranks_available"')
|
bsw@483
|
192 :add_group_by('"issue"."status_quo_schulze_rank"')
|
poelzi@140
|
193 :add_group_by('"issue"."cleaned"')
|
bsw/jbe@6
|
194 :add_group_by('"issue"."snapshot"')
|
bsw/jbe@6
|
195 :add_group_by('"issue"."latest_snapshot_event"')
|
bsw/jbe@6
|
196 :add_group_by('"issue"."population"')
|
bsw/jbe@6
|
197 :add_group_by('"issue"."voter_count"')
|
bsw@75
|
198 :add_group_by('"issue"."admission_time"')
|
bsw@75
|
199 :add_group_by('"issue"."discussion_time"')
|
bsw@75
|
200 :add_group_by('"issue"."verification_time"')
|
bsw@75
|
201 :add_group_by('"issue"."voting_time"')
|
bsw/jbe@19
|
202 :add_group_by('"_interest"."member_id"')
|
bsw@480
|
203 :add_group_by("_delegating_interest.delegate_member_ids")
|
bsw/jbe@6
|
204 --:set_distinct()
|
bsw/jbe@0
|
205 end
|
bsw/jbe@0
|
206
|
bsw@75
|
207 function Issue:modify_selector_for_state(initiatives_selector, state)
|
bsw@51
|
208 if state == "new" then
|
bsw@75
|
209 initiatives_selector:add_where("issue.accepted ISNULL AND issue.closed ISNULL")
|
bsw@51
|
210 elseif state == "accepted" then
|
bsw@75
|
211 initiatives_selector:add_where("issue.accepted NOTNULL AND issue.half_frozen ISNULL AND issue.closed ISNULL")
|
bsw@51
|
212 elseif state == "frozen" then
|
bsw@75
|
213 initiatives_selector:add_where("issue.half_frozen NOTNULL AND issue.fully_frozen ISNULL AND issue.closed ISNULL")
|
bsw@51
|
214 elseif state == "voting" then
|
bsw@75
|
215 initiatives_selector:add_where("issue.fully_frozen NOTNULL AND issue.closed ISNULL")
|
bsw@51
|
216 elseif state == "finished" then
|
bsw@75
|
217 initiatives_selector:add_where("issue.fully_frozen NOTNULL AND issue.closed NOTNULL")
|
bsw@51
|
218 elseif state == "cancelled" then
|
bsw@75
|
219 initiatives_selector:add_where("issue.fully_frozen ISNULL AND issue.closed NOTNULL")
|
bsw@75
|
220 else
|
bsw@75
|
221 error("Invalid state")
|
bsw@51
|
222 end
|
bsw@51
|
223 end
|
bsw@51
|
224
|
bsw/jbe@0
|
225 function Issue.object_get:state()
|
bsw/jbe@52
|
226 if self.closed then
|
bsw/jbe@52
|
227 if self.fully_frozen then
|
bsw/jbe@5
|
228 return "finished"
|
bsw/jbe@0
|
229 else
|
bsw/jbe@52
|
230 return "cancelled"
|
bsw/jbe@0
|
231 end
|
bsw/jbe@52
|
232 elseif self.fully_frozen then
|
bsw/jbe@52
|
233 return "voting"
|
bsw/jbe@52
|
234 elseif self.half_frozen then
|
bsw/jbe@52
|
235 return "frozen"
|
bsw/jbe@52
|
236 elseif self.accepted then
|
bsw/jbe@52
|
237 return "accepted"
|
bsw/jbe@0
|
238 else
|
bsw/jbe@52
|
239 return "new"
|
bsw/jbe@0
|
240 end
|
bsw/jbe@52
|
241
|
bsw@2
|
242 end
|
bsw@2
|
243
|
bsw@2
|
244 function Issue.object_get:state_name()
|
bsw@2
|
245 return Issue:get_state_name_for_state(self.state)
|
bsw@2
|
246 end
|
bsw@2
|
247
|
bsw@2
|
248 function Issue.object_get:state_time_left()
|
bsw@2
|
249 local state = self.state
|
bsw@2
|
250 local last_event_time
|
bsw@2
|
251 local duration
|
bsw@2
|
252 if state == "new" then
|
bsw@2
|
253 last_event_time = self.created
|
bsw@25
|
254 duration = self.admission_time
|
bsw@2
|
255 elseif state == "accepted" then
|
bsw@2
|
256 last_event_time = self.accepted
|
bsw@25
|
257 duration = self.discussion_time
|
bsw@2
|
258 elseif state == "frozen" then
|
bsw@2
|
259 last_event_time = self.half_frozen
|
bsw@25
|
260 duration = self.verification_time
|
bsw@2
|
261 elseif state == "voting" then
|
bsw@2
|
262 last_event_time = self.fully_frozen
|
bsw@25
|
263 duration = self.voting_time
|
bsw@2
|
264 end
|
poelzi@125
|
265 return db:query{ "SELECT ?::timestamp + ?::interval - CURRENT_TIMESTAMP(0) as time_left", last_event_time, duration }[1].time_left
|
bsw@2
|
266 end
|
bsw@2
|
267
|
bsw@2
|
268 function Issue.object_get:next_states()
|
bsw@2
|
269 local state = self.state
|
bsw@2
|
270 local next_states
|
bsw@2
|
271 if state == "new" then
|
bsw@2
|
272 next_states = { "accepted", "cancelled" }
|
bsw@2
|
273 elseif state == "accepted" then
|
bsw@2
|
274 next_states = { "frozen" }
|
bsw@2
|
275 elseif state == "frozen" then
|
bsw@2
|
276 next_states = { "voting" }
|
bsw@2
|
277 elseif state == "voting" then
|
bsw@2
|
278 next_states = { "finished" }
|
bsw@2
|
279 end
|
bsw@2
|
280 return next_states
|
bsw@2
|
281 end
|
bsw@2
|
282
|
bsw@2
|
283 function Issue.object_get:next_states_names()
|
bsw@2
|
284 local next_states = self.next_states
|
bsw@2
|
285 if not next_states then
|
bsw@2
|
286 return
|
bsw@2
|
287 end
|
bsw@2
|
288 local state_names = {}
|
bsw@2
|
289 for i, state in ipairs(self.next_states) do
|
bsw@2
|
290 state_names[#state_names+1] = Issue:get_state_name_for_state(state)
|
bsw@2
|
291 end
|
bsw@2
|
292 return table.concat(state_names, ", ")
|
bsw@525
|
293 end
|
bsw@525
|
294
|
bsw@525
|
295 function Issue.object_get:etherpad_url()
|
bsw@525
|
296 return config.etherpad.base_url .. "p/" .. config.etherpad.group_id .. "$Issue" .. self.id
|
bsw/jbe@0
|
297 end |