Commit 17af835387c996f82b46f3bade67d513b4e40cc5

Authored by Dmitriy Zaporozhets
1 parent 4675ff46

Add event filter for group and project show pages

app/assets/javascripts/activities.js.coffee 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +class Activities
  2 + constructor: ->
  3 + Pager.init 20, true
  4 + $(".event_filter_link").bind "click", (event) =>
  5 + event.preventDefault()
  6 + @toggleFilter($(event.currentTarget))
  7 + @reloadActivities()
  8 +
  9 + reloadActivities: ->
  10 + $(".content_list").html ''
  11 + Pager.init 20, true
  12 +
  13 +
  14 + toggleFilter: (sender) ->
  15 + sender.parent().toggleClass "inactive"
  16 + event_filters = $.cookie("event_filter")
  17 + filter = sender.attr("id").split("_")[0]
  18 + if event_filters
  19 + event_filters = event_filters.split(",")
  20 + else
  21 + event_filters = new Array()
  22 +
  23 + index = event_filters.indexOf(filter)
  24 + if index is -1
  25 + event_filters.push filter
  26 + else
  27 + event_filters.splice index, 1
  28 +
  29 + $.cookie "event_filter", event_filters.join(","), { path: '/' }
  30 +
  31 +@Activities = Activities
app/assets/javascripts/dashboard.js.coffee
1 class Dashboard 1 class Dashboard
2 constructor: -> 2 constructor: ->
3 - Pager.init 20, true  
4 @initSidebarTab() 3 @initSidebarTab()
5 4
6 - $(".event_filter_link").bind "click", (event) =>  
7 - event.preventDefault()  
8 - @toggleFilter($(event.currentTarget))  
9 - @reloadActivities()  
10 -  
11 $(".dash-filter").keyup -> 5 $(".dash-filter").keyup ->
12 terms = $(this).val() 6 terms = $(this).val()
13 uiBox = $(this).parents('.ui-box').first() 7 uiBox = $(this).parents('.ui-box').first()
@@ -24,27 +18,6 @@ class Dashboard @@ -24,27 +18,6 @@ class Dashboard
24 18
25 19
26 20
27 - reloadActivities: ->  
28 - $(".content_list").html ''  
29 - Pager.init 20, true  
30 -  
31 - toggleFilter: (sender) ->  
32 - sender.parent().toggleClass "inactive"  
33 - event_filters = $.cookie("event_filter")  
34 - filter = sender.attr("id").split("_")[0]  
35 - if event_filters  
36 - event_filters = event_filters.split(",")  
37 - else  
38 - event_filters = new Array()  
39 -  
40 - index = event_filters.indexOf(filter)  
41 - if index is -1  
42 - event_filters.push filter  
43 - else  
44 - event_filters.splice index, 1  
45 -  
46 - $.cookie "event_filter", event_filters.join(","), { path: '/' }  
47 -  
48 initSidebarTab: -> 21 initSidebarTab: ->
49 key = "dashboard_sidebar_filter" 22 key = "dashboard_sidebar_filter"
50 23
app/assets/javascripts/dispatcher.js.coffee
@@ -20,10 +20,11 @@ class Dispatcher @@ -20,10 +20,11 @@ class Dispatcher
20 Issues.init() 20 Issues.init()
21 when 'dashboard:show' 21 when 'dashboard:show'
22 new Dashboard() 22 new Dashboard()
  23 + new Activities()
23 when 'projects:commit:show' 24 when 'projects:commit:show'
24 new Commit() 25 new Commit()
25 when 'groups:show', 'projects:show' 26 when 'groups:show', 'projects:show'
26 - Pager.init(20, true) 27 + new Activities()
27 when 'projects:new', 'projects:edit' 28 when 'projects:new', 'projects:edit'
28 new Project() 29 new Project()
29 when 'projects:walls:show' 30 when 'projects:walls:show'
app/controllers/application_controller.rb
@@ -155,4 +155,9 @@ class ApplicationController < ActionController::Base @@ -155,4 +155,9 @@ class ApplicationController < ActionController::Base
155 redirect_to new_profile_password_path and return 155 redirect_to new_profile_password_path and return
156 end 156 end
157 end 157 end
  158 +
  159 + def event_filter
  160 + filters = cookies['event_filter'].split(',') if cookies['event_filter'].present?
  161 + @event_filter ||= EventFilter.new(filters)
  162 + end
158 end 163 end
app/controllers/dashboard_controller.rb
@@ -66,9 +66,4 @@ class DashboardController < ApplicationController @@ -66,9 +66,4 @@ class DashboardController < ApplicationController
66 def load_projects 66 def load_projects
67 @projects = current_user.authorized_projects.sorted_by_activity 67 @projects = current_user.authorized_projects.sorted_by_activity
68 end 68 end
69 -  
70 - def event_filter  
71 - filters = cookies['event_filter'].split(',') if cookies['event_filter'].present?  
72 - @event_filter ||= EventFilter.new(filters)  
73 - end  
74 end 69 end
app/controllers/groups_controller.rb
@@ -31,7 +31,9 @@ class GroupsController < ApplicationController @@ -31,7 +31,9 @@ class GroupsController < ApplicationController
31 end 31 end
32 32
33 def show 33 def show
34 - @events = Event.in_projects(project_ids).limit(20).offset(params[:offset] || 0) 34 + @events = Event.in_projects(project_ids)
  35 + @events = event_filter.apply_filter(@events)
  36 + @events = @events.limit(20).offset(params[:offset] || 0)
35 @last_push = current_user.recent_push 37 @last_push = current_user.recent_push
36 38
37 respond_to do |format| 39 respond_to do |format|
app/controllers/projects_controller.rb
@@ -55,7 +55,10 @@ class ProjectsController < Projects::ApplicationController @@ -55,7 +55,10 @@ class ProjectsController < Projects::ApplicationController
55 55
56 def show 56 def show
57 limit = (params[:limit] || 20).to_i 57 limit = (params[:limit] || 20).to_i
58 - @events = @project.events.recent.limit(limit).offset(params[:offset] || 0) 58 +
  59 + @events = @project.events.recent
  60 + @events = event_filter.apply_filter(@events)
  61 + @events = @events.limit(limit).offset(params[:offset] || 0)
59 62
60 # Ensure project default branch is set if it possible 63 # Ensure project default branch is set if it possible
61 # Normally it defined on push or during creation 64 # Normally it defined on push or during creation
app/helpers/events_helper.rb
@@ -28,7 +28,7 @@ module EventsHelper @@ -28,7 +28,7 @@ module EventsHelper
28 end 28 end
29 29
30 content_tag :div, class: "filter_icon #{inactive}" do 30 content_tag :div, class: "filter_icon #{inactive}" do
31 - link_to dashboard_path, class: 'has_tooltip event_filter_link', id: "#{key}_event_filter", 'data-original-title' => tooltip do 31 + link_to request.path, class: 'has_tooltip event_filter_link', id: "#{key}_event_filter", 'data-original-title' => tooltip do
32 content_tag :i, nil, class: icon_for_event[key] 32 content_tag :i, nil, class: icon_for_event[key]
33 end 33 end
34 end 34 end
app/views/dashboard/_activities.html.haml
1 = render "events/event_last_push", event: @last_push 1 = render "events/event_last_push", event: @last_push
2 -  
3 -.event_filter  
4 - = event_filter_link EventFilter.push, 'Push events'  
5 - = event_filter_link EventFilter.merged, 'Merge events'  
6 - = event_filter_link EventFilter.comments, 'Comments'  
7 - = event_filter_link EventFilter.team, 'Team' 2 += render 'shared/event_filter'
8 3
9 - if @events.any? 4 - if @events.any?
10 .content_list 5 .content_list
app/views/groups/show.html.haml
@@ -6,6 +6,7 @@ @@ -6,6 +6,7 @@
6   6  
7 %span.cgray You will only see events from projects in this group 7 %span.cgray You will only see events from projects in this group
8 %hr 8 %hr
  9 + = render 'shared/event_filter'
9 - if @events.any? 10 - if @events.any?
10 .content_list 11 .content_list
11 - else 12 - else
app/views/projects/show.html.haml
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 .row 3 .row
4 .span9 4 .span9
5 = render "events/event_last_push", event: @last_push 5 = render "events/event_last_push", event: @last_push
  6 + = render 'shared/event_filter'
6 .content_list 7 .content_list
7 .loading.hide 8 .loading.hide
8 .span3 9 .span3
app/views/shared/_event_filter.html.haml 0 → 100644
@@ -0,0 +1,5 @@ @@ -0,0 +1,5 @@
  1 +.event_filter
  2 + = event_filter_link EventFilter.push, 'Push events'
  3 + = event_filter_link EventFilter.merged, 'Merge events'
  4 + = event_filter_link EventFilter.comments, 'Comments'
  5 + = event_filter_link EventFilter.team, 'Team'