Class: Triannon::AnnotationsController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- Triannon::AnnotationsController
- Includes:
- RdfResponseFormats
- Defined in:
- app/controllers/triannon/annotations_controller.rb
Instance Method Summary collapse
-
#create ⇒ Object
POST /annotations.
-
#destroy ⇒ Object
DELETE /annotations/1.
-
#index ⇒ Object
GET /annotations.
-
#new ⇒ Object
GET /annotations/new.
-
#show ⇒ Object
GET /annotations/1.
Methods included from RdfResponseFormats
#context_url_from_accept, #context_url_from_link, #default_format_jsonld, #mime_type_from_accept
Methods inherited from ApplicationController
#access_token_data, #access_token_generate, #access_token_valid?
Instance Method Details
#create ⇒ Object
POST /annotations
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
# File 'app/controllers/triannon/annotations_controller.rb', line 68 def create # FIXME: this is probably a bad way of allowing app form to be used as well as direct post requests # see https://github.com/sul-dlss/triannon/issues/90 -- prob just want to fix the form to do a POST # note that need to check for empty? if HTTP Header Content-Type is json (but not jsonld). if params["annotation"] && !params["annotation"].empty? # it's from app html form params.require(:annotation).permit(:data) if params["annotation"]["data"] @annotation = Annotation.new(data: params["annotation"]["data"], root_container: params[:anno_root]) end else # it's a direct post request content_type = request.headers["Content-Type"] @annotation = Annotation.new(data: request.body.read, expected_content_type: content_type, root_container: params[:anno_root]) end if @annotation.save default_format_jsonld # NOTE: this must be here and not in before_filter or we get Missing template errors flash[:notice] = "Annotation #{@annotation.id} was successfully created." respond_to do |format| format.jsonld { context_url = context_url_from_link ? context_url_from_link : context_url_from_accept if context_url && context_url == OA::Graph::IIIF_CONTEXT_URL render json: @annotation.jsonld_iiif, status: 201, content_type: "application/ld+json" else render json: @annotation.jsonld_oa, status: 201, content_type: "application/ld+json" end } format.ttl { accept_return_type = mime_type_from_accept(["application/x-turtle", "text/turtle"]) render body: @annotation.graph.to_ttl, status: 201, content_type: accept_return_type if accept_return_type } format.rdfxml { accept_return_type = mime_type_from_accept(["application/rdf+xml", "text/rdf+xml", "text/rdf"]) render body: @annotation.graph.to_rdfxml, status: 201, content_type: accept_return_type if accept_return_type } format.json { accept_return_type = mime_type_from_accept(["application/json", "text/x-json", "application/jsonrequest"]) context_url = context_url_from_link ? context_url_from_link : context_url_from_accept if context_url && context_url == OA::Graph::IIIF_CONTEXT_URL render json: @annotation.jsonld_iiif, status: 201, content_type: accept_return_type if accept_return_type else render json: @annotation.jsonld_oa, status: 201, content_type: accept_return_type if accept_return_type end } format.xml { accept_return_type = mime_type_from_accept(["application/xml", "text/xml", "application/x-xml"]) render body: @annotation.graph.to_rdfxml, status: 201, content_type: accept_return_type if accept_return_type } format.html { redirect_to annotations_path(anno_root: params[:anno_root], id: @annotation.id) } end else render :new, status: 400 end end |
#destroy ⇒ Object
DELETE /annotations/1
132 133 134 135 |
# File 'app/controllers/triannon/annotations_controller.rb', line 132 def destroy @annotation.destroy redirect_to annotations_path(anno_root: params[:anno_root]), status: 204, notice: 'Annotation was successfully destroyed.' end |
#index ⇒ Object
GET /annotations
15 16 17 18 19 20 21 |
# File 'app/controllers/triannon/annotations_controller.rb', line 15 def index if params[:anno_root].present? redirect_to "/#{params[:anno_root]}#{search_path}" else redirect_to search_path end end |
#new ⇒ Object
GET /annotations/new
58 59 60 |
# File 'app/controllers/triannon/annotations_controller.rb', line 58 def new @annotation = Annotation.new end |
#show ⇒ Object
GET /annotations/1
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'app/controllers/triannon/annotations_controller.rb', line 24 def show # TODO: json.set! "@context", OA::Graph::OA_DATED_CONTEXT_URL - would this work? respond_to do |format| format.jsonld { context_url = context_url_from_accept ? context_url_from_accept : context_url_from_link if context_url && context_url == OA::Graph::IIIF_CONTEXT_URL render_jsonld_per_context("iiif", "application/ld+json") else render_jsonld_per_context(params[:jsonld_context], "application/ld+json") end } format.ttl { accept_return_type = mime_type_from_accept(["application/x-turtle", "text/turtle"]) render body: @annotation.graph.to_ttl, content_type: accept_return_type if accept_return_type } format.rdfxml { accept_return_type = mime_type_from_accept(["application/rdf+xml", "text/rdf+xml", "text/rdf"]) render body: @annotation.graph.to_rdfxml, content_type: accept_return_type if accept_return_type } format.json { accept_return_type = mime_type_from_accept(["application/json", "text/x-json", "application/jsonrequest"]) context_url = context_url_from_link ? context_url_from_link : context_url_from_accept if context_url && context_url == OA::Graph::IIIF_CONTEXT_URL render_jsonld_per_context("iiif", accept_return_type) else render_jsonld_per_context(params[:jsonld_context], accept_return_type) end } format.xml { accept_return_type = mime_type_from_accept(["application/xml", "text/xml", "application/x-xml"]) render xml: @annotation.graph.to_rdfxml, content_type: accept_return_type if accept_return_type } format.html { render :show } end end |