Create and restore current view of module instance
To use the plugin Share current view plugin, the developers should define how the current view of a module instance is defined and how the current view can be restored from this definition.
Definition of a view in the module
A view can be described via a module configuration, which is transferred to the module during initialization or when displaying the module (showModule). Or also by a route that leads to the current view.
So that the plugin Share current view plugin is made available in the module, the function getCurrentModuleState should be defined in the main class of the module.
This function should return an object that contains either the route to the current view or the module configuration of the current view.
The function and the return value can look like this:
Ext.define("monitor.view.Main", {
// ..........
/**
* Function should return current state object of this module (JSON)
* Current state can consist of it's current route or current moduleCfg
* You can define, what is current state is this function
* The current state can be process in function this.updateInstance(moduleCfg, route)
* and restore the current state on client side
* @returns object {route: "", moduleCfg: {}}
*/
getCurrentModuleState : function () {
const currentState = {
moduleCfg: this.getCurrentState(),
route: this.getCurrentRoute();
};
return currentState;
},
});
|
|
Restoration of the current view
moduleCfg and route are available as properties moduleCfg and moduleRoute of the module during initialization.
This means that you have access to the two variables in the initComponent function in the main class of the module.
When updating the route, if moduleCfg and route are present in the route, they are received as Parameters in the updateInstance(moduleCfg, route) function.
To restore the current view using the URL, you should evaluate moduleCfg or route in the initComponent or updateInstance function.
Usually, moduleCfg or route are evaluated in updateInstance; during initialization, this function is called once in initComponent.
This means that the evaluation code for restoring the current view does not have to be repeated.
Ext.define("monitor.view.Main", {
// .........
initComponent : function () {
// .........
this.callParent();
this.updateInstance(this.moduleCfg, this.moduleRoute);
},
updateInstance : (moduleCfg, moduleRoute) {
// .........
},
/**
* Function should return current state object of this module (JSON)
* Current state can consist of it's current route or current moduleCfg
* You can define what is current state is this function
* The current state can be process in function this.updateInstance(moduleCfg, route)
* and restore the current state on client side
* @returns object {route: "", moduleCfg: {}}
*/
getCurrentModuleState : function () {
const currentState = {
moduleCfg: this.getCurrentState(),
route: this.getCurrentRoute();
};
return currentState;
},
});