• 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

    ma-calc with angular expression into ma-switch-img

    Dashboard Designer & Custom AngularJS Pages
    4
    8
    3.1k
    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.
    • S
      shaun
      last edited by

      Hi all,

      I'm trying to use ma-calc to evaluate to a true/false and then feed this into an ma-switch-img, but it doesn't seem to work.

      ma-switch-img doesn't seem to evaluate the true-false and always picks the default-src.

      I've verified that I'm getting 'true' as the output for ma-calc by just doing {{STS1_S1_available}} inline and i see "true" on the page.

      Is this something to do with the data type that the angular expression is spitting out? or is there something else I'm missing?

      Is there perhaps a better way to do this?

      <ma-get-point-value/ point="STS1_Input_S1_Voltage" point-xid="DP_R10_STS1_Input_S1_Voltage">
      <ma-calc/ input="STS1_Input_S1_Voltage.value > 200" output="STS1_S1_available">
      <ma-switch-img/ point="STS1_S1_available" src-false="/modules/dashboards/web/images/led_circle_black.png" src-true="/modules/dashboards/web/images/led_circle_green.png" default-src="/modules/dashboards/web/images/led_circle_black.png" width="30px">
      

      also, on a side note, is there any better docs about ma-fn than whats in the examples/docs that are included with mango?
      What i've read so far doesn't really tell me enough to figure out how it works. There are a few things I could do as a function for code reuse.

      Cheers!
      -Shaun

      1 Reply Last reply Reply Quote 0
      • phildunlapP
        phildunlap
        last edited by phildunlap

        Hey Shaun,

        I'm only so-so with Angular, but I think you could solve this by adding an ng-init to the ma-switch-img like so:

        <ma-get-point-value/ point="STS1_Input_S1_Voltage" point-xid="DP_R10_STS1_Input_S1_Voltage">
        <ma-calc/ input="STS1_Input_S1_Voltage.value > 200" output="STS1_S1_available">
        <ma-switch-img/ ng-init='{{switchPoint={"value":STS1_S1_available, "enabled":point.enabled};""}}' point="switchPoint" src-false="/modules/dashboards/web/images/led_circle_black.png" src-true="/modules/dashboards/web/images/led_circle_green.png" default-src="/modules/dashboards/web/images/led_circle_black.png" width="30px">
        

        The issue is that the "point" on the ma-switch-img needs to be an object with a "value" property to work. There's also some functionality from the enabled property.

        1 Reply Last reply Reply Quote 0
        • Will GellerW
          Will Geller
          last edited by

          <ma-switch-img> is designed to be used with a point object that would come directly from <ma-get-point-value>

          Therefore what Phillip is showing you is using ng-init to create a object that mimics the point object. While it may work it is probably cleaner to just use a meta data point.

          You could just set up a boolean meta data point that returns true when the value of that other point in > 200.

          I think it would look something like this:

          if (pNum.value > 200) {
              return true
          }
          else {
              return false
          }
          

          Where pNum is set to STS1_Input_S1_Voltage is the script context.

          Then you could avoid using ma-calc and just use <ma-get-point-value> with the meta data points xid and <ma-switch-img> with that point object.

          I will try to reply back shortly with a good example of using <ma-fn>

          Infinite Automation - UI Developer

          1 Reply Last reply Reply Quote 0
          • phildunlapP
            phildunlap
            last edited by

            It seems we switched hats this morning Will :D!

            Shaun, using a Meta point will also provide you the benefit of doing statistical rollups of the time in the > 200 condition, should such a thing prove relevant to your application in the future.

            1 Reply Last reply Reply Quote 0
            • S
              shaun
              last edited by

              Thanks guys... a meta data point sounds like the best bet, but I can't see where I can set the datatype to boolean... I can do binary though, is that what you mean?

              1 Reply Last reply Reply Quote 0
              • Will GellerW
                Will Geller
                last edited by

                Yes I meant binary!

                cheers
                Will

                Infinite Automation - UI Developer

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

                  @shaun I'm just going to chime in and mention that you should not forget about the standard angular directives such as ngSrc which is what the switchImg directive uses itself.

                  <ma-get-point-value point="STS1_Input_S1_Voltage" point-xid="DP_R10_STS1_Input_S1_Voltage"></ma-get-point-value>
                  <img ng-src="/modules/dashboards/web/images/led_circle_{{STS1_Input_S1_Voltage.value > 200 ? 'green' : 'black'}}.png">
                  

                  If you need to indicate when the point is disabled or mango is down then you will need a little more code but this should work for the main case.

                  Developer at Radix IoT

                  1 Reply Last reply Reply Quote 0
                  • S
                    shaun
                    last edited by

                    Thanks all!...

                    @Jared-Wiltshire thats good to know :) I'm starting to get the hang of angular now and how to embed expressions for simple logic operations now.

                    In this case, I ended up going with the metadata point @Will-Geller suggested. Works like a charm!
                    @phildunlap was right too, having historical data is actually very handy in this case, especially for the reporting I'll have to do.

                    Cheers!

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