diff --git a/Gemfile b/Gemfile index 40ec3337b25046075afcaa4ac43633975d7dc9e8..9497177fda3f60fb26176e9976a3f533c7a870e1 100644 --- a/Gemfile +++ b/Gemfile @@ -18,8 +18,7 @@ # You should have received a copy of the GNU Affero General Public License # along with Redhopper. If not, see . # -gem 'resort', '~> 0.5.0' - +gem 'acts_as_list' gem 'haml', '~> 4.0.6' group :development do @@ -35,3 +34,5 @@ group :development do # Hence does not mamange .rake files :( gem 'copyright-header', '~> 1.0.8' end + +gem 'byebug', group: [:development, :test] diff --git a/app/controllers/redhopper_issues_controller.rb b/app/controllers/redhopper_issues_controller.rb index f92eeb5b8e92b93a4de3d92f3cfd59a6052b9035..e762bea4957ab40de0c8f8ca6630931f59334ba1 100644 --- a/app/controllers/redhopper_issues_controller.rb +++ b/app/controllers/redhopper_issues_controller.rb @@ -31,13 +31,9 @@ class RedhopperIssuesController < ApplicationController issue_to_move = RedhopperIssue.find(params[:id]) target_issue = RedhopperIssue.find(params[:target_id]) - new_previous = "after" == params[:insert] ? target_issue : target_issue.previous - - if new_previous - issue_to_move.append_to new_previous - else - issue_to_move.prepend - end + new_position = target_issue.position + new_position += 1 if "after" == params[:insert] + issue_to_move.insert_at new_position redirect_to project_kanbans_path(issue_to_move.issue.project) end @@ -68,4 +64,4 @@ class RedhopperIssuesController < ApplicationController redirect_to project_kanbans_path(project) end -end \ No newline at end of file +end diff --git a/app/models/kanban_board.rb b/app/models/kanban_board.rb index 7e3e1aa99d0156b75ef0581713ff0732c9dc32af..9520a4228767398f2a8f8125051d3821b22879dd 100644 --- a/app/models/kanban_board.rb +++ b/app/models/kanban_board.rb @@ -32,12 +32,10 @@ class KanbanBoard project_issues = issues - RedhopperIssue.ordered.each do |redhopper_issue| + RedhopperIssue.where(issue: project_issues).includes(:issue).ordered.each do |redhopper_issue| issue = redhopper_issue.issue - if project_issues.include?(issue) - column_for_issue_status(issue.status) << redhopper_issue - project_issues.delete issue - end + column_for_issue_status(issue.status) << redhopper_issue + project_issues.delete issue end project_issues.each do |issue| @@ -62,20 +60,15 @@ class KanbanBoard def tracker_ids trackers_to_remove = (Setting.plugin_redhopper && Setting.plugin_redhopper["hidden_tracker_ids"] || []).map(&:to_i) - @project.trackers.map(&:id) - trackers_to_remove + @project.trackers.ids - trackers_to_remove end def statuses result = IssueStatus.sorted result = result.where(is_closed: false) if Feature.enabled("only_open_statuses") - necessary_statuses = [] - WorkflowTransition.where(:tracker_id => tracker_ids, :role_id => Role.all.map(&:id)).each do |transition| - necessary_statuses << transition.old_status - necessary_statuses << transition.new_status - end - - result & necessary_statuses.uniq + necessary_statuse_ids = WorkflowTransition.where(tracker_id: tracker_ids, role_id: Role.ids).pluck(:old_status_id, :new_status_id).flatten.uniq + result.where(id: necessary_statuse_ids) end end diff --git a/app/models/redhopper_issue.rb b/app/models/redhopper_issue.rb index ebbc214781d124d940386657314c6cb9707d44fe..751531ea9da17f2e6c52a46035cfd02d1bb239f2 100644 --- a/app/models/redhopper_issue.rb +++ b/app/models/redhopper_issue.rb @@ -20,13 +20,15 @@ # class RedhopperIssue < ActiveRecord::Base unloadable - resort! + acts_as_list belongs_to :issue attr_accessible :issue validates :issue, uniqueness: true + scope :ordered, -> { order(position: :asc) } + def blocked_with_comment? blocked? end diff --git a/db/migrate/004_move_from_resort_to_acts_as_list.rb b/db/migrate/004_move_from_resort_to_acts_as_list.rb new file mode 100644 index 0000000000000000000000000000000000000000..42bd861678549c9da522118f28fdd854c6401c09 --- /dev/null +++ b/db/migrate/004_move_from_resort_to_acts_as_list.rb @@ -0,0 +1,36 @@ +# +# Redhopper - Kanban boards for Redmine, inspired by Jira Agile (formerly known as +# Greenhopper), but following its own path. +# Copyright (C) 2015-2017 infoPiiaf +# +# This file is part of Redhopper. +# +# Redhopper is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Redhopper is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Redhopper. If not, see . +# +class MoveFromResortToActsAsList < ActiveRecord::Migration + def up + add_column :redhopper_issues, :position, :integer + + redhopper_issue = RedhopperIssue.where(first: true).first + counter = 1 + while redhopper_issue.present? + redhopper_issue.insert_at(counter) + redhopper_issue = RedhopperIssue.find_by_id(redhopper_issue.next_id) + counter += 1 + end + + remove_column :redhopper_issues, :next_id + remove_column :redhopper_issues, :first + end +end