diff --git a/app/assets/images/event_filter_comments.png b/app/assets/images/event_filter_comments.png new file mode 100644 index 0000000000000000000000000000000000000000..aed113faa7ae70e5c5fbe307ff24d5be39258d1f Binary files /dev/null and b/app/assets/images/event_filter_comments.png differ diff --git a/app/assets/images/event_filter_merged.png b/app/assets/images/event_filter_merged.png new file mode 100644 index 0000000000000000000000000000000000000000..30aea0b6e55985cc8e881d952d1f4282cc80a046 Binary files /dev/null and b/app/assets/images/event_filter_merged.png differ diff --git a/app/assets/images/event_filter_push.png b/app/assets/images/event_filter_push.png new file mode 100644 index 0000000000000000000000000000000000000000..930faee6aa2a441ab0805910cf815212f95cfe83 Binary files /dev/null and b/app/assets/images/event_filter_push.png differ diff --git a/app/assets/images/event_filter_team.png b/app/assets/images/event_filter_team.png new file mode 100644 index 0000000000000000000000000000000000000000..2dc66c85165bd02f5f2368415ccdf4820d4754d0 Binary files /dev/null and b/app/assets/images/event_filter_team.png differ diff --git a/app/assets/javascripts/main.js.coffee b/app/assets/javascripts/main.js.coffee index fb82f79900728fbd54aab0db646d9d42f1e9b236..04e6b2ef9d1278468cb173c33fa4f127da79cf4b 100644 --- a/app/assets/javascripts/main.js.coffee +++ b/app/assets/javascripts/main.js.coffee @@ -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"]', @) diff --git a/app/assets/stylesheets/sections/events.scss b/app/assets/stylesheets/sections/events.scss index 17df600c1af4faf8781483018c17969e191e76bf..99523639fe79fed5d7a080ea0d8ea11f7a098c4b 100644 --- a/app/assets/stylesheets/sections/events.scss +++ b/app/assets/stylesheets/sections/events.scss @@ -115,3 +115,29 @@ margin: -3px; } } + +/** + * Event filter + * + */ +.event_filter { + position: absolute; + width: 40px; + margin-left: -50px; + + .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; + } + } +} diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index af23f970a6d8914b6da26da3b5ca173d94b9f72e..012d86764ab9fd0eefb89ff7452b6a2e4f17bb5c 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a4d36c9bbc88566a9f83184f7122d8e3bf677b35..cba34c963a0b9db60f820f31cf0ccc7b7d0adff1 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -36,7 +36,7 @@ module ApplicationHelper else gravatar_prefix = request.ssl? ? "https://secure" : "http://www" user_email.strip! - "#{gravatar_prefix}.gravatar.com/avatar/#{Digest::MD5.hexdigest(user_email.downcase)}?s=#{size}&d=identicon" + "#{gravatar_prefix}.gravatar.com/avatar/#{Digest::MD5.hexdigest(user_email.downcase)}?s=#{size}&d=mm" end end diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 0eb87caadd7572686977c436b96b2e8efa54d297..a2548a23e5e3b80803bf2561445cb4bab4d1cf40 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -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 diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml index 6c4ff96bb50ffa78488e3fd81430f98ea2907878..d0882c6dab72af3e89151829a9f565d5e520f25d 100644 --- a/app/views/dashboard/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -3,10 +3,17 @@ .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 - %h4.nothing_here_message Projects activity will be displayed here + %p.nothing_here_message Projects activity will be displayed here .loading.hide .side - if @groups.present? diff --git a/lib/event_filter.rb b/lib/event_filter.rb new file mode 100644 index 0000000000000000000000000000000000000000..14ab0193bf125a6e872d5979a31aae356401ed1a --- /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