Add a Tag That Reads Marketing to the Metadata for This Document and Then Return to the Document
A couple of months agone I had started working on an export tool that would export a Google doc in the OU-XML format. The rationale? The commencement couple of drafts of the instruction material that will exist delivered through the VLE in the forthcoming (October, 2015) OU Data management and assay course (TM351) accept been prepared in Google docs, and the production procedure will shortly have to movement to the Open Academy'southward XML workflow. This workflow is built around an OU divers schema, often referred to equally OU-XML (or OUXML), and is supported by a couple of oXygen XML editor extensions that make it piece of cake to preview rendered versions of the documents in a exam VLE site.
The schema itself includes several elements that are more akin to metadata elements than bodily content – things like the class code, course championship, for case, or the byline (or atomic number 82 author) of a particular unit.
Support for a small amount of metadata is provided by Google Drive, but the only easily customisable element is a free text description chemical element.
So whilst patching a couple of "problems" today with the Google Docs to OU-XML generator, and adding a menu option that allows users to create a nix file in Google Drive that contains the OU-XML and any associated image files for a particular Google md, I thought information technology might also be handy to add some support for additional metadata elements. Google Drive apps support a Backdrop class that allows metadata properties represented as central-value pairs to exist associated with a detail certificate, user or script. Google Apps Script can be used to set and retrieve these properties. In addition, Google Apps Script tin can be used to generate templated HTML user interface forms that can exist used to extend Google docs or spreadsheets functionality.
In detail, I created a handful of Google Apps Script functions to pop up a templated console, save metadata descriptions entered into the metadata course as document backdrop, and think the value of a particular metadata chemical element.
//Pop up the metadata edit/brandish console //The document is created as a templated HTML document function metadataView() { // Generate the HTML html= HtmlService .createTemplateFromFile('metadata') .evaluate() .setSandboxMode(HtmlService.SandboxMode.IFRAME); //Popular upwardly a console and render the HTML describing the metadata grade inside it DocumentApp.getUi().showModalDialog(html, 'Metadata'); } //This function sets the document backdrop from the metadata form elements function processMetadataForm(theForm) { var props=PropertiesService.getDocumentProperties() //Process each form chemical element (atm, they are just input text elements) for (var particular in theForm) { props.setProperty(item,theForm[item]) Logger.log(item+':::'+theForm[detail]); } }
The templated HTML course is configured using a set of desired metadata elements. Each element is described using a label that is displayed in the class, an attribute proper name which should exist a single discussion) and an optional default value. The template also demonstrates how we tin can phone call a server side Apps Script role from the dialogue using the google.script.run.FUNCTION_NAME construction.
<script src="//ajax.googleapis.com/ajax/libs/jquery/ane.9.i/jquery.min.js"></script> <? //Add metadata fields here in the following format: //[Label, a unique identifier (unique word, no spaces or punctuation), an optional default value] var metadataItems =[ ["Lead Writer","leadAuthor"], ["Course Code","courseCode"], ["Course Title","courseTitle"], ["Unit Title","unitTitle"], ["Rendering","rendering","VLE2 staff (learn3)"] ] ?> <? var metadata = PropertiesService.getDocumentProperties() ?> <script> //When the metadata has been successfully saved as document properties // shut the metadata grade panel function onSave() {google.script.host.shut()} </script> <course id='metadataForm'> <!-- Construct a gear up of form elements, one for each metadata item --> <? for (var i = 0; i < metadataItems.length; i++) { ?> <div><?= metadataItems[i][0] ?>: <input type="text" name = "<?= metadataItems[i][1] ?>" <? val='' if (metadataItems[i].length>2) val= metadataItems[i][2] ?> value= "<?= metadata.getProperty(metadataItems[i][i]) ? metadata.getProperty(metadataItems[i][i]) : val ?>" /> </div> <? } ?> </form> <div> <input type="push" value="Save & Close" onclick="google.script.run.withSuccessHandler(onSave).processMetadataForm(certificate.getElementById('metadataForm'))" /> <input type="button" value="Cancel" onclick="google.script.host.close()" /> </div>
When the metadataView() function is called from the Add together-Ons menu, it pops a dialogue that looks (in unstyled class) something similar this:
Metadata elements are loaded in to the form if they be or a default value is specified.
When generating the export OU-XML, a helper function grabs the value of the relevant metadata chemical element from the certificate properties. This value then and then exist inserted into the OU XML at the appropriate betoken.
//A helper function to display a particular metadata element //This office is chosen from the metadata class function getProp(key) { var props= PropertiesService.getDocumentProperties() return props.getProperty(key) ? props.getProperty(key) : ''; } var COURSECODE= getProp('courseCode');
Ane effect with this approach is that if we have lots of documents relating to different units for the same course, we may need to enter the same values for several metadata elements beyond each document (for example, the form lawmaking and course championship). Unfortunately, Google Drive does not back up capricious backdrop for folders. 1 solution, suggested by Tom Smith/@everythingabili was to employ the description element for a folder to shop JSON represented metadata. I think we could actually simplify that, using a line based representation or a simple delimited representation that we can easily split on, something like:
courseCode :: TM351;; courseTitle:: Data Management and Analysis
for case. Nosotros could then separate on ;; to get each pair, strip whitespace, split on :: and strip whitespace again to become the primal:value elements for each metadata detail.
I guess one manner of getting the folder decription given a particular certificate equally a starting point is to find the parent folder using file#getParents() perhaps?) and then call binder#getDescription()?
Another arroyo might exist to have a dummy, canonically named file in each folder (metadata for example), that we add metadata to, and and then whenever we open a new file in the folder we look for the metadata file, get its metadata property values, and use those to seed the metadata values for our content document.
Finally, it'south peradventure worth also pondering the issue of generating the OU-XML consign for all the documents within a given binder? One way to do this might be to create a function off a each certificate that will find the parent binder, observe all the files (except, perhaps, a metadata file?!) in that binder, and and so run the OU-XML generator over all of them, bundling them up into a single zip file, maybe with a directory construction that puts the OU XML for each certificate, along with any image files associated with it, into separate folders?
Only it probably isn't.. I suspect that if the migration to the OU-XML format, if it hasn't already happened, will involve copying and pasting…
PS for completeness, the menu option can be installed equally follows:
function onOpen(e) { DocumentApp.getUi().createAddonMenu() .addItem('Metadata','metadataView') .addToUi(); }
Source: https://blog.ouseful.info/2015/01/28/adding-metadata-to-google-docs/
0 Response to "Add a Tag That Reads Marketing to the Metadata for This Document and Then Return to the Document"
Publicar un comentario