diff options
author | Felipe Artur <felipefac@gmail.com> | 2017-06-08 22:55:50 +0300 |
---|---|---|
committer | Felipe Artur <felipefac@gmail.com> | 2017-06-16 18:01:41 +0300 |
commit | 673bc07c0f6cb936fbc2037440634133ad32afaf (patch) | |
tree | 48c625891376898e1bc9389064ae49ff3cb1309f /app | |
parent | 86fc145c3c0c5056d7c6be1d62cd0b5beec2b1a9 (diff) |
Order merge requests by priority
Diffstat (limited to 'app')
-rw-r--r-- | app/assets/javascripts/milestone.js | 146 | ||||
-rw-r--r-- | app/controllers/concerns/milestone_actions.rb | 2 | ||||
-rw-r--r-- | app/models/concerns/milestoneish.rb | 6 | ||||
-rw-r--r-- | app/models/dashboard_milestone.rb | 2 | ||||
-rw-r--r-- | app/models/group_milestone.rb | 2 | ||||
-rw-r--r-- | app/models/milestone.rb | 2 | ||||
-rw-r--r-- | app/views/shared/milestones/_tabs.html.haml | 4 | ||||
-rw-r--r-- | app/views/shared/milestones/_top.html.haml | 2 |
8 files changed, 10 insertions, 156 deletions
diff --git a/app/assets/javascripts/milestone.js b/app/assets/javascripts/milestone.js index 8778ed0124e..3e07ec4d0aa 100644 --- a/app/assets/javascripts/milestone.js +++ b/app/assets/javascripts/milestone.js @@ -4,86 +4,7 @@ (function() { this.Milestone = (function() { - Milestone.updateIssue = function(li, issue_url, data) { - return $.ajax({ - type: "PUT", - url: issue_url, - data: data, - success: function(_data) { - return Milestone.successCallback(_data, li); - }, - error: function(data) { - return new Flash("Issue update failed", 'alert'); - }, - dataType: "json" - }); - }; - - Milestone.sortIssues = function(url, data) { - return $.ajax({ - type: "PUT", - url, - data: data, - success: function(_data) { - return Milestone.successCallback(_data); - }, - error: function() { - return new Flash("Issues update failed", 'alert'); - }, - dataType: "json" - }); - }; - - Milestone.sortMergeRequests = function(url, data) { - return $.ajax({ - type: "PUT", - url, - data: data, - success: function(_data) { - return Milestone.successCallback(_data); - }, - error: function(data) { - return new Flash("Issue update failed", 'alert'); - }, - dataType: "json" - }); - }; - - Milestone.updateMergeRequest = function(li, merge_request_url, data) { - return $.ajax({ - type: "PUT", - url: merge_request_url, - data: data, - success: function(_data) { - return Milestone.successCallback(_data, li); - }, - error: function(data) { - return new Flash("Issue update failed", 'alert'); - }, - dataType: "json" - }); - }; - - Milestone.successCallback = function(data, element) { - const $avatarContainer = $(element).find('.assignee-icon'); - $avatarContainer.empty(); - - if (data.assignees && data.assignees.length > 0) { - const $avatars = data.assignees.map((assignee) => { - const img_tag = $('<img/>'); - img_tag.attr('src', assignee.avatar_url); - img_tag.addClass('avatar s16'); - return img_tag; - }); - - $avatarContainer.append($avatars); - } - }; - function Milestone() { - this.issuesSortEndpoint = $('#tab-issues').data('sort-endpoint'); - this.mergeRequestsSortEndpoint = $('#tab-merge-requests').data('sort-endpoint'); - this.bindTabsSwitching(); // Load merge request tab if it is active @@ -102,69 +23,6 @@ }); }; - Milestone.prototype.bindMergeRequestSorting = function() { - if (!this.mergeRequestsSortEndpoint) return; - - $("#merge_requests-list-unassigned, #merge_requests-list-ongoing, #merge_requests-list-closed").each(function (i, el) { - this.createSortable(el, { - group: 'merge-request-list', - listEls: $(".merge_requests-sortable-list:not(#merge_requests-list-merged)"), - fieldName: 'merge_request', - sortCallback: (data) => { - Milestone.sortMergeRequests(this.mergeRequestsSortEndpoint, data); - }, - updateCallback: Milestone.updateMergeRequest, - }); - }.bind(this)); - }; - - Milestone.prototype.createSortable = function(el, opts) { - return Sortable.create(el, { - group: opts.group, - filter: '.is-disabled', - forceFallback: true, - onStart: function(e) { - opts.listEls.css('min-height', e.item.offsetHeight); - }, - onEnd: function () { - opts.listEls.css("min-height", "0px"); - }, - onUpdate: function(e) { - var ids = this.toArray(), - data; - - if (ids.length) { - data = ids.map(function(id) { - return 'sortable_' + opts.fieldName + '[]=' + id; - }).join('&'); - - opts.sortCallback(data); - } - }, - onAdd: function (e) { - var data, issuableId, issuableUrl, newState; - newState = e.to.dataset.state; - issuableUrl = e.item.dataset.url; - data = (function() { - switch (newState) { - case 'ongoing': - return `${opts.fieldName}[assignee_ids][]=${gon.current_user_id}`; - case 'unassigned': - return `${opts.fieldName}[assignee_ids][]=0`; - case 'closed': - return opts.fieldName + '[state_event]=close'; - } - })(); - if (e.from.dataset.state === 'closed') { - data += '&' + opts.fieldName + '[state_event]=reopen'; - } - - opts.updateCallback(e.item, issuableUrl, data); - this.options.onUpdate.call(this, e); - } - }); - }; - Milestone.prototype.loadInitialTab = function() { const $target = $(`.js-milestone-tabs a[href="${location.hash}"]`); @@ -186,10 +44,6 @@ .done((data) => { $(tabElId).html(data.html); $target.addClass('is-loaded'); - - if (tabElId === '#tab-merge-requests') { - this.bindMergeRequestSorting(); - } }); } }; diff --git a/app/controllers/concerns/milestone_actions.rb b/app/controllers/concerns/milestone_actions.rb index b2536a1c949..4bda26fdfd1 100644 --- a/app/controllers/concerns/milestone_actions.rb +++ b/app/controllers/concerns/milestone_actions.rb @@ -6,7 +6,7 @@ module MilestoneActions format.html { redirect_to milestone_redirect_path } format.json do render json: tabs_json("shared/milestones/_merge_requests_tab", { - merge_requests: @milestone.merge_requests, + merge_requests: @milestone.merge_requests.sort('priority'), show_project_name: true }) end diff --git a/app/models/concerns/milestoneish.rb b/app/models/concerns/milestoneish.rb index 2b177641ecc..a3247210314 100644 --- a/app/models/concerns/milestoneish.rb +++ b/app/models/concerns/milestoneish.rb @@ -1,7 +1,7 @@ module Milestoneish def closed_items_count(user) memoize_per_user(user, :closed_items_count) do - (count_issues_by_state(user)['closed'].count || 0) + merge_requests.closed_and_merged.size + (count_issues_by_state(user)['closed']&.length || 0) + merge_requests.closed_and_merged.size end end @@ -39,7 +39,7 @@ module Milestoneish def issues_visible_to_user(user) memoize_per_user(user, :issues_visible_to_user) do - IssuesFinder.new(user, issues_finder_params.merge({ sort: 'priority'})) + IssuesFinder.new(user, issues_finder_params) .execute.preload(:assignees).where(milestone_id: milestoneish_ids) end end @@ -81,6 +81,6 @@ module Milestoneish # override in a class that includes this module to get a faster query # from IssuesFinder def issues_finder_params - {} + { sort: 'priority' } end end diff --git a/app/models/dashboard_milestone.rb b/app/models/dashboard_milestone.rb index 646c1e5ce1a..e2af4040870 100644 --- a/app/models/dashboard_milestone.rb +++ b/app/models/dashboard_milestone.rb @@ -1,5 +1,5 @@ class DashboardMilestone < GlobalMilestone def issues_finder_params - { authorized_only: true } + super.merge({ authorized_only: true }) end end diff --git a/app/models/group_milestone.rb b/app/models/group_milestone.rb index 86d38e5468b..4db20470220 100644 --- a/app/models/group_milestone.rb +++ b/app/models/group_milestone.rb @@ -14,6 +14,6 @@ class GroupMilestone < GlobalMilestone end def issues_finder_params - { group_id: group.id } + super.merge({ group_id: group.id }) end end diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 0a6fc064aec..14647602c02 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -187,6 +187,6 @@ class Milestone < ActiveRecord::Base end def issues_finder_params - { project_id: project_id } + super.merge({ project_id: project_id }) end end diff --git a/app/views/shared/milestones/_tabs.html.haml b/app/views/shared/milestones/_tabs.html.haml index b18f903bc1f..b1d24578daf 100644 --- a/app/views/shared/milestones/_tabs.html.haml +++ b/app/views/shared/milestones/_tabs.html.haml @@ -32,11 +32,11 @@ - if milestone.is_a?(GlobalMilestone) || can?(current_user, :read_issue, @project) .tab-pane.active#tab-issues{ data: { sort_endpoint: (sort_issues_namespace_project_milestone_path(@project.namespace, @project, @milestone) if @project && current_user) } } = render 'shared/milestones/issues_tab', issues: milestone.issues_visible_to_user(current_user).preload_associations, show_project_name: show_project_name, show_full_project_name: show_full_project_name - .tab-pane#tab-merge-requests{ data: { sort_endpoint: (sort_merge_requests_namespace_project_milestone_path(@project.namespace, @project, @milestone) if @project && current_user) } } + .tab-pane#tab-merge-requests -# loaded async = render "shared/milestones/tab_loading" - else - .tab-pane.active#tab-merge-requests{ data: { sort_endpoint: (sort_merge_requests_namespace_project_milestone_path(@project.namespace, @project, @milestone) if @project && current_user) } } + .tab-pane.active#tab-merge-requests -# loaded async = render "shared/milestones/tab_loading" .tab-pane#tab-participants diff --git a/app/views/shared/milestones/_top.html.haml b/app/views/shared/milestones/_top.html.haml index 2562f085338..36c2969a555 100644 --- a/app/views/shared/milestones/_top.html.haml +++ b/app/views/shared/milestones/_top.html.haml @@ -50,7 +50,7 @@ - project_name = group ? ms.project.name : ms.project.name_with_namespace = link_to project_name, namespace_project_milestone_path(ms.project.namespace, ms.project, ms) %td - = ms.issues_visible_to_user(current_user).opened.count + = ms.issues_visible_to_user(current_user).opened.length %td - if ms.closed? Closed |