Format closed_at correctly in changeset API responses
[rails.git] / app / views / api / changesets / _changeset.builder
1 # basic attributes
2
3 attrs = {
4   "id" => changeset.id,
5   "created_at" => changeset.created_at.xmlschema,
6   "open" => changeset.is_open?,
7   "comments_count" => changeset.comments.length,
8   "changes_count" => changeset.num_changes
9 }
10 attrs["closed_at"] = changeset.closed_at.xmlschema unless changeset.is_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           "date" => comment.created_at.xmlschema
32         }
33         if comment.author.data_public?
34           cattrs["uid"] = comment.author.id
35           cattrs["user"] = comment.author.display_name
36         end
37         discussion_xml_node.comment(cattrs) do |comment_xml_node|
38           comment_xml_node.text(comment.body)
39         end
40       end
41     end
42   end
43 end