-
Notifications
You must be signed in to change notification settings - Fork 2
ActionLogger Tutorial
This tutorial describes how to set up and use the ActionLogger in the context of scaffolding apps and labs in the Go-Lab project. The ActionLogger is a middleware component to ease developers the implementation of action logging features; not caring about the actual sending of actions.
To make use of the ActionLogger, it is neccessary to include the following Javascript sources:
- the jquery.cookie library, e.g. from http://plugins.jquery.com/cookie/
- the ILS library, https://github.com/go-lab/ils/blob/master/main/ils.js
- the MetadataHandler, https://github.com/go-lab/ils/blob/master/metadata/MetadataHandler.js
- and the ActionLogger itself, https://github.com/go-lab/ils/blob/master/applog/ActionLogger.js
To create an ActionLogger instance, an instance of the GoLabMetadataHandler has to be created first. The MetadataHandler holds information about the current user, document, tool and ILS. This metadata will be automatically added to every log action. The MetadataHandler needs to be initialized with a default set of metadata, where some items will be automatically overridden with information from the ILS metawidget. A developer has to provide a document type (e.g. "conceptMap" or "hypotheses") and a tool name (e.g. "ut.tools.conceptmapper" or "ut.tools.hypothesisScratchpad") with the default metadata set, as these information is specific for each tool. Please note: Creating a MetadataHandler requires to use a callback function, since the creation requires to use aynchronous OpenSocial calls from the ILS libaray.
The following code snippet presents an example of how to create an instance of the ActionLogger:
var documentType = "newDocumentType"; var toolName = "golab.newtool"; var initialMetadata = { "id": "", "published": "", "actor": { "objectType": "person", "id": "unknown", "displayName": "unknown" }, "target": { "objectType": documentType, "id": ut.commons.utils.generateUUID(), "displayName": "unnamed " + documentType }, "generator": { "objectType": "application", "url": window.location.href, "id": ut.commons.utils.generateUUID(), "displayName": toolName }, "provider": { "objectType": "ils", "url": window.location.href, "id": "unknown", "inquiryPhase": "unknown", "displayName": "unknown" } }; new window.golab.ils.metadata.GoLabMetadataHandler(initialMetadata, function(metadataHandler) { var actionLogger = new window.ut.commons.actionlogging.ActionLogger(metadataHandler); //here, actionLogger is ready for usage });