~~NOTOC~~
Sunstone client-side has a plugin-oriented structure that allows users to select which features are active and to develop their own extensions and easily include them in the web interface. Plugins can use the Sunstone interface to run and modify common OpenNebula actions, show custom information panels and offer extended capabilities for Sunstone.
This guide will explain how to configure existing plugins, how plugins work and what can be achieved with them. A full reference of the plugin API can be found [[.:sunstone_plugin_reference|here]].
======Configuring Sunstone Plugins======
===== sunstone-plugins.yaml =====
Sunstone plugins configuration file states which Sunstone base plugin files should be loaded after the user successfully logs in the Sunstone interface.
It can be found at ''/etc/one/sunstone-plugins.yaml''.
In practice, the Sunstone base plugins are equivalent the main menu tabs in the Sunstone interface:
{{ :documentation:rel3.0:sunstone:menu.png |}}
This configuration file uses the YAML format, and allows to indicate for which users or groups certain plugin files will load. This is done through the following procedure:
* First check: is there a rule enabling/disabling the plugin for the user?
* Second check: is there a rule enabling/disabling the plugin for the user group?
* Third check: is there a rule enabling/disabling the plugin for all users?
The configuration file uses de following syntax:
- plugin/file/path.js:
:ALL: true|false # Should this file be loaded for everyone?
:users: # List of users
user1: true|false # Enable/disable file for this user
user2: true|false # Enable/disable file for this user
:groups:
group1: true|false # Enable/disable file for users in this group
**Example**: the admin dashboard plugin file is disabled for all users, and loaded only for users belonging to the ''oneadmin'' group. The user dashboard is enabled for all users, but disabled for users belonging to the ''oneadmin'' group:
- plugins/dashboard-tab.js:
:ALL: false
:user:
:group:
oneadmin: true
- plugins/dashboard-users-tab.js:
:ALL: true
:user:
:group:
oneadmin: false
=====User Plugins=====
User plugins should be dropped in the ''public/js/user-plugins'' folder in the Suntone base directory. These plugins will be loaded automatically after successful user login, following alphabetic order of their filename, and after the base plugins are loaded.
======Customizable elements in Sunstone======
=====Actions=====
Actions are configurable objects which allow Sunstone to run common and custom methods. Plugins can easily:
* Customize the actions (change behaviour, complete it, tweak it)
* Add conditions to the actions (allow execution only if certain conditions are met).
* Use opennebula.js methods. ''Sunstone.runAction()'', A wrapper for the opennebula.js methods (containing ajax communication with the server side of Sunstone for actions on OpenNebula), is provided to ease the utilization of them.
* Pop-up custom information dialogs when actions are executed or fail.
:?: **Why using actions?** Actions have an associated function (''call'') which is defined by a configuration object which must be added to Sunstone. Then ''Suntone.runAction()'' is used to execute their associated function ([[#2. Sunstone options setup|see instructions below]]). You may be wondering why so much hassle when you can simply use the action ''call'' directly from your code and get things going.
When you define an action, you are not only taking advantage of the ''opennebula.js'' wrapper, the built-in ''notify'' option to inform the user or the ''condition'' check before running your function. You can take care of all this manually without many problems. The real added value of actions is that they can be changed, tweaked and replaced by any other plugins willing to do so. So by defining an action you are implicitly accepting that someone else may come and change it's behaviour, disable it or simply re-use it very easily in exact the terms you defined in the action object.
=====Main tabs=====
Main tabs are the elements on the left-side menu. When clicking on the menu items, the content of the clicked //main tab// is shown on the main window. Sunstone allows to add/remove/modify these tabs.
=====Set of action buttons=====
Action buttons are a set of clickable elements associated with an action that can be added, customized. rearranged very easily. Buttons are contained within the main tabs, generated automaticly from an configuration object and included in their content. They offer as well the possibility to use standard confirmation dialogs before running their associated action.
=====Extended information panels=====
Information panels pop-up from the bottom of the GUI to offer extended informations about a particular element (like a Virtual Machine). They are composed by tabs. Sunstone plugins can easily create and modify their own information panels, tabs and contents. Sunstone provides an easy method to pop-up the panels when needed.
======Writing a plugin for Sunstone======
=====Files=====
Sunstone plugins need to be written in Javascript. There are two main files in Sunstone (public/js folder) related to the development of plugins and 9 standard plugins:
* ''sunstone.js'' offers a full interface for plugins to manage the customizable capabilities of the interface (see the [[.:sunstone_plugin_reference| Sunstone Plugin Reference]]).
* ''sunstone-util.js'' contains multiple helper functions to ease common tasks of the base Sunstone plugins.
* ''dashboard-tab.js'', ''dashboard-users-tab.js'', ''hosts-tab.js'', ''vms-tab.js'', ''users-tab.js'', ''vnets-tab.js'', ''templates-tab.js'', ''images-tab.js'', ''groups-tab.js'', ''acls-tab.js'' can be found under the plugins/ folder. They are the standard plugins for Sunstone corresponding to each of the main tabs of the GUI. They can be inspiring when writing new plugins or customizing its current features.
For user contributed plugins, they should be placed under the ''public/js/user-plugins'' folder.
=====Structure=====
We have used the following structure when writing a plugin, though it is as flexible as the Javascript language allows:
==== 1. Variable declaration - static contents ====
Declare first the global variables and static contents that your plugin will be using.
* //Example//: ''users-tab.js'' plugin
Users plugin declares the tab content (HTML for the user list table inside a form -as it as buttons, also the HTML content for the user creation dialog and two variables to store the user list in JSON format and the JQuery dataTable.
var users_tab_content =
'