Permalink
Browse files

Use FilteringService for Dashboard, Group pages

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
  • Loading branch information...
1 parent 5e96ee3 commit 6153aa136007daa4b5c592190b72de389de8b032 @dzaporozhets dzaporozhets committed Jan 15, 2014
@@ -3,6 +3,8 @@ class DashboardController < ApplicationController
before_filter :load_projects, except: [:projects]
before_filter :event_filter, only: :show
+ before_filter :default_filter, only: [:issues, :merge_requests]
+
def show
# Fetch only 30 projects.
@@ -51,12 +53,12 @@ def projects
end
def merge_requests
- @merge_requests = FilterContext.new(MergeRequest, current_user, params).execute
+ @merge_requests = FilteringService.new.execute(MergeRequest, current_user, params)
@merge_requests = @merge_requests.recent.page(params[:page]).per(20)
end
def issues
- @issues = FilterContext.new(Issue, current_user, params).execute
+ @issues = FilteringService.new.execute(Issue, current_user, params)
@issues = @issues.recent.page(params[:page]).per(20)
@issues = @issues.includes(:author, :project)
@@ -71,4 +73,9 @@ def issues
def load_projects
@projects = current_user.authorized_projects.sorted_by_activity.non_archived
end
+
+ def default_filter
+ params[:scope] = 'assigned-to-me' if params[:scope].blank?
+ params[:state] = 'opened' if params[:state].blank?
+ end
end
@@ -10,6 +10,8 @@ class GroupsController < ApplicationController
# Load group projects
before_filter :projects, except: [:new, :create]
+ before_filter :default_filter, only: [:issues, :merge_requests]
+
layout :determine_layout
before_filter :set_title, only: [:new, :create]
@@ -43,18 +45,14 @@ def show
end
end
- # Get authored or assigned open merge requests
def merge_requests
- @merge_requests = FilterContext.new(MergeRequest, current_user, params).execute
- @merge_requests = @merge_requests.of_group(@group)
- @merge_requests = @merge_requests.recent.page(params[:page]).per(20)
+ @merge_requests = FilteringService.new.execute(MergeRequest, current_user, params)
+ @merge_requests = @merge_requests.page(params[:page]).per(20)
end
- # Get only assigned issues
def issues
- @issues = FilterContext.new(Issue, current_user, params).execute
- @issues = @issues.of_group(@group)
- @issues = @issues.recent.page(params[:page]).per(20)
+ @issues = FilteringService.new.execute(Issue, current_user, params)
+ @issues = @issues.page(params[:page]).per(20)
@issues = @issues.includes(:author, :project)
respond_to do |format|
@@ -130,4 +128,10 @@ def determine_layout
'group'
end
end
+
+ def default_filter
+ params[:scope] = 'assigned-to-me' if params[:scope].blank?
+ params[:state] = 'opened' if params[:state].blank?
+ params[:group_id] = @group.id
+ end
end
@@ -1,7 +1,7 @@
module DashboardHelper
def filter_path(entity, options={})
exist_opts = {
- status: params[:status],
+ state: params[:state],
scope: params[:scope],
project_id: params[:project_id],
}
@@ -2,8 +2,8 @@
= form_tag filter_path(entity), method: 'get' do
%fieldset.scope-filter
%ul.nav.nav-pills.nav-stacked
- %li{class: ("active" if params[:scope].blank?)}
- = link_to filter_path(entity, scope: nil) do
+ %li{class: ("active" if params[:scope] == 'assigned-to-me')}
+ = link_to filter_path(entity, scope: 'assigned-to-me') do
Assigned to me
%li{class: ("active" if params[:scope] == 'authored')}
= link_to filter_path(entity, scope: 'authored') do
@@ -15,14 +15,14 @@
%fieldset.status-filter
%legend State
%ul.nav.nav-pills
- %li{class: ("active" if params[:status].blank?)}
- = link_to filter_path(entity, status: nil) do
+ %li{class: ("active" if params[:state] == 'opened')}
+ = link_to filter_path(entity, state: 'opened') do
Open
- %li{class: ("active" if params[:status] == 'closed')}
- = link_to filter_path(entity, status: 'closed') do
+ %li{class: ("active" if params[:state] == 'closed')}
+ = link_to filter_path(entity, state: 'closed') do
Closed
- %li{class: ("active" if params[:status] == 'all')}
- = link_to filter_path(entity, status: 'all') do
+ %li{class: ("active" if params[:state] == 'all')}
+ = link_to filter_path(entity, state: 'all') do
All
%fieldset
@@ -36,8 +36,8 @@
%small.pull-right= entities_per_project(project, entity)
%fieldset
- - if params[:status].present? || params[:project_id].present?
- = link_to filter_path(entity, status: nil, project_id: nil), class: 'pull-right cgray' do
+ - if params[:state].present? || params[:project_id].present?
+ = link_to filter_path(entity, state: nil, project_id: nil), class: 'pull-right cgray' do
%i.icon-remove
%strong Clear filter

0 comments on commit 6153aa1

Please sign in to comment.