diff --git a/app/assets/javascripts/dashboard.js.coffee b/app/assets/javascripts/dashboard.js.coffee new file mode 100644 index 00000000000..b0ae6bf8a02 --- /dev/null +++ b/app/assets/javascripts/dashboard.js.coffee @@ -0,0 +1,30 @@ +$ -> + dashboardPage() + +dashboardPage = -> + Pager.init 20, true + $(".event_filter_link").bind "click", (event) -> + event.preventDefault() + toggleFilter $(this) + reloadActivities() + +reloadActivities = -> + $(".content_list").html '' + Pager.init 20, true + +toggleFilter = (sender) -> + sender.parent().toggleClass "inactive" + event_filters = $.cookie("event_filter") + filter = sender.attr("id").split("_")[0] + if event_filters + event_filters = event_filters.split(",") + else + event_filters = new Array() + + index = event_filters.indexOf(filter) + if index is -1 + event_filters.push filter + else + event_filters.splice index, 1 + + $.cookie "event_filter", event_filters.join(",") diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 4bd840a07fb..c0ec4708e0a 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -60,6 +60,7 @@ class DashboardController < ApplicationController end def event_filter - @event_filter ||= EventFilter.new(params[:event_filter]) + filters = cookies['event_filter'].split(',') if cookies['event_filter'] + @event_filter ||= EventFilter.new(filters) end end diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index 2b9e7186bcd..9b9d2a913e9 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -22,9 +22,6 @@ module EventsHelper def event_filter_link key, tooltip key = key.to_s - - filter = @event_filter.options key - inactive = if @event_filter.active? key nil else @@ -32,7 +29,7 @@ module EventsHelper end content_tag :div, class: "filter_icon #{inactive}" do - link_to dashboard_path(event_filter: filter), class: 'has_tooltip', 'data-original-title' => tooltip do + link_to dashboard_path, class: 'has_tooltip event_filter_link', id: "#{key}_event_filter", 'data-original-title' => tooltip do image_tag "event_filter_#{key}.png" end end diff --git a/app/views/dashboard/index.html.haml b/app/views/dashboard/index.html.haml index d1422bda617..abbe3101fc3 100644 --- a/app/views/dashboard/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -7,5 +7,3 @@ - else = render "zero_authorized_projects" -:javascript - $(function(){ Pager.init(20, true); }); diff --git a/features/dashboard/event_filters.feature b/features/dashboard/event_filters.feature new file mode 100644 index 00000000000..e0c6b84b008 --- /dev/null +++ b/features/dashboard/event_filters.feature @@ -0,0 +1,51 @@ +Feature: Event filters + Background: + Given I sign in as a user + And I own a project + And this project has push event + And this project has new member event + And this project has merge request event + And I visit dashboard page + + @javascript + Scenario: I should see all events + Then I should see push event + And I should see new member event + And I should see merge request event + + @javascript + Scenario: I should see only pushed events + When I click "push" event filter + Then I should see push event + And I should not see new member event + And I should not see merge request event + + @javascript + Scenario: I should see only joined events + When I click "team" event filter + Then I should see new member event + And I should not see push event + And I should not see merge request event + + @javascript + Scenario: I should see only merged events + When I click "merge" event filter + Then I should see merge request event + And I should not see push event + And I should not see new member event + + @javascript + Scenario: I should see only selected events while page reloaded + When I click "push" event filter + And I visit dashboard page + Then I should see push event + And I should not see new member event + When I click "team" event filter + And I visit dashboard page + Then I should see push event + And I should see new member event + And I should not see merge request event + When I click "push" event filter + Then I should not see push event + And I should see new member event + And I should not see merge request event diff --git a/features/steps/dashboard/dashboard_event_filters.rb b/features/steps/dashboard/dashboard_event_filters.rb new file mode 100644 index 00000000000..bfc053631ab --- /dev/null +++ b/features/steps/dashboard/dashboard_event_filters.rb @@ -0,0 +1,87 @@ +class EventFilters < Spinach::FeatureSteps + include SharedAuthentication + include SharedPaths + include SharedProject + + Then 'I should see push event' do + page.should have_selector('span.pushed') + end + + Then 'I should not see push event' do + page.should_not have_selector('span.pushed') + end + + Then 'I should see new member event' do + page.should have_selector('span.joined') + end + + And 'I should not see new member event' do + page.should_not have_selector('span.joined') + end + + Then 'I should see merge request event' do + page.should have_selector('span.merged') + end + + And 'I should not see merge request event' do + page.should_not have_selector('span.merged') + end + + And 'this project has push event' do + data = { + before: "0000000000000000000000000000000000000000", + after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e", + ref: "refs/heads/new_design", + user_id: @user.id, + user_name: @user.name, + repository: { + name: @project.name, + url: "localhost/rubinius", + description: "", + homepage: "localhost/rubinius", + private: true + } + } + + @event = Event.create( + project: @project, + action: Event::Pushed, + data: data, + author_id: @user.id + ) + end + + And 'this project has new member event' do + user = create(:user, {name: "John Doe"}) + Event.create( + project: @project, + author_id: user.id, + action: Event::Joined + ) + end + + And 'this project has merge request event' do + merge_request = create :merge_request, author: @user, project: @project + Event.create( + project: @project, + action: Event::Merged, + target_id: merge_request.id, + target_type: "MergeRequest", + author_id: @user.id + ) + end + + When 'I click "push" event filter' do + click_link("push_event_filter") + end + + When 'I click "team" event filter' do + click_link("team_event_filter") + end + + When 'I click "merge" event filter' do + click_link("merged_event_filter") + end + +end +