Commit 0098a94db8b3e719b3750487aac7a843be44bb03

Authored by oleg
1 parent e034733a

merge from feature/TB-74

... ... @@ -16,7 +16,7 @@
16 16
17 17 -->
18 18 <md-content flex class="md-padding tb-absolute-fill" layout="column">
19   - <section layout="row" ng-show="!disableAttributeScopeSelection">
  19 + <section ng-show="!disableAttributeScopeSelection">
20 20 <md-input-container class="md-block" style="width: 200px;">
21 21 <label translate>attribute.attributes-scope</label>
22 22 <md-select ng-model="attributeScope" ng-disabled="loading() || attributeScopeSelectionReadonly">
... ... @@ -26,7 +26,7 @@
26 26 </md-select>
27 27 </md-input-container>
28 28 </section>
29   - <div layout="column" class="md-whiteframe-z1" ng-class="{flex: mode==='widget'}">
  29 + <div class="md-whiteframe-z1" ng-class="{flex: mode==='widget'}">
30 30 <md-toolbar class="md-table-toolbar md-default" ng-show="mode==='default'
31 31 && !selectedAttributes.length
32 32 && query.search === null">
... ...
... ... @@ -33,7 +33,8 @@ export default function ExtensionTableDirective() {
33 33 scope: true,
34 34 bindToController: {
35 35 entityId: '=',
36   - entityType: '@'
  36 + entityType: '@',
  37 + transferredAttributes: '<'
37 38 },
38 39 controller: ExtensionTableController,
39 40 controllerAs: 'vm',
... ... @@ -82,6 +83,51 @@ function ExtensionTableController($scope, $filter, $document, $translate, types,
82 83 }
83 84 });
84 85
  86 + $scope.$watch('vm.transferredAttributes', function () {
  87 + if (vm.transferredAttributes && vm.transferredAttributes.data && vm.transferredAttributes.data.length) {
  88 + vm.transferredAttributes.data
  89 + .some(attribute=>{
  90 + if (attribute.key === "appliedConfiguration") {
  91 + vm.appliedConfiguration = attribute.value;
  92 + }
  93 + });
  94 +
  95 + checkForSync();
  96 + }
  97 + });
  98 +
  99 +
  100 + checkForSync();
  101 + function checkForSync() {
  102 + if (vm.appliedConfiguration === vm.extensionsJSON) {
  103 + vm.syncStatus = $translate.instant('extension.sync.sync');
  104 + vm.syncLastTime = formatDate();
  105 + } else {
  106 + vm.syncStatus = $translate.instant('extension.sync.not-sync');
  107 + }
  108 + }
  109 +
  110 +
  111 + function formatDate(date) {
  112 + let d;
  113 + if (date) {
  114 + d = date;
  115 + } else {
  116 + d = new Date();
  117 + }
  118 +
  119 + d = d.getFullYear() +'/'+ addZero(d.getMonth()+1) +'/'+ addZero(d.getDate()) + ' ' + addZero(d.getHours()) + ':' + addZero(d.getMinutes()) +':'+ addZero(d.getSeconds());
  120 + return d;
  121 +
  122 +
  123 + function addZero(num) {
  124 + if ((angular.isNumber(num) && num < 10) || (angular.isString(num) && num.length === 1)) {
  125 + num = '0' + num;
  126 + }
  127 + return num;
  128 + }
  129 + }
  130 +
85 131 function enterFilterMode() {
86 132 vm.query.search = '';
87 133 }
... ... @@ -238,5 +284,61 @@ function ExtensionTableController($scope, $filter, $document, $translate, types,
238 284 vm.extensionsCount = result.length;
239 285 var startIndex = vm.query.limit * (vm.query.page - 1);
240 286 vm.extensions = result.slice(startIndex, startIndex + vm.query.limit);
  287 + vm.extensionsJSON = angular.toJson(vm.extensions);
241 288 }
  289 +
  290 +
  291 + // vm.subscriptionId = null;
  292 + // $scope.checkSubscription = function() {
  293 + // var newSubscriptionId = null;
  294 + // if (vm.entityId && vm.entityType) {
  295 + // newSubscriptionId = attributeService.subscribeForEntityAttributes(vm.entityType, vm.entityId, 'extension/SHARED_SCOPE');
  296 + // }
  297 + // if (vm.subscriptionId && vm.subscriptionId != newSubscriptionId) {
  298 + // attributeService.unsubscribeForEntityAttributes(vm.subscriptionId);
  299 + // }
  300 + // vm.subscriptionId = newSubscriptionId;
  301 + // }
  302 + //
  303 + //
  304 + // // $scope.attributesData = {};
  305 + // // var entityAttributesSubscriptionMap = [];
  306 + // //
  307 + // $scope.subscribeForEntityAttributes = function (entityType=vm.entityType, entityId=vm.entityId, attributeScope="SHARED_SCOPE") {
  308 + // var subscriptionId = entityType + entityId + attributeScope;
  309 + // var entityAttributesSubscription = entityAttributesSubscriptionMap[subscriptionId];
  310 + // if (!entityAttributesSubscription) {
  311 + // var subscriptionCommand = {
  312 + // entityType: entityType,
  313 + // entityId: entityId,
  314 + // scope: attributeScope
  315 + // };
  316 + //
  317 + // var type = attributeScope === types.latestTelemetry.value ?
  318 + // types.dataKeyType.timeseries : types.dataKeyType.attribute;
  319 + //
  320 + // var subscriber = {
  321 + // subscriptionCommands: [subscriptionCommand],
  322 + // type: type,
  323 + // onData: function (data) {
  324 + // if (data.data) {
  325 + // onSubscriptionData(data.data, subscriptionId);
  326 + // }
  327 + // }
  328 + // };
  329 + // entityAttributesSubscription = {
  330 + // subscriber: subscriber,
  331 + // attributes: null
  332 + // };
  333 + // entityAttributesSubscriptionMap[subscriptionId] = entityAttributesSubscription;
  334 + // telemetryWebsocketService.subscribe(subscriber);
  335 + // }
  336 + // return subscriptionId;
  337 + // };
  338 + //
  339 + // function onSubscriptionData(data/*, subscriptionId*/) {
  340 + // $scope.attributesData = data;
  341 + // }
  342 +
  343 + // telemetryWebsocketService.subscribe(subscriber);
242 344 }
\ No newline at end of file
... ...
... ... @@ -13,4 +13,19 @@
13 13 * See the License for the specific language governing permissions and
14 14 * limitations under the License.
15 15 */
16   -@import '../../scss/constants';
\ No newline at end of file
  16 +@import '../../scss/constants';
  17 +
  18 +
  19 +.extension-table md-input-container .md-errors-spacer {
  20 + min-height: 0;
  21 +}
  22 +
  23 +.extension__syncStatus--black {
  24 + color: #000000!important;
  25 +}
  26 +.extension__syncStatus--green {
  27 + color: #228634!important;
  28 +}
  29 +.extension__syncStatus--red {
  30 + color: #862222!important;
  31 +}
\ No newline at end of file
... ...
... ... @@ -16,7 +16,7 @@
16 16
17 17 -->
18 18
19   -<md-content flex class="md-padding tb-absolute-fill tb-data-table" layout="column">
  19 +<md-content flex class="md-padding tb-absolute-fill tb-data-table extension-table" layout="column">
20 20 <div layout="column" class="md-whiteframe-z1">
21 21 <md-toolbar class="md-table-toolbar md-default" ng-show="!vm.selectedExtensions.length
22 22 && vm.query.search === null">
... ... @@ -78,6 +78,25 @@
78 78 </md-button>
79 79 </div>
80 80 </md-toolbar>
  81 +
  82 + <div class="md-padding" flex layout="row">
  83 + <md-input-container flex="50" class="md-block">
  84 + <label translate>extension.sync.status</label>
  85 + <input ng-model="vm.syncStatus"
  86 + ng-class="{'extension__syncStatus--green':vm.appliedConfiguration === vm.extensionsJSON, 'extension__syncStatus--red':vm.appliedConfiguration !== vm.extensionsJSON}"
  87 + disabled
  88 + >
  89 + </md-input-container>
  90 +
  91 + <md-input-container flex="50" class="md-block">
  92 + <label translate>extension.sync.last-sync-time</label>
  93 + <input ng-model="vm.syncLastTime"
  94 + class="extension__syncStatus--black"
  95 + disabled
  96 + >
  97 + </md-input-container>
  98 + </div>
  99 +
81 100 <md-table-container>
82 101 <table md-table md-row-select multiple="" ng-model="vm.selectedExtensions" md-progress="vm.extensionsDeferred.promise">
83 102 <thead md-head md-order="vm.query.order" md-on-reorder="vm.onReorder">
... ...
... ... @@ -777,6 +777,14 @@ export default angular.module('thingsboard.locale', [])
777 777 "timeseries": "Timeseries",
778 778 "add-timeseries": "Add timeseries",
779 779
  780 +
  781 + "sync": {
  782 + "status": "Status",
  783 + "sync": "Sync",
  784 + "not-sync": "Not sync",
  785 + "last-sync-time": "Last sync time",
  786 + },
  787 +
780 788 "opc-field-required": "Field is required",
781 789 "opc-server": "Servers",
782 790 "opc-add-server-hint": "Add server",
... ...