Connecting Dashboard Plugin in the Web Application

A plugin is a separately written block that can be connected to a dashboard.

On working with plugins in the desktop application, units written in the Fore language are used. To work in the web application, a plugin must be written on JavaScript.

Plugins are registered in general repository parameters and refer to the Fore unit for working in the desktop application and to the script for working in the web application.

To connect a plugin in the web application:

  1. Create a *.js file of plugin taking into account JS script.

  2. Add the *.js plugin to the web application root folder, for example: C:\Program Files (x86)\Foresight\Foresight Analytics Platform 9 Web Application\plugins.

  3. Connect the plugin using one of the methods:

Connect plugin via repository

Connect plugin via the PP.xml file

Connect plugin via the regPluginBlock registration method

NOTE. When the regPluginBlock registration method is used, the plugin is connected on method call, in other cases it is connected on system login.

After executing the operations the plugin is registered in the web application:

Plugins are displayed in the drop-down menu of the  Plugins button on the dashboard ribbon.

Plugin JS Script Structure

When writing a plugin and new classes follow code writing recommendations.

Plugin JS script structure:

// Set manual registration block
(function ()
{
  if (window.Kap)
  {
    Kap.regPluginBlock({
      Id: "MyLabel",  //ID, by which plugin block is connected with its implementation
      Name: "MyLabelText",  //block type name
      View: "PP.Ui.Dashboard.MyLabel",  //visualizer class or visualizer class name
      Icon: "../build/img/app/MainIcon.png",  //path to plugin icon (16*16), optional parameter
      SourceClass: PP.Mb.MetabaseObjectClass.KE_CLASS_EXPRESSREPORT, // typeof code of data source class
      Js: "../plugins/MyLabel.js",  //for dynamic script loading with plugin implementation, mandatory parameter
      Master: "PP.Ui.MyMaster",  //wizard class or wizard class name
      Props: {  // additional plugin parameters for setting default, optional parameter
        pluginProps: {}
      }
    });
  }
})();
 
if (!PP.Ui.MyLabel)
{
  PP.Ui.MyLabel = {};
  PP.initNamespace(PP.Ui.MyLabel, "PP.Ui.MyLabel");
}
 
// Create a visualizer prototype for registered block
PP.Ui.MyLabel = function(settings) {
  this._Source = null;
  this._bgFlag = false;
  this.PropertyChanged = new PP.Delegate();
  this.Refreshed = new PP.Delegate();
  PP.Ui.MyLabel.base.constructor.apply(this, arguments);
  this.setContent("MyLabelText");
};
PP.initClass(PP.Ui.MyLabel, PP.Ui.Label, "PP.Ui.MyLabel");
 
PP.Ui.MyLabel.prototype._propertyChangedFire = function () {
  this.PropertyChanged.fire(this);
};
 
PP.Ui.MyLabel.prototype._refreshedFire = function () {
  console.log("My Label Refreshed");
  this.Refreshed.fire(this);
};
 
// If plugin is to support work with data source, // set a data source for visualizer opened in dashboard PP.Ui.MyLabel.prototype.setSource = function(source) {   this._Source = source;   this.setContent("Source loaded: " + this._Source.getId());   this._refreshedFire(); };  
// If plugin is to support stored properties,set the setProps and getProps methods PP.Ui.MyLabel.prototype.setProps = function(value) {  // method for setting stored block properties   if (value) {     var props = JSON.parse(value);     this._bgFlag = props.bgFlag ? props.bgFlag : false;   } else {     this._bgFlag = false;   }   this.refresh(); };   PP.Ui.MyLabel.prototype.getProps = function() {  //method that gives dashboard properties to be stored   var props = {     bgFlag: this._bgFlag   };   return JSON.stringify(props); };   PP.Ui.MyLabel.prototype.refresh = function() {   this._DomNode.style.backgroundColor = this._bgFlag ? "green" : "transparent";   this._refreshedFire(); };   PP.Ui.MyLabel.prototype.refreshAll = function () {  // method is called on data block refresh };   PP.Ui.MyLabel.prototype.setWidth = function () {   if (this._Instance)   this._redraw(); };   PP.Ui.MyLabel.prototype.setHeight = function () {   if (this._Instance)   this._redraw(); };   // If plugin is to have proper context menu, set the getContextMenu method PP.Ui.MyLabel.prototype.getContextMenu = function() {   var _DataView = this;   var menu = new PP.Ui.Menu({     Items : [ {       MenuItem : {         Id : "pluginMenuItem",         Content : "plugin menu item",         Checked : _DataView._bgFlag,         CheckedChanged : function(sender, args) {           _DataView._bgFlag = sender.getChecked();           _DataView.refresh();         }       }     }]   });   return menu; };   // Create a wizard prototype for registered block PP.Ui.MyMaster = function(settings) {   this._DataView;   PP.Ui.MyMaster.base.constructor.apply(this, arguments);   var myPanel = new PP.Ui.MasterPanel(   {     Id: "MyPluginMaster",     ViewType: PP.Ui.NavigationItem,     Content: "Plugin settings...",     Title: "My plugin master"   });   myPanel.getHeaderControl().CheckedChanged.add(this._onPropsChanged, this);   this.addMasterPanel(myPanel); }; PP.initClass(PP.Ui.MyMaster, PP.Ui.Master, "PP.Ui.MyMaster");   // If additional side panel tabs containing its settings are to be displayed for plugin, // set implementation of the setDataView(view) method where view is plugin visualizer instance. // Set the additional Master property in registration block PP.Ui.MyMaster.prototype.setDataView = function(view) {   this._DataView = view;   for (var i = 0; i < this.getItems().length; i++) {     var item = this.getItem(i);     if (item.getId() === "MyPluginMaster") {       item.setTitle("My plugin master. Data view type: " + view.getTypeName());       if (view._bgFlag) {         item.getHeaderControl().setChecked(view._bgFlag, false);       }     }   } };   PP.Ui.MyMaster.prototype._onPropsChanged = function(sender, args) {   this._DataView._bgFlag = args.CheckedState;   this._DataView._propertyChangedFire();   this._DataView.refresh(); };

See also:

Code Writing Recommendations | Registering Plugin in the Desktop Application