liquid_feedback_frontend
diff 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 |
line diff
1.1 --- a/model/issue.lua Wed Nov 18 12:00:00 2009 +0100 1.2 +++ b/model/issue.lua Mon Nov 23 12:00:00 2009 +0100 1.3 @@ -67,6 +67,15 @@ 1.4 } 1.5 1.6 Issue:add_reference{ 1.7 + mode = '1m', 1.8 + to = "Delegation", 1.9 + this_key = 'id', 1.10 + that_key = 'issue_id', 1.11 + ref = 'delegations', 1.12 + back_ref = 'issue' 1.13 +} 1.14 + 1.15 +Issue:add_reference{ 1.16 mode = 'mm', 1.17 to = "Member", 1.18 this_key = 'id', 1.19 @@ -78,32 +87,95 @@ 1.20 } 1.21 1.22 function Issue:get_state_name_for_state(value) 1.23 - local state_name_table = {} 1.24 + local state_name_table = { 1.25 + new = _"New", 1.26 + accepted = _"Accepted", 1.27 + frozen = _"Frozen", 1.28 + voting = _"Voting", 1.29 + finished = _"Finished", 1.30 + cancelled = _"Cancelled" 1.31 + } 1.32 return state_name_table[value] or value 1.33 end 1.34 1.35 -function Issue:search(search_string) 1.36 +function Issue:get_search_selector(search_string) 1.37 return self:new_selector() 1.38 :join('"initiative"', nil, '"initiative"."issue_id" = "issue"."id"') 1.39 - :add_where{ '"initiative"."name" ILIKE ?', "%" .. search_string:gsub("%%", "") .. "%" } 1.40 + :add_where{ '"initiative"."text_search_data" @@ "text_search_query"(?)', search_string } 1.41 :set_distinct() 1.42 - :exec() 1.43 end 1.44 1.45 function Issue.object_get:state() 1.46 if self.accepted then 1.47 - if self.frozen then 1.48 + if self.fully_frozen then 1.49 + return "voting" 1.50 + elseif self.half_frozen then 1.51 return "frozen" 1.52 elseif self.closed then 1.53 - return "closed" 1.54 + if self.ranks_available then 1.55 + return "finished" 1.56 + else 1.57 + return "cancelled" 1.58 + end 1.59 else 1.60 return "accepted" 1.61 end 1.62 else 1.63 if self.closed then 1.64 - return "closed" 1.65 + return "cancelled" 1.66 else 1.67 return "new" 1.68 end 1.69 end 1.70 +end 1.71 + 1.72 +function Issue.object_get:state_name() 1.73 + return Issue:get_state_name_for_state(self.state) 1.74 +end 1.75 + 1.76 +function Issue.object_get:state_time_left() 1.77 + local state = self.state 1.78 + local last_event_time 1.79 + local duration 1.80 + if state == "new" then 1.81 + last_event_time = self.created 1.82 + duration = self.policy.admission_time 1.83 + elseif state == "accepted" then 1.84 + last_event_time = self.accepted 1.85 + duration = self.policy.discussion_time 1.86 + elseif state == "frozen" then 1.87 + last_event_time = self.half_frozen 1.88 + duration = self.policy.verification_time 1.89 + elseif state == "voting" then 1.90 + last_event_time = self.fully_frozen 1.91 + duration = self.policy.voting_time 1.92 + end 1.93 + return db:query{ "SELECT ?::timestamp + ?::interval - now() as time_left", last_event_time, duration }[1].time_left 1.94 +end 1.95 + 1.96 +function Issue.object_get:next_states() 1.97 + local state = self.state 1.98 + local next_states 1.99 + if state == "new" then 1.100 + next_states = { "accepted", "cancelled" } 1.101 + elseif state == "accepted" then 1.102 + next_states = { "frozen" } 1.103 + elseif state == "frozen" then 1.104 + next_states = { "voting" } 1.105 + elseif state == "voting" then 1.106 + next_states = { "finished" } 1.107 + end 1.108 + return next_states 1.109 +end 1.110 + 1.111 +function Issue.object_get:next_states_names() 1.112 + local next_states = self.next_states 1.113 + if not next_states then 1.114 + return 1.115 + end 1.116 + local state_names = {} 1.117 + for i, state in ipairs(self.next_states) do 1.118 + state_names[#state_names+1] = Issue:get_state_name_for_state(state) 1.119 + end 1.120 + return table.concat(state_names, ", ") 1.121 end 1.122 \ No newline at end of file