Skip to content

Commit f555578

Browse files
author
Dmitriy Zaporozhets
committed
Added EventFilter class. Compeleted first version of dashbaord filtering
1 parent ba567c8 commit f555578

File tree

10 files changed

+137
-1
lines changed

10 files changed

+137
-1
lines changed
750 Bytes
Loading
463 Bytes
Loading
632 Bytes
Loading
1.31 KB
Loading

app/assets/javascripts/main.js.coffee

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ $ ->
2727
# Initialize chosen selects
2828
$('select.chosen').chosen()
2929

30+
# Initialize tooltips
31+
$('.has_tooltip').tooltip()
32+
3033
# Disable form buttons while a form is submitting
3134
$('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) ->
3235
buttons = $('[type="submit"]', @)

app/assets/stylesheets/sections/events.scss

+31
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,34 @@
115115
margin: -3px;
116116
}
117117
}
118+
119+
/**
120+
* Event filter
121+
*
122+
*/
123+
.event_filter {
124+
position: absolute;
125+
width: 40px;
126+
127+
.filter_icon {
128+
float: left;
129+
border-left: 3px solid #4bc;
130+
padding: 7px;
131+
background: #f9f9f9;
132+
margin-bottom: 10px;
133+
img {
134+
width:20px;
135+
}
136+
137+
&.inactive {
138+
border-left: 3px solid #EEE;
139+
opacity: 0.5;
140+
}
141+
}
142+
}
143+
144+
.activities {
145+
.content_list {
146+
margin-left:50px;
147+
}
148+
}

app/controllers/dashboard_controller.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,17 @@
11
class DashboardController < ApplicationController
22
respond_to :html
33

4+
before_filter :event_filter, only: :index
5+
46
def index
57
@groups = Group.where(id: current_user.projects.pluck(:group_id))
68
@projects = current_user.projects_with_events
79
@projects = @projects.page(params[:page]).per(30)
810

9-
@events = Event.in_projects(current_user.project_ids).limit(20).offset(params[:offset] || 0)
11+
@events = Event.in_projects(current_user.project_ids)
12+
@events = @event_filter.apply_filter(@events)
13+
@events = @events.limit(20).offset(params[:offset] || 0)
14+
1015
@last_push = current_user.recent_push
1116

1217
respond_to do |format|
@@ -34,4 +39,8 @@ def issues
3439
format.atom { render layout: false }
3540
end
3641
end
42+
43+
def event_filter
44+
@event_filter ||= EventFilter.new(params[:event_filter])
45+
end
3746
end

app/helpers/events_helper.rb

+18
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,22 @@ def event_image event
3333
image_tag event_image_path
3434
end
3535
end
36+
37+
def event_filter_link key, tooltip
38+
key = key.to_s
39+
40+
filter = @event_filter.options key
41+
42+
inactive = if @event_filter.active? key
43+
nil
44+
else
45+
'inactive'
46+
end
47+
48+
content_tag :div, class: "filter_icon #{inactive}" do
49+
link_to dashboard_path(event_filter: filter), class: 'has_tooltip', 'data-original-title' => tooltip do
50+
image_tag "event_filter_#{key}.png"
51+
end
52+
end
53+
end
3654
end

app/views/dashboard/index.html.haml

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
.activities.span8
44
= render "events/event_last_push", event: @last_push
55
= render 'shared/no_ssh'
6+
7+
.event_filter
8+
= event_filter_link EventFilter.push, 'Push events'
9+
= event_filter_link EventFilter.merged, 'Merge events'
10+
= event_filter_link EventFilter.comments, 'Comments'
11+
= event_filter_link EventFilter.team, 'Team'
12+
613
- if @events.any?
714
.content_list= render @events
815
- else

lib/event_filter.rb

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
class EventFilter
2+
attr_accessor :params
3+
4+
class << self
5+
def default_filter
6+
%w{ push issues merge_requests team}
7+
end
8+
9+
def push
10+
'push'
11+
end
12+
13+
def merged
14+
'merged'
15+
end
16+
17+
def comments
18+
'comments'
19+
end
20+
21+
def team
22+
'team'
23+
end
24+
end
25+
26+
def initialize params
27+
@params = if params
28+
params.dup
29+
else
30+
[]#EventFilter.default_filter
31+
end
32+
end
33+
34+
def apply_filter events
35+
return events unless params.present?
36+
37+
filter = params.dup
38+
39+
actions = []
40+
actions << Event::Pushed if filter.include? 'push'
41+
actions << Event::Merged if filter.include? 'merged'
42+
43+
if filter.include? 'team'
44+
actions << Event::Joined
45+
actions << Event::Left
46+
end
47+
48+
actions << Event::Commented if filter.include? 'comments'
49+
50+
events = events.where(action: actions)
51+
end
52+
53+
def options key
54+
filter = params.dup
55+
56+
if filter.include? key
57+
filter.delete key
58+
else
59+
filter << key
60+
end
61+
62+
filter
63+
end
64+
65+
def active? key
66+
params.include? key
67+
end
68+
end

0 commit comments

Comments
 (0)