Hi! We are making a module which add Ignition Perspective components (react components). For this we need some common settings, this could be badge handling, style type, etc.
So I have made a project property view in the designer:
But I haven’t found a good way to store the data and to get the data down to the component.
ChatGPT suggested to use model delegate to send the data from the gateway to the component.
I use this to set the data:
public ObComponentTypeProjectSettingsEditor(DesignerContext context) {
super(new GridBagLayout());
project = context.getProject();
Optional<Resource> resource = project.getSingletonResource(RESOURCE_TYPE);
if (resource.isPresent()) {
try {
settings = ResourceUtil.decodeOrNull(resource.get(), context.createDeserializer(), ObComponentTypeProjectSettings.class);
} catch (Exception e) {
log.error("Failed to decode ObComponentTypeProjectSettings", e);
settings = new ObComponentTypeProjectSettings();
}
} else {
log.error("Failed to get ObComponentTypeProjectSettings");
settings = new ObComponentTypeProjectSettings();
}
…
@Override
public Object commit() {
settings.setComponentType((String) componentTypeDropdown.getSelectedItem());
return settings;
}
I’m not sure if this works. But the naming of the functions seems promising (project.getSingletonResource) and I hope the commit function stores the resource.
But in the model delegate I have trouble accessing this resource. As the gateway context don’t have “context.getProject”.
So I need some guidance.
Is the suggested method to use resource and model delegate the correct way to get the project settings down to the component? Or should we use other methods?
@paul-griffith for us we would like to have a project setting (which is the same for all sessions). I think I only need a guidance on how to store a setting from the "Project Properties" view in the designer (as shown above) and how to retrieve that setting in an Gateway endpoint.
Yeah - to me, the "natural" way to do that that end users would have a good time with (if they need to bind to it or otherwise read it easily) would be a read-only session property that your module is in charge of providing.
Ben's workaround(s) are probably the best solution in the short term - he's got more practical experience extending Perspective than anyone else I'm aware of.
Our solution to the same problem first party is simple - we just made the requisite changes first party in the page loading, and didn't think about the use case of third parties needing to extend things.
100%, the way I suggested is just a work around.
At the moment the only thing easy about extending Perspective is adding components. Beyond that, it gets hacky pretty quickly.
I’d like to see the access be controllable.
Some properties would benefit from read/write (similar to session.props.theme), while others only need read access (similar to session.props.id).
Now I'm depending on the naming convention of the resource collection. The code will fail, if the mapping between project name and collection name changes.