Permalink
Browse files

Fixes #439

  • Loading branch information...
1 parent 24efa28 commit 1e041a4f46f3de71048545bb756ac3ff3688cce8 friflaj committed Apr 8, 2012
Showing with 47 additions and 0 deletions.
  1. +2 −0 init.rb
  2. +45 −0 lib/backlogs_issues_controller_patch.rb
View
@@ -21,7 +21,9 @@
require_dependency 'backlogs_version_patch'
require_dependency 'backlogs_project_patch'
require_dependency 'backlogs_user_patch'
+
require_dependency 'backlogs_my_controller_patch'
+ require_dependency 'backlogs_issues_controller_patch'
require_dependency 'backlogs_hooks'
@@ -0,0 +1,45 @@
+require_dependency 'issues_controller'
+require 'nokogiri'
+require 'json'
+
+module Backlogs
+ module IssuesControllerPatch
+ def self.included(base) # :nodoc:
+ base.extend(ClassMethods)
+ base.send(:include, InstanceMethods)
+
+ base.class_eval do
+ unloadable # Send unloadable so it will not be unloaded in development
+ after_filter :add_backlogs_fields, :only => [:index]
+ end
+ end
+
+ module ClassMethods
+ end
+
+ module InstanceMethods
+ def add_backlogs_fields
+ story_trackers = RbStory.trackers
+
+ case params[:format]
+ when 'xml'
+ body = Nokogiri::XML(response.body)
+ body.xpath('//issue').each{|issue|
+ next unless story_trackers.include?(Integer(issue.at('.//tracker')['id']))
+ issue << body.create_element('story_points', RbStory.find(issue.at('.//id').text).story_points.to_s)
+ }
+ response.body = body.to_xml
+ when 'json'
+ body = JSON.parse(response.body)
+ body['issues'].each{|issue|
+ next unless story_trackers.include?(issue['tracker']['id'])
+ issue['story_points'] = RbStory.find(issue['id']).story_points
+ }
+ response.body = body.to_json
+ end
+ end
+ end
+ end
+end
+
+IssuesController.send(:include, Backlogs::IssuesControllerPatch) unless IssuesController.included_modules.include? Backlogs::IssuesControllerPatch

0 comments on commit 1e041a4

Please sign in to comment.