Return GeoJSON for notes when JSON format is requested

This commit is contained in:
Tom Hughes 2011-09-18 18:54:39 +01:00
parent 3a654c8919
commit d5295fb485
6 changed files with 37 additions and 16 deletions

View file

@ -52,7 +52,7 @@ class NoteController < ApplicationController
format.rss
format.js
format.xml
format.json { render :json => @notes.to_json }
format.json
format.gpx
end
end
@ -200,7 +200,7 @@ class NoteController < ApplicationController
respond_to do |format|
format.xml
format.rss
format.json { render :json => @note.to_json }
format.json
format.gpx
end
end
@ -256,7 +256,7 @@ class NoteController < ApplicationController
format.rss { render :action => :list }
format.js
format.xml { render :action => :list }
format.json { render :json => @notes.to_json }
format.json { render :action => :list }
format.gpx { render :action => :list }
end
end

View file

@ -72,17 +72,4 @@ class Note < ActiveRecord::Base
def author_name
self.comments.first.author_name
end
# Custom JSON output routine for notes
def to_json(options = {})
super options.reverse_merge(
:methods => [ :lat, :lon ],
:only => [ :id, :status, :created_at ],
:include => {
:comments => {
:only => [ :event, :author_name, :created_at, :body ]
}
}
)
end
end

View file

@ -0,0 +1,19 @@
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ <%= note.lon %>, <%= note.lat %> ]
},
"properties": {
"id": <%= note.id %>,
"date_created": "<%= note.created_at %>",
"nearby": "<%= note.nearby_place %>",
"status": "<%= note.status %>",
<% if note.status == "closed" -%>
"closed_at": "<%= note.closed_at %>",
<% end -%>
"comments": [
<%= render :partial => "note_comment", :collection => note.comments, :spacer_template => "note_spacer" -%>
]
}
}

View file

@ -0,0 +1,8 @@
{
"date": "<%= note_comment.created_at %>",
<% unless note_comment.author_id.nil? -%>
"uid": <%= note_comment.author_id %>,
<% end -%>
"user": "<%= note_comment.author_name %>",
"text": "<%= note_comment.body %>"
}

View file

@ -0,0 +1 @@
,

View file

@ -0,0 +1,6 @@
{
"type": "FeatureCollection",
"features": [
<%= render :partial => "note", :collection => @notes, :spacer_template=> "note_spacer" -%>
]
}