liquid_feedback_frontend
view model/issue.lua @ 3:768faea1096d
Version alpha4
Members interested in an issue or supporting an initiative have a weight information attached. Browsing the members causing that weight is possible.
Initiatives may provide a link to an external discussion platform
Direct link on every initiative page to create an alternative initiative
Bugfix: No error when clicking "neutral", when "neutral" is currently selected
Members interested in an issue or supporting an initiative have a weight information attached. Browsing the members causing that weight is possible.
Initiatives may provide a link to an external discussion platform
Direct link on every initiative page to create an alternative initiative
Bugfix: No error when clicking "neutral", when "neutral" is currently selected
author | bsw |
---|---|
date | Mon Nov 30 12:00:00 2009 +0100 (2009-11-30) |
parents | 5c601807d397 |
children | afd9f769c7ae |
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 if self.ranks_available then
123 return "finished"
124 else
125 return "cancelled"
126 end
127 elseif self.fully_frozen then
128 return "voting"
129 elseif self.half_frozen then
130 return "frozen"
131 else
132 return "accepted"
133 end
134 else
135 if self.closed then
136 return "cancelled"
137 else
138 return "new"
139 end
140 end
141 end
143 function Issue.object_get:state_name()
144 return Issue:get_state_name_for_state(self.state)
145 end
147 function Issue.object_get:state_time_left()
148 local state = self.state
149 local last_event_time
150 local duration
151 if state == "new" then
152 last_event_time = self.created
153 duration = self.policy.admission_time
154 elseif state == "accepted" then
155 last_event_time = self.accepted
156 duration = self.policy.discussion_time
157 elseif state == "frozen" then
158 last_event_time = self.half_frozen
159 duration = self.policy.verification_time
160 elseif state == "voting" then
161 last_event_time = self.fully_frozen
162 duration = self.policy.voting_time
163 end
164 return db:query{ "SELECT ?::timestamp + ?::interval - now() as time_left", last_event_time, duration }[1].time_left
165 end
167 function Issue.object_get:next_states()
168 local state = self.state
169 local next_states
170 if state == "new" then
171 next_states = { "accepted", "cancelled" }
172 elseif state == "accepted" then
173 next_states = { "frozen" }
174 elseif state == "frozen" then
175 next_states = { "voting" }
176 elseif state == "voting" then
177 next_states = { "finished" }
178 end
179 return next_states
180 end
182 function Issue.object_get:next_states_names()
183 local next_states = self.next_states
184 if not next_states then
185 return
186 end
187 local state_names = {}
188 for i, state in ipairs(self.next_states) do
189 state_names[#state_names+1] = Issue:get_state_name_for_state(state)
190 end
191 return table.concat(state_names, ", ")
192 end