first trial of linked data map response
This commit is contained in:
parent
1a4a2df6c6
commit
e22c3f33e9
3 changed files with 55 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
||||||
class MapsController < ApplicationController
|
class MapsController < ApplicationController
|
||||||
|
include MapsHelper
|
||||||
|
|
||||||
before_filter :require_user, only: [:create, :update, :screenshot, :destroy]
|
before_filter :require_user, only: [:create, :update, :screenshot, :destroy]
|
||||||
|
|
||||||
|
@ -123,6 +124,21 @@ class MapsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# GET maps/:id/ld
|
||||||
|
def ld
|
||||||
|
|
||||||
|
@current = current_user
|
||||||
|
@map = Map.find(params[:id]).authorize_to_show(@current)
|
||||||
|
|
||||||
|
if not @map
|
||||||
|
redirect_to root_url, notice: "Access denied. That map is private." and return
|
||||||
|
end
|
||||||
|
|
||||||
|
respond_to do |format|
|
||||||
|
format.json { render json: linkeddata(@map) }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# POST maps
|
# POST maps
|
||||||
def create
|
def create
|
||||||
|
|
||||||
|
|
|
@ -33,4 +33,39 @@ module MapsHelper
|
||||||
return temp
|
return temp
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def linkeddata(map)
|
||||||
|
|
||||||
|
@alltopics = map.topics.delete_if {|t| t.permission == "private" && (!authenticated? || (authenticated? && @current.id != t.user_id)) }
|
||||||
|
|
||||||
|
js = Hash.new()
|
||||||
|
|
||||||
|
js['@context'] = { "@vocab" => "http://schema.org/", "mm" => "http://ns.metamaps.cc/", "mmc" => "http://metamaps.cc/metacodes/" }
|
||||||
|
js['@id'] = "http://metamaps.cc/maps/" + map.id.to_s
|
||||||
|
js['@type'] = [ "CreativeWork", "mm:Metamap" ]
|
||||||
|
js['name'] = map.name
|
||||||
|
js['description'] = map.desc
|
||||||
|
|
||||||
|
graph = []
|
||||||
|
|
||||||
|
@alltopics.each do |t|
|
||||||
|
topic = Hash.new()
|
||||||
|
topic['@id'] = 'http://metamaps.cc/topics/' + t.id.to_s
|
||||||
|
topic['@type'] = [
|
||||||
|
'mmc:' + t.metacode_id.to_s
|
||||||
|
]
|
||||||
|
topic['name'] = t.name
|
||||||
|
|
||||||
|
t.synapses2.each do |s|
|
||||||
|
topic['http://metamaps.cc/synapses/' + s.id.to_s] = [ 'http://metamaps.cc/topics/' + s.node1_id.to_s ]
|
||||||
|
end
|
||||||
|
|
||||||
|
graph.push(topic)
|
||||||
|
end
|
||||||
|
|
||||||
|
js['@graph'] = graph
|
||||||
|
|
||||||
|
return js
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,10 @@ Metamaps::Application.routes.draw do
|
||||||
match 'explore/mapper/:id', to: 'maps#index', via: :get, as: :usermaps
|
match 'explore/mapper/:id', to: 'maps#index', via: :get, as: :usermaps
|
||||||
resources :maps, except: [:new, :edit]
|
resources :maps, except: [:new, :edit]
|
||||||
match 'maps/:id/contains', to: 'maps#contains', via: :get, as: :contains
|
match 'maps/:id/contains', to: 'maps#contains', via: :get, as: :contains
|
||||||
|
|
||||||
|
# for linked data structure
|
||||||
|
match 'maps/:id/ld', to: 'maps#ld', via: :get, as: :ld
|
||||||
|
|
||||||
match 'maps/:id/upload_screenshot', to: 'maps#screenshot', via: :post, as: :screenshot
|
match 'maps/:id/upload_screenshot', to: 'maps#screenshot', via: :post, as: :screenshot
|
||||||
|
|
||||||
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => [:sessions]
|
devise_for :users, controllers: { registrations: 'users/registrations', passwords: 'users/passwords', sessions: 'devise/sessions' }, :skip => [:sessions]
|
||||||
|
|
Loading…
Reference in a new issue