thingsboard-aplcache

UI: Improve state controller API.

10/5/2017 7:30:50 AM

Details

diff --git a/ui/src/app/dashboard/states/default-state-controller.js b/ui/src/app/dashboard/states/default-state-controller.js
index fb02147..8d85c59 100644
--- a/ui/src/app/dashboard/states/default-state-controller.js
+++ b/ui/src/app/dashboard/states/default-state-controller.js
@@ -28,6 +28,8 @@ export default function DefaultStateController($scope, $timeout, $location, $sta
     vm.getStateObject = getStateObject;
     vm.navigatePrevState = navigatePrevState;
     vm.getStateId = getStateId;
+    vm.getStateIndex = getStateIndex;
+    vm.getStateIdAtIndex = getStateIdAtIndex;
     vm.getStateParams = getStateParams;
     vm.getStateParamsByStateId = getStateParamsByStateId;
     vm.getEntityId = getEntityId;
@@ -100,6 +102,22 @@ export default function DefaultStateController($scope, $timeout, $location, $sta
         }
     }
 
+    function getStateIndex() {
+        if (vm.stateObject && vm.stateObject.length) {
+            return vm.stateObject.length-1;
+        } else {
+            return -1;
+        }
+    }
+
+    function getStateIdAtIndex(index) {
+        if (vm.stateObject && vm.stateObject[index]) {
+            return vm.stateObject[index].id;
+        } else {
+            return '';
+        }
+    }
+
     function getStateParams() {
         if (vm.stateObject && vm.stateObject.length) {
             return vm.stateObject[vm.stateObject.length - 1].params;
diff --git a/ui/src/app/dashboard/states/entity-state-controller.js b/ui/src/app/dashboard/states/entity-state-controller.js
index cfa664d..ba2bc64 100644
--- a/ui/src/app/dashboard/states/entity-state-controller.js
+++ b/ui/src/app/dashboard/states/entity-state-controller.js
@@ -30,6 +30,8 @@ export default function EntityStateController($scope, $timeout, $location, $stat
     vm.getStateObject = getStateObject;
     vm.navigatePrevState = navigatePrevState;
     vm.getStateId = getStateId;
+    vm.getStateIndex = getStateIndex;
+    vm.getStateIdAtIndex = getStateIdAtIndex;
     vm.getStateParams = getStateParams;
     vm.getStateParamsByStateId = getStateParamsByStateId;
     vm.getEntityId = getEntityId;
@@ -108,6 +110,22 @@ export default function EntityStateController($scope, $timeout, $location, $stat
         }
     }
 
+    function getStateIndex() {
+        if (vm.stateObject && vm.stateObject.length) {
+            return vm.stateObject.length-1;
+        } else {
+            return -1;
+        }
+    }
+
+    function getStateIdAtIndex(index) {
+        if (vm.stateObject && vm.stateObject[index]) {
+            return vm.stateObject[index].id;
+        } else {
+            return '';
+        }
+    }
+
     function getStateParams() {
         if (vm.stateObject && vm.stateObject.length) {
             return vm.stateObject[vm.stateObject.length - 1].params;
diff --git a/ui/src/app/dashboard/states/states-component.directive.js b/ui/src/app/dashboard/states/states-component.directive.js
index 1f83a61..8864d74 100644
--- a/ui/src/app/dashboard/states/states-component.directive.js
+++ b/ui/src/app/dashboard/states/states-component.directive.js
@@ -72,6 +72,22 @@ export default function StatesComponent($compile, $templateCache, $controller, s
                 }
             }
 
+            stateController.getStateIndex = function() {
+                if (scope.statesController) {
+                    return scope.statesController.getStateIndex();
+                } else {
+                    return -1;
+                }
+            }
+
+            stateController.getStateIdAtIndex = function(index) {
+                if (scope.statesController) {
+                    return scope.statesController.getStateIdAtIndex(index);
+                } else {
+                    return '';
+                }
+            }
+
             stateController.getStateParams = function() {
                 if (scope.statesController) {
                     return scope.statesController.getStateParams();