diff --git a/app/assets/javascripts/dashboard.js b/app/assets/javascripts/dashboard.js new file mode 100644 index 0000000000000000000000000000000000000000..0261926af2b52594498102f2e9f6eb7bdfd417cb --- /dev/null +++ b/app/assets/javascripts/dashboard.js @@ -0,0 +1,27 @@ +/** + * Init dashboard page + * + */ +function dashboardPage(){ + $(".event_filter_link").bind('click',(function(){ + enableFilter(this.id); + })); +} + +function enableFilter(sender_id){ + var event_filters = $.cookie('event_filter'); + var filter = sender_id.split('_')[0]; + if (!event_filters) { + event_filters = new Array(); + } else { + event_filters = event_filters.split(','); + } + var index = event_filters.indexOf(filter); + if (index == -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 461dd51b5700c318b10cbbbca317aaeb92a39350..57b5d312c0166cffcb7d01521f284c060e229bc0 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -58,7 +58,8 @@ 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 def dashboard_filter items diff --git a/app/helpers/events_helper.rb b/app/helpers/events_helper.rb index a2548a23e5e3b80803bf2561445cb4bab4d1cf40..f58d7f7b8521051df2569c7d014ba7316a3d94cc 100644 --- a/app/helpers/events_helper.rb +++ b/app/helpers/events_helper.rb @@ -36,9 +36,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 @@ -46,7 +43,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 6b360dc1fefef945e569f666c131eb66edd30293..1f94a16bcae5b407d8dbc8089922bfbed41936c2 100644 --- a/app/views/dashboard/index.html.haml +++ b/app/views/dashboard/index.html.haml @@ -1,3 +1,4 @@ += javascript_include_tag 'dashboard' - if @projects.any? .projects .activities.span8 @@ -45,6 +46,8 @@ - else If you will be added to project - it will be displayed here - :javascript - $(function(){ Pager.init(20); }); + $(function(){ + dashboardPage(); + Pager.init(20); + }); diff --git a/features/dashboard/event_filters.feature b/features/dashboard/event_filters.feature new file mode 100644 index 0000000000000000000000000000000000000000..635bf40570d91098b915012c45f3e966f34b6cb6 --- /dev/null +++ b/features/dashboard/event_filters.feature @@ -0,0 +1,50 @@ +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 + + 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 0000000000000000000000000000000000000000..bfc053631ab241c416ab007504e63c0e0f5bb608 --- /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 +