Namespace: clbAutomator

Member Of Module: clb-automator

Description

clbAutomator is an AngularJS factory that provide task automation to accomplish a sequence of common operation in Collaboratory.

How to add new tasks

New tasks can be added by calling clbAutomator.registerHandler.

You can see a few example of tasks in the tasks folder.

Evaluate the automator

From the root of this project, you can start a server that will let you write a descriptor and run it.

gulp example

Function: task

Instantiate a new Task intance that will run the code describe for a handlers with the give name.

The descriptor is passed to the task and parametrize it. The task context is computed at the time the task is ran. A default context can be given at load time and it will be fed with the result of each parent (but not sibling) tasks as well.

task(name[, descriptor][, descriptor.after][, context])
Arguments:
  • name (string) – the name of the task to instantiate
  • descriptor (object) – a configuration object that will determine which task to run and in which order
  • descriptor.after (object) – an array of task to run after this one
  • context (object) – a default context to run the task with
Return Task:
  • the new task instance

Function: run

Directly generate tasks from given description and run them.

run(descriptor[, context])
Arguments:
  • descriptor (object) – description of the tasks to run
  • context (object) – the initial context
Return Promise:

promise of the top level task result

Function: createSubtasks

Create an array of tasks given an array containing object where the key is the task name to run and the value is the descriptor parameter.

createSubtasks(after)
Arguments:
  • after (object) – the content of descriptor.after
Return Array/Task:
 

array of subtasks

Function: missingDataError

Return a HbpError when a parameter is missing.

missingDataError(key, config)
Arguments:
  • key (string) – name of the key
  • config (object) – the invalid configuration object
Return HbpError:
 

a HbpError instance

Function: ensureParameters

Ensure that all parameters listed after config are presents.

ensureParameters(config)
Arguments:
  • config (object) – task descriptor
Return object:

created entities

Function: extractAttributes

Return an object that only contains attributes from the attrs list.

extractAttributes(config, attrs)
Arguments:
  • config (object) – key-value store
  • attrs (Array) – a list of keys to extract from config
Return object:

key-value store containing only keys from attrs found in config

Examples

Create a Collab with a few navigation items
// Create a Collab with a few navigation items.
angular.module('MyModule', ['clb-automator'])
.run(function(clbAutomator, $log) {
  var config = {
    title: 'My Custom Collab',
    content: 'My Collab Content',
    private: false
  };
  clbAutomator.task(config).run().then(function(collab) {
      $log.info('Created Collab', collab);
  });
})
Create a Collab with entities and navigation items
clbAutomator.run({
  "collab": {
    "title": "Test Collab Creation",
    "content": "My Collab Description",
    "private": true,
    "after": [
      {
        "storage": {
          "entities": {
            // Use one of your file UUID here.
            "sample.ipynb": "155c1bcc-ee9c-43e2-8190-50c66befa1fa"
          },
          "after": [{
            "nav": {
              "name": "Example Code",
              "app": "Jupyter Notebook",
              "entity": "sample.ipynb"
            }
          }]
        }
      },
      {
        "nav": {
          "name": "Empty Notebook",
          "app": "Jupyter Notebook"
        }
      },
      {
        "nav": {
          "name": "Introduction",
          "app": "Rich Text Editor"
        }
      }
    ]
  }
}).then(function(collab) {
  $log.info('Created Collab', collab);
});
Create a Collab with a pre-filled overview
clbAutomator.run({
  "collab": {
    "title": "Test Collab With Pre Filled Overview",
    "content": "Test collab creation with  a pre filled overview",
    "private": true,
    "after": [{
      "overview": {
        // Use one of your HTML file UUID here.
        "entity": "155c1bcc-ee9c-43e2-8190-50c66befa1fa"
      }
    }]
  }
}).then(function(collab) {
  $log.info('Created Collab', collab);
});