2014-09-02 18:07:02 +05:30
|
|
|
class EventFilter
|
|
|
|
attr_accessor :params
|
|
|
|
|
|
|
|
class << self
|
2016-11-03 12:29:30 +05:30
|
|
|
def all
|
|
|
|
'all'
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def push
|
|
|
|
'push'
|
|
|
|
end
|
|
|
|
|
|
|
|
def merged
|
|
|
|
'merged'
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def issue
|
|
|
|
'issue'
|
|
|
|
end
|
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
def comments
|
|
|
|
'comments'
|
|
|
|
end
|
|
|
|
|
|
|
|
def team
|
|
|
|
'team'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def initialize(params)
|
2014-09-02 18:07:02 +05:30
|
|
|
@params = if params
|
|
|
|
params.dup
|
|
|
|
else
|
2016-06-16 23:09:34 +05:30
|
|
|
[] # EventFilter.default_filter
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def apply_filter(events)
|
2017-08-17 22:00:37 +05:30
|
|
|
return events if params.blank? || params == EventFilter.all
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
case params
|
2016-11-03 12:29:30 +05:30
|
|
|
when EventFilter.push
|
2017-08-17 22:00:37 +05:30
|
|
|
events.where(action: Event::PUSHED)
|
2016-11-03 12:29:30 +05:30
|
|
|
when EventFilter.merged
|
2017-08-17 22:00:37 +05:30
|
|
|
events.where(action: Event::MERGED)
|
2016-11-03 12:29:30 +05:30
|
|
|
when EventFilter.comments
|
2017-08-17 22:00:37 +05:30
|
|
|
events.where(action: Event::COMMENTED)
|
2016-11-03 12:29:30 +05:30
|
|
|
when EventFilter.team
|
2017-08-17 22:00:37 +05:30
|
|
|
events.where(action: [Event::JOINED, Event::LEFT, Event::EXPIRED])
|
|
|
|
when EventFilter.issue
|
|
|
|
events.where(action: [Event::CREATED, Event::UPDATED, Event::CLOSED, Event::REOPENED])
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def options(key)
|
2014-09-02 18:07:02 +05:30
|
|
|
filter = params.dup
|
|
|
|
|
|
|
|
if filter.include? key
|
|
|
|
filter.delete key
|
|
|
|
else
|
|
|
|
filter << key
|
|
|
|
end
|
|
|
|
|
|
|
|
filter
|
|
|
|
end
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def active?(key)
|
2017-08-17 22:00:37 +05:30
|
|
|
if params.present?
|
|
|
|
params.include? key
|
|
|
|
else
|
|
|
|
key == EventFilter.all
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|