liquid_feedback_frontend
view model/issue.lua @ 6:8d91bccab0bf
Version beta2
Possibility to browse voters of a closed issue
Registration with invite code
Email confirmation and password recovery
Download function (for database dumps) added
Critical bug solved, which made it impossible to select your opinion on other peoples suggestions
Catching error, when trying to set an opinion on a suggestion which has been meanwhile deleted
Fixed wrong sorting order for "supporters" or "potential supporters"
Added format info for birthday (Error when entering dates in wrong format is NOT fixed in this release)
Strip space characters from certain fields and ensure they contain at least 3 characters
Showing grade in opinion/list as clear text instead of integer value
More information on initiative is displayed while voting
Colored notification box shown on pages of issues or initiatives which are currently in voting state
Changed default filter for issues to "Open"
Back link on suggestion page
Some optical changes
Removed wrong space character in LICENSE file
Possibility to browse voters of a closed issue
Registration with invite code
Email confirmation and password recovery
Download function (for database dumps) added
Critical bug solved, which made it impossible to select your opinion on other peoples suggestions
Catching error, when trying to set an opinion on a suggestion which has been meanwhile deleted
Fixed wrong sorting order for "supporters" or "potential supporters"
Added format info for birthday (Error when entering dates in wrong format is NOT fixed in this release)
Strip space characters from certain fields and ensure they contain at least 3 characters
Showing grade in opinion/list as clear text instead of integer value
More information on initiative is displayed while voting
Colored notification box shown on pages of issues or initiatives which are currently in voting state
Changed default filter for issues to "Open"
Back link on suggestion page
Some optical changes
Removed wrong space character in LICENSE file
author | bsw/jbe |
---|---|
date | Sat Jan 02 12:00:00 2010 +0100 (2010-01-02) |
parents | afd9f769c7ae |
children | 72c5e0ee7c98 |
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 Issue:add_reference{
101 mode = 'mm',
102 to = "Member",
103 this_key = 'id',
104 that_key = 'id',
105 connected_by_table = 'direct_voter',
106 connected_by_this_key = 'issue_id',
107 connected_by_that_key = 'member_id',
108 ref = 'direct_voters'
109 }
113 function Issue:get_state_name_for_state(value)
114 local state_name_table = {
115 new = _"New",
116 accepted = _"Discussion",
117 frozen = _"Frozen",
118 voting = _"Voting",
119 finished = _"Finished",
120 cancelled = _"Cancelled"
121 }
122 return state_name_table[value] or value
123 end
125 function Issue:get_search_selector(search_string)
126 return self:new_selector()
127 :join('"initiative"', nil, '"initiative"."issue_id" = "issue"."id"')
128 :join('"draft"', nil, '"draft"."initiative_id" = "initiative"."id"')
129 :add_where{ '"initiative"."text_search_data" @@ "text_search_query"(?) OR "draft"."text_search_data" @@ "text_search_query"(?)', search_string, search_string }
130 :add_group_by('"issue"."id"')
131 :add_group_by('"issue"."area_id"')
132 :add_group_by('"issue"."policy_id"')
133 :add_group_by('"issue"."created"')
134 :add_group_by('"issue"."accepted"')
135 :add_group_by('"issue"."half_frozen"')
136 :add_group_by('"issue"."fully_frozen"')
137 :add_group_by('"issue"."closed"')
138 :add_group_by('"issue"."ranks_available"')
139 :add_group_by('"issue"."snapshot"')
140 :add_group_by('"issue"."latest_snapshot_event"')
141 :add_group_by('"issue"."population"')
142 :add_group_by('"issue"."vote_now"')
143 :add_group_by('"issue"."vote_later"')
144 :add_group_by('"issue"."voter_count"')
145 --:set_distinct()
146 end
148 function Issue.object_get:state()
149 if self.accepted then
150 if self.closed then
151 return "finished"
152 elseif self.fully_frozen then
153 return "voting"
154 elseif self.half_frozen then
155 return "frozen"
156 else
157 return "accepted"
158 end
159 else
160 if self.closed then
161 return "cancelled"
162 else
163 return "new"
164 end
165 end
166 end
168 function Issue.object_get:state_name()
169 return Issue:get_state_name_for_state(self.state)
170 end
172 function Issue.object_get:state_time_left()
173 local state = self.state
174 local last_event_time
175 local duration
176 if state == "new" then
177 last_event_time = self.created
178 duration = self.policy.admission_time
179 elseif state == "accepted" then
180 last_event_time = self.accepted
181 duration = self.policy.discussion_time
182 elseif state == "frozen" then
183 last_event_time = self.half_frozen
184 duration = self.policy.verification_time
185 elseif state == "voting" then
186 last_event_time = self.fully_frozen
187 duration = self.policy.voting_time
188 end
189 return db:query{ "SELECT ?::timestamp + ?::interval - now() as time_left", last_event_time, duration }[1].time_left
190 end
192 function Issue.object_get:next_states()
193 local state = self.state
194 local next_states
195 if state == "new" then
196 next_states = { "accepted", "cancelled" }
197 elseif state == "accepted" then
198 next_states = { "frozen" }
199 elseif state == "frozen" then
200 next_states = { "voting" }
201 elseif state == "voting" then
202 next_states = { "finished" }
203 end
204 return next_states
205 end
207 function Issue.object_get:next_states_names()
208 local next_states = self.next_states
209 if not next_states then
210 return
211 end
212 local state_names = {}
213 for i, state in ipairs(self.next_states) do
214 state_names[#state_names+1] = Issue:get_state_name_for_state(state)
215 end
216 return table.concat(state_names, ", ")
217 end