diff --git a/app/assets/javascripts/milestone.js.coffee b/app/assets/javascripts/milestone.js.coffee index 4a2c5068babc0daff09e9410b3a223a2dcfa6c93..3418832a9cc6f2365c8976b1e2dc35fa5739d4bc 100644 --- a/app/assets/javascripts/milestone.js.coffee +++ b/app/assets/javascripts/milestone.js.coffee @@ -11,6 +11,18 @@ class Milestone new Flash("Issue update failed", 'alert') 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) -> $.ajax type: "PUT" @@ -31,6 +43,10 @@ class Milestone $("#issues-list-unassigned, #issues-list-ongoing, #issues-list-closed").sortable( connectWith: ".issues-sortable-list", dropOnEmpty: true, + update: (event, ui) -> + data = $(this).sortable("serialize") + Milestone.sortIssues(data) + receive: (event, ui) -> new_state = $(this).data('state') issue_id = ui.item.data('iid') diff --git a/app/controllers/projects/milestones_controller.rb b/app/controllers/projects/milestones_controller.rb index 227cc1dfba739392b8147f895cf4c15f42c9e054..139470237d2968adafa356bb468e55c26c68b04e 100644 --- a/app/controllers/projects/milestones_controller.rb +++ b/app/controllers/projects/milestones_controller.rb @@ -1,6 +1,6 @@ class Projects::MilestonesController < Projects::ApplicationController 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 before_filter :authorize_read_milestone! @@ -72,6 +72,16 @@ class Projects::MilestonesController < Projects::ApplicationController 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 def milestone diff --git a/app/views/projects/milestones/_issue.html.haml b/app/views/projects/milestones/_issue.html.haml index fe93164a704f88fb2e6e18a6da4ddce1e311807d..7c993e01c23178a561621bcb90f68ddf150710fd 100644 --- a/app/views/projects/milestones/_issue.html.haml +++ b/app/views/projects/milestones/_issue.html.haml @@ -1,4 +1,4 @@ -%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 = link_to [@project, issue] do %span.cgray ##{issue.iid} diff --git a/app/views/projects/milestones/_issues.html.haml b/app/views/projects/milestones/_issues.html.haml index 9dbcab19a2a52d5dd4edc35e6fc6b82bea97dc38..95a4a9296cbc126c687484106e7ed3dbbe3bd81a 100644 --- a/app/views/projects/milestones/_issues.html.haml +++ b/app/views/projects/milestones/_issues.html.haml @@ -1,6 +1,6 @@ .panel.panel-default .panel-heading= title %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 %li.light Drag and drop available diff --git a/config/routes.rb b/config/routes.rb index 67ff66757e6367e93bd34ebfc9ff5606ca92d304..c38b5c42a7bfbfc7a4a030911a38ee72e4d6b974 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -278,7 +278,11 @@ Gitlab::Application.routes.draw do end 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 collection do