Return GeoJSON for notes when JSON format is requested
This commit is contained in:
parent
3a654c8919
commit
d5295fb485
6 changed files with 37 additions and 16 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
19
app/views/note/_note.json.erb
Normal file
19
app/views/note/_note.json.erb
Normal 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" -%>
|
||||
]
|
||||
}
|
||||
}
|
8
app/views/note/_note_comment.json.erb
Normal file
8
app/views/note/_note_comment.json.erb
Normal 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 %>"
|
||||
}
|
1
app/views/note/_note_spacer.json.erb
Normal file
1
app/views/note/_note_spacer.json.erb
Normal file
|
@ -0,0 +1 @@
|
|||
,
|
6
app/views/note/list.json.erb
Normal file
6
app/views/note/list.json.erb
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"type": "FeatureCollection",
|
||||
"features": [
|
||||
<%= render :partial => "note", :collection => @notes, :spacer_template=> "note_spacer" -%>
|
||||
]
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue