import OlapicWidgetsHandler from 'olapic-devkit/src/core/entities/widget/widget.handler.js'
OlapicWidgetsHandler
Extends:
The entities handler for the Olapic widgets in DevKit. It's basically a set of static methods used to create and obtain widgets from the API or DevKit itself.
Static Method Summary
Static Public Methods | ||
public static |
entityFromJSON(json: Object): OlapicWidgetEntity It parses a raw API JSON information and returns a widget entity. |
|
public static |
getSettingsByID(ID: String): Promise<Object, Error> Gets an Olapic widget settings by its unique ID. |
|
public static |
getSettingsByUrl(url: String): Promise<Object, Error> Gets an Olapic widget settings by its API url. |
|
public static |
getWidgetCategory(widget: *): Promise<OlapicCategoryEntity, Error> Gets the widget selected category. |
|
public static |
Gets an Olapic widget by its unique hash. |
|
public static |
Gets an Olapic widget by its API url. |
|
public static |
getWidgetSettings(widget: OlapicWidgetEntity): Promise<Object, Error> Gets the settings for a widget. |
|
public static |
getWidgetStream(widget: *): Promise<OlapicStreamEntity, Error> Gets a widget selected stream. |
Inherited Summary
From class OlapicEntitiesHandler | ||
public static get |
DevKit: OlapicDevKit: * A quick shortcut to get access to the DevKit singleton. |
|
public static |
getFormsFromObject(obj: Object): Object This will be used when creating an entity to parse any list of action forms and returns them with a better format. |
|
public static |
getResourcesFromObject(obj: Object): Object This will be used when creating an entity to parse any list of linked entities and returns them with a better format. |
Static Public Methods
public static entityFromJSON(json: Object): OlapicWidgetEntity source
It parses a raw API JSON information and returns a widget entity.
Params:
Name | Type | Attribute | Description |
json | Object | The raw API JSON object to parse. |
Example:
let JSONInfo = {
metadata: {},
data: {
name: 'My Widget',
},
};
let widget = OlapicWidgetsHandler.entityFromJSON(JSONInfo);
// It will log 'My Widget'
console.log(widget.get('name'));
public static getSettingsByID(ID: String): Promise<Object, Error> source
Gets an Olapic widget settings by its unique ID.
Params:
Name | Type | Attribute | Description |
ID | String | The settings ID. |
Example:
OlapicWidgetsHandler.getSettingsByID(12)
.then((settings) => {
console.log('Settings: ', settings);
});
public static getSettingsByUrl(url: String): Promise<Object, Error> source
Gets an Olapic widget settings by its API url.
Params:
Name | Type | Attribute | Description |
url | String | The Olapic API url for the widget settings. |
Example:
OlapicWidgetsHandler.getSettingsByUrl('http://...')
.then((settings) => {
console.log('Settings: ', settings);
});
public static getWidgetCategory(widget: *): Promise<OlapicCategoryEntity, Error> source
Gets the widget selected category.
Params:
Name | Type | Attribute | Description |
widget | * |
Return:
Promise<OlapicCategoryEntity, Error> | It will return an category entity or
an |
Example:
OlapicWidgetsHandler.getWidgetCategory(widgetEntity).then((category) => {
console.log(category.get('name'));
});
public static getWidgetInstanceByHash(hash: String): Promise<OlapicWidgetEntity, Error> source
Gets an Olapic widget by its unique hash.
Params:
Name | Type | Attribute | Description |
hash | String | The Olapic widget unique hash. |
Return:
Promise<OlapicWidgetEntity, Error> | The widget entity or an |
Example:
OlapicWidgetsHandler.getWidgetInstanceByHash('abc')
.then((widget) => {
console.log('Widget: ', widget);
});
public static getWidgetInstanceByUrl(url: String): Promise<OlapicWidgetEntity, Error> source
Gets an Olapic widget by its API url.
Params:
Name | Type | Attribute | Description |
url | String | The Olapic API url for the widget. |
Return:
Promise<OlapicWidgetEntity, Error> | The widget entity or an |
Example:
OlapicWidgetsHandler.getWidgetInstanceByUrl('http://...')
.then((widget) => {
console.log('Widget: ', widget);
});
public static getWidgetSettings(widget: OlapicWidgetEntity): Promise<Object, Error> source
Gets the settings for a widget.
Params:
Name | Type | Attribute | Description |
widget | OlapicWidgetEntity | The widget entity for which the settings are for. |
public static getWidgetStream(widget: *): Promise<OlapicStreamEntity, Error> source
Gets a widget selected stream.
Params:
Name | Type | Attribute | Description |
widget | * |
Return:
Promise<OlapicStreamEntity, Error> | It will return an stream entity or an |
Example:
OlapicWidgetsHandler.getWidgetStream(widgetEntity).then((stream) => {
console.log(stream.get('name'));
});