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