Commit f555578414347855be452cc8ee095c1304768c2b
1 parent
ba567c8d
Exists in
master
and in
4 other branches
Added EventFilter class. Compeleted first version of dashbaord filtering
Showing
10 changed files
with
137 additions
and
1 deletions
Show diff stats
750 Bytes
463 Bytes
632 Bytes
1.31 KB
app/assets/javascripts/main.js.coffee
@@ -27,6 +27,9 @@ $ -> | @@ -27,6 +27,9 @@ $ -> | ||
27 | # Initialize chosen selects | 27 | # Initialize chosen selects |
28 | $('select.chosen').chosen() | 28 | $('select.chosen').chosen() |
29 | 29 | ||
30 | + # Initialize tooltips | ||
31 | + $('.has_tooltip').tooltip() | ||
32 | + | ||
30 | # Disable form buttons while a form is submitting | 33 | # Disable form buttons while a form is submitting |
31 | $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) -> | 34 | $('body').on 'ajax:complete, ajax:beforeSend, submit', 'form', (e) -> |
32 | buttons = $('[type="submit"]', @) | 35 | buttons = $('[type="submit"]', @) |
app/assets/stylesheets/sections/events.scss
@@ -115,3 +115,34 @@ | @@ -115,3 +115,34 @@ | ||
115 | margin: -3px; | 115 | margin: -3px; |
116 | } | 116 | } |
117 | } | 117 | } |
118 | + | ||
119 | +/** | ||
120 | + * Event filter | ||
121 | + * | ||
122 | + */ | ||
123 | +.event_filter { | ||
124 | + position: absolute; | ||
125 | + width: 40px; | ||
126 | + | ||
127 | + .filter_icon { | ||
128 | + float: left; | ||
129 | + border-left: 3px solid #4bc; | ||
130 | + padding: 7px; | ||
131 | + background: #f9f9f9; | ||
132 | + margin-bottom: 10px; | ||
133 | + img { | ||
134 | + width:20px; | ||
135 | + } | ||
136 | + | ||
137 | + &.inactive { | ||
138 | + border-left: 3px solid #EEE; | ||
139 | + opacity: 0.5; | ||
140 | + } | ||
141 | + } | ||
142 | +} | ||
143 | + | ||
144 | +.activities { | ||
145 | + .content_list { | ||
146 | + margin-left:50px; | ||
147 | + } | ||
148 | +} |
app/controllers/dashboard_controller.rb
1 | class DashboardController < ApplicationController | 1 | class DashboardController < ApplicationController |
2 | respond_to :html | 2 | respond_to :html |
3 | 3 | ||
4 | + before_filter :event_filter, only: :index | ||
5 | + | ||
4 | def index | 6 | def index |
5 | @groups = Group.where(id: current_user.projects.pluck(:group_id)) | 7 | @groups = Group.where(id: current_user.projects.pluck(:group_id)) |
6 | @projects = current_user.projects_with_events | 8 | @projects = current_user.projects_with_events |
7 | @projects = @projects.page(params[:page]).per(30) | 9 | @projects = @projects.page(params[:page]).per(30) |
8 | 10 | ||
9 | - @events = Event.in_projects(current_user.project_ids).limit(20).offset(params[:offset] || 0) | 11 | + @events = Event.in_projects(current_user.project_ids) |
12 | + @events = @event_filter.apply_filter(@events) | ||
13 | + @events = @events.limit(20).offset(params[:offset] || 0) | ||
14 | + | ||
10 | @last_push = current_user.recent_push | 15 | @last_push = current_user.recent_push |
11 | 16 | ||
12 | respond_to do |format| | 17 | respond_to do |format| |
@@ -34,4 +39,8 @@ class DashboardController < ApplicationController | @@ -34,4 +39,8 @@ class DashboardController < ApplicationController | ||
34 | format.atom { render layout: false } | 39 | format.atom { render layout: false } |
35 | end | 40 | end |
36 | end | 41 | end |
42 | + | ||
43 | + def event_filter | ||
44 | + @event_filter ||= EventFilter.new(params[:event_filter]) | ||
45 | + end | ||
37 | end | 46 | end |
app/helpers/events_helper.rb
@@ -33,4 +33,22 @@ module EventsHelper | @@ -33,4 +33,22 @@ module EventsHelper | ||
33 | image_tag event_image_path | 33 | image_tag event_image_path |
34 | end | 34 | end |
35 | end | 35 | end |
36 | + | ||
37 | + def event_filter_link key, tooltip | ||
38 | + key = key.to_s | ||
39 | + | ||
40 | + filter = @event_filter.options key | ||
41 | + | ||
42 | + inactive = if @event_filter.active? key | ||
43 | + nil | ||
44 | + else | ||
45 | + 'inactive' | ||
46 | + end | ||
47 | + | ||
48 | + content_tag :div, class: "filter_icon #{inactive}" do | ||
49 | + link_to dashboard_path(event_filter: filter), class: 'has_tooltip', 'data-original-title' => tooltip do | ||
50 | + image_tag "event_filter_#{key}.png" | ||
51 | + end | ||
52 | + end | ||
53 | + end | ||
36 | end | 54 | end |
app/views/dashboard/index.html.haml
@@ -3,6 +3,13 @@ | @@ -3,6 +3,13 @@ | ||
3 | .activities.span8 | 3 | .activities.span8 |
4 | = render "events/event_last_push", event: @last_push | 4 | = render "events/event_last_push", event: @last_push |
5 | = render 'shared/no_ssh' | 5 | = render 'shared/no_ssh' |
6 | + | ||
7 | + .event_filter | ||
8 | + = event_filter_link EventFilter.push, 'Push events' | ||
9 | + = event_filter_link EventFilter.merged, 'Merge events' | ||
10 | + = event_filter_link EventFilter.comments, 'Comments' | ||
11 | + = event_filter_link EventFilter.team, 'Team' | ||
12 | + | ||
6 | - if @events.any? | 13 | - if @events.any? |
7 | .content_list= render @events | 14 | .content_list= render @events |
8 | - else | 15 | - else |
@@ -0,0 +1,68 @@ | @@ -0,0 +1,68 @@ | ||
1 | +class EventFilter | ||
2 | + attr_accessor :params | ||
3 | + | ||
4 | + class << self | ||
5 | + def default_filter | ||
6 | + %w{ push issues merge_requests team} | ||
7 | + end | ||
8 | + | ||
9 | + def push | ||
10 | + 'push' | ||
11 | + end | ||
12 | + | ||
13 | + def merged | ||
14 | + 'merged' | ||
15 | + end | ||
16 | + | ||
17 | + def comments | ||
18 | + 'comments' | ||
19 | + end | ||
20 | + | ||
21 | + def team | ||
22 | + 'team' | ||
23 | + end | ||
24 | + end | ||
25 | + | ||
26 | + def initialize params | ||
27 | + @params = if params | ||
28 | + params.dup | ||
29 | + else | ||
30 | + []#EventFilter.default_filter | ||
31 | + end | ||
32 | + end | ||
33 | + | ||
34 | + def apply_filter events | ||
35 | + return events unless params.present? | ||
36 | + | ||
37 | + filter = params.dup | ||
38 | + | ||
39 | + actions = [] | ||
40 | + actions << Event::Pushed if filter.include? 'push' | ||
41 | + actions << Event::Merged if filter.include? 'merged' | ||
42 | + | ||
43 | + if filter.include? 'team' | ||
44 | + actions << Event::Joined | ||
45 | + actions << Event::Left | ||
46 | + end | ||
47 | + | ||
48 | + actions << Event::Commented if filter.include? 'comments' | ||
49 | + | ||
50 | + events = events.where(action: actions) | ||
51 | + end | ||
52 | + | ||
53 | + def options key | ||
54 | + filter = params.dup | ||
55 | + | ||
56 | + if filter.include? key | ||
57 | + filter.delete key | ||
58 | + else | ||
59 | + filter << key | ||
60 | + end | ||
61 | + | ||
62 | + filter | ||
63 | + end | ||
64 | + | ||
65 | + def active? key | ||
66 | + params.include? key | ||
67 | + end | ||
68 | +end |