Commit d1f3643c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Merge branch 'sort-milestone-merge-requests' into 'master'

Sort milestone merge requests

Part of #1207
......@@ -23,6 +23,18 @@ class Milestone
new Flash("Issues update failed", 'alert')
dataType: "json"
@sortMergeRequests: (data) ->
sort_mr_url = location.href + "/sort_merge_requests"
type: "PUT"
url: sort_mr_url
data: data
success: (data) ->
if data.saved != true
new Flash("MR update failed", 'alert')
dataType: "json"
@updateMergeRequest: (li, merge_request_url, data) ->
type: "PUT"
......@@ -71,6 +83,10 @@ class Milestone
$("#merge_requests-list-unassigned, #merge_requests-list-ongoing, #merge_requests-list-closed").sortable(
connectWith: ".merge_requests-sortable-list",
dropOnEmpty: true,
update: (event, ui) ->
data = $(this).sortable("serialize")
receive: (event, ui) ->
new_state = $(this).data('state')
merge_request_id ='iid')
class Projects::MilestonesController < Projects::ApplicationController
before_filter :module_enabled
before_filter :milestone, only: [:edit, :update, :destroy, :show, :sort_issues]
before_filter :milestone, only: [:edit, :update, :destroy, :show, :sort_issues, :sort_merge_requests]
# Allow read any milestone
before_filter :authorize_read_milestone!
......@@ -82,6 +82,16 @@ def sort_issues
render json: { saved: true }
def sort_merge_requests
@merge_requests = @milestone.merge_requests.where(id: params['sortable_merge_request'])
@merge_requests.each do |merge_request|
merge_request.position = params['sortable_merge_request'].index( + 1
render json: { saved: true }
def milestone
%li{ class: 'mr-row', 'data-iid' => merge_request.iid, 'data-url' => project_merge_request_path(@project, merge_request) }
%li{ id: dom_id(merge_request, 'sortable'), class: 'mr-row', 'data-iid' => merge_request.iid, 'data-url' => project_merge_request_path(@project, merge_request) }
= link_to [@project, merge_request] do
%span.cgray ##{merge_request.iid}
.panel-heading= title
%ul{ class: "well-list merge_requests-sortable-list", id: "merge_requests-list-#{id}", "data-state" => id }
- merge_requests.each do |merge_request|
- merge_requests.sort_by(&:position).each do |merge_request|
= render 'merge_request', merge_request: merge_request
%li.light Drag and drop available
......@@ -281,6 +281,7 @@
resources :milestones, except: [:destroy], constraints: {id: /\d+/} do
member do
put :sort_issues
put :sort_merge_requests
class AddPositionToMergeRequest < ActiveRecord::Migration
def change
add_column :merge_requests, :position, :integer, default: 0
......@@ -11,7 +11,7 @@
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140502125220) do
ActiveRecord::Schema.define(version: 20140611135229) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
......@@ -121,9 +121,9 @@
add_index "merge_request_diffs", ["merge_request_id"], name: "index_merge_request_diffs_on_merge_request_id", unique: true, using: :btree
create_table "merge_requests", force: true do |t|
t.string "target_branch", null: false
t.string "source_branch", null: false
t.integer "source_project_id", null: false
t.string "target_branch", null: false
t.string "source_branch", null: false
t.integer "source_project_id", null: false
t.integer "author_id"
t.integer "assignee_id"
t.string "title"
......@@ -132,9 +132,10 @@
t.integer "milestone_id"
t.string "state"
t.string "merge_status"
t.integer "target_project_id", null: false
t.integer "target_project_id", null: false
t.integer "iid"
t.text "description"
t.integer "position", default: 0
add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree
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