diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-12-23 19:49:39 +0300 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-12-23 19:49:39 +0300 |
commit | 47634e392fab457dd0634225961944804bc04efe (patch) | |
tree | 8d70528e0a9a1d18264e9937c10054d5507462a0 /app | |
parent | 32eb5de510a7e32d9bb886595aa47d95dc00490f (diff) |
Refactor issues and merge requests lists
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app')
20 files changed, 140 insertions, 210 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f1e1bebe5ce..0ddd743f053 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -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 diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb index 5aff526d1b5..bfd1361f2df 100644 --- a/app/controllers/dashboard_controller.rb +++ b/app/controllers/dashboard_controller.rb @@ -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 diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 36222758eb2..a28f4cc4072 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -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 diff --git a/app/controllers/projects/application_controller.rb b/app/controllers/projects/application_controller.rb index 6b7fe06d59f..7e4580017dd 100644 --- a/app/controllers/projects/application_controller.rb +++ b/app/controllers/projects/application_controller.rb @@ -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 diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index 22235123826..0266c51babb 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -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) diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 4d6f41e9de5..20d1222326e 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -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 diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 01aa4a60d4c..90cc58f44b7 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -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 diff --git a/app/helpers/dashboard_helper.rb b/app/helpers/dashboard_helper.rb index acc0eeb76b3..976a396e7b6 100644 --- a/app/helpers/dashboard_helper.rb +++ b/app/helpers/dashboard_helper.rb @@ -1,18 +1,4 @@ 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) diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 6568f438e25..e489d431e84 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -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 diff --git a/app/views/dashboard/issues.html.haml b/app/views/dashboard/issues.html.haml index 7c1f1ddbb80..db19a46cb26 100644 --- a/app/views/dashboard/issues.html.haml +++ b/app/views/dashboard/issues.html.haml @@ -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' diff --git a/app/views/dashboard/merge_requests.html.haml b/app/views/dashboard/merge_requests.html.haml index c96584c7b6b..97a42461b4e 100644 --- a/app/views/dashboard/merge_requests.html.haml +++ b/app/views/dashboard/merge_requests.html.haml @@ -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' diff --git a/app/views/groups/issues.html.haml b/app/views/groups/issues.html.haml index 1932ba2f644..6c0d89c4e7c 100644 --- a/app/views/groups/issues.html.haml +++ b/app/views/groups/issues.html.haml @@ -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' diff --git a/app/views/groups/merge_requests.html.haml b/app/views/groups/merge_requests.html.haml index 86d5acdaa32..1ad74905636 100644 --- a/app/views/groups/merge_requests.html.haml +++ b/app/views/groups/merge_requests.html.haml @@ -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' diff --git a/app/views/layouts/nav/_group.html.haml b/app/views/layouts/nav/_group.html.haml index 78d6b768155..3c8f47a7bea 100644 --- a/app/views/layouts/nav/_group.html.haml +++ b/app/views/layouts/nav/_group.html.haml @@ -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 diff --git a/app/views/projects/_issues_nav.html.haml b/app/views/projects/_issues_nav.html.haml index 18628eb6207..4e2ef3202f9 100644 --- a/app/views/projects/_issues_nav.html.haml +++ b/app/views/projects/_issues_nav.html.haml @@ -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 diff --git a/app/views/projects/issues/_issues.html.haml b/app/views/projects/issues/_issues.html.haml index 15c84c7ced2..010ca3b68b3 100644 --- a/app/views/projects/issues/_issues.html.haml +++ b/app/views/projects/issues/_issues.html.haml @@ -1,7 +1,7 @@ .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 diff --git a/app/views/projects/merge_requests/index.html.haml b/app/views/projects/merge_requests/index.html.haml index 6a615266ca3..2654ea70990 100644 --- a/app/views/projects/merge_requests/index.html.haml +++ b/app/views/projects/merge_requests/index.html.haml @@ -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 diff --git a/app/views/shared/_filter.html.haml b/app/views/shared/_filter.html.haml deleted file mode 100644 index d366dd97a71..00000000000 --- a/app/views/shared/_filter.html.haml +++ /dev/null @@ -1,50 +0,0 @@ -.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 - diff --git a/app/views/projects/_issuable_filter.html.haml b/app/views/shared/_issuable_filter.html.haml index 45b5137a1b3..56d58a52686 100644 --- a/app/views/projects/_issuable_filter.html.haml +++ b/app/views/shared/_issuable_filter.html.haml @@ -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' diff --git a/app/views/shared/_sort_dropdown.html.haml b/app/views/shared/_sort_dropdown.html.haml index 54f59245690..93ed9b67336 100644 --- a/app/views/shared/_sort_dropdown.html.haml +++ b/app/views/shared/_sort_dropdown.html.haml @@ -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 |