Skip to content

ActionLogger Tutorial

larsb edited this page Aug 6, 2014 · 26 revisions

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.

Preparations

To make use of the ActionLogger, it is neccessary to include the following Javascript sources:

Creating an ActionLogger instance

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
  });
Clone this wiki locally