liquid_feedback_frontend
annotate model/issue.lua @ 75:733f65c0c0a0
Bugfixes, feature enhancements, code-cleanup, and major work on API
Details:
- API
-- Allow relation name to be passed to helper function util.autoapi{...}
-- Added area API
-- Bugfixes in API
--- Correctly return initiatives (bug #162)
--- Correctly process "id" parameter for initiative API
--- Bugfix related to "state" parameter (bug #165)
--- Changed constant "discussion" to "accepted" (in model/issue.lua, used by API)
--- Fixed JSON encoding in auto_api (bug #181)
--- Ignore list filter "voted" in case of public access
--- Enable access to API without session
- Work on RSS feed (incomplete yet)
- Other bugfixes
-- Handle empty browser identification string
-- Handle invalid date in member/update.lua (bugs #24 #109 #115 #136)
-- Better handle errors while converting uploaded images. (bug #79 +5 duplicates)
-- Don't display revoked initiatives in list of new drafts (bug #134)
-- Fixed syntax error in app/main/member/_action/update_name.lua throwing unexpected error, when new name was too short
-- Do not display refresh support button for revoked initiatives
-- Repaired issue search (bug #150)
-- Fixed typos in german translation files
--- "initi(i)erte"
--- "Er(g)eignisse" (bug #161)
- Code cleanup
-- Removed deprecated motd files locale/motd/de.txt and locale/motd/de_public.txt
-- Removed redundant code in app/main/index/_updated_drafts.lua
- New features and (optical) enhancements
-- Support change of notify email; notification of not approved address added to start page
-- Settings dialog splitted into single pages
-- Mark deactivated members
-- Calendar for birthday selection in profile
-- Policy list public readable when public access is enabled
Details:
- API
-- Allow relation name to be passed to helper function util.autoapi{...}
-- Added area API
-- Bugfixes in API
--- Correctly return initiatives (bug #162)
--- Correctly process "id" parameter for initiative API
--- Bugfix related to "state" parameter (bug #165)
--- Changed constant "discussion" to "accepted" (in model/issue.lua, used by API)
--- Fixed JSON encoding in auto_api (bug #181)
--- Ignore list filter "voted" in case of public access
--- Enable access to API without session
- Work on RSS feed (incomplete yet)
- Other bugfixes
-- Handle empty browser identification string
-- Handle invalid date in member/update.lua (bugs #24 #109 #115 #136)
-- Better handle errors while converting uploaded images. (bug #79 +5 duplicates)
-- Don't display revoked initiatives in list of new drafts (bug #134)
-- Fixed syntax error in app/main/member/_action/update_name.lua throwing unexpected error, when new name was too short
-- Do not display refresh support button for revoked initiatives
-- Repaired issue search (bug #150)
-- Fixed typos in german translation files
--- "initi(i)erte"
--- "Er(g)eignisse" (bug #161)
- Code cleanup
-- Removed deprecated motd files locale/motd/de.txt and locale/motd/de_public.txt
-- Removed redundant code in app/main/index/_updated_drafts.lua
- New features and (optical) enhancements
-- Support change of notify email; notification of not approved address added to start page
-- Settings dialog splitted into single pages
-- Mark deactivated members
-- Calendar for birthday selection in profile
-- Policy list public readable when public access is enabled
author | bsw |
---|---|
date | Thu Jul 08 18:44:02 2010 +0200 (2010-07-08) |
parents | 88ac7798b562 |
children | eb6509288d67 |
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@3 | 89 Issue:add_reference{ |
bsw@3 | 90 mode = 'mm', |
bsw@3 | 91 to = "Member", |
bsw@3 | 92 this_key = 'id', |
bsw@3 | 93 that_key = 'id', |
bsw@3 | 94 connected_by_table = 'direct_interest_snapshot', |
bsw@3 | 95 connected_by_this_key = 'issue_id', |
bsw@3 | 96 connected_by_that_key = 'member_id', |
bsw@3 | 97 ref = 'interested_members_snapshot' |
bsw@3 | 98 } |
bsw@3 | 99 |
bsw/jbe@6 | 100 Issue:add_reference{ |
bsw/jbe@6 | 101 mode = 'mm', |
bsw/jbe@6 | 102 to = "Member", |
bsw/jbe@6 | 103 this_key = 'id', |
bsw/jbe@6 | 104 that_key = 'id', |
bsw/jbe@6 | 105 connected_by_table = 'direct_voter', |
bsw/jbe@6 | 106 connected_by_this_key = 'issue_id', |
bsw/jbe@6 | 107 connected_by_that_key = 'member_id', |
bsw/jbe@6 | 108 ref = 'direct_voters' |
bsw/jbe@6 | 109 } |
bsw/jbe@6 | 110 |
bsw/jbe@6 | 111 |
bsw/jbe@6 | 112 |
bsw/jbe@0 | 113 function Issue:get_state_name_for_state(value) |
bsw@2 | 114 local state_name_table = { |
bsw@2 | 115 new = _"New", |
bsw@3 | 116 accepted = _"Discussion", |
bsw@2 | 117 frozen = _"Frozen", |
bsw@2 | 118 voting = _"Voting", |
bsw@2 | 119 finished = _"Finished", |
bsw@2 | 120 cancelled = _"Cancelled" |
bsw@2 | 121 } |
bsw@10 | 122 return state_name_table[value] or value or '' |
bsw/jbe@0 | 123 end |
bsw/jbe@0 | 124 |
bsw@2 | 125 function Issue:get_search_selector(search_string) |
bsw/jbe@0 | 126 return self:new_selector() |
bsw/jbe@0 | 127 :join('"initiative"', nil, '"initiative"."issue_id" = "issue"."id"') |
bsw/jbe@6 | 128 :join('"draft"', nil, '"draft"."initiative_id" = "initiative"."id"') |
bsw/jbe@6 | 129 :add_where{ '"initiative"."text_search_data" @@ "text_search_query"(?) OR "draft"."text_search_data" @@ "text_search_query"(?)', search_string, search_string } |
bsw/jbe@6 | 130 :add_group_by('"issue"."id"') |
bsw/jbe@6 | 131 :add_group_by('"issue"."area_id"') |
bsw/jbe@6 | 132 :add_group_by('"issue"."policy_id"') |
bsw/jbe@6 | 133 :add_group_by('"issue"."created"') |
bsw/jbe@6 | 134 :add_group_by('"issue"."accepted"') |
bsw/jbe@6 | 135 :add_group_by('"issue"."half_frozen"') |
bsw/jbe@6 | 136 :add_group_by('"issue"."fully_frozen"') |
bsw/jbe@6 | 137 :add_group_by('"issue"."closed"') |
bsw/jbe@6 | 138 :add_group_by('"issue"."ranks_available"') |
bsw/jbe@6 | 139 :add_group_by('"issue"."snapshot"') |
bsw/jbe@6 | 140 :add_group_by('"issue"."latest_snapshot_event"') |
bsw/jbe@6 | 141 :add_group_by('"issue"."population"') |
bsw/jbe@6 | 142 :add_group_by('"issue"."vote_now"') |
bsw/jbe@6 | 143 :add_group_by('"issue"."vote_later"') |
bsw/jbe@6 | 144 :add_group_by('"issue"."voter_count"') |
bsw@75 | 145 :add_group_by('"issue"."admission_time"') |
bsw@75 | 146 :add_group_by('"issue"."discussion_time"') |
bsw@75 | 147 :add_group_by('"issue"."verification_time"') |
bsw@75 | 148 :add_group_by('"issue"."voting_time"') |
bsw/jbe@19 | 149 :add_group_by('"_interest"."member_id"') |
bsw/jbe@6 | 150 --:set_distinct() |
bsw/jbe@0 | 151 end |
bsw/jbe@0 | 152 |
bsw@75 | 153 function Issue:modify_selector_for_state(initiatives_selector, state) |
bsw@51 | 154 if state == "new" then |
bsw@75 | 155 initiatives_selector:add_where("issue.accepted ISNULL AND issue.closed ISNULL") |
bsw@51 | 156 elseif state == "accepted" then |
bsw@75 | 157 initiatives_selector:add_where("issue.accepted NOTNULL AND issue.half_frozen ISNULL AND issue.closed ISNULL") |
bsw@51 | 158 elseif state == "frozen" then |
bsw@75 | 159 initiatives_selector:add_where("issue.half_frozen NOTNULL AND issue.fully_frozen ISNULL AND issue.closed ISNULL") |
bsw@51 | 160 elseif state == "voting" then |
bsw@75 | 161 initiatives_selector:add_where("issue.fully_frozen NOTNULL AND issue.closed ISNULL") |
bsw@51 | 162 elseif state == "finished" then |
bsw@75 | 163 initiatives_selector:add_where("issue.fully_frozen NOTNULL AND issue.closed NOTNULL") |
bsw@51 | 164 elseif state == "cancelled" then |
bsw@75 | 165 initiatives_selector:add_where("issue.fully_frozen ISNULL AND issue.closed NOTNULL") |
bsw@75 | 166 else |
bsw@75 | 167 error("Invalid state") |
bsw@51 | 168 end |
bsw@51 | 169 end |
bsw@51 | 170 |
bsw/jbe@0 | 171 function Issue.object_get:state() |
bsw/jbe@52 | 172 if self.closed then |
bsw/jbe@52 | 173 if self.fully_frozen then |
bsw/jbe@5 | 174 return "finished" |
bsw/jbe@0 | 175 else |
bsw/jbe@52 | 176 return "cancelled" |
bsw/jbe@0 | 177 end |
bsw/jbe@52 | 178 elseif self.fully_frozen then |
bsw/jbe@52 | 179 return "voting" |
bsw/jbe@52 | 180 elseif self.half_frozen then |
bsw/jbe@52 | 181 return "frozen" |
bsw/jbe@52 | 182 elseif self.accepted then |
bsw/jbe@52 | 183 return "accepted" |
bsw/jbe@0 | 184 else |
bsw/jbe@52 | 185 return "new" |
bsw/jbe@0 | 186 end |
bsw/jbe@52 | 187 |
bsw@2 | 188 end |
bsw@2 | 189 |
bsw@2 | 190 function Issue.object_get:state_name() |
bsw@2 | 191 return Issue:get_state_name_for_state(self.state) |
bsw@2 | 192 end |
bsw@2 | 193 |
bsw@2 | 194 function Issue.object_get:state_time_left() |
bsw@2 | 195 local state = self.state |
bsw@2 | 196 local last_event_time |
bsw@2 | 197 local duration |
bsw@2 | 198 if state == "new" then |
bsw@2 | 199 last_event_time = self.created |
bsw@25 | 200 duration = self.admission_time |
bsw@2 | 201 elseif state == "accepted" then |
bsw@2 | 202 last_event_time = self.accepted |
bsw@25 | 203 duration = self.discussion_time |
bsw@2 | 204 elseif state == "frozen" then |
bsw@2 | 205 last_event_time = self.half_frozen |
bsw@25 | 206 duration = self.verification_time |
bsw@2 | 207 elseif state == "voting" then |
bsw@2 | 208 last_event_time = self.fully_frozen |
bsw@25 | 209 duration = self.voting_time |
bsw@2 | 210 end |
bsw@2 | 211 return db:query{ "SELECT ?::timestamp + ?::interval - now() as time_left", last_event_time, duration }[1].time_left |
bsw@2 | 212 end |
bsw@2 | 213 |
bsw@2 | 214 function Issue.object_get:next_states() |
bsw@2 | 215 local state = self.state |
bsw@2 | 216 local next_states |
bsw@2 | 217 if state == "new" then |
bsw@2 | 218 next_states = { "accepted", "cancelled" } |
bsw@2 | 219 elseif state == "accepted" then |
bsw@2 | 220 next_states = { "frozen" } |
bsw@2 | 221 elseif state == "frozen" then |
bsw@2 | 222 next_states = { "voting" } |
bsw@2 | 223 elseif state == "voting" then |
bsw@2 | 224 next_states = { "finished" } |
bsw@2 | 225 end |
bsw@2 | 226 return next_states |
bsw@2 | 227 end |
bsw@2 | 228 |
bsw@2 | 229 function Issue.object_get:next_states_names() |
bsw@2 | 230 local next_states = self.next_states |
bsw@2 | 231 if not next_states then |
bsw@2 | 232 return |
bsw@2 | 233 end |
bsw@2 | 234 local state_names = {} |
bsw@2 | 235 for i, state in ipairs(self.next_states) do |
bsw@2 | 236 state_names[#state_names+1] = Issue:get_state_name_for_state(state) |
bsw@2 | 237 end |
bsw@2 | 238 return table.concat(state_names, ", ") |
bsw/jbe@0 | 239 end |