AnsweredAssumed Answered

Problems with trying to return ContentItems to the Rich Context Editor

Question asked by Gerald Q. Maguire on Jul 27, 2016
Latest reply on Sep 4, 2016 by Stefanie Sanders

I have written a small simple chunk of ruby sinatra code to be able to add a button to the Rich Content Editor

 

(1) the img insert does not include the alt text:

<img style="width: 32px; height: 32px;" src="https://localhost:14921/emacs_16.png" alt="" /></p>

 

The code is as follows:

 

# Handle POST requests to the endpoint "/lti_launch"

post "/lti_launch" do

    # NOTE: This process isn't checking for correct signatures, anyone that sends a

    # POST request to /lti_launch with the two required parameters will be able

    # to set a placement with a follow-up request to /set_video. I'll cover adding

    # that in another example. There are some great libraries that make it pretty

    # easy, but that wasn't the point of this first example.

    puts "params to /lti_launch"

    puts params

# {"oauth_consumer_key"=>"consumerkey",

#   "oauth_signature_method"=>"HMAC-SHA1",

#   "oauth_timestamp"=>"1469633132", "oauth_nonce"=>"WBo7X2jy4RbwHOrpoMjktPcEflvZVBcVdvkLw1iJZE", "oauth_version"=>"1.0",

#   "context_id"=>"08d76eee8fbed3381e05c688c1f630b7d84cf06c", "context_label"=>"Chip", "context_title"=>"Chip sandbox", "custom_canvas_enrollment_state"=>"active", "custom_fooo"=>"125690",

#   "ext_content_intended_use"=>"embed", "ext_content_return_types"=>"oembed,lti_launch_url,url,image_url,iframe",

#   "ext_content_return_url"=>"https://kth.instructure.com/courses/11/external_content/success/external_tool_dialog",

#   "ext_roles"=>"urn:lti:instrole:ims/lis/Instructor,urn:lti:role:ims/lis/Instructor,urn:lti:sysrole:ims/lis/User",

#   "launch_presentation_document_target"=>"iframe", "launch_presentation_height"=>"500", "launch_presentation_locale"=>"en-GB",

#   "launch_presentation_return_url"=>"https://kth.instructure.com/courses/11/external_content/success/external_tool_dialog",

#   "launch_presentation_width"=>"500", "lti_message_type"=>"basic-lti-launch-request", "lti_version"=>"LTI-1p0",

#   "oauth_callback"=>"about:blank", "resource_link_id"=>"08d76eee8fbed3381e05c688c1f630b7d84cf06c",

#   "resource_link_title"=>"test app", "roles"=>"Instructor", "selection_directive"=>"embed_content",

#   "text"=>"modify", "tool_consumer_info_product_family_code"=>"canvas", "tool_consumer_info_version"=>"cloud",

#   "tool_consumer_instance_contact_email"=>"notifications@instructure.com", "tool_consumer_instance_guid"=>"ySt5cF5tiEU8j5oIzxT2J98caTu54Vl6y9s6gYdS:canvas-lms",

#   "tool_consumer_instance_name"=>"KTH Royal Institute of Technology", "user_id"=>"97d0ab13fafc432d23aa6cd73fc51d769d651f21", "oauth_signature"=>"4/+DYlNxEIa8ZvPEp2LmJ5Fp5Js="}

 

 

    string_to_insert="<p>Some text to insert <a href=\" http://imscatalog.org/\">catalog of certified products</a> junkk junk and more junk</p>"

    # puts "string_to_insert: "

    # puts string_to_insert

    # puts "params['ext_content_return_url']: "

    # puts params['ext_content_return_url']

    #

    # to insert a URL

    #new_url=params['ext_content_return_url']+"?return_type=url&url="+CGI::escape("http://localhost:14921/text_to_return.html")+"&title="+CGI::escape("inserted text")+"&text="+CGI::escape(string_to_insert)

    #

    # to insert a IMG

    new_url=params['ext_content_return_url']+"?return_type=image_url&url="+CGI::escape("https://localhost:14921/emacs_16.png")+"&alt="+CGI::escape("inserted_text")+"&height=32&width=32"

    #

    # to insert a iframe

    #new_url=params['ext_content_return_url']+"?return_type=iframe&url="+CGI::escape("http://localhost:14921/text_to_return.html")+"&title="+CGI::escape("inserted text")+"&height=32&width=32"

    #new_url=params['ext_content_return_url']+"?return_type=iframe&url="+CGI::escape("http://localhost:14921/text_to_return.html")+"&title="+CGI::escape("inserted text")

 

 

    puts new_url

    redirect to (new_url)

end

 

The URL insert produces:

<a title="inserted text" href="http://localhost:14921/text_to_return.html" target="_blank">&lt;p&gt;Some text to insert &lt;a href=" http://imscatalog.org/"&gt;catalog of certified products&lt;/a&gt; junkk junk and more junk&lt;/p&gt;</a>

 

The iframe inserts:

<iframe title="inserted text" src="http://localhost:14921/text_to_return.html" width="300" height="150" allowfullscreen="allowfullscreen" webkitallowfullscreen="webkitallowfullscreen" mozallowfullscreen="mozallowfullscreen"></iframe>

 

text_to_return.html contains:

<p>Some text to insert <a href=\" http://imscatalog.org/\">catalog of certified

    products</a> junkk junk and more junk</p>

 

(2) I have been unable to get the ContentItems returns to work, when I add

"lti_message_type"=>"ContentItemSelectionRequest" to the button

 

and use content_type "application/vnd.ims.lti.v1.contentitems+json"

 

to try to directly return from the post "/lti_launch" do:

...

    {

      "lti_message_type" => "ContentItemSelection",

      "lti_version" => "LTI-1p0",

      "content_items" => {

        "@context" => "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",

        "@graph" => [{

                     "@type" => "ContentItem",

                     "url" => "http://localhost:14921/text_to_return.html",

                     "title" =>  "inserted text",

                     "text" =>  string_to_insert,

                     "mediaType"=>  "text/html",

                     "placementAdvice" => { "presentationDocumentTarget" => "embed" }

                     }]

      }

   }.to_json

 

I do not get anything added to the text in the Rich Context Editor.

 

My goal is to try to insert the equivalent of a Word field so that I can add Zotero bibliographic citations and bibliographies to Canvas Web pages, see the attached.

Outcomes