diff options
author | jessib <jessib@leap.se> | 2012-12-18 13:45:49 -0800 |
---|---|---|
committer | jessib <jessib@leap.se> | 2012-12-18 13:45:49 -0800 |
commit | 66ce152d5124be52f31d51fc4171fd53ba3a915c (patch) | |
tree | a1381abbc899be4f5249fe9f3bd5fc71b19e4529 /help/app/models/ticket_selection.rb | |
parent | e61cae8d2fc5d5818e56433a45056a539b621bd3 (diff) |
Refactoring of code to filter/order tickets.
Diffstat (limited to 'help/app/models/ticket_selection.rb')
-rw-r--r-- | help/app/models/ticket_selection.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/help/app/models/ticket_selection.rb b/help/app/models/ticket_selection.rb new file mode 100644 index 0000000..77720f7 --- /dev/null +++ b/help/app/models/ticket_selection.rb @@ -0,0 +1,38 @@ +class TicketSelection + + def initialize(options = {}) + @options = options + end + + def finder_method + method = 'by_' + method += 'includes_post_by_and_' if !@options[:is_admin] or (@options[:admin_status] == 'mine') + method += 'is_open_and_' if @options[:open_status] != 'all' + method += @options[:sort_order].sub(/_(de|a)sc$/, '') + end + + def startkey + startkeys = [] + startkeys << @options[:user_id] if !@options[:is_admin] or (@options[:admin_status] == 'mine') + startkeys << (@options[:open_status] == 'open') if @options[:open_status] != 'all' + startkeys << 0 + startkeys = startkeys.join if startkeys.length == 1 #want string not array if just one thing in array + startkeys + end + + def endkey + endtime = Time.now + 2.days #TODO + if self.startkey.is_a?(Array) + endkeys = self.startkey + endkeys.pop + endkeys << endtime + else + endtime + end + end + + def order + 'descending' if @options[:sort_order].end_with? 'desc' + end + +end |