Commit aca0caa8cc1a6bd481f87dd810284e69d3747050

Authored by Dmitriy Zaporozhets
2 parents d27cc91e d7bc1214

Merge pull request #2534 from AlexDenisov/ajax_activities

Reload activities/events on the dashboard page via ajax
app/assets/javascripts/dashboard.js.coffee 0 → 100644
... ... @@ -0,0 +1,30 @@
  1 +$ ->
  2 + dashboardPage()
  3 +
  4 +dashboardPage = ->
  5 + Pager.init 20, true
  6 + $(".event_filter_link").bind "click", (event) ->
  7 + event.preventDefault()
  8 + toggleFilter $(this)
  9 + reloadActivities()
  10 +
  11 +reloadActivities = ->
  12 + $(".content_list").html ''
  13 + Pager.init 20, true
  14 +
  15 +toggleFilter = (sender) ->
  16 + sender.parent().toggleClass "inactive"
  17 + event_filters = $.cookie("event_filter")
  18 + filter = sender.attr("id").split("_")[0]
  19 + if event_filters
  20 + event_filters = event_filters.split(",")
  21 + else
  22 + event_filters = new Array()
  23 +
  24 + index = event_filters.indexOf(filter)
  25 + if index is -1
  26 + event_filters.push filter
  27 + else
  28 + event_filters.splice index, 1
  29 +
  30 + $.cookie "event_filter", event_filters.join(",")
... ...
app/controllers/dashboard_controller.rb
... ... @@ -60,6 +60,7 @@ class DashboardController < ApplicationController
60 60 end
61 61  
62 62 def event_filter
63   - @event_filter ||= EventFilter.new(params[:event_filter])
  63 + filters = cookies['event_filter'].split(',') if cookies['event_filter']
  64 + @event_filter ||= EventFilter.new(filters)
64 65 end
65 66 end
... ...
app/helpers/events_helper.rb
... ... @@ -22,9 +22,6 @@ module EventsHelper
22 22  
23 23 def event_filter_link key, tooltip
24 24 key = key.to_s
25   -
26   - filter = @event_filter.options key
27   -
28 25 inactive = if @event_filter.active? key
29 26 nil
30 27 else
... ... @@ -32,7 +29,7 @@ module EventsHelper
32 29 end
33 30  
34 31 content_tag :div, class: "filter_icon #{inactive}" do
35   - link_to dashboard_path(event_filter: filter), class: 'has_tooltip', 'data-original-title' => tooltip do
  32 + link_to dashboard_path, class: 'has_tooltip event_filter_link', id: "#{key}_event_filter", 'data-original-title' => tooltip do
36 33 image_tag "event_filter_#{key}.png"
37 34 end
38 35 end
... ...
app/views/dashboard/index.html.haml
... ... @@ -7,5 +7,3 @@
7 7  
8 8 - else
9 9 = render "zero_authorized_projects"
10   -:javascript
11   - $(function(){ Pager.init(20, true); });
... ...
features/dashboard/event_filters.feature 0 → 100644
... ... @@ -0,0 +1,51 @@
  1 +Feature: Event filters
  2 + Background:
  3 + Given I sign in as a user
  4 + And I own a project
  5 + And this project has push event
  6 + And this project has new member event
  7 + And this project has merge request event
  8 + And I visit dashboard page
  9 +
  10 + @javascript
  11 + Scenario: I should see all events
  12 + Then I should see push event
  13 + And I should see new member event
  14 + And I should see merge request event
  15 +
  16 + @javascript
  17 + Scenario: I should see only pushed events
  18 + When I click "push" event filter
  19 + Then I should see push event
  20 + And I should not see new member event
  21 + And I should not see merge request event
  22 +
  23 + @javascript
  24 + Scenario: I should see only joined events
  25 + When I click "team" event filter
  26 + Then I should see new member event
  27 + And I should not see push event
  28 + And I should not see merge request event
  29 +
  30 + @javascript
  31 + Scenario: I should see only merged events
  32 + When I click "merge" event filter
  33 + Then I should see merge request event
  34 + And I should not see push event
  35 + And I should not see new member event
  36 +
  37 + @javascript
  38 + Scenario: I should see only selected events while page reloaded
  39 + When I click "push" event filter
  40 + And I visit dashboard page
  41 + Then I should see push event
  42 + And I should not see new member event
  43 + When I click "team" event filter
  44 + And I visit dashboard page
  45 + Then I should see push event
  46 + And I should see new member event
  47 + And I should not see merge request event
  48 + When I click "push" event filter
  49 + Then I should not see push event
  50 + And I should see new member event
  51 + And I should not see merge request event
... ...
features/steps/dashboard/dashboard_event_filters.rb 0 → 100644
... ... @@ -0,0 +1,87 @@
  1 +class EventFilters < Spinach::FeatureSteps
  2 + include SharedAuthentication
  3 + include SharedPaths
  4 + include SharedProject
  5 +
  6 + Then 'I should see push event' do
  7 + page.should have_selector('span.pushed')
  8 + end
  9 +
  10 + Then 'I should not see push event' do
  11 + page.should_not have_selector('span.pushed')
  12 + end
  13 +
  14 + Then 'I should see new member event' do
  15 + page.should have_selector('span.joined')
  16 + end
  17 +
  18 + And 'I should not see new member event' do
  19 + page.should_not have_selector('span.joined')
  20 + end
  21 +
  22 + Then 'I should see merge request event' do
  23 + page.should have_selector('span.merged')
  24 + end
  25 +
  26 + And 'I should not see merge request event' do
  27 + page.should_not have_selector('span.merged')
  28 + end
  29 +
  30 + And 'this project has push event' do
  31 + data = {
  32 + before: "0000000000000000000000000000000000000000",
  33 + after: "0220c11b9a3e6c69dc8fd35321254ca9a7b98f7e",
  34 + ref: "refs/heads/new_design",
  35 + user_id: @user.id,
  36 + user_name: @user.name,
  37 + repository: {
  38 + name: @project.name,
  39 + url: "localhost/rubinius",
  40 + description: "",
  41 + homepage: "localhost/rubinius",
  42 + private: true
  43 + }
  44 + }
  45 +
  46 + @event = Event.create(
  47 + project: @project,
  48 + action: Event::Pushed,
  49 + data: data,
  50 + author_id: @user.id
  51 + )
  52 + end
  53 +
  54 + And 'this project has new member event' do
  55 + user = create(:user, {name: "John Doe"})
  56 + Event.create(
  57 + project: @project,
  58 + author_id: user.id,
  59 + action: Event::Joined
  60 + )
  61 + end
  62 +
  63 + And 'this project has merge request event' do
  64 + merge_request = create :merge_request, author: @user, project: @project
  65 + Event.create(
  66 + project: @project,
  67 + action: Event::Merged,
  68 + target_id: merge_request.id,
  69 + target_type: "MergeRequest",
  70 + author_id: @user.id
  71 + )
  72 + end
  73 +
  74 + When 'I click "push" event filter' do
  75 + click_link("push_event_filter")
  76 + end
  77 +
  78 + When 'I click "team" event filter' do
  79 + click_link("team_event_filter")
  80 + end
  81 +
  82 + When 'I click "merge" event filter' do
  83 + click_link("merged_event_filter")
  84 + end
  85 +
  86 +end
  87 +
... ...