webMethods Business Console Documentation 10.5 | webMethods Business Console Documentation | Developing Gadgets for Business Console | Programming Gadgets | Base Controller for Programming Gadgets | Functions Defined in Base Controller
 
Functions Defined in Base Controller
init
The init function can be considered as the constructor function of the controller class. init function is invoked when the gadget is loading into the dashboard. Gadget loading occurs when a gadget is added to a dashboard or when an existing dashboard is launched. All invocations or business logic that are required for loading a gadget must be included in the init function. The init function arguments must match the injected components in the controller. For example, code as shown below.
....
init : function($scope, restClient,eventBus,log,config)
{
....
}
....

ExampleController.$inject = [ '$scope', 'RestServiceProvider','EventBus','$log',
'config'];
The ExampleController controller is injected with $scope, RestServiceProvider, EventBus, $log, and $config objects. These are the services that the gadget framework exposes for various business logic. The order of the injection must match the order of the arguments in the init function to receive the injected object in the init function. Once the objects are injected in the init function, specify a call as shown below.
this._super($scope,eventBus,restClient);
This call registers the $scope, eventBus, and restClient objects with the BaseController.
defineScope
All functions required to be defined on the controller scope is defined here. The scope functions are the main business logic of the gadget that are related to the user interface. Scope functions can be invoked in the init function (after _super call) or through any other flow (for example, on event handling).
As a best practice, all functions that are related to the user interface such as a button click should be defined under the defineScope block. Since scope is an AngularJS object accessibly locally within a gadget, any function defined the defineScope block makes the function available for invocation from the user interface (for example, using ng-click=<function name> ) or from any other place that has access to the controller scope. However, generic business logic that is not tied to the user interface should not be made a part of the controller and should be added to an AngularJS service or factory. This allows the code, to be injectable as well as unit testable.
defineListeners
This function block is invoked once during controller load, and is used to define all the listeners on the EventBus that are related to the controller. Event listeners are fined as shown below.
this.eventBus.addEventListener("EVENT_TYPE_NAME", this._handleEvents.bind(this));
The code above will register the controller as a listener for the type of event mentioned in the first argument of addEventListener. For every listener added to the controller, a respective handling block should be provided under the _handleEvents function block.
destroy
The destroy function is synonymous to the defineListeners block mentioned above.

Copyright © 2014-2019 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.