Commit 6153aa13 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Use FilteringService for Dashboard, Group pages

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 5e96ee34
...@@ -3,6 +3,8 @@ class DashboardController < ApplicationController ...@@ -3,6 +3,8 @@ class DashboardController < ApplicationController
before_filter :load_projects, except: [:projects] before_filter :load_projects, except: [:projects]
before_filter :event_filter, only: :show before_filter :event_filter, only: :show
before_filter :default_filter, only: [:issues, :merge_requests]
def show def show
# Fetch only 30 projects. # Fetch only 30 projects.
...@@ -51,12 +53,12 @@ class DashboardController < ApplicationController ...@@ -51,12 +53,12 @@ class DashboardController < ApplicationController
end end
def merge_requests 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) @merge_requests = @merge_requests.recent.page(params[:page]).per(20)
end end
def issues 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.recent.page(params[:page]).per(20)
@issues = @issues.includes(:author, :project) @issues = @issues.includes(:author, :project)
...@@ -71,4 +73,9 @@ class DashboardController < ApplicationController ...@@ -71,4 +73,9 @@ class DashboardController < ApplicationController
def load_projects def load_projects
@projects = current_user.authorized_projects.sorted_by_activity.non_archived @projects = current_user.authorized_projects.sorted_by_activity.non_archived
end end
def default_filter
params[:scope] = 'assigned-to-me' if params[:scope].blank?
params[:state] = 'opened' if params[:state].blank?
end
end end
...@@ -10,6 +10,8 @@ class GroupsController < ApplicationController ...@@ -10,6 +10,8 @@ class GroupsController < ApplicationController
# Load group projects # Load group projects
before_filter :projects, except: [:new, :create] before_filter :projects, except: [:new, :create]
before_filter :default_filter, only: [:issues, :merge_requests]
layout :determine_layout layout :determine_layout
before_filter :set_title, only: [:new, :create] before_filter :set_title, only: [:new, :create]
...@@ -43,18 +45,14 @@ class GroupsController < ApplicationController ...@@ -43,18 +45,14 @@ class GroupsController < ApplicationController
end end
end end
# Get authored or assigned open merge requests
def merge_requests 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.of_group(@group) @merge_requests = @merge_requests.page(params[:page]).per(20)
@merge_requests = @merge_requests.recent.page(params[:page]).per(20)
end end
# Get only assigned issues
def issues def issues
@issues = FilterContext.new(Issue, current_user, params).execute @issues = FilteringService.new.execute(Issue, current_user, params)
@issues = @issues.of_group(@group) @issues = @issues.page(params[:page]).per(20)
@issues = @issues.recent.page(params[:page]).per(20)
@issues = @issues.includes(:author, :project) @issues = @issues.includes(:author, :project)
respond_to do |format| respond_to do |format|
...@@ -130,4 +128,10 @@ class GroupsController < ApplicationController ...@@ -130,4 +128,10 @@ class GroupsController < ApplicationController
'group' 'group'
end end
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 end
module DashboardHelper module DashboardHelper
def filter_path(entity, options={}) def filter_path(entity, options={})
exist_opts = { exist_opts = {
status: params[:status], state: params[:state],
scope: params[:scope], scope: params[:scope],
project_id: params[:project_id], project_id: params[:project_id],
} }
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
= form_tag filter_path(entity), method: 'get' do = form_tag filter_path(entity), method: 'get' do
%fieldset.scope-filter %fieldset.scope-filter
%ul.nav.nav-pills.nav-stacked %ul.nav.nav-pills.nav-stacked
%li{class: ("active" if params[:scope].blank?)} %li{class: ("active" if params[:scope] == 'assigned-to-me')}
= link_to filter_path(entity, scope: nil) do = link_to filter_path(entity, scope: 'assigned-to-me') do
Assigned to me Assigned to me
%li{class: ("active" if params[:scope] == 'authored')} %li{class: ("active" if params[:scope] == 'authored')}
= link_to filter_path(entity, scope: 'authored') do = link_to filter_path(entity, scope: 'authored') do
...@@ -15,14 +15,14 @@ ...@@ -15,14 +15,14 @@
%fieldset.status-filter %fieldset.status-filter
%legend State %legend State
%ul.nav.nav-pills %ul.nav.nav-pills
%li{class: ("active" if params[:status].blank?)} %li{class: ("active" if params[:state] == 'opened')}
= link_to filter_path(entity, status: nil) do = link_to filter_path(entity, state: 'opened') do
Open Open
%li{class: ("active" if params[:status] == 'closed')} %li{class: ("active" if params[:state] == 'closed')}
= link_to filter_path(entity, status: 'closed') do = link_to filter_path(entity, state: 'closed') do
Closed Closed
%li{class: ("active" if params[:status] == 'all')} %li{class: ("active" if params[:state] == 'all')}
= link_to filter_path(entity, status: 'all') do = link_to filter_path(entity, state: 'all') do
All All
%fieldset %fieldset
...@@ -36,8 +36,8 @@ ...@@ -36,8 +36,8 @@
%small.pull-right= entities_per_project(project, entity) %small.pull-right= entities_per_project(project, entity)
%fieldset %fieldset
- if params[:status].present? || params[:project_id].present? - if params[:state].present? || params[:project_id].present?
= link_to filter_path(entity, status: nil, project_id: nil), class: 'pull-right cgray' do = link_to filter_path(entity, state: nil, project_id: nil), class: 'pull-right cgray' do
%i.icon-remove %i.icon-remove
%strong Clear filter %strong Clear filter
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment