thingsboard-developers

merge from feature/TB-74

11/29/2017 1:21:00 PM

Details

diff --git a/ui/src/app/entity/attribute/attribute-table.tpl.html b/ui/src/app/entity/attribute/attribute-table.tpl.html
index 6f862ba..3b19e9d 100644
--- a/ui/src/app/entity/attribute/attribute-table.tpl.html
+++ b/ui/src/app/entity/attribute/attribute-table.tpl.html
@@ -16,7 +16,7 @@
 
 -->
 <md-content flex class="md-padding tb-absolute-fill" layout="column">
-    <section layout="row" ng-show="!disableAttributeScopeSelection">
+    <section ng-show="!disableAttributeScopeSelection">
         <md-input-container class="md-block" style="width: 200px;">
             <label translate>attribute.attributes-scope</label>
             <md-select ng-model="attributeScope" ng-disabled="loading() || attributeScopeSelectionReadonly">
@@ -26,7 +26,7 @@
             </md-select>
         </md-input-container>
     </section>
-    <div layout="column" class="md-whiteframe-z1" ng-class="{flex: mode==='widget'}">
+    <div class="md-whiteframe-z1" ng-class="{flex: mode==='widget'}">
         <md-toolbar class="md-table-toolbar md-default" ng-show="mode==='default'
                                                                  && !selectedAttributes.length
                                                                  && query.search === null">
diff --git a/ui/src/app/extension/extension-table.directive.js b/ui/src/app/extension/extension-table.directive.js
index 21d716b..e109ad9 100644
--- a/ui/src/app/extension/extension-table.directive.js
+++ b/ui/src/app/extension/extension-table.directive.js
@@ -33,7 +33,8 @@ export default function ExtensionTableDirective() {
         scope: true,
         bindToController: {
             entityId: '=',
-            entityType: '@'
+            entityType: '@',
+            transferredAttributes: '<'
         },
         controller: ExtensionTableController,
         controllerAs: 'vm',
@@ -82,6 +83,51 @@ function ExtensionTableController($scope, $filter, $document, $translate, types,
         }
     });
 
+    $scope.$watch('vm.transferredAttributes', function () {
+        if (vm.transferredAttributes && vm.transferredAttributes.data && vm.transferredAttributes.data.length) {
+            vm.transferredAttributes.data
+                .some(attribute=>{
+                    if (attribute.key === "appliedConfiguration") {
+                        vm.appliedConfiguration = attribute.value;
+                    }
+                });
+
+            checkForSync();
+        }
+    });
+
+
+    checkForSync();
+    function checkForSync() {
+        if (vm.appliedConfiguration === vm.extensionsJSON) {
+            vm.syncStatus = $translate.instant('extension.sync.sync');
+            vm.syncLastTime = formatDate();
+        } else {
+            vm.syncStatus = $translate.instant('extension.sync.not-sync');
+        }
+    }
+
+
+    function formatDate(date) {
+        let d;
+        if (date) {
+            d = date;
+        } else {
+            d = new Date();
+        }
+
+        d = d.getFullYear() +'/'+ addZero(d.getMonth()+1) +'/'+ addZero(d.getDate()) + ' ' + addZero(d.getHours()) + ':' + addZero(d.getMinutes()) +':'+ addZero(d.getSeconds());
+        return d;
+
+
+        function addZero(num) {
+            if ((angular.isNumber(num) && num < 10) || (angular.isString(num) && num.length === 1)) {
+                num = '0' + num;
+            }
+            return num;
+        }
+    }
+
     function enterFilterMode() {
         vm.query.search = '';
     }
@@ -238,5 +284,61 @@ function ExtensionTableController($scope, $filter, $document, $translate, types,
         vm.extensionsCount = result.length;
         var startIndex = vm.query.limit * (vm.query.page - 1);
         vm.extensions = result.slice(startIndex, startIndex + vm.query.limit);
+        vm.extensionsJSON = angular.toJson(vm.extensions);
     }
+
+
+    // vm.subscriptionId = null;
+    // $scope.checkSubscription = function() {
+    //     var newSubscriptionId = null;
+    //     if (vm.entityId && vm.entityType) {
+    //         newSubscriptionId = attributeService.subscribeForEntityAttributes(vm.entityType, vm.entityId, 'extension/SHARED_SCOPE');
+    //     }
+    //     if (vm.subscriptionId && vm.subscriptionId != newSubscriptionId) {
+    //         attributeService.unsubscribeForEntityAttributes(vm.subscriptionId);
+    //     }
+    //     vm.subscriptionId = newSubscriptionId;
+    // }
+    //
+    //
+    // // $scope.attributesData = {};
+    // // var entityAttributesSubscriptionMap = [];
+    // //
+    // $scope.subscribeForEntityAttributes = function (entityType=vm.entityType, entityId=vm.entityId, attributeScope="SHARED_SCOPE") {
+    //     var subscriptionId = entityType + entityId + attributeScope;
+    //     var entityAttributesSubscription = entityAttributesSubscriptionMap[subscriptionId];
+    //     if (!entityAttributesSubscription) {
+    //         var subscriptionCommand = {
+    //             entityType: entityType,
+    //             entityId: entityId,
+    //             scope: attributeScope
+    //         };
+    //
+    //         var type = attributeScope === types.latestTelemetry.value ?
+    //             types.dataKeyType.timeseries : types.dataKeyType.attribute;
+    //
+    //         var subscriber = {
+    //             subscriptionCommands: [subscriptionCommand],
+    //             type: type,
+    //             onData: function (data) {
+    //                 if (data.data) {
+    //                     onSubscriptionData(data.data, subscriptionId);
+    //                 }
+    //             }
+    //         };
+    //         entityAttributesSubscription = {
+    //             subscriber: subscriber,
+    //             attributes: null
+    //         };
+    //         entityAttributesSubscriptionMap[subscriptionId] = entityAttributesSubscription;
+    //         telemetryWebsocketService.subscribe(subscriber);
+    //     }
+    //     return subscriptionId;
+    // };
+    //
+    // function onSubscriptionData(data/*, subscriptionId*/) {
+    //     $scope.attributesData = data;
+    // }
+
+    // telemetryWebsocketService.subscribe(subscriber);
 }
\ No newline at end of file
diff --git a/ui/src/app/extension/extension-table.scss b/ui/src/app/extension/extension-table.scss
index c6c19a5..ee2a570 100644
--- a/ui/src/app/extension/extension-table.scss
+++ b/ui/src/app/extension/extension-table.scss
@@ -13,4 +13,19 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-@import '../../scss/constants';
\ No newline at end of file
+@import '../../scss/constants';
+
+
+.extension-table md-input-container .md-errors-spacer {
+  min-height: 0;
+}
+
+.extension__syncStatus--black {
+  color: #000000!important;
+}
+.extension__syncStatus--green {
+  color: #228634!important;
+}
+.extension__syncStatus--red {
+  color: #862222!important;
+}
\ No newline at end of file
diff --git a/ui/src/app/extension/extension-table.tpl.html b/ui/src/app/extension/extension-table.tpl.html
index 558b9c2..3a42576 100644
--- a/ui/src/app/extension/extension-table.tpl.html
+++ b/ui/src/app/extension/extension-table.tpl.html
@@ -16,7 +16,7 @@
 
 -->
 
-<md-content flex class="md-padding tb-absolute-fill tb-data-table" layout="column">
+<md-content flex class="md-padding tb-absolute-fill tb-data-table extension-table" layout="column">
     <div layout="column" class="md-whiteframe-z1">
         <md-toolbar class="md-table-toolbar md-default" ng-show="!vm.selectedExtensions.length
                                                                  && vm.query.search === null">
@@ -78,6 +78,25 @@
                 </md-button>
             </div>
         </md-toolbar>
+
+        <div class="md-padding" flex layout="row">
+            <md-input-container flex="50" class="md-block">
+                <label translate>extension.sync.status</label>
+                <input ng-model="vm.syncStatus"
+                       ng-class="{'extension__syncStatus--green':vm.appliedConfiguration === vm.extensionsJSON, 'extension__syncStatus--red':vm.appliedConfiguration !== vm.extensionsJSON}"
+                       disabled
+                >
+            </md-input-container>
+
+            <md-input-container flex="50" class="md-block">
+                <label translate>extension.sync.last-sync-time</label>
+                <input ng-model="vm.syncLastTime"
+                       class="extension__syncStatus--black"
+                       disabled
+                >
+            </md-input-container>
+        </div>
+
         <md-table-container>
             <table md-table md-row-select multiple="" ng-model="vm.selectedExtensions" md-progress="vm.extensionsDeferred.promise">
                 <thead md-head md-order="vm.query.order" md-on-reorder="vm.onReorder">
diff --git a/ui/src/app/locale/locale.constant.js b/ui/src/app/locale/locale.constant.js
index 6f626b5..8272fbb 100644
--- a/ui/src/app/locale/locale.constant.js
+++ b/ui/src/app/locale/locale.constant.js
@@ -777,6 +777,14 @@ export default angular.module('thingsboard.locale', [])
                     "timeseries": "Timeseries",
                     "add-timeseries": "Add timeseries",
 
+
+                    "sync": {
+                        "status": "Status",
+                        "sync": "Sync",
+                        "not-sync": "Not sync",
+                        "last-sync-time": "Last sync time",
+                    },
+
                     "opc-field-required": "Field is required",
                     "opc-server": "Servers",
                     "opc-add-server-hint": "Add server",