Merge pull request #2534 from AlexDenisov/ajax_activities

Reload activities/events on the dashboard page via ajax
This commit is contained in:
Dmitriy Zaporozhets 2013-01-09 13:26:54 -08:00
commit aca0caa8cc
6 changed files with 171 additions and 7 deletions

View file

@ -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(",")

View file

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

View file

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

View file

@ -7,5 +7,3 @@
- else
= render "zero_authorized_projects"
:javascript
$(function(){ Pager.init(20, true); });

View file

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

View file

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