Profitbase InVision is built using AngularJS (1.0 right now), so some experience with AngularJS is required for building plugins.

You can download the source code and sample database for this demo from the link above. I won’t talk about how I built the UI since there’s nothing InVision specific about it, it’s just standard HTML, CSS and AngularJS.

We’ll create a Workbook used by Sienar Fleet Systems to register incidents with their TIE Fighter starships. The Workbook will contain a plugin for registering the incidents, and two standard charts to visualize the types and number of incidents. When a new incident is added, we’ll update the charts immediately, showing how plugins and standard components can interact with each other.

For those of you not familiar with InVision, I want to point out that you can create this type of app by just using the standard components. You don’t need to create a plugin for it. However, I didn’t want to create some complex plugin that would probably overshadow the point of this series, which is to show the concepts of creating a plugin and how to use the InVision programming model.

Here’s a taste of what it will look like when we’re done. Yes, I know, it’s an amazing piece of software 🙂

Setting up the environment

Before we can start creating a plugin, we need to set up our development environment. I’ll use Visual Studio Code and Typescript for writing code, but you can use any editor you’d like. Also, we’ll need to install NodeJS, the Node Package Manager (npm), git and the TypeScript compiler.

Make sure the installer adds the path to the NodeJS executable to the PATH environment variable. It usually only adds npm.
Edit the system Environment Variables and add the path to nodejs (usually C:\Program Files\node)

Grant at least Modify, Read and execute, Write permissions to the Client install folder. You can do this by opening Windows File Explorer and go to the InVision install folder, usually C:\Program Files (x86)\Profitbase\Profitbase InVision 2.0 xxx. Right click the Client folder, Properties -> Security -> Edit -> grant at least Modify, Read and execute + Write permissions to a user group you belong to. (Users (xxx) will normally work)

Open a command prompt as Administrator and go to the Client web site folder, usually C:\Program Files (x86)\Profitbase\Profitbase InVision 2.0 xxx\Client. (Note! If you left the command prompt open after installing nodejs or git, close and reopen it.

Run npm install
This command will install the node modules required to run the plugin build script.

To display a plugin in a Workbook, you need to add a plugin component which acts as the placeholder for indicating its type, position and size. You can do this step before or after you have created the plugin, but I’ll do it upfront this time.

Open / create an InVision Solution

Create a new Workbook and add a page

In the Workbook Designer, expand the Extension folder in the Resources Toolbox.

Drag and drop a Generic Plugin onto the page, and size it to a desired size

In the Part Properties window, set the following properties:

Name : SFS Incidents (optional and not important, the name is just for us mortals, InVision does not use it for anything)

Selector : sienar-incidents. This property is important. It indicates the type of our plugin, which angularjs uses to render our view and bootstrap our plugin code.

Developing the plugin

Having defined where we want the plugin to go, and with our development environment is up and running, we’re ready for the fun part – developing the plugin.

When InVision is installed, a sample plugin is installed which can be used as a template for creating a new plugin. We’ll use the sample plugin as a starting point to get up and running quickly. Let’s call our plugin SienarIncidents (Sienar Fleet Systems Incidents).

Navigate to the <install path>\Client\PluginSrc folder

Copy the SampleOne folder and rename it to SienarIncidents

Open the folder and delete SampleOne.js and SampleOne.js.map

Rename SampleOne.ts to sienarincidents.ts

Open the folder in Visual Studio Code. The easiest way of doing this is right clicking an empty space and choose “Open with Code”.

In VS Code, expand the .vscode node and open tasks.json

Find the “args” property and change the item in the array from “SampleOne.ts” to “sienarincidents.ts”. This tells the TypeScript compiler which source code files to compile / transpile into JavaScript.

in VS Code, add a new file, “sienarincidents.html”. This fill will contain our user interface code (HTML). Add a simple text to the document, “Sienar Incidents”.

In VS Code, open sienarincidents.ts and uncomment the contents of the file.

Modify the sample code so that it looks like the code below.

The basic code required for our (or any) plugin looks like what’s shown below. Since learning angularjs is outside the scope of this post, I won’t go into details about the angular parts of the code, but rather focus on the key concepts that are InVision specific.

The reference directives at the top ( /// <reference path=”….) gives you IntelliSense while typing. The d.ts-files contains the API definition for InVision and the 3rd party libraries included with InVision.

The templateUrl property of the directive points to the .html-file we added to the folder. It must contain the path relative to the pluginSrc folder.

The SienarIncidentsComponent (class) is where we’ll write our business logic. The class extens the PluginComponet base class provided by InVision. By extending the PluginComponent base class, your plugin gets initialized properly and the InVision application services will be available within the plugin.

The onGenericAction gets called when the GenericAction of the plugin is called by some other Workbook component or process. The action event argument passed to the function contains information about the event so that you can decide what to do when the function gets called. The action must always return a promise.

The calls to angular.module(‘invision’) registers the controller, directive and the component itself so that angular can instantiate our plugin and provide dependency injection.
A very important part is the line angular.module(‘invision’).directive(‘sienarIncidents’,….); This is where we specify the plugin type. It directly reflects the selector name we provided in the earlier step when we added the plugin placeholder to the Workbook.
We specified the selector name to be sienar-incidents, and we specified the directive to be sienarIncidents. Angular uses attribute normalization, so InVision will insert a <sienar-incidents></sienar-incidents> HTML element into the document. So by convention, angular expects “sienarIncidents” directive to be registered.

Compile and publish the plugin

With our code ready, it needs to be compiled and published so it gets loaded to the browser.

In the command prompt, go to the folder where the client application is installed (<install path>\Client) and run npm run plugins. Running the command will do the following:

Bundle all .js files in subdirectories of PluginSrc into a single plugins.js file and copy it to Scripts\plugins

Bundle all .html files in subdirectories of PluginSrc into a single plugins.views.js file and copy it to Scripts\plugins

Bundle all .css files in subdirectories of PluginSrc into a single plugins.css file and copy it to Scripts\plugins.

View your amazing work come to life

Open or reload the workbook we created earlier. The plugin should apprear and display the text we added. If it does not appear, open the browser dev tools (F12) and review the Console (log) for any errors.