eLabSDK.Plugin

Functions

NameDescription
writeConfig(configObject, [onReady])Write (save) plugin configuration data to the server.

This persists plugin configuration settings to the database, allowing plugins to store
user preferences, state, or settings. The configuration is identified by the plugin's
namespace (rootVar) specified during Plugin initialization. The configuration object is
serialized to JSON and stored. The operation is asynchronous and executes an optional
callback on completion. Use this to save plugin settings, persist user preferences, or
store plugin state between sessions.
readConfig(callBackFn) | Read (retrieve) plugin configuration data from the server.

This fetches the stored plugin configuration settings from the database. The configuration
is identified by the plugin's namespace (rootVar) specified during Plugin initialization.
The configuration is retrieved asynchronously and passed to the callback as a parsed
JavaScript object. If the plugin is not installed, an error is logged. Use this to load
plugin settings at startup, restore user preferences, or access stored plugin state.

writeConfig(configObject, [onReady])

Write (save) plugin configuration data to the server.

This persists plugin configuration settings to the database, allowing plugins to store
user preferences, state, or settings. The configuration is identified by the plugin's
namespace (rootVar) specified during Plugin initialization. The configuration object is
serialized to JSON and stored. The operation is asynchronous and executes an optional
callback on completion. Use this to save plugin settings, persist user preferences, or
store plugin state between sessions.

Kind: global function

ParamTypeDescription
configObjectObjectConfiguration object to save (any serializable JavaScript object)
[onReady]functionOptional callback executed after save completes
onReady.successbooleanTrue if save was successful, false otherwise

Example

// Save plugin configuration
var plugin = new eLabSDK.Plugin({ namespace: 'MyCustomPlugin' });

var config = {
  setting1: 'value1',
  setting2: 42,
  enabled: true
};

plugin.writeConfig(config, function(success) {
  if (success) {
    console.log('Configuration saved successfully');
  } else {
    console.error('Failed to save configuration');
  }
});

Example

// Read, modify, and save configuration
var plugin = new eLabSDK.Plugin({ namespace: 'MyPlugin' });

plugin.readConfig(function(data) {
  if (data.foundPlugin) {
    // Modify existing config
    data.config.counter = (data.config.counter || 0) + 1;
    data.config.lastAccess = new Date().toISOString();
    
    // Save updated config
    plugin.writeConfig(data.config, function(success) {
      console.log('Config updated. Counter: ' + data.config.counter);
    });
  }
});

Example

// Save user preferences
var plugin = new eLabSDK.Plugin({ namespace: 'DataVisualizerPlugin' });

$('#savePreferencesBtn').on('click', function() {
  var preferences = {
    chartType: $('#chartType').val(),
    colorScheme: $('#colorScheme').val(),
    autoRefresh: $('#autoRefresh').is(':checked'),
    refreshInterval: parseInt($('#refreshInterval').val())
  };
  
  plugin.writeConfig(preferences, function(success) {
    if (success) {
      alert('Preferences saved');
    }
  });
});

readConfig(callBackFn)

Read (retrieve) plugin configuration data from the server.

This fetches the stored plugin configuration settings from the database. The configuration
is identified by the plugin's namespace (rootVar) specified during Plugin initialization.
The configuration is retrieved asynchronously and passed to the callback as a parsed
JavaScript object. If the plugin is not installed, an error is logged. Use this to load
plugin settings at startup, restore user preferences, or access stored plugin state.

Kind: global function

ParamTypeDescription
callBackFnfunctionCallback function executed with the configuration data
callBackFn.dataObjectResult object containing plugin status and configuration
callBackFn.data.foundPluginbooleanTrue if plugin is installed, false otherwise
callBackFn.data.configObjectThe parsed configuration object (if plugin found)

Example

// Read and use plugin configuration
var plugin = new eLabSDK.Plugin({ namespace: 'MyCustomPlugin' });

plugin.readConfig(function(data) {
  if (data.foundPlugin) {
    console.log('Plugin configuration:', data.config);
    applySettings(data.config);
  } else {
    console.log('Plugin not installed');
  }
});

Example

// Initialize plugin with saved settings
var plugin = new eLabSDK.Plugin({ namespace: 'DataVisualizerPlugin' });

plugin.readConfig(function(data) {
  if (data.foundPlugin && data.config) {
    // Apply saved preferences
    $('#chartType').val(data.config.chartType || 'bar');
    $('#colorScheme').val(data.config.colorScheme || 'default');
    $('#autoRefresh').prop('checked', data.config.autoRefresh || false);
    $('#refreshInterval').val(data.config.refreshInterval || 60);
    
    console.log('Loaded user preferences');
  } else {
    // Use defaults
    console.log('No saved preferences, using defaults');
  }
});

Example

// Increment counter on each access
var plugin = new eLabSDK.Plugin({ namespace: 'UsageTrackerPlugin' });

plugin.readConfig(function(data) {
  var config = data.config || {};
  
  // Increment access counter
  config.accessCount = (config.accessCount || 0) + 1;
  config.lastAccess = new Date().toISOString();
  
  // Save updated config
  plugin.writeConfig(config, function(success) {
    console.log('Access count: ' + config.accessCount);
  });
});

Example

// Conditional feature based on config
var plugin = new eLabSDK.Plugin({ namespace: 'AdvancedFeaturesPlugin' });

plugin.readConfig(function(data) {
  if (data.foundPlugin && data.config.enableAdvancedMode) {
    console.log('Advanced mode enabled');
    enableAdvancedFeatures();
  } else {
    console.log('Basic mode');
    enableBasicFeatures();
  }
});

© 2023 eLabNext