Using AngularJS services to call REST API
-
Using AngularJS services to call REST API
-
@jared-wiltshire This is an old thread, but do you have an example on how to invoke the rest API via the AngularJS services? What I would like to do is read in a configuration file (JSON) and populate datasources, datapoints based on the rules defined in the JSON file. The template configuration file seems to take require too much effort.
Otherwise, I'll revert to node.js but prefer to have everything in Mango.
pjc
-
@chrapchp I've moved your post to a new thread.
There are services for creating/updating/deleting data points and data sources. These services are AngularJS resources, see the documentation here - https://docs.angularjs.org/api/ngResource/service/$resource
These are the docs pages for the services, change the hostname and port to your Mango instance's hostname and port.
http://localhost:8080/ui/docs/ng-mango-services/ma-point
http://localhost:8080/ui/docs/ng-mango-services/ma-data-sourceIn short -
//get data point and update maPoint.get({xid:'your-xid'}).$promise.then(dataPoint => { dataPoint.name = 'New name'; return dataPoint.$update(); }); // create new data source and add data point const newDataSource = new maDataSource({ name: 'Test data source', enabled: true, modelType: 'VIRTUAL', pollPeriod: { periods: 5, type: 'SECONDS' }, purgeSettings: { override: false, frequency: { periods: 1, type: 'YEARS' } }, alarmLevels: { POLL_ABORTED: 'URGENT' }, editPermission: null }).$save().then(ds => { const newDataPoint = new maPoint({ enabled: true, name: 'test name', deviceName: 'test deviceName', dataSourceXid : ds.xid, pointLocator : { startValue : '0', modelType : 'PL.VIRTUAL', dataType : 'NUMERIC', changeType : 'NO_CHANGE', } }); return newDataPoint.$save(); });
-
Thanks. I will try this out on the weekend. BTW, is there an ETA when there will full CRUD REST API for points hierarchy? So far it "gets". Will the use the json-emport to import the JSON that I create do the job? That said, I don't see a way to pragmatically prune and build a points hierarchy. Is that statement correct?
pjc
-
@chrapchp said in Using AngularJS services to call REST API:
is there an ETA when there will full CRUD REST API for points hierarchy?
I would put that ETA at probably never. We are focused on phasing out the point hierarchy and replacing it with tags at the moment. You can set the
pointFolderId
property of a data point to put it in a certain folder but that's it.@chrapchp said in Using AngularJS services to call REST API:
Will the use the json-emport to import the JSON that I create do the job?
You can use the
maImportExport
service to import a JSON config file yes, it can contain data sources, data points and point hierarchy in one config file that is imported all at once.maImportExport.importData(jsonConfigObject).then(status => { //poll for status status.getStatus(() => { //is it done yet? }) });
@chrapchp said in Using AngularJS services to call REST API:
That said, I don't see a way to pragmatically prune and build a points hierarchy. Is that statement correct?
You can import arbitrary point hierarchies using the configuration import/export service and page. There is no way to delete folders AFAIK.
-
Ok. Fair enough as a tag based model provides flexibility in forming queries. Is there some info on what that will look like? Are they assigned at a data point level or span beyond that? Do you have an ETA for that functionality?
pjc
-
@chrapchp said in Using AngularJS services to call REST API:
Ok. Fair enough as a tag based model provides flexibility in forming queries. Is there some info on what that will look like? Are they assigned at a data point level or span beyond that? Do you have an ETA for that functionality?
pjc
Data point tags have been implemented as of v3.3.0. They are string:string pairs and are assigned to each data point. You can add tags via the new "Bulk data point edit" page in the latest UI module or using the "JSON config import/export" page.
You can use the existing data point REST API / AngularJS services and components to query based on tags. e.g.
/rest/v2/data-points?tags.site=Boulder&tags.device=PowerMeter
-
Thanks. I missed that one. Will look to use to avoid the points hierarchy,
pjc