Dashboard Module¶
Dashboard module is a module for displaying brief information as blocks. Based on the widget model.
Module structure¶
The Dashboard consists of the three basic components: manager, layout и widget.
Manager¶
Manager is a main component of the module for creating and initializing widgets and layouts and connecting the dashboard to other modules.
let manager = require('modules/dashboard/manager');
Layout¶
Layout is a EJS template, which defines the layout of widgets, parameters of widget templates, a plugin for managing layout grid on the client (for example gridster), and connects common resources.
Basic module layouts are located in the folder /dashboard/layouts. The published ones from the metadata are located in the folder /applications/${meta-namespace}/layouts.
Each layout has a unique ID. When publishing from meta, a prefix is added to the ID.
let dashboard = require('modules/dashboard');
dashboard.getLayout('demo');
dashboard.getLayout('develop-and-test-demo');
When rendering a layout, you must pass an object to manager.
res.render(dashboard.getLayout('demo'), { dashboard });
Widget¶
Widget is an object which is located on the layout and interacts with the server through the ajax-requests.
Basic widgets are located in the folder /dashboard/widgets. The published ones from the metadata are located in the folder /applications/${meta-namespace}/widgets.
A widget contains the the index.js file class and the view.ejs view template. The class must be inherited from the base class /dashboard/base-widget or its descendants.
- The init() method is responsible for the widget initialization when the server starts.
- The refresh() method is called when receiving an ajax request from a client.
- The job() method gets the data for the widget.
Each widget has a unique ID. When publishing a widget from meta, a prefix is added to the ID.
dashboard.getWidget('demo');
dashboard.getWidget('develop-and-test-demo');
When rendering a widget view, you must pass an object to the widget.
<% var widget = dashboard.getWidget('develop-and-test-demo') %>
<%- partial(widget.view, {widget}) %>
Publishing from the meta¶
Example of the structure in applications/develop-and-test:
dashboard
layouts
demo-layout
widgets
demo-widget
index.js
view.ejs
static
layouts
widgets
demo-widget
If you want that the data from meta loaded to the dashboard modules, add the following snippet to the "modules"
section of the ``deploy.json``configuration file of the application:
"dashboard": {
"globals": {
"namespaces": {
"develop-and-test": "Мета для тестирования и разработки"
},
"root": {
"develop-and-test": "applications/develop-and-test/dashboard"
}
}
}