Commit 5efe90e853b641c01845f50b486841d754f5fad7

Authored by Igor Kulikov
Committed by GitHub
2 parents ec2bbbc2 abc16e6b

Merge pull request #310 from Terny22/master

Issue 304
... ... @@ -17,7 +17,14 @@ export default angular.module('thingsboard.api.dashboard', [])
17 17 .factory('dashboardService', DashboardService).name;
18 18
19 19 /*@ngInject*/
20   -function DashboardService($http, $q, $location, customerService) {
  20 +function DashboardService($rootScope, $http, $q, $location, customerService) {
  21 +
  22 + var stDiffPromise;
  23 +
  24 + $rootScope.dadshboardServiceStateChangeStartHandle = $rootScope.$on('$stateChangeStart', function () {
  25 + stDiffPromise = undefined;
  26 + });
  27 +
21 28
22 29 var service = {
23 30 assignDashboardToCustomer: assignDashboardToCustomer,
... ... @@ -113,18 +120,23 @@ function DashboardService($http, $q, $location, customerService) {
113 120 }
114 121
115 122 function getServerTimeDiff() {
116   - var deferred = $q.defer();
117   - var url = '/api/dashboard/serverTime';
118   - var ct1 = Date.now();
119   - $http.get(url, { ignoreLoading: true }).then(function success(response) {
120   - var ct2 = Date.now();
121   - var st = response.data;
122   - var stDiff = Math.ceil(st - (ct1+ct2)/2);
123   - deferred.resolve(stDiff);
124   - }, function fail() {
125   - deferred.reject();
126   - });
127   - return deferred.promise;
  123 + if (stDiffPromise) {
  124 + return stDiffPromise;
  125 + } else {
  126 + var deferred = $q.defer();
  127 + stDiffPromise = deferred.promise;
  128 + var url = '/api/dashboard/serverTime';
  129 + var ct1 = Date.now();
  130 + $http.get(url, {ignoreLoading: true}).then(function success(response) {
  131 + var ct2 = Date.now();
  132 + var st = response.data;
  133 + var stDiff = Math.ceil(st - (ct1 + ct2) / 2);
  134 + deferred.resolve(stDiff);
  135 + }, function fail() {
  136 + deferred.reject();
  137 + });
  138 + }
  139 + return stDiffPromise;
128 140 }
129 141
130 142 function getDashboard(dashboardId) {
... ...
... ... @@ -80,9 +80,7 @@ export default class Subscription {
80 80 this.alarms = [];
81 81
82 82 this.originalTimewindow = null;
83   - this.timeWindow = {
84   - stDiff: this.ctx.stDiff
85   - }
  83 + this.timeWindow = {};
86 84 this.useDashboardTimewindow = options.useDashboardTimewindow;
87 85
88 86 if (this.useDashboardTimewindow) {
... ... @@ -124,9 +122,7 @@ export default class Subscription {
124 122 this.data = [];
125 123 this.hiddenData = [];
126 124 this.originalTimewindow = null;
127   - this.timeWindow = {
128   - stDiff: this.ctx.stDiff
129   - }
  125 + this.timeWindow = {};
130 126 this.useDashboardTimewindow = options.useDashboardTimewindow;
131 127 this.stateData = options.stateData;
132 128 if (this.useDashboardTimewindow) {
... ... @@ -213,27 +209,51 @@ export default class Subscription {
213 209 }
214 210 }
215 211
216   - initAlarmSubscription() {
  212 + loadStDiff() {
217 213 var deferred = this.ctx.$q.defer();
218   - if (!this.ctx.aliasController) {
219   - this.configureAlarmsData();
220   - deferred.resolve();
221   - } else {
222   - var subscription = this;
223   - this.ctx.aliasController.resolveAlarmSource(this.alarmSource).then(
224   - function success(alarmSource) {
225   - subscription.alarmSource = alarmSource;
226   - subscription.configureAlarmsData();
  214 + if (this.ctx.getStDiff && this.timeWindow) {
  215 + this.ctx.getStDiff().then(
  216 + (stDiff) => {
  217 + this.timeWindow.stDiff = stDiff;
227 218 deferred.resolve();
228 219 },
229   - function fail() {
230   - deferred.reject();
  220 + () => {
  221 + this.timeWindow.stDiff = 0;
  222 + deferred.resolve();
231 223 }
232 224 );
  225 + } else {
  226 + if (this.timeWindow) {
  227 + this.timeWindow.stDiff = 0;
  228 + }
  229 + deferred.resolve();
233 230 }
234 231 return deferred.promise;
235 232 }
236 233
  234 + initAlarmSubscription() {
  235 + var deferred = this.ctx.$q.defer();
  236 + var subscription = this;
  237 + this.loadStDiff().then(() => {
  238 + if (!subscription.ctx.aliasController) {
  239 + subscription.configureAlarmsData();
  240 + deferred.resolve();
  241 + } else {
  242 + subscription.ctx.aliasController.resolveAlarmSource(subscription.alarmSource).then(
  243 + function success(alarmSource) {
  244 + subscription.alarmSource = alarmSource;
  245 + subscription.configureAlarmsData();
  246 + deferred.resolve();
  247 + },
  248 + function fail() {
  249 + deferred.reject();
  250 + }
  251 + );
  252 + }
  253 + });
  254 + return deferred.promise;
  255 + }
  256 +
237 257 configureAlarmsData() {
238 258 var subscription = this;
239 259 var registration;
... ... @@ -252,22 +272,24 @@ export default class Subscription {
252 272
253 273 initDataSubscription() {
254 274 var deferred = this.ctx.$q.defer();
255   - if (!this.ctx.aliasController) {
256   - this.configureData();
257   - deferred.resolve();
258   - } else {
259   - var subscription = this;
260   - this.ctx.aliasController.resolveDatasources(this.datasources).then(
261   - function success(datasources) {
262   - subscription.datasources = datasources;
263   - subscription.configureData();
264   - deferred.resolve();
265   - },
266   - function fail() {
267   - deferred.reject();
268   - }
269   - );
270   - }
  275 + var subscription = this;
  276 + this.loadStDiff().then(() => {
  277 + if (!subscription.ctx.aliasController) {
  278 + subscription.configureData();
  279 + deferred.resolve();
  280 + } else {
  281 + subscription.ctx.aliasController.resolveDatasources(subscription.datasources).then(
  282 + function success(datasources) {
  283 + subscription.datasources = datasources;
  284 + subscription.configureData();
  285 + deferred.resolve();
  286 + },
  287 + function fail() {
  288 + deferred.reject();
  289 + }
  290 + );
  291 + }
  292 + });
271 293 return deferred.promise;
272 294 }
273 295
... ...
... ... @@ -75,7 +75,6 @@ function Dashboard() {
75 75 prepareDashboardContextMenu: '&?',
76 76 prepareWidgetContextMenu: '&?',
77 77 loadWidgets: '&?',
78   - getStDiff: '&?',
79 78 onInit: '&?',
80 79 onInitFailed: '&?',
81 80 dashboardStyle: '=?',
... ... @@ -102,8 +101,6 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
102 101
103 102 vm.gridster = null;
104 103
105   - vm.stDiff = 0;
106   -
107 104 vm.isMobileDisabled = angular.isDefined(vm.isMobileDisabled) ? vm.isMobileDisabled : false;
108 105
109 106 vm.isMobileSize = false;
... ... @@ -500,7 +497,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
500 497 sortWidgets();
501 498 });
502 499
503   - loadStDiff();
  500 + loadDashboard();
504 501
505 502 function sortWidgets() {
506 503 vm.widgets.sort(function (widget1, widget2) {
... ... @@ -515,28 +512,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
515 512 }
516 513
517 514 function reload() {
518   - loadStDiff();
519   - }
520   -
521   - function loadStDiff() {
522   - if (vm.getStDiff) {
523   - var promise = vm.getStDiff();
524   - if (promise) {
525   - promise.then(function (stDiff) {
526   - vm.stDiff = stDiff;
527   - loadDashboard();
528   - }, function () {
529   - vm.stDiff = 0;
530   - loadDashboard();
531   - });
532   - } else {
533   - vm.stDiff = 0;
534   - loadDashboard();
535   - }
536   - } else {
537   - vm.stDiff = 0;
538   - loadDashboard();
539   - }
  515 + loadDashboard();
540 516 }
541 517
542 518 function loadDashboard() {
... ...
... ... @@ -113,7 +113,6 @@
113 113 stateController: vm.stateController,
114 114 isEdit: vm.isEdit,
115 115 isMobile: vm.isMobileSize,
116   - stDiff: vm.stDiff,
117 116 dashboardTimewindow: vm.dashboardTimewindow,
118 117 dashboardTimewindowApi: vm.dashboardTimewindowApi }">
119 118 </div>
... ...
... ... @@ -21,7 +21,7 @@ import Subscription from '../../api/subscription';
21 21
22 22 /*@ngInject*/
23 23 export default function WidgetController($scope, $state, $timeout, $window, $element, $q, $log, $injector, $filter, $compile, tbRaf, types, utils, timeService,
24   - datasourceService, alarmService, entityService, deviceService, visibleRect, isEdit, isMobile, stDiff, dashboardTimewindow,
  24 + datasourceService, alarmService, entityService, dashboardService, deviceService, visibleRect, isEdit, isMobile, dashboardTimewindow,
25 25 dashboardTimewindowApi, widget, aliasController, stateController, widgetInfo, widgetType) {
26 26
27 27 var vm = this;
... ... @@ -159,7 +159,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele
159 159 widgetUtils: widgetContext.utils,
160 160 dashboardTimewindowApi: dashboardTimewindowApi,
161 161 types: types,
162   - stDiff: stDiff,
  162 + getStDiff: dashboardService.getServerTimeDiff,
163 163 aliasController: aliasController
164 164 };
165 165
... ...
... ... @@ -170,7 +170,6 @@ export default function DashboardController(types, utils, dashboardUtils, widget
170 170 }
171 171 }
172 172
173   - vm.getServerTimeDiff = getServerTimeDiff;
174 173 vm.addWidget = addWidget;
175 174 vm.addWidgetFromType = addWidgetFromType;
176 175 vm.exportDashboard = exportDashboard;
... ... @@ -334,10 +333,6 @@ export default function DashboardController(types, utils, dashboardUtils, widget
334 333 }
335 334 }
336 335
337   - function getServerTimeDiff() {
338   - return dashboardService.getServerTimeDiff();
339   - }
340   -
341 336 function loadDashboard() {
342 337 if (vm.widgetEditMode) {
343 338 var widget = {
... ...
... ... @@ -137,8 +137,7 @@
137 137 dashboard-ctx="vm.dashboardCtx"
138 138 is-edit="vm.isEdit"
139 139 is-mobile="vm.forceDashboardMobileMode"
140   - widget-edit-mode="vm.widgetEditMode"
141   - get-st-diff="vm.getServerTimeDiff()">
  140 + widget-edit-mode="vm.widgetEditMode">
142 141 </tb-dashboard-layout>
143 142 </div>
144 143 <md-sidenav ng-if="vm.layouts.right.show"
... ... @@ -157,8 +156,7 @@
157 156 dashboard-ctx="vm.dashboardCtx"
158 157 is-edit="vm.isEdit"
159 158 is-mobile="vm.forceDashboardMobileMode"
160   - widget-edit-mode="vm.widgetEditMode"
161   - get-st-diff="vm.getServerTimeDiff()">
  159 + widget-edit-mode="vm.widgetEditMode">
162 160 </tb-dashboard-layout>
163 161 </md-sidenav>
164 162 </div>
... ...
... ... @@ -29,8 +29,7 @@ export default function DashboardLayout() {
29 29 dashboardCtx: '=',
30 30 isEdit: '=',
31 31 isMobile: '=',
32   - widgetEditMode: '=',
33   - getStDiff: '&?'
  32 + widgetEditMode: '='
34 33 },
35 34 controller: DashboardLayoutController,
36 35 controllerAs: 'vm',
... ...
... ... @@ -64,7 +64,6 @@
64 64 prepare-dashboard-context-menu="vm.prepareDashboardContextMenu()"
65 65 prepare-widget-context-menu="vm.prepareWidgetContextMenu(widget)"
66 66 on-remove-widget="vm.removeWidget(event, widget)"
67   - get-st-diff="vm.getStDiff()"
68 67 on-init="vm.dashboardInited(dashboard)"
69 68 on-init-failed="vm.dashboardInitFailed(e)"
70 69 ignore-loading="vm.layoutCtx.ignoreLoading">
... ...
... ... @@ -31,7 +31,7 @@ import AliasController from '../../api/alias-controller';
31 31 /*@ngInject*/
32 32 export default function AttributeTableDirective($compile, $templateCache, $rootScope, $q, $mdEditDialog, $mdDialog,
33 33 $mdUtil, $document, $translate, $filter, utils, types, dashboardUtils,
34   - dashboardService, entityService, attributeService, widgetService) {
  34 + entityService, attributeService, widgetService) {
35 35
36 36 var linker = function (scope, element, attrs) {
37 37
... ... @@ -407,10 +407,6 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
407 407 scope.getEntityAttributes(true);
408 408 }
409 409
410   - scope.getServerTimeDiff = function() {
411   - return dashboardService.getServerTimeDiff();
412   - }
413   -
414 410 scope.addWidgetToDashboard = function($event) {
415 411 if (scope.mode === 'widget' && scope.widgetsListCache.length > 0) {
416 412 var widget = scope.widgetsListCache[scope.widgetsCarousel.index][0];
... ...
... ... @@ -158,7 +158,6 @@
158 158 <tb-dashboard
159 159 alias-controller="aliasController"
160 160 widgets="widgets"
161   - get-st-diff="getServerTimeDiff()"
162 161 columns="20"
163 162 is-edit="false"
164 163 is-mobile-disabled="true"
... ...
... ... @@ -30,7 +30,7 @@
30 30 <md-input-container class="md-block">
31 31 <label translate>user.email</label>
32 32 <input required name="email"
33   - ng-pattern="/^[_a-z0-9]+(\.[_a-z0-9]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$/"
  33 + ng-pattern='/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/'
34 34 ng-model="user.email">
35 35 <div ng-messages="theForm.email.$error">
36 36 <div translate ng-message="required">user.email-required</div>
... ...