Custom model for Mango 2.8
-
I'm trying to set up a custom dropdown box for my dashboard. Something along the lines of select a device, and then display points related to that device. I think I need a custom model for it in Angular looking something like
{id:1, name: field_device1, value:tag_prefix_1 }
where I will have 'field_device1' in the drop down, and use 'tag_prefix_1'+'tag_suffix' to get tag names.
(Device here is a physical device. I have a number of devices on the same modbus channel that are identical save for the slave ID. Tags are also identical, only having different prefix.)
I have two questions:
-
Am I correct to think I need a custom model for this (not new to programming, but new to AngularJS)?
-
all the tutorials I can find seem to refer to mango 3.3, and I'm using 2.8. In my version, where should I put my customModule.js, and do I (and how) link it to app.js? Or should I just add my custom function to app.js?
-
-
@vlasta said in Custom model for Mango 2.8:
Am I correct to think I need a custom model for this (not new to programming, but new to AngularJS)?
I don't think you need a custom AngularJS module to achieve what you are trying to do.
@vlasta said in Custom model for Mango 2.8:
all the tutorials I can find seem to refer to mango 3.3, and I'm using 2.8. In my version, where should I put my customModule.js, and do I (and how) link it to app.js? Or should I just add my custom function to app.js?
You cannot set a user module file in Mango v2.8.x this is a feature of later versions of Mango. I highly recommend to upgrade to the latest version.
When you are referring to tags what are you talking about? Data point tags were added in Mango v3.3. From what I can gather you are trying to get a list of data points by querying their device name? You are proposing to hard code a list of prefixes in the first drop down then query the REST API for actual device names that start with the prefix to populate the second drop down?
-
Hi Jared,
Yes, by 'tags' I mean data points (different SCADA systems call it different things...)
I'm using 2.8 because its licensing model fits better with what I'm doing. Upgrade is not likely to happen any time soon.What I have:
single modbus channel ('data source') has a number of field devices attached to it. Devices are identical, each has unique slave ID. Data point names look like 'dev1_property1', 'dev1_property2', 'dev2_property1'...What I want to do:
drop down list listing 'human legible' device name (so 'dev1' will be 'device name 1', and so on)
Based on the selection, I want to populate the rest of the page with values of the data points associated with that device.So, only one drop down list, and some code that will use the value of the selected item, concatenate it with the suffix to form a data point name, and then query API for the value(s).
I tried using standard html dropdown list, but got stuck with feeding the concatenated string to the API.
Tried using Angular JS version of the dropdown, but got stuck with the custom model.If I'm doing it all wrong, and there is a better approach, I'm open for suggestions :-)
-
If I'm doing it all wrong, and there is a better approach, I'm open for suggestions :-)
Perhaps not the easiest, but one can write a module (see ma-modules-public in github for some examples) to supply new API endpoints appropriate for their dashboard. There's also the possibility of writing a DWR and driving your dashboard that way.
-
@vlasta said in Custom model for Mango 2.8:
Data point names look like 'dev1_property1', 'dev1_property2', 'dev2_property1'...
I would suggest changing the data point names to just property1, property2 etc and making the device names dev1, dev2 etc. This will make it easier to query for the data points and use the points on the dashboard.
However this is how you would do it for your configuration:
<!-- create a top-level data object with a device preselected --> <div ng-init="data = {selectedDevice: 'dev1'}"></div> <!-- angular material drop down --> <md-input-container> <label>Select device</label> <md-select ng-model="data.selectedDevice"> <md-option value="dev1">Device one</md-option> <md-option value="dev2">Device two</md-option> <md-option value="dev3">Device three</md-option> </md-select> </md-input-container> <!-- plain html drop down --> <select ng-model="data.selectedDevice"> <option value="dev1">Device one</option> <option value="dev2">Device two</option> <option value="dev3">Device three</option> </select> <!-- query for points using RQL --> <ma-point-query query="'name=like=' + data.selectedDevice + '_*'" points="data.points"></ma-point-query> <div> <!-- find a point with a name containing "property1" and display its value --> <ma-point-value point="(data.points | filter:{name: 'property1'})[0]"></ma-point-value> </div> <!-- display the contents of our data for debugging --> <!-- <pre ng-bind="data | json"></pre> -->
-
<facepalm> For some reason I thought that device name = data source name... </facepalm>
Of course, if I change device names, I can filter by device and the rest becomes much easier.
Your example works just fine too, even with my over complicated configuration.
Thanks heaps!
-
@vlasta said in Custom model for Mango 2.8:
For some reason I thought that device name = data source name...
Well it does default to that, so I can see where you went wrong. Just a heads up in Mango >= 3.3.0 you can add any number of arbitrary data point tags to help differentiate and locate your data points, e.g. site = xyz, boiler = 1 etc Just something to keep in mind if your system becomes more complicated.
@vlasta said in Custom model for Mango 2.8:
Your example works just fine too, even with my over complicated configuration.
Thanks heaps!No worries.