Commit dd86ce3f authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Sort issues in milestone

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 1f5891e9
...@@ -11,6 +11,18 @@ class Milestone ...@@ -11,6 +11,18 @@ class Milestone
new Flash("Issue update failed", 'alert') new Flash("Issue update failed", 'alert')
dataType: "json" dataType: "json"
@sortIssues: (data) ->
sort_issues_url = location.href + "/sort_issues"
$.ajax
type: "PUT"
url: sort_issues_url
data: data
success: (data) ->
if data.saved != true
new Flash("Issues update failed", 'alert')
dataType: "json"
@updateMergeRequest: (li, merge_request_url, data) -> @updateMergeRequest: (li, merge_request_url, data) ->
$.ajax $.ajax
type: "PUT" type: "PUT"
...@@ -31,6 +43,10 @@ class Milestone ...@@ -31,6 +43,10 @@ class Milestone
$("#issues-list-unassigned, #issues-list-ongoing, #issues-list-closed").sortable( $("#issues-list-unassigned, #issues-list-ongoing, #issues-list-closed").sortable(
connectWith: ".issues-sortable-list", connectWith: ".issues-sortable-list",
dropOnEmpty: true, dropOnEmpty: true,
update: (event, ui) ->
data = $(this).sortable("serialize")
Milestone.sortIssues(data)
receive: (event, ui) -> receive: (event, ui) ->
new_state = $(this).data('state') new_state = $(this).data('state')
issue_id = ui.item.data('iid') issue_id = ui.item.data('iid')
......
class Projects::MilestonesController < Projects::ApplicationController class Projects::MilestonesController < Projects::ApplicationController
before_filter :module_enabled before_filter :module_enabled
before_filter :milestone, only: [:edit, :update, :destroy, :show] before_filter :milestone, only: [:edit, :update, :destroy, :show, :sort_issues]
# Allow read any milestone # Allow read any milestone
before_filter :authorize_read_milestone! before_filter :authorize_read_milestone!
...@@ -72,6 +72,16 @@ class Projects::MilestonesController < Projects::ApplicationController ...@@ -72,6 +72,16 @@ class Projects::MilestonesController < Projects::ApplicationController
end end
end end
def sort_issues
@issues = @milestone.issues.where(id: params['sortable_issue'])
@issues.each do |issue|
issue.position = params['sortable_issue'].index(issue.id.to_s) + 1
issue.save
end
render json: { saved: true }
end
protected protected
def milestone def milestone
......
%li{ class: 'issue-row', 'data-iid' => issue.iid, 'data-url' => project_issue_path(@project, issue) } %li{ id: dom_id(issue, 'sortable'), class: 'issue-row', 'data-iid' => issue.iid, 'data-url' => project_issue_path(@project, issue) }
%span.str-truncated %span.str-truncated
= link_to [@project, issue] do = link_to [@project, issue] do
%span.cgray ##{issue.iid} %span.cgray ##{issue.iid}
......
.panel.panel-default .panel.panel-default
.panel-heading= title .panel-heading= title
%ul{ class: "well-list issues-sortable-list", id: "issues-list-#{id}", "data-state" => id } %ul{ class: "well-list issues-sortable-list", id: "issues-list-#{id}", "data-state" => id }
- issues.each do |issue| - issues.sort_by(&:position).each do |issue|
= render 'issue', issue: issue = render 'issue', issue: issue
%li.light Drag and drop available %li.light Drag and drop available
...@@ -278,7 +278,11 @@ Gitlab::Application.routes.draw do ...@@ -278,7 +278,11 @@ Gitlab::Application.routes.draw do
end end
resources :team, controller: 'team_members', only: [:index] resources :team, controller: 'team_members', only: [:index]
resources :milestones, except: [:destroy], constraints: {id: /\d+/} resources :milestones, except: [:destroy], constraints: {id: /\d+/} do
member do
put :sort_issues
end
end
resources :labels, only: [:index] do resources :labels, only: [:index] do
collection do collection do
......
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