• Recent
    • Tags
    • Popular
    • Register
    • Login

    Please Note This forum exists for community support for the Mango product family and the Radix IoT Platform. Although Radix IoT employees participate in this forum from time to time, there is no guarantee of a response to anything posted here, nor can Radix IoT, LLC guarantee the accuracy of any information expressed or conveyed. Specific project questions from customers with active support contracts are asked to send requests to support@radixiot.com.

    Radix IoT Website Mango 3 Documentation Website Mango 4 Documentation Website Mango 5 Documentation Website

    Using AngularJS services to call REST API

    Dashboard Designer & Custom AngularJS Pages
    2
    8
    2.5k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Jared WiltshireJ
      Jared Wiltshire
      last edited by

      Using AngularJS services to call REST API

      Developer at Radix IoT

      1 Reply Last reply Reply Quote 0
      • C
        chrapchp @Jared Wiltshire
        last edited by

        @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

        1 Reply Last reply Reply Quote 0
        • Jared WiltshireJ
          Jared Wiltshire
          last edited by

          @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-source

          In 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();
          });
          

          Developer at Radix IoT

          1 Reply Last reply Reply Quote 0
          • C
            chrapchp
            last edited by

            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

            Jared WiltshireJ 1 Reply Last reply Reply Quote 0
            • Jared WiltshireJ
              Jared Wiltshire @chrapchp
              last edited by

              @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.

              Developer at Radix IoT

              1 Reply Last reply Reply Quote 0
              • C
                chrapchp
                last edited by

                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

                Jared WiltshireJ 1 Reply Last reply Reply Quote 0
                • Jared WiltshireJ
                  Jared Wiltshire @chrapchp
                  last edited by

                  @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

                  Developer at Radix IoT

                  1 Reply Last reply Reply Quote 0
                  • C
                    chrapchp
                    last edited by

                    Thanks. I missed that one. Will look to use to avoid the points hierarchy,

                    pjc

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post