liquid_feedback_frontend
view model/issue.lua @ 5:afd9f769c7ae
Version beta1
Final voting with Schulze-Method is now possible
Many bug fixes and code cleanup
Registration with invite codes
More sort and filter options
Seperated display of "supporters" and "potential supporters"
Optical changes
Flood limit / initiative contigent is now checked by frontend
Neccessary changes to access core beta11
Final voting with Schulze-Method is now possible
Many bug fixes and code cleanup
Registration with invite codes
More sort and filter options
Seperated display of "supporters" and "potential supporters"
Optical changes
Flood limit / initiative contigent is now checked by frontend
Neccessary changes to access core beta11
author | bsw/jbe |
---|---|
date | Fri Dec 25 12:00:00 2009 +0100 (2009-12-25) |
parents | 768faea1096d |
children | 8d91bccab0bf |
line source
1 Issue = mondelefant.new_class()
2 Issue.table = 'issue'
4 Issue:add_reference{
5 mode = 'm1',
6 to = "Area",
7 this_key = 'area_id',
8 that_key = 'id',
9 ref = 'area',
10 }
12 Issue:add_reference{
13 mode = 'm1',
14 to = "Policy",
15 this_key = 'policy_id',
16 that_key = 'id',
17 ref = 'policy',
18 }
20 Issue:add_reference{
21 mode = '1m',
22 to = "Initiative",
23 this_key = 'id',
24 that_key = 'issue_id',
25 ref = 'initiatives',
26 back_ref = 'issue'
27 }
29 Issue:add_reference{
30 mode = '1m',
31 to = "Interest",
32 this_key = 'id',
33 that_key = 'issue_id',
34 ref = 'interests',
35 back_ref = 'issue',
36 default_order = '"id"'
37 }
39 Issue:add_reference{
40 mode = '1m',
41 to = "Supporter",
42 this_key = 'id',
43 that_key = 'issue_id',
44 ref = 'supporters',
45 back_ref = 'issue',
46 default_order = '"id"'
47 }
49 Issue:add_reference{
50 mode = '1m',
51 to = "DirectVoter",
52 this_key = 'id',
53 that_key = 'issue_id',
54 ref = 'direct_voters',
55 back_ref = 'issue',
56 default_order = '"member_id"'
57 }
59 Issue:add_reference{
60 mode = '1m',
61 to = "Vote",
62 this_key = 'id',
63 that_key = 'issue_id',
64 ref = 'votes',
65 back_ref = 'issue',
66 default_order = '"member_id", "initiative_id"'
67 }
69 Issue:add_reference{
70 mode = '1m',
71 to = "Delegation",
72 this_key = 'id',
73 that_key = 'issue_id',
74 ref = 'delegations',
75 back_ref = 'issue'
76 }
78 Issue:add_reference{
79 mode = 'mm',
80 to = "Member",
81 this_key = 'id',
82 that_key = 'id',
83 connected_by_table = 'interest',
84 connected_by_this_key = 'issue_id',
85 connected_by_that_key = 'member_id',
86 ref = 'members'
87 }
89 Issue:add_reference{
90 mode = 'mm',
91 to = "Member",
92 this_key = 'id',
93 that_key = 'id',
94 connected_by_table = 'direct_interest_snapshot',
95 connected_by_this_key = 'issue_id',
96 connected_by_that_key = 'member_id',
97 ref = 'interested_members_snapshot'
98 }
100 function Issue:get_state_name_for_state(value)
101 local state_name_table = {
102 new = _"New",
103 accepted = _"Discussion",
104 frozen = _"Frozen",
105 voting = _"Voting",
106 finished = _"Finished",
107 cancelled = _"Cancelled"
108 }
109 return state_name_table[value] or value
110 end
112 function Issue:get_search_selector(search_string)
113 return self:new_selector()
114 :join('"initiative"', nil, '"initiative"."issue_id" = "issue"."id"')
115 :add_where{ '"initiative"."text_search_data" @@ "text_search_query"(?)', search_string }
116 :set_distinct()
117 end
119 function Issue.object_get:state()
120 if self.accepted then
121 if self.closed then
122 return "finished"
123 elseif self.fully_frozen then
124 return "voting"
125 elseif self.half_frozen then
126 return "frozen"
127 else
128 return "accepted"
129 end
130 else
131 if self.closed then
132 return "cancelled"
133 else
134 return "new"
135 end
136 end
137 end
139 function Issue.object_get:state_name()
140 return Issue:get_state_name_for_state(self.state)
141 end
143 function Issue.object_get:state_time_left()
144 local state = self.state
145 local last_event_time
146 local duration
147 if state == "new" then
148 last_event_time = self.created
149 duration = self.policy.admission_time
150 elseif state == "accepted" then
151 last_event_time = self.accepted
152 duration = self.policy.discussion_time
153 elseif state == "frozen" then
154 last_event_time = self.half_frozen
155 duration = self.policy.verification_time
156 elseif state == "voting" then
157 last_event_time = self.fully_frozen
158 duration = self.policy.voting_time
159 end
160 return db:query{ "SELECT ?::timestamp + ?::interval - now() as time_left", last_event_time, duration }[1].time_left
161 end
163 function Issue.object_get:next_states()
164 local state = self.state
165 local next_states
166 if state == "new" then
167 next_states = { "accepted", "cancelled" }
168 elseif state == "accepted" then
169 next_states = { "frozen" }
170 elseif state == "frozen" then
171 next_states = { "voting" }
172 elseif state == "voting" then
173 next_states = { "finished" }
174 end
175 return next_states
176 end
178 function Issue.object_get:next_states_names()
179 local next_states = self.next_states
180 if not next_states then
181 return
182 end
183 local state_names = {}
184 for i, state in ipairs(self.next_states) do
185 state_names[#state_names+1] = Issue:get_state_name_for_state(state)
186 end
187 return table.concat(state_names, ", ")
188 end