djplaner / word-to-canvas-module

A userscript that will create a Canvas Module (including all module items) from a Word document (using special styles)

Home Page:https://djplaner.github.io/word-to-canvas-module/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add an file link style

djplaner opened this issue · comments

Have a canvas file link style in word that allows linking to files within pages.

anchor text is the display name, the link is either file name or link.

  • Define the Word doc style Canvas File Link
  • wordConverter: Recognise and convert to canvasFileLink
  • add canvasFileLink to "find" resources
  • add canvasFileLink to "add" resources to module
  • do more tresting 1499edn
  • do more testing com31
  • Figure out what to do with file types that can't be previewed
  • Handle/fallback on errors somewhat better
  • tidy up code

Required change

Original

<span class="canvasFileLink">Lifelong Learning and Alice Srpings.docx</span>

Where the innerText is the name of the file.

preview_in_overlay

<span class="instructure_file_holder link_holder instructure_file_link_holder">
<a class="inline_disabled preview_in_overlay" href="FILE_URL?wrap=1" target="_blank"
    data-canvas-previewable="true" data-api-endpoint="FILE_URL" data-api-returntype="File">
</span>

preview inline

<span class="instructure_file_holder link_holder instructure_file_link_holder">
<a class="file_preview_link" href="FILE_URL?wrap=1" target="_blank"
    data-canvas-previewable="true" data-api-endpoint="FILE_URL" data-api-returntype="File"
    aria-expanded="false" aria-controls="preview_1"
>
</span>

Implementation

  • Modify to check the HTML for canvasFileLinks so they can be added to the "find"
  • Make sure they are searched for and the result recorded (success or not) - where is this info stored?
  • Modify the HTML of the item to replace span with detail

Code

c2m_CompletedView calls

  1. model.createModule
  2. checkEmptyModuleCreated (event handler) which calls findOrCreateModuleItems
  3. checkItemFoundCreated (eventHandler) which calls addModuleItem to add first found item
  4. checkModuleItemAdded (eventHandler) which calls
    1. addModuleItem when not finished to add the next item
    2. renderCreationResults when finished

findOrCreateModuleItems

Currently loops through each item and then calls findOrCreteItem

  • Modify createModule to create this.canvasModules.fileLinks amd ...numFileLinks

    • Create a new data structure with each of the file links to be added
    • Each fileLink includes the item index to which it belongs, the filename to search for and space for the return data
  • checkEmptyModuleCreated should then call new findFileLinks to find all the file links

  • insert checkFileLinksCreated as new event handler for findFileLinks which eventually calls findOrCeateModuleItems when all created

  • modify findOrCreateModuleItem to check if there are any fleLinks for this item, if there is it needs to update the HTML/body for the item before it is created. So that it adds the right informatoin

  • Will need a timeout

  • Modify to check if item html contains span.canvasFileLink,

May need to create a new item type OR perhaps call a different method findExistingFile

  • take item index and the file link