Commit ed610043a8d7e60f0bd796005a8d7cdb10565206
Exists in
spb-stable
and in
2 other branches
Merge branch 'milestone-issue-position' into 'master'
Milestone issues sorting Now issues save sort position inside milestone lists Part of #1207
Showing
5 changed files
with
34 additions
and
4 deletions
Show diff stats
app/assets/javascripts/milestone.js.coffee
... | ... | @@ -11,6 +11,18 @@ class Milestone |
11 | 11 | new Flash("Issue update failed", 'alert') |
12 | 12 | dataType: "json" |
13 | 13 | |
14 | + @sortIssues: (data) -> | |
15 | + sort_issues_url = location.href + "/sort_issues" | |
16 | + | |
17 | + $.ajax | |
18 | + type: "PUT" | |
19 | + url: sort_issues_url | |
20 | + data: data | |
21 | + success: (data) -> | |
22 | + if data.saved != true | |
23 | + new Flash("Issues update failed", 'alert') | |
24 | + dataType: "json" | |
25 | + | |
14 | 26 | @updateMergeRequest: (li, merge_request_url, data) -> |
15 | 27 | $.ajax |
16 | 28 | type: "PUT" |
... | ... | @@ -31,6 +43,10 @@ class Milestone |
31 | 43 | $("#issues-list-unassigned, #issues-list-ongoing, #issues-list-closed").sortable( |
32 | 44 | connectWith: ".issues-sortable-list", |
33 | 45 | dropOnEmpty: true, |
46 | + update: (event, ui) -> | |
47 | + data = $(this).sortable("serialize") | |
48 | + Milestone.sortIssues(data) | |
49 | + | |
34 | 50 | receive: (event, ui) -> |
35 | 51 | new_state = $(this).data('state') |
36 | 52 | issue_id = ui.item.data('iid') | ... | ... |
app/controllers/projects/milestones_controller.rb
1 | 1 | class Projects::MilestonesController < Projects::ApplicationController |
2 | 2 | before_filter :module_enabled |
3 | - before_filter :milestone, only: [:edit, :update, :destroy, :show] | |
3 | + before_filter :milestone, only: [:edit, :update, :destroy, :show, :sort_issues] | |
4 | 4 | |
5 | 5 | # Allow read any milestone |
6 | 6 | before_filter :authorize_read_milestone! |
... | ... | @@ -72,6 +72,16 @@ class Projects::MilestonesController < Projects::ApplicationController |
72 | 72 | end |
73 | 73 | end |
74 | 74 | |
75 | + def sort_issues | |
76 | + @issues = @milestone.issues.where(id: params['sortable_issue']) | |
77 | + @issues.each do |issue| | |
78 | + issue.position = params['sortable_issue'].index(issue.id.to_s) + 1 | |
79 | + issue.save | |
80 | + end | |
81 | + | |
82 | + render json: { saved: true } | |
83 | + end | |
84 | + | |
75 | 85 | protected |
76 | 86 | |
77 | 87 | def milestone | ... | ... |
app/views/projects/milestones/_issue.html.haml
1 | -%li{ class: 'issue-row', 'data-iid' => issue.iid, 'data-url' => project_issue_path(@project, issue) } | |
1 | +%li{ id: dom_id(issue, 'sortable'), class: 'issue-row', 'data-iid' => issue.iid, 'data-url' => project_issue_path(@project, issue) } | |
2 | 2 | %span.str-truncated |
3 | 3 | = link_to [@project, issue] do |
4 | 4 | %span.cgray ##{issue.iid} | ... | ... |
app/views/projects/milestones/_issues.html.haml
1 | 1 | .panel.panel-default |
2 | 2 | .panel-heading= title |
3 | 3 | %ul{ class: "well-list issues-sortable-list", id: "issues-list-#{id}", "data-state" => id } |
4 | - - issues.each do |issue| | |
4 | + - issues.sort_by(&:position).each do |issue| | |
5 | 5 | = render 'issue', issue: issue |
6 | 6 | %li.light Drag and drop available | ... | ... |
config/routes.rb
... | ... | @@ -278,7 +278,11 @@ Gitlab::Application.routes.draw do |
278 | 278 | end |
279 | 279 | |
280 | 280 | resources :team, controller: 'team_members', only: [:index] |
281 | - resources :milestones, except: [:destroy], constraints: {id: /\d+/} | |
281 | + resources :milestones, except: [:destroy], constraints: {id: /\d+/} do | |
282 | + member do | |
283 | + put :sort_issues | |
284 | + end | |
285 | + end | |
282 | 286 | |
283 | 287 | resources :labels, only: [:index] do |
284 | 288 | collection do | ... | ... |