]> git.openstreetmap.org Git - rails.git/blob - app/views/api/changesets/_changeset.xml.builder
Merge remote-tracking branch 'upstream/pull/4272'
[rails.git] / app / views / api / changesets / _changeset.xml.builder
1 # basic attributes
2
3 attrs = {
4   "id" => changeset.id,
5   "created_at" => changeset.created_at.xmlschema,
6   "open" => changeset.open?,
7   "comments_count" => changeset.comments.length,
8   "changes_count" => changeset.num_changes
9 }
10 attrs["closed_at"] = changeset.closed_at.xmlschema unless changeset.open?
11 changeset.bbox.to_unscaled.add_bounds_to(attrs, "_") if changeset.bbox.complete?
12
13 # user attributes
14
15 if changeset.user.data_public?
16   attrs["uid"] = changeset.user_id
17   attrs["user"] = changeset.user.display_name
18 end
19
20 xml.changeset(attrs) do |changeset_xml_node|
21   changeset.tags.each do |k, v|
22     changeset_xml_node.tag(:k => k, :v => v)
23   end
24
25   # include discussion if requested
26
27   if @include_discussion
28     changeset_xml_node.discussion do |discussion_xml_node|
29       changeset.comments.includes(:author).each do |comment|
30         cattrs = {
31           "id" => comment.id,
32           "date" => comment.created_at.xmlschema
33         }
34         if comment.author.data_public?
35           cattrs["uid"] = comment.author.id
36           cattrs["user"] = comment.author.display_name
37         end
38         discussion_xml_node.comment(cattrs) do |comment_xml_node|
39           comment_xml_node.text(comment.body)
40         end
41       end
42     end
43   end
44 end