Commit 47634e39 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Refactor issues and merge requests lists

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 32eb5de5
......@@ -239,4 +239,46 @@ class ApplicationController < ActionController::Base
redirect_to profile_path, notice: 'Please complete your profile with email address' and return
end
end
def set_filters_defaults
params[:sort] ||= 'newest'
params[:scope] = 'all' if params[:scope].blank?
params[:state] = 'opened' if params[:state].blank?
@sort = params[:sort].humanize
if @project
params[:project_id] = @project.id
elsif @group
params[:group_id] = @group.id
else
params[:authorized_only] = true
unless params[:assignee_id].present?
params[:assignee_id] = current_user.id
end
end
end
def set_filter_values(collection)
assignee_id = params[:assignee_id]
author_id = params[:author_id]
milestone_id = params[:milestone_id]
@assignees = User.where(id: collection.pluck(:assignee_id))
@authors = User.where(id: collection.pluck(:author_id))
@milestones = Milestone.where(id: collection.pluck(:milestone_id))
if assignee_id.present? && !assignee_id.to_i.zero?
@assignee = @assignees.find(assignee_id)
end
if author_id.present? && !author_id.to_i.zero?
@author = @authors.find(author_id)
end
if milestone_id.present? && !milestone_id.to_i.zero?
@milestone = @milestones.find(milestone_id)
end
end
end
......@@ -3,8 +3,6 @@ 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.
......@@ -55,13 +53,17 @@ class DashboardController < ApplicationController
end
def merge_requests
set_filters_defaults
@merge_requests = MergeRequestsFinder.new.execute(current_user, params)
set_filter_values(@merge_requests)
@merge_requests = @merge_requests.page(params[:page]).per(20)
@merge_requests = @merge_requests.preload(:author, :target_project)
end
def issues
set_filters_defaults
@issues = IssuesFinder.new.execute(current_user, params)
set_filter_values(@issues)
@issues = @issues.page(params[:page]).per(20)
@issues = @issues.preload(:author, :project)
......@@ -76,10 +78,4 @@ 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?
params[:authorized_only] = true
end
end
......@@ -11,8 +11,6 @@ class GroupsController < ApplicationController
# Load group projects
before_filter :load_projects, except: [:new, :create, :projects, :edit, :update]
before_filter :default_filter, only: [:issues, :merge_requests]
layout :determine_layout
before_filter :set_title, only: [:new, :create]
......@@ -47,13 +45,17 @@ class GroupsController < ApplicationController
end
def merge_requests
set_filters_defaults
@merge_requests = MergeRequestsFinder.new.execute(current_user, params)
set_filter_values(@merge_requests)
@merge_requests = @merge_requests.page(params[:page]).per(20)
@merge_requests = @merge_requests.preload(:author, :target_project)
end
def issues
set_filters_defaults
@issues = IssuesFinder.new.execute(current_user, params)
set_filter_values(@issues)
@issues = @issues.page(params[:page]).per(20)
@issues = @issues.preload(:author, :project)
......@@ -148,18 +150,6 @@ class GroupsController < ApplicationController
end
end
def default_filter
if params[:scope].blank?
if current_user
params[:scope] = 'assigned-to-me'
else
params[:scope] = 'all'
end
end
params[:state] = 'opened' if params[:state].blank?
params[:group_id] = @group.id
end
def group_params
params.require(:group).permit(:name, :description, :path, :avatar)
end
......
......@@ -29,31 +29,4 @@ class Projects::ApplicationController < ApplicationController
redirect_to project_tree_path(@project, @ref), notice: "This action is not allowed unless you are on top of a branch"
end
end
def set_filter_variables(collection)
params[:sort] ||= 'newest'
params[:scope] = 'all' if params[:scope].blank?
params[:state] = 'opened' if params[:state].blank?
@sort = params[:sort].humanize
assignee_id = params[:assignee_id]
author_id = params[:author_id]
milestone_id = params[:milestone_id]
if assignee_id.present? && !assignee_id.to_i.zero?
@assignee = @project.team.find(assignee_id)
end
if author_id.present? && !author_id.to_i.zero?
@author = @project.team.find(assignee_id)
end
if milestone_id.present? && !milestone_id.to_i.zero?
@milestone = @project.milestones.find(milestone_id)
end
@assignees = User.where(id: collection.pluck(:assignee_id))
@authors = User.where(id: collection.pluck(:author_id))
end
end
......@@ -18,9 +18,9 @@ class Projects::IssuesController < Projects::ApplicationController
def index
terms = params['issue_search']
set_filter_variables(@project.issues)
@issues = IssuesFinder.new.execute(current_user, params.merge(project_id: @project.id))
set_filters_defaults
@issues = IssuesFinder.new.execute(current_user, params)
set_filter_values(@issues)
@issues = @issues.full_search(terms) if terms.present?
@issues = @issues.page(params[:page]).per(20)
......
......@@ -17,9 +17,9 @@ class Projects::MergeRequestsController < Projects::ApplicationController
before_filter :authorize_modify_merge_request!, only: [:close, :edit, :update, :sort]
def index
set_filter_variables(@project.merge_requests)
@merge_requests = MergeRequestsFinder.new.execute(current_user, params.merge(project_id: @project.id))
set_filters_defaults
@merge_requests = MergeRequestsFinder.new.execute(current_user, params)
set_filter_values(@merge_requests)
@merge_requests = @merge_requests.page(params[:page]).per(20)
end
......
......@@ -275,4 +275,22 @@ module ApplicationHelper
def promo_url
'https://' + promo_host
end
def page_filter_path(options={})
exist_opts = {
state: params[:state],
scope: params[:scope],
label_name: params[:label_name],
milestone_id: params[:milestone_id],
assignee_id: params[:assignee_id],
author_id: params[:author_id],
sort: params[:sort],
}
options = exist_opts.merge(options)
path = request.path
path << "?#{options.to_param}"
path
end
end
module DashboardHelper
def filter_path(entity, options={})
exist_opts = {
state: params[:state],
scope: params[:scope],
project_id: params[:project_id],
}
options = exist_opts.merge(options)
path = request.path
path << "?#{options.to_param}"
path
end
def entities_per_project(project, entity)
case entity.to_sym
when :issue then @issues.where(project_id: project.id)
......
......@@ -68,23 +68,6 @@ module ProjectsHelper
project_nav_tabs.include? name
end
def project_filter_path(options={})
exist_opts = {
state: params[:state],
scope: params[:scope],
label_name: params[:label_name],
milestone_id: params[:milestone_id],
assignee_id: params[:assignee_id],
sort: params[:sort],
}
options = exist_opts.merge(options)
path = request.path
path << "?#{options.to_param}"
path
end
def project_active_milestones
@project.milestones.active.order("due_date, title ASC")
end
......
......@@ -5,10 +5,6 @@
List all issues from all projects you have access to.
%hr
.row
.fixed.sidebar-expand-button.hidden-lg.hidden-md
%i.fa.fa-list.fa-2x
.col-md-3.responsive-side
= render 'shared/filter', entity: 'issue'
.col-md-9
= render 'shared/issues'
.append-bottom-20
= render 'shared/issuable_filter'
= render 'shared/issues'
......@@ -5,10 +5,6 @@
%p.light
List all merge requests from all projects you have access to.
%hr
.row
.fixed.sidebar-expand-button.hidden-lg.hidden-md
%i.fa.fa-list.fa-2x
.col-md-3.responsive-side
= render 'shared/filter', entity: 'merge_request'
.col-md-9
= render 'shared/merge_requests'
.append-bottom-20
= render 'shared/issuable_filter'
= render 'shared/merge_requests'
......@@ -9,10 +9,6 @@
To see all issues you should visit #{link_to 'dashboard', issues_dashboard_path} page.
%hr
.row
.fixed.sidebar-expand-button.hidden-lg.hidden-md
%i.fa.fa-list.fa-2x
.col-md-3.responsive-side
= render 'shared/filter', entity: 'issue'
.col-md-9
= render 'shared/issues'
.append-bottom-20
= render 'shared/issuable_filter'
= render 'shared/issues'
......@@ -8,10 +8,6 @@
- if current_user
To see all merge requests you should visit #{link_to 'dashboard', merge_requests_dashboard_path} page.
%hr
.row
.fixed.sidebar-expand-button.hidden-lg.hidden-md
%i.fa.fa-list.fa-2x
.col-md-3.responsive-side
= render 'shared/filter', entity: 'merge_request'
.col-md-9
= render 'shared/merge_requests'
.append-bottom-20
= render 'shared/issuable_filter'
= render 'shared/merge_requests'
......@@ -13,13 +13,13 @@
%i.fa.fa-exclamation-circle
Issues
- if current_user
%span.count= current_user.assigned_issues.opened.of_group(@group).count
%span.count= Issue.opened.of_group(@group).count
= nav_link(path: 'groups#merge_requests') do
= link_to merge_requests_group_path(@group) do
%i.fa.fa-tasks
Merge Requests
- if current_user
%span.count= current_user.cared_merge_requests.opened.of_group(@group).count
%span.count= MergeRequest.opened.of_group(@group).count
= nav_link(path: 'groups#members') do
= link_to members_group_path(@group) do
%i.fa.fa-users
......
......@@ -2,15 +2,22 @@
- if project_nav_tab? :issues
= nav_link(controller: :issues) do
= link_to project_issues_path(@project), class: "tab" do
%i.fa.fa-exclamation-circle
Issues
- if project_nav_tab? :merge_requests
= nav_link(controller: :merge_requests) do
= link_to project_merge_requests_path(@project), class: "tab" do
%i.fa.fa-tasks
Merge Requests
= nav_link(controller: :milestones) do
= link_to 'Milestones', project_milestones_path(@project), class: "tab"
= link_to project_milestones_path(@project), class: "tab" do
%i.fa.fa-clock-o
Milestones
= nav_link(controller: :labels) do
= link_to 'Labels', project_labels_path(@project), class: "tab"
= link_to project_labels_path(@project), class: "tab" do
%i.fa.fa-tags
Labels
- if current_controller?(:milestones)
%li.pull-right
......
.append-bottom-10
.check-all-holder
= check_box_tag "check_all_issues", nil, false, class: "check_all_issues left"
= render 'projects/issuable_filter'
= render 'shared/issuable_filter'
.clearfix
.issues_bulk_update.hide
......
......@@ -2,7 +2,7 @@
.merge-requests-holder
.append-bottom-10
= render 'projects/issuable_filter'
= render 'shared/issuable_filter'
.panel.panel-default
%ul.well-list.mr-list
= render @merge_requests
......
.side-filters
= form_tag filter_path(entity), method: 'get' do
- if current_user
%fieldset.scope-filter
%ul.nav.nav-pills.nav-stacked
%li{class: ("active" if params[:scope] == 'assigned-to-me')}
= link_to filter_path(entity, scope: 'assigned-to-me') do
Assigned to me
%span.pull-right
= assigned_entities_count(current_user, entity, @group)
%li{class: ("active" if params[:scope] == 'authored')}
= link_to filter_path(entity, scope: 'authored') do
Created by me
%span.pull-right
= authored_entities_count(current_user, entity, @group)
%li{class: ("active" if params[:scope] == 'all')}
= link_to filter_path(entity, scope: 'all') do
Everyone's
%span.pull-right
= authorized_entities_count(current_user, entity, @group)
%fieldset.status-filter
%legend State
%ul.nav.nav-pills
%li{class: ("active" if params[:state] == 'opened')}
= link_to filter_path(entity, state: 'opened') do
Open
%li{class: ("active" if params[:state] == 'closed')}
= link_to filter_path(entity, state: 'closed') do
Closed
%li{class: ("active" if params[:state] == 'all')}
= link_to filter_path(entity, state: 'all') do
All
%fieldset
%legend Projects
%ul.nav.nav-pills.nav-stacked.nav-small
- @projects.each do |project|
- unless entities_per_project(project, entity).zero?
%li{class: ("active" if params[:project_id] == project.id.to_s)}
= link_to filter_path(entity, project_id: project.id) do
= project.name_with_namespace
%small.pull-right= entities_per_project(project, entity)
%fieldset
- if params[:state].present? || params[:project_id].present?
= link_to filter_path(entity, state: nil, project_id: nil), class: 'pull-right cgray' do
%i.fa.fa-times
%strong Clear filter
......@@ -2,15 +2,15 @@
.pull-left.append-right-20
%ul.nav.nav-pills.nav-compact
%li{class: ("active" if params[:state] == 'opened')}
= link_to project_filter_path(state: 'opened') do
= link_to page_filter_path(state: 'opened') do
%i.fa.fa-exclamation-circle
Open
%li{class: ("active" if params[:state] == 'closed')}
= link_to project_filter_path(state: 'closed') do
= link_to page_filter_path(state: 'closed') do
%i.fa.fa-check-circle
Closed
%li{class: ("active" if params[:state] == 'all')}
= link_to project_filter_path(state: 'all') do
= link_to page_filter_path(state: 'all') do
%i.fa.fa-compass
All
......@@ -27,13 +27,13 @@
%b.caret
%ul.dropdown-menu
%li
= link_to project_filter_path(assignee_id: nil) do
= link_to page_filter_path(assignee_id: nil) do
Any
= link_to project_filter_path(assignee_id: 0) do
= link_to page_filter_path(assignee_id: 0) do
Unassigned
- @assignees.sort_by(&:name).each do |user|
%li
= link_to project_filter_path(assignee_id: user.id) do
= link_to page_filter_path(assignee_id: user.id) do
= image_tag avatar_icon(user.email), class: "avatar s16", alt: ''
= user.name
......@@ -50,13 +50,13 @@
%b.caret
%ul.dropdown-menu
%li
= link_to project_filter_path(author_id: nil) do
= link_to page_filter_path(author_id: nil) do
Any
= link_to project_filter_path(author_id: 0) do
= link_to page_filter_path(author_id: 0) do
Unassigned
- @authors.sort_by(&:name).each do |user|
%li
= link_to project_filter_path(author_id: user.id) do
= link_to page_filter_path(author_id: user.id) do
= image_tag avatar_icon(user.email), class: "avatar s16", alt: ''
= user.name
......@@ -73,39 +73,40 @@
%b.caret
%ul.dropdown-menu
%li
= link_to project_filter_path(milestone_id: nil) do
= link_to page_filter_path(milestone_id: nil) do
Any
= link_to project_filter_path(milestone_id: 0) do
= link_to page_filter_path(milestone_id: 0) do
None (backlog)
- project_active_milestones.each do |milestone|
- @milestones.each do |milestone|
%li
= link_to project_filter_path(milestone_id: milestone.id) do
= link_to page_filter_path(milestone_id: milestone.id) do
%strong= milestone.title
%small.light= milestone.expires_at
.dropdown.inline.prepend-left-10
%a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"}
%i.fa.fa-user
%span.light label:
- if params[:label_name].present?
%strong= params[:label_name]
- else
Any
%b.caret
%ul.dropdown-menu
%li
= link_to project_filter_path(label_name: nil) do
- if @project
.dropdown.inline.prepend-left-10
%a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"}
%i.fa.fa-tags
%span.light label:
- if params[:label_name].present?
%strong= params[:label_name]
- else
Any
- if @project.labels.any?
- @project.labels.order_by_name.each do |label|
%li
= link_to project_filter_path(label_name: label.name) do
= render_colored_label(label)
- else
%b.caret
%ul.dropdown-menu
%li
= link_to generate_project_labels_path(@project, redirect: request.original_url), method: :post do
%i.fa.fa-plus-circle
Create default labels
= link_to page_filter_path(label_name: nil) do
Any
- if @project.labels.any?
- @project.labels.order_by_name.each do |label|
%li
= link_to page_filter_path(label_name: label.name) do
= render_colored_label(label)
- else
%li
= link_to generate_project_labels_path(@project, redirect: request.original_url), method: :post do
%i.fa.fa-plus-circle
Create default labels
.pull-right
= render 'shared/sort_dropdown'
......@@ -8,15 +8,15 @@
%b.caret
%ul.dropdown-menu
%li
= link_to project_filter_path(sort: 'newest') do
= link_to page_filter_path(sort: 'newest') do
= sort_title_recently_created
= link_to project_filter_path(sort: 'oldest') do
= link_to page_filter_path(sort: 'oldest') do
= sort_title_oldest_created
= link_to project_filter_path(sort: 'recently_updated') do
= link_to page_filter_path(sort: 'recently_updated') do
= sort_title_recently_updated
= link_to project_filter_path(sort: 'last_updated') do
= link_to page_filter_path(sort: 'last_updated') do
= sort_title_oldest_updated
= link_to project_filter_path(sort: 'milestone_due_soon') do
= link_to page_filter_path(sort: 'milestone_due_soon') do
Milestone due soon
= link_to project_filter_path(sort: 'milestone_due_later') do
= link_to page_filter_path(sort: 'milestone_due_later') do
Milestone due later
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