liquid_feedback_frontend

view model/issue.lua @ 2:5c601807d397

Version alpha3

Dark green part of issue supporter bargraph represents all satisfied supporters, regardless of having seen the latest draft

Wiki formatting for drafts

Showing differences between two drafts of the same initiative

Display of outgoing delegation chains

Many other improvements
author bsw
date Mon Nov 23 12:00:00 2009 +0100 (2009-11-23)
parents 3bfb2fcf7ab9
children 768faea1096d
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 function Issue:get_state_name_for_state(value)
90 local state_name_table = {
91 new = _"New",
92 accepted = _"Accepted",
93 frozen = _"Frozen",
94 voting = _"Voting",
95 finished = _"Finished",
96 cancelled = _"Cancelled"
97 }
98 return state_name_table[value] or value
99 end
101 function Issue:get_search_selector(search_string)
102 return self:new_selector()
103 :join('"initiative"', nil, '"initiative"."issue_id" = "issue"."id"')
104 :add_where{ '"initiative"."text_search_data" @@ "text_search_query"(?)', search_string }
105 :set_distinct()
106 end
108 function Issue.object_get:state()
109 if self.accepted then
110 if self.fully_frozen then
111 return "voting"
112 elseif self.half_frozen then
113 return "frozen"
114 elseif self.closed then
115 if self.ranks_available then
116 return "finished"
117 else
118 return "cancelled"
119 end
120 else
121 return "accepted"
122 end
123 else
124 if self.closed then
125 return "cancelled"
126 else
127 return "new"
128 end
129 end
130 end
132 function Issue.object_get:state_name()
133 return Issue:get_state_name_for_state(self.state)
134 end
136 function Issue.object_get:state_time_left()
137 local state = self.state
138 local last_event_time
139 local duration
140 if state == "new" then
141 last_event_time = self.created
142 duration = self.policy.admission_time
143 elseif state == "accepted" then
144 last_event_time = self.accepted
145 duration = self.policy.discussion_time
146 elseif state == "frozen" then
147 last_event_time = self.half_frozen
148 duration = self.policy.verification_time
149 elseif state == "voting" then
150 last_event_time = self.fully_frozen
151 duration = self.policy.voting_time
152 end
153 return db:query{ "SELECT ?::timestamp + ?::interval - now() as time_left", last_event_time, duration }[1].time_left
154 end
156 function Issue.object_get:next_states()
157 local state = self.state
158 local next_states
159 if state == "new" then
160 next_states = { "accepted", "cancelled" }
161 elseif state == "accepted" then
162 next_states = { "frozen" }
163 elseif state == "frozen" then
164 next_states = { "voting" }
165 elseif state == "voting" then
166 next_states = { "finished" }
167 end
168 return next_states
169 end
171 function Issue.object_get:next_states_names()
172 local next_states = self.next_states
173 if not next_states then
174 return
175 end
176 local state_names = {}
177 for i, state in ipairs(self.next_states) do
178 state_names[#state_names+1] = Issue:get_state_name_for_state(state)
179 end
180 return table.concat(state_names, ", ")
181 end

Impressum / About Us