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
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 @@ class DashboardController < ApplicationController
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 @@ class DashboardController < ApplicationController
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 @@ class GroupsController < ApplicationController
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 @@ class GroupsController < ApplicationController
'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
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
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