summaryrefslogtreecommitdiff
path: root/lib/event_filter.rb
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com>2012-11-05 20:12:26 +0200
committerDmitriy Zaporozhets <dzaporozhets@sphereconsultinginc.com>2012-11-05 20:12:26 +0200
commitf555578414347855be452cc8ee095c1304768c2b (patch)
treebc752a4b3798478c837175dc34a3b9cf622e9d00 /lib/event_filter.rb
parentba567c8d76dabeb1cd80f0dce3683977a966a9a1 (diff)
downloadgitlab-ce-f555578414347855be452cc8ee095c1304768c2b.tar.gz
Added EventFilter class. Compeleted first version of dashbaord filtering
Diffstat (limited to 'lib/event_filter.rb')
-rw-r--r--lib/event_filter.rb68
1 files changed, 68 insertions, 0 deletions
diff --git a/lib/event_filter.rb b/lib/event_filter.rb
new file mode 100644
index 00000000000..14ab0193bf1
--- /dev/null
+++ b/lib/event_filter.rb
@@ -0,0 +1,68 @@
+class EventFilter
+ attr_accessor :params
+
+ class << self
+ def default_filter
+ %w{ push issues merge_requests team}
+ end
+
+ def push
+ 'push'
+ end
+
+ def merged
+ 'merged'
+ end
+
+ def comments
+ 'comments'
+ end
+
+ def team
+ 'team'
+ end
+ end
+
+ def initialize params
+ @params = if params
+ params.dup
+ else
+ []#EventFilter.default_filter
+ end
+ end
+
+ def apply_filter events
+ return events unless params.present?
+
+ filter = params.dup
+
+ actions = []
+ actions << Event::Pushed if filter.include? 'push'
+ actions << Event::Merged if filter.include? 'merged'
+
+ if filter.include? 'team'
+ actions << Event::Joined
+ actions << Event::Left
+ end
+
+ actions << Event::Commented if filter.include? 'comments'
+
+ events = events.where(action: actions)
+ end
+
+ def options key
+ filter = params.dup
+
+ if filter.include? key
+ filter.delete key
+ else
+ filter << key
+ end
+
+ filter
+ end
+
+ def active? key
+ params.include? key
+ end
+end