Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/redmine3 #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ if (!File.exists? redmine_version_file)
redmine_version_file = File.expand_path("lib/redmine/version.rb");
end
version_file = IO.read(redmine_version_file)
redmine_version_minor = version_file.match(/MINOR =/).post_match.match(/\d/)[0].to_i
redmine_version_major = version_file.match(/MAJOR =/).post_match.match(/\d/)[0].to_i

gem "holidays", "~>1.0.3"
gem "icalendar"
gem "nokogiri", "~>1.6.8"
#gem "nokogiri", "~>1.6.8"
gem "open-uri-cached"
gem "prawn"
gem 'json'
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/rb_master_backlogs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,14 @@ def menu


respond_to do |format|
format.html { render :json => links }
format.json { render json: links }
end
end

def default_serializer_options
{ root: false }
end

if Rails::VERSION::MAJOR < 3
def view_context
@template
Expand Down
41 changes: 25 additions & 16 deletions lib/backlogs_activerecord_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,26 @@ def self.find_by_rank(r) #this is a scope, used only in tests. combine with back
end

module InstanceMethods
def move_to_top()
def set_position(pos)
# self.position = pos
write_attribute(:position, pos)
pos
end
def get_position
read_attribute(:position)
end

def move_to_top(options={})
top = self.class.minimum(:position)
return if self.position == top && !top.blank?
self.position = top.blank? ? 0 : (top - self.class.list_spacing)
return if get_position == top && !top.blank?
set_position(top.blank? ? 0 : (top - self.class.list_spacing))
list_commit
end

def move_to_bottom()
bottom = self.class.maximum(:position)
return if self.position == bottom && !bottom.blank?
self.position = bottom.blank? ? 0 : (bottom + self.class.list_spacing)
return if get_position == bottom && !bottom.blank?
set_position(bottom.blank? ? 0 : (bottom + self.class.list_spacing))
list_commit
end

Expand Down Expand Up @@ -115,7 +124,7 @@ def list_with_gaps_options
def rank
@rank ||= self.class.
backlog_scope(self.list_with_gaps_options).
where(["#{self.class.table_name}.position <= ?", self.position]).
where(["#{self.class.table_name}.position <= ?", self.get_position]).
count
end
attr_writer :rank
Expand All @@ -126,11 +135,11 @@ def move_after(reference)
if nxt.blank?
move_to_bottom
else
if (nxt.position - reference.position) < 2
if (nxt.get_position - reference.get_position) < 2
self.class.connection.execute("update #{self.class.table_name} set position = position + #{self.class.list_spacing} where position >= #{nxt.position}")
nxt.position += self.class.list_spacing
nxt.set_position(nxt.get_position + self.class.list_spacing)
end
self.position = (nxt.position + reference.position) / 2
set_position((nxt.get_position + reference.get_position) / 2)
end

list_commit
Expand All @@ -143,11 +152,11 @@ def move_before(reference)
if prev.blank?
move_to_top
else
if (reference.position - prev.position) < 2
self.class.connection.execute("update #{self.class.table_name} set position = position - #{self.class.list_spacing} where position <= #{prev.position}")
prev.position -= self.class.list_spacing
if (reference.get_position - prev.get_position) < 2
self.class.connection.execute("update #{self.class.table_name} set position = position - #{self.class.list_spacing} where position <= #{prev.get_position}")
prev.set_position(prev.get_position - self.class.list_spacing)
end
self.position = (reference.position + prev.position) / 2
set_position((reference.get_position + prev.get_position) / 2)
end

list_commit
Expand All @@ -167,14 +176,14 @@ def lower_item_unscoped()
end

def list_commit
self.class.connection.execute("update #{self.class.table_name} set position = #{self.position} where id = #{self.id}") unless self.new_record?
self.class.connection.execute("update #{self.class.table_name} set position = #{get_position} where id = #{self.id}") unless self.new_record?
#FIXME now the cached lower/higher_item are wrong during this request. So are those from our old and new peers.
end

def list_prev_next(dir, scoped=true)
return nil if self.new_record?
raise "#{self.class}##{self.id}: cannot request #{dir} for nil position" unless self.position
whereclause = ["#{self.class.table_name}.position #{dir == :prev ? '<' : '>'} ?", self.position]
raise "#{self.class}##{self.id}: cannot request #{dir} for nil position" unless self.get_position
whereclause = ["#{self.class.table_name}.position #{dir == :prev ? '<' : '>'} ?", self.get_position]
orderclause = "#{self.class.table_name}.position #{dir == :prev ? 'desc' : 'asc'}"

if scoped
Expand Down
4 changes: 2 additions & 2 deletions lib/backlogs_hooks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def view_issues_form_details_bottom(context={ })
def view_issues_new_top(context={ })
#Remove the copy_subtasks functionality from redmine 2.1+ since backlogs offers it with a choice to copy only open tasks
project = context[:project]
return '' unless project.module_enabled?('backlogs')
return '' unless project && project.module_enabled?('backlogs')
return '<script type="text/javascript">$(function(){try{$("#copy_subtasks")[0].checked=false;$($("#copy_subtasks")[0].parentNode).hide();}catch(e){}});</script>' if (Redmine::VERSION::MAJOR == 2 && Redmine::VERSION::MINOR >= 1) || Redmine::VERSION::MAJOR > 2
end

Expand Down Expand Up @@ -351,7 +351,7 @@ def controller_issues_new_after_save(context={ })
nt = Issue.new
nt.copy_from(t)
nt.parent_issue_id = issue.id
nt.position = nil # will assign a new position
nt.set_position(nil) # will assign a new position
nt.save!
}
end
Expand Down
4 changes: 2 additions & 2 deletions lib/backlogs_issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ def backlogs_before_save
end
self.remaining_hours = self.leaves.sum("COALESCE(remaining_hours, 0)").to_f unless self.leaves.empty?

self.move_to_top if self.position.blank? || (@copied_from.present? && @copied_from.position == self.position)
self.move_to_top if self.get_position.blank? || (@copied_from.present? && @copied_from.get_position == self.get_position)

# scrub position from the journal by copying the new value to the old
@attributes_before_change['position'] = self.position if @attributes_before_change
@attributes_before_change['position'] = self.get_position if @attributes_before_change

@backlogs_new_record = self.new_record?

Expand Down