Determine "Functional" images by association

The functional, or running, images should be determined by looking
at the functional association, not by looking at priority 0.
An image could be functional but not priority 0, this happens
after activating a new image.

Get the functional images by looking at the endpoints of
/xyz/openbmc_project/software/functional.

Resolves openbmc/openbmc#2945

Tested: Verified the correct image is functional after activation
and during other times of code updating.
Change-Id: Ia5ad172b0874e634c0042576018b376b5260e31e
Signed-off-by: Gunnar Mills <gmills@us.ibm.com>
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js
index 6268f8c..5eadb33 100644
--- a/app/common/services/api-utils.js
+++ b/app/common/services/api-utils.js
@@ -614,6 +614,7 @@
                       var hostActiveVersion = "";
                       var imageType = "";
                       var extendedVersions = [];
+                      var functionalImages = [];
 
                       function getFormatedExtendedVersions(extendedVersion){
                         var versions = [];
@@ -641,16 +642,23 @@
                         return versions;
                       }
 
+                      // Get the list of functional images so we can compare
+                      // later if an image is functional
+                      if (content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH])
+                      {
+                        functionalImages = content.data[Constants.FIRMWARE.FUNCTIONAL_OBJPATH].endpoints;
+                      }
                       for(var key in content.data){
                         if(content.data.hasOwnProperty(key) && content.data[key].hasOwnProperty('Version')){
                           // If the image is "Functional" use that for the
                           // activation status, else use the value of "Activation"
                           // github.com/openbmc/phosphor-dbus-interfaces/blob/master/xyz/openbmc_project/Software/Activation.interface.yaml
                           activationStatus = content.data[key].Activation.split(".").pop();
-                          if (content.data[key].Priority == 0)
+                          if (functionalImages.includes(key))
                           {
                             activationStatus = "Functional";
                           }
+
                           imageType = content.data[key].Purpose.split(".").pop();
                           isExtended = content.data[key].hasOwnProperty('ExtendedVersion') && content.data[key].ExtendedVersion != "";
                           if(isExtended){