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