Added EventFilter class. Compeleted first version of dashbaord filtering

This commit is contained in:
Dmitriy Zaporozhets 2012-11-05 20:12:26 +02:00
parent ba567c8d76
commit f555578414
10 changed files with 137 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 750 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 463 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 632 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -27,6 +27,9 @@ $ ->
# Initialize chosen selects
$('select.chosen').chosen()
# Initialize tooltips
$('.has_tooltip').tooltip()
# Disable form buttons while a form is submitting
$('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) ->
buttons = $('[type="submit"]', @)

View file

@ -115,3 +115,34 @@
margin: -3px;
}
}
/**
* Event filter
*
*/
.event_filter {
position: absolute;
width: 40px;
.filter_icon {
float: left;
border-left: 3px solid #4bc;
padding: 7px;
background: #f9f9f9;
margin-bottom: 10px;
img {
width:20px;
}
&.inactive {
border-left: 3px solid #EEE;
opacity: 0.5;
}
}
}
.activities {
.content_list {
margin-left:50px;
}
}

View file

@ -1,12 +1,17 @@
class DashboardController < ApplicationController
respond_to :html
before_filter :event_filter, only: :index
def index
@groups = Group.where(id: current_user.projects.pluck(:group_id))
@projects = current_user.projects_with_events
@projects = @projects.page(params[:page]).per(30)
@events = Event.in_projects(current_user.project_ids).limit(20).offset(params[:offset] || 0)
@events = Event.in_projects(current_user.project_ids)
@events = @event_filter.apply_filter(@events)
@events = @events.limit(20).offset(params[:offset] || 0)
@last_push = current_user.recent_push
respond_to do |format|
@ -34,4 +39,8 @@ class DashboardController < ApplicationController
format.atom { render layout: false }
end
end
def event_filter
@event_filter ||= EventFilter.new(params[:event_filter])
end
end

View file

@ -33,4 +33,22 @@ module EventsHelper
image_tag event_image_path
end
end
def event_filter_link key, tooltip
key = key.to_s
filter = @event_filter.options key
inactive = if @event_filter.active? key
nil
else
'inactive'
end
content_tag :div, class: "filter_icon #{inactive}" do
link_to dashboard_path(event_filter: filter), class: 'has_tooltip', 'data-original-title' => tooltip do
image_tag "event_filter_#{key}.png"
end
end
end
end

View file

@ -3,6 +3,13 @@
.activities.span8
= render "events/event_last_push", event: @last_push
= render 'shared/no_ssh'
.event_filter
= event_filter_link EventFilter.push, 'Push events'
= event_filter_link EventFilter.merged, 'Merge events'
= event_filter_link EventFilter.comments, 'Comments'
= event_filter_link EventFilter.team, 'Team'
- if @events.any?
.content_list= render @events
- else

68
lib/event_filter.rb Normal file
View file

@ -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