Add seed code for sdnr app based on ONF Centennial
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / dlux / dlux-web / src / common / general / common.general.directives.js
diff --git a/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/common/general/common.general.directives.js b/sdnr/wireless-transport/code-Carbon-SR1/apps/dlux/dlux-web/src/common/general/common.general.directives.js
new file mode 100644 (file)
index 0000000..78429dc
--- /dev/null
@@ -0,0 +1,43 @@
+define(['common/general/common.general.module'], function(general) {
+
+  general.directive('stateIcon', function() {
+      return {
+          restrict: 'E',
+          replace: true,
+          scope: {
+              stateValue: '@value'
+          },
+          template: '<span class="glyphicon glyphicon-{{stateIcon}}-sign"></span>',
+          controller: ['$scope', function ($scope) {
+              var value = $scope.stateValue;
+
+              var icons = {1: 'ok', 0: 'exclamation'};
+              var textStates = {'true': 1, 'false': 0};
+
+              if (_.isString(value) && !value.match('^[0-9]$')) {
+                  value = textStates[value];
+              }
+              $scope.stateIcon = icons[value];
+          }]
+
+      };
+  });
+
+  general.directive('portState', function() {
+      return {
+          restrict: 'E',
+          replace: true,
+          scope: {
+              stateValue: '@value'
+          },
+          template: '<span ng-style="{color: stateColor}">{{stateString}}</span>',
+          controller: ['$scope', function ($scope) {
+              var states = {0: 'DOWN', 1: 'UP'};
+              var colors = {0: 'red', 1: 'green'};
+
+              $scope.stateString = states[$scope.stateValue];
+              $scope.stateColor = colors[$scope.stateValue];
+          }]
+      };
+  });
+});