issue_serialization_patch.diff

Adam Soltys, 2010-08-15 23:46

Download (7.26 KB)

View differences:

app/controllers/issues_controller.rb
109 109
  rescue ActiveRecord::RecordNotFound
110 110
    render_404
111 111
  end
112
  
112

  
113 113
  def show
114 114
    @journals = @issue.journals.find(:all, :include => [:user, :details], :order => "#{Journal.table_name}.created_on ASC")
115 115
    @journals.each_with_index {|j,i| j.indice = i+1}
......
120 120
    @edit_allowed = User.current.allowed_to?(:edit_issues, @project)
121 121
    @priorities = IssuePriority.all
122 122
    @time_entry = TimeEntry.new
123

  
123 124
    respond_to do |format|
124 125
      format.html { render :template => 'issues/show.rhtml' }
125
      format.xml  { render :layout => false }
126
      format.xml  { render :text => @issue.to_xml, :layout => false }
126 127
      format.json { render :text => @issue.to_json, :layout => false }
127 128
      format.atom { render :action => 'changes', :layout => false, :content_type => 'application/atom+xml' }
128 129
      format.pdf  { send_data(issue_to_pdf(@issue), :type => 'application/pdf', :filename => "#{@project.identifier}-#{@issue.id}.pdf") }
app/models/issue.rb
615 615
    end
616 616
    projects
617 617
  end
618

  
619
  def to_xml
620
    xml = Builder::XmlMarkup.new
621
    xml.instruct!
622
    xml.issue do
623
      xml.id					id
624
      xml.project(:id => project_id, :name => project.name) unless project.nil?
625
      xml.tracker(:id => tracker_id, :name => tracker.name) unless tracker.nil?
626
      xml.status(:id => status_id, :name => status.name) unless status.nil?
627
      xml.priority(:id => priority_id, :name => priority.name) unless priority.nil?
628
      xml.author(:id => author_id, :name => author.name) unless author.nil?
629
      xml.assigned_to(:id => assigned_to_id, :name => assigned_to.name) unless assigned_to.nil?
630
      xml.category(:id => category_id, :name => category.name) unless category.nil?
631
      xml.fixed_version(:id => fixed_version_id, :name => fixed_version.name) unless fixed_version.nil?
632
      xml.parent(:id => parent_id) unless parent.nil?
633
      
634
      xml.subject 		subject
635
      xml.description description
636
      xml.start_date 	start_date
637
      xml.due_date 		due_date
638
      xml.done_ratio 	done_ratio
639
      xml.estimated_hours estimated_hours
640
      if User.current.allowed_to?(:view_time_entries, project)
641
        xml.spent_hours		spent_hours
642
      end
643
      
644
      xml.custom_fields do
645
        custom_field_values.each do |custom_value|
646
          xml.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name
647
        end
648
      end unless custom_field_values.empty?
649
      
650
      xml.created_on created_on
651
      xml.updated_on updated_on
652
      
653
      xml.relations do
654
        relations.select {|r| r.other_issue(self).visible? }.each do |relation|
655
          xml.relation(:id => relation.id, :issue_id => relation.other_issue(self).id, :relation_type => relation.relation_type_for(self), :delay => relation.delay)
656
        end
657
      end
658
      
659
      xml.changesets do
660
        changesets.each do |changeset|
661
          xml.changeset :revision => changeset.revision do
662
            xml.user(:id => changeset.user_id, :name => changeset.user.name) unless changeset.user.nil?
663
            xml.comments changeset.comments
664
            xml.committed_on changeset.committed_on
665
          end
666
        end
667
      end if User.current.allowed_to?(:view_changesets, project) && changesets.any?
668
      
669
      xml.journals do
670
        journals.each do |journal|
671
          xml.journal :id => journal.id do
672
            xml.user(:id => journal.user_id, :name => journal.user.name) unless journal.user.nil?
673
            xml.notes journal.notes
674
            xml.details do
675
              journal.details.each do |detail|
676
                xml.detail :property => detail.property, :name => detail.prop_key, :old => detail.old_value, :new => detail.value
677
              end
678
            end
679
          end
680
        end
681
      end unless journals.empty?
682
    end
683

  
684
    return xml.target!
685
  end
686

  
687
  def to_json
688
    Hash.from_xml(to_xml).to_json
689
  end
618 690
   
619 691
  private
620 692
  
app/views/issues/show.xml.builder
1
xml.instruct!
2
xml.issue do
3
  xml.id					@issue.id
4
	xml.project(:id => @issue.project_id, :name => @issue.project.name) unless @issue.project.nil?
5
	xml.tracker(:id => @issue.tracker_id, :name => @issue.tracker.name) unless @issue.tracker.nil?
6
	xml.status(:id => @issue.status_id, :name => @issue.status.name) unless @issue.status.nil?
7
	xml.priority(:id => @issue.priority_id, :name => @issue.priority.name) unless @issue.priority.nil?
8
 	xml.author(:id => @issue.author_id, :name => @issue.author.name) unless @issue.author.nil?
9
 	xml.assigned_to(:id => @issue.assigned_to_id, :name => @issue.assigned_to.name) unless @issue.assigned_to.nil?
10
  xml.category(:id => @issue.category_id, :name => @issue.category.name) unless @issue.category.nil?
11
  xml.fixed_version(:id => @issue.fixed_version_id, :name => @issue.fixed_version.name) unless @issue.fixed_version.nil?
12
  xml.parent(:id => @issue.parent_id) unless @issue.parent.nil?
13
  
14
  xml.subject 		@issue.subject
15
  xml.description @issue.description
16
  xml.start_date 	@issue.start_date
17
  xml.due_date 		@issue.due_date
18
  xml.done_ratio 	@issue.done_ratio
19
  xml.estimated_hours @issue.estimated_hours
20
  if User.current.allowed_to?(:view_time_entries, @project)
21
  	xml.spent_hours		@issue.spent_hours
22
 	end
23
  
24
  xml.custom_fields do
25
  	@issue.custom_field_values.each do |custom_value|
26
  		xml.custom_field custom_value.value, :id => custom_value.custom_field_id, :name => custom_value.custom_field.name
27
  	end
28
  end unless @issue.custom_field_values.empty?
29
  
30
  xml.created_on @issue.created_on
31
  xml.updated_on @issue.updated_on
32
  
33
  xml.relations do
34
  	@issue.relations.select {|r| r.other_issue(@issue).visible? }.each do |relation|
35
  		xml.relation(:id => relation.id, :issue_id => relation.other_issue(@issue).id, :relation_type => relation.relation_type_for(@issue), :delay => relation.delay)
36
  	end
37
  end
38
  
39
  xml.changesets do
40
  	@issue.changesets.each do |changeset|
41
  		xml.changeset :revision => changeset.revision do
42
  			xml.user(:id => changeset.user_id, :name => changeset.user.name) unless changeset.user.nil?
43
  			xml.comments changeset.comments
44
  			xml.committed_on changeset.committed_on
45
  		end
46
  	end
47
  end if User.current.allowed_to?(:view_changesets, @project) && @issue.changesets.any?
48
  
49
  xml.journals do
50
  	@issue.journals.each do |journal|
51
  		xml.journal :id => journal.id do
52
			 	xml.user(:id => journal.user_id, :name => journal.user.name) unless journal.user.nil?
53
  			xml.notes journal.notes
54
  			xml.details do
55
  				journal.details.each do |detail|
56
  					xml.detail :property => detail.property, :name => detail.prop_key, :old => detail.old_value, :new => detail.value
57
  				end
58
  			end
59
  		end
60
  	end
61
  end unless @issue.journals.empty?
62
end