Commit 52d59a4e authored by Phil Hughes's avatar Phil Hughes

Load milestone tabs asynchronously

parent f00bb1c2
...@@ -81,9 +81,7 @@ ...@@ -81,9 +81,7 @@
}; };
function Milestone() { function Milestone() {
var oldMouseStart;
this.bindIssuesSorting(); this.bindIssuesSorting();
this.bindMergeRequestSorting();
this.bindTabsSwitching(); this.bindTabsSwitching();
} }
...@@ -100,13 +98,14 @@ ...@@ -100,13 +98,14 @@
}; };
Milestone.prototype.bindTabsSwitching = function() { Milestone.prototype.bindTabsSwitching = function() {
return $('a[data-toggle="tab"]').on('show.bs.tab', function(e) { return $('a[data-toggle="tab"]').on('show.bs.tab', (e) => {
var currentTabClass, previousTabClass; const $target = $(e.target);
currentTabClass = $(e.target).data('show'); const endpoint = $target.data('endpoint');
previousTabClass = $(e.relatedTarget).data('show');
$(previousTabClass).hide(); if (endpoint && !$target.hasClass('is-loaded')) {
$(currentTabClass).removeClass('hidden'); this.loadMergeRequests($target.attr('href'), endpoint)
return $(currentTabClass).show(); .done(() => $target.addClass('is-loaded'));
}
}); });
}; };
...@@ -169,6 +168,18 @@ ...@@ -169,6 +168,18 @@
}); });
}; };
Milestone.prototype.loadMergeRequests = function(elId, url) {
return $.ajax({
url,
dataType: 'JSON',
})
.fail(() => new Flash('Error loading merge requests'))
.done((data) => {
$(elId).html(data.html);
this.bindMergeRequestSorting();
});
};
return Milestone; return Milestone;
})(); })();
}).call(window); }).call(window);
module MilestoneActions
extend ActiveSupport::Concern
def merge_requests
respond_to do |format|
format.json do
render json: tabs_json("shared/milestones/_merge_requests_tab", {
merge_requests: @milestone.merge_requests,
show_project_name: true
})
end
end
end
def participants
respond_to do |format|
format.json do
render json: tabs_json("shared/milestones/_participants_tab", {
users: @milestone.participants
})
end
end
end
def labels
respond_to do |format|
format.json do
render json: tabs_json("shared/milestones/_labels_tab", {
labels: @milestone.labels
})
end
end
end
private
def tabs_json(partial, data = {})
{
html: view_to_html_string(partial, data)
}
end
end
class Groups::MilestonesController < Groups::ApplicationController class Groups::MilestonesController < Groups::ApplicationController
include MilestoneActions
before_action :group_projects before_action :group_projects
before_action :milestone, only: [:show, :update] before_action :milestone, only: [:show, :update, :merge_requests, :participants, :labels]
before_action :authorize_admin_milestones!, only: [:new, :create, :update] before_action :authorize_admin_milestones!, only: [:new, :create, :update]
def index def index
......
class Projects::MilestonesController < Projects::ApplicationController class Projects::MilestonesController < Projects::ApplicationController
include MilestoneActions
before_action :module_enabled before_action :module_enabled
before_action :milestone, only: [:edit, :update, :destroy, :show, :sort_issues, :sort_merge_requests] before_action :milestone, only: [:edit, :update, :destroy, :show, :sort_issues, :sort_merge_requests, :merge_requests, :participants, :labels]
# Allow read any milestone # Allow read any milestone
before_action :authorize_read_milestone! before_action :authorize_read_milestone!
......
...@@ -115,4 +115,28 @@ module MilestonesHelper ...@@ -115,4 +115,28 @@ module MilestonesHelper
end end
end end
end end
def milestone_merge_request_path(milestone)
if @project
merge_requests_namespace_project_milestone_path(@project.namespace, @project, milestone, format: :json)
elsif @group
merge_requests_group_milestone_path(@group, milestone.safe_title, title: milestone.title, format: :json)
end
end
def milestone_participants_path(milestone)
if @project
participants_namespace_project_milestone_path(@project.namespace, @project, milestone, format: :json)
elsif @group
participants_group_milestone_path(@group, milestone.safe_title, title: milestone.title, format: :json)
end
end
def milestone_labels_path(milestone)
if @project
labels_namespace_project_milestone_path(@project.namespace, @project, milestone, format: :json)
elsif @group
labels_group_milestone_path(@group, milestone.safe_title, title: milestone.title, format: :json)
end
end
end end
...@@ -8,20 +8,20 @@ ...@@ -8,20 +8,20 @@
Issues Issues
%span.badge= milestone.issues_visible_to_user(current_user).size %span.badge= milestone.issues_visible_to_user(current_user).size
%li %li
= link_to '#tab-merge-requests', 'data-toggle' => 'tab', 'data-show' => '.tab-merge-requests-buttons' do = link_to '#tab-merge-requests', 'data-toggle' => 'tab', 'data-endpoint': milestone_merge_request_path(milestone) do
Merge Requests Merge Requests
%span.badge= milestone.merge_requests.size %span.badge= milestone.merge_requests.size
- else - else
%li.active %li.active
= link_to '#tab-merge-requests', 'data-toggle' => 'tab', 'data-show' => '.tab-merge-requests-buttons' do = link_to '#tab-merge-requests', 'data-toggle' => 'tab', 'data-endpoint': milestone_merge_request_path(milestone) do
Merge Requests Merge Requests
%span.badge= milestone.merge_requests.size %span.badge= milestone.merge_requests.size
%li %li
= link_to '#tab-participants', 'data-toggle' => 'tab' do = link_to '#tab-participants', 'data-toggle' => 'tab', 'data-endpoint': milestone_participants_path(milestone) do
Participants Participants
%span.badge= milestone.participants.count %span.badge= milestone.participants.count
%li %li
= link_to '#tab-labels', 'data-toggle' => 'tab' do = link_to '#tab-labels', 'data-toggle' => 'tab', 'data-endpoint': milestone_labels_path(milestone) do
Labels Labels
%span.badge= milestone.labels.count %span.badge= milestone.labels.count
...@@ -33,11 +33,19 @@ ...@@ -33,11 +33,19 @@
.tab-pane.active#tab-issues .tab-pane.active#tab-issues
= render 'shared/milestones/issues_tab', issues: milestone.issues_visible_to_user(current_user).include_associations, show_project_name: show_project_name, show_full_project_name: show_full_project_name = render 'shared/milestones/issues_tab', issues: milestone.issues_visible_to_user(current_user).include_associations, show_project_name: show_project_name, show_full_project_name: show_full_project_name
.tab-pane#tab-merge-requests .tab-pane#tab-merge-requests
= render 'shared/milestones/merge_requests_tab', merge_requests: milestone.merge_requests, show_project_name: show_project_name, show_full_project_name: show_full_project_name -# loaded async
.text-center.prepend-top-default
= icon('spin spinner 2x')
- else - else
.tab-pane.active#tab-merge-requests .tab-pane.active#tab-merge-requests
= render 'shared/milestones/merge_requests_tab', merge_requests: milestone.merge_requests, show_project_name: show_project_name, show_full_project_name: show_full_project_name -# loaded async
.text-center.prepend-top-default
= icon('spin spinner 2x')
.tab-pane#tab-participants .tab-pane#tab-participants
= render 'shared/milestones/participants_tab', users: milestone.participants -# loaded async
.text-center.prepend-top-default
= icon('spin spinner 2x')
.tab-pane#tab-labels .tab-pane#tab-labels
= render 'shared/milestones/labels_tab', labels: milestone.labels -# loaded async
.text-center.prepend-top-default
= icon('spin spinner 2x')
...@@ -10,7 +10,13 @@ scope(path: 'groups/*group_id', ...@@ -10,7 +10,13 @@ scope(path: 'groups/*group_id',
end end
resource :avatar, only: [:destroy] resource :avatar, only: [:destroy]
resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create] resources :milestones, constraints: { id: /[^\/]+/ }, only: [:index, :show, :update, :new, :create] do
member do
get :merge_requests
get :participants
get :labels
end
end
resources :labels, except: [:show] do resources :labels, except: [:show] do
post :toggle_subscription, on: :member post :toggle_subscription, on: :member
......
...@@ -205,6 +205,9 @@ constraints(ProjectUrlConstrainer.new) do ...@@ -205,6 +205,9 @@ constraints(ProjectUrlConstrainer.new) do
member do member do
put :sort_issues put :sort_issues
put :sort_merge_requests put :sort_merge_requests
get :merge_requests
get :participants
get :labels
end end
end end
......
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