UI: Fix server time diff calculation.
This commit is contained in:
parent
d7e9da6321
commit
abc16e6bb6
@ -17,7 +17,14 @@ export default angular.module('thingsboard.api.dashboard', [])
|
|||||||
.factory('dashboardService', DashboardService).name;
|
.factory('dashboardService', DashboardService).name;
|
||||||
|
|
||||||
/*@ngInject*/
|
/*@ngInject*/
|
||||||
function DashboardService($http, $q, $location, customerService) {
|
function DashboardService($rootScope, $http, $q, $location, customerService) {
|
||||||
|
|
||||||
|
var stDiffPromise;
|
||||||
|
|
||||||
|
$rootScope.dadshboardServiceStateChangeStartHandle = $rootScope.$on('$stateChangeStart', function () {
|
||||||
|
stDiffPromise = undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
var service = {
|
var service = {
|
||||||
assignDashboardToCustomer: assignDashboardToCustomer,
|
assignDashboardToCustomer: assignDashboardToCustomer,
|
||||||
@ -113,18 +120,23 @@ function DashboardService($http, $q, $location, customerService) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getServerTimeDiff() {
|
function getServerTimeDiff() {
|
||||||
var deferred = $q.defer();
|
if (stDiffPromise) {
|
||||||
var url = '/api/dashboard/serverTime';
|
return stDiffPromise;
|
||||||
var ct1 = Date.now();
|
} else {
|
||||||
$http.get(url, { ignoreLoading: true }).then(function success(response) {
|
var deferred = $q.defer();
|
||||||
var ct2 = Date.now();
|
stDiffPromise = deferred.promise;
|
||||||
var st = response.data;
|
var url = '/api/dashboard/serverTime';
|
||||||
var stDiff = Math.ceil(st - (ct1+ct2)/2);
|
var ct1 = Date.now();
|
||||||
deferred.resolve(stDiff);
|
$http.get(url, {ignoreLoading: true}).then(function success(response) {
|
||||||
}, function fail() {
|
var ct2 = Date.now();
|
||||||
deferred.reject();
|
var st = response.data;
|
||||||
});
|
var stDiff = Math.ceil(st - (ct1 + ct2) / 2);
|
||||||
return deferred.promise;
|
deferred.resolve(stDiff);
|
||||||
|
}, function fail() {
|
||||||
|
deferred.reject();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return stDiffPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDashboard(dashboardId) {
|
function getDashboard(dashboardId) {
|
||||||
|
|||||||
@ -80,9 +80,7 @@ export default class Subscription {
|
|||||||
this.alarms = [];
|
this.alarms = [];
|
||||||
|
|
||||||
this.originalTimewindow = null;
|
this.originalTimewindow = null;
|
||||||
this.timeWindow = {
|
this.timeWindow = {};
|
||||||
stDiff: this.ctx.stDiff
|
|
||||||
}
|
|
||||||
this.useDashboardTimewindow = options.useDashboardTimewindow;
|
this.useDashboardTimewindow = options.useDashboardTimewindow;
|
||||||
|
|
||||||
if (this.useDashboardTimewindow) {
|
if (this.useDashboardTimewindow) {
|
||||||
@ -124,9 +122,7 @@ export default class Subscription {
|
|||||||
this.data = [];
|
this.data = [];
|
||||||
this.hiddenData = [];
|
this.hiddenData = [];
|
||||||
this.originalTimewindow = null;
|
this.originalTimewindow = null;
|
||||||
this.timeWindow = {
|
this.timeWindow = {};
|
||||||
stDiff: this.ctx.stDiff
|
|
||||||
}
|
|
||||||
this.useDashboardTimewindow = options.useDashboardTimewindow;
|
this.useDashboardTimewindow = options.useDashboardTimewindow;
|
||||||
this.stateData = options.stateData;
|
this.stateData = options.stateData;
|
||||||
if (this.useDashboardTimewindow) {
|
if (this.useDashboardTimewindow) {
|
||||||
@ -213,27 +209,51 @@ export default class Subscription {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
initAlarmSubscription() {
|
loadStDiff() {
|
||||||
var deferred = this.ctx.$q.defer();
|
var deferred = this.ctx.$q.defer();
|
||||||
if (!this.ctx.aliasController) {
|
if (this.ctx.getStDiff && this.timeWindow) {
|
||||||
this.configureAlarmsData();
|
this.ctx.getStDiff().then(
|
||||||
deferred.resolve();
|
(stDiff) => {
|
||||||
} else {
|
this.timeWindow.stDiff = stDiff;
|
||||||
var subscription = this;
|
|
||||||
this.ctx.aliasController.resolveAlarmSource(this.alarmSource).then(
|
|
||||||
function success(alarmSource) {
|
|
||||||
subscription.alarmSource = alarmSource;
|
|
||||||
subscription.configureAlarmsData();
|
|
||||||
deferred.resolve();
|
deferred.resolve();
|
||||||
},
|
},
|
||||||
function fail() {
|
() => {
|
||||||
deferred.reject();
|
this.timeWindow.stDiff = 0;
|
||||||
|
deferred.resolve();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
if (this.timeWindow) {
|
||||||
|
this.timeWindow.stDiff = 0;
|
||||||
|
}
|
||||||
|
deferred.resolve();
|
||||||
}
|
}
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
initAlarmSubscription() {
|
||||||
|
var deferred = this.ctx.$q.defer();
|
||||||
|
var subscription = this;
|
||||||
|
this.loadStDiff().then(() => {
|
||||||
|
if (!subscription.ctx.aliasController) {
|
||||||
|
subscription.configureAlarmsData();
|
||||||
|
deferred.resolve();
|
||||||
|
} else {
|
||||||
|
subscription.ctx.aliasController.resolveAlarmSource(subscription.alarmSource).then(
|
||||||
|
function success(alarmSource) {
|
||||||
|
subscription.alarmSource = alarmSource;
|
||||||
|
subscription.configureAlarmsData();
|
||||||
|
deferred.resolve();
|
||||||
|
},
|
||||||
|
function fail() {
|
||||||
|
deferred.reject();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return deferred.promise;
|
||||||
|
}
|
||||||
|
|
||||||
configureAlarmsData() {
|
configureAlarmsData() {
|
||||||
var subscription = this;
|
var subscription = this;
|
||||||
var registration;
|
var registration;
|
||||||
@ -252,22 +272,24 @@ export default class Subscription {
|
|||||||
|
|
||||||
initDataSubscription() {
|
initDataSubscription() {
|
||||||
var deferred = this.ctx.$q.defer();
|
var deferred = this.ctx.$q.defer();
|
||||||
if (!this.ctx.aliasController) {
|
var subscription = this;
|
||||||
this.configureData();
|
this.loadStDiff().then(() => {
|
||||||
deferred.resolve();
|
if (!subscription.ctx.aliasController) {
|
||||||
} else {
|
subscription.configureData();
|
||||||
var subscription = this;
|
deferred.resolve();
|
||||||
this.ctx.aliasController.resolveDatasources(this.datasources).then(
|
} else {
|
||||||
function success(datasources) {
|
subscription.ctx.aliasController.resolveDatasources(subscription.datasources).then(
|
||||||
subscription.datasources = datasources;
|
function success(datasources) {
|
||||||
subscription.configureData();
|
subscription.datasources = datasources;
|
||||||
deferred.resolve();
|
subscription.configureData();
|
||||||
},
|
deferred.resolve();
|
||||||
function fail() {
|
},
|
||||||
deferred.reject();
|
function fail() {
|
||||||
}
|
deferred.reject();
|
||||||
);
|
}
|
||||||
}
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
return deferred.promise;
|
return deferred.promise;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -75,7 +75,6 @@ function Dashboard() {
|
|||||||
prepareDashboardContextMenu: '&?',
|
prepareDashboardContextMenu: '&?',
|
||||||
prepareWidgetContextMenu: '&?',
|
prepareWidgetContextMenu: '&?',
|
||||||
loadWidgets: '&?',
|
loadWidgets: '&?',
|
||||||
getStDiff: '&?',
|
|
||||||
onInit: '&?',
|
onInit: '&?',
|
||||||
onInitFailed: '&?',
|
onInitFailed: '&?',
|
||||||
dashboardStyle: '=?',
|
dashboardStyle: '=?',
|
||||||
@ -102,8 +101,6 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
|
|||||||
|
|
||||||
vm.gridster = null;
|
vm.gridster = null;
|
||||||
|
|
||||||
vm.stDiff = 0;
|
|
||||||
|
|
||||||
vm.isMobileDisabled = angular.isDefined(vm.isMobileDisabled) ? vm.isMobileDisabled : false;
|
vm.isMobileDisabled = angular.isDefined(vm.isMobileDisabled) ? vm.isMobileDisabled : false;
|
||||||
|
|
||||||
vm.isMobileSize = false;
|
vm.isMobileSize = false;
|
||||||
@ -500,7 +497,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
|
|||||||
sortWidgets();
|
sortWidgets();
|
||||||
});
|
});
|
||||||
|
|
||||||
loadStDiff();
|
loadDashboard();
|
||||||
|
|
||||||
function sortWidgets() {
|
function sortWidgets() {
|
||||||
vm.widgets.sort(function (widget1, widget2) {
|
vm.widgets.sort(function (widget1, widget2) {
|
||||||
@ -515,28 +512,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
|
|||||||
}
|
}
|
||||||
|
|
||||||
function reload() {
|
function reload() {
|
||||||
loadStDiff();
|
loadDashboard();
|
||||||
}
|
|
||||||
|
|
||||||
function loadStDiff() {
|
|
||||||
if (vm.getStDiff) {
|
|
||||||
var promise = vm.getStDiff();
|
|
||||||
if (promise) {
|
|
||||||
promise.then(function (stDiff) {
|
|
||||||
vm.stDiff = stDiff;
|
|
||||||
loadDashboard();
|
|
||||||
}, function () {
|
|
||||||
vm.stDiff = 0;
|
|
||||||
loadDashboard();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
vm.stDiff = 0;
|
|
||||||
loadDashboard();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
vm.stDiff = 0;
|
|
||||||
loadDashboard();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadDashboard() {
|
function loadDashboard() {
|
||||||
|
|||||||
@ -113,7 +113,6 @@
|
|||||||
stateController: vm.stateController,
|
stateController: vm.stateController,
|
||||||
isEdit: vm.isEdit,
|
isEdit: vm.isEdit,
|
||||||
isMobile: vm.isMobileSize,
|
isMobile: vm.isMobileSize,
|
||||||
stDiff: vm.stDiff,
|
|
||||||
dashboardTimewindow: vm.dashboardTimewindow,
|
dashboardTimewindow: vm.dashboardTimewindow,
|
||||||
dashboardTimewindowApi: vm.dashboardTimewindowApi }">
|
dashboardTimewindowApi: vm.dashboardTimewindowApi }">
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -21,7 +21,7 @@ import Subscription from '../../api/subscription';
|
|||||||
|
|
||||||
/*@ngInject*/
|
/*@ngInject*/
|
||||||
export default function WidgetController($scope, $state, $timeout, $window, $element, $q, $log, $injector, $filter, $compile, tbRaf, types, utils, timeService,
|
export default function WidgetController($scope, $state, $timeout, $window, $element, $q, $log, $injector, $filter, $compile, tbRaf, types, utils, timeService,
|
||||||
datasourceService, alarmService, entityService, deviceService, visibleRect, isEdit, isMobile, stDiff, dashboardTimewindow,
|
datasourceService, alarmService, entityService, dashboardService, deviceService, visibleRect, isEdit, isMobile, dashboardTimewindow,
|
||||||
dashboardTimewindowApi, widget, aliasController, stateController, widgetInfo, widgetType) {
|
dashboardTimewindowApi, widget, aliasController, stateController, widgetInfo, widgetType) {
|
||||||
|
|
||||||
var vm = this;
|
var vm = this;
|
||||||
@ -159,7 +159,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele
|
|||||||
widgetUtils: widgetContext.utils,
|
widgetUtils: widgetContext.utils,
|
||||||
dashboardTimewindowApi: dashboardTimewindowApi,
|
dashboardTimewindowApi: dashboardTimewindowApi,
|
||||||
types: types,
|
types: types,
|
||||||
stDiff: stDiff,
|
getStDiff: dashboardService.getServerTimeDiff,
|
||||||
aliasController: aliasController
|
aliasController: aliasController
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -170,7 +170,6 @@ export default function DashboardController(types, utils, dashboardUtils, widget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vm.getServerTimeDiff = getServerTimeDiff;
|
|
||||||
vm.addWidget = addWidget;
|
vm.addWidget = addWidget;
|
||||||
vm.addWidgetFromType = addWidgetFromType;
|
vm.addWidgetFromType = addWidgetFromType;
|
||||||
vm.exportDashboard = exportDashboard;
|
vm.exportDashboard = exportDashboard;
|
||||||
@ -334,10 +333,6 @@ export default function DashboardController(types, utils, dashboardUtils, widget
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getServerTimeDiff() {
|
|
||||||
return dashboardService.getServerTimeDiff();
|
|
||||||
}
|
|
||||||
|
|
||||||
function loadDashboard() {
|
function loadDashboard() {
|
||||||
if (vm.widgetEditMode) {
|
if (vm.widgetEditMode) {
|
||||||
var widget = {
|
var widget = {
|
||||||
|
|||||||
@ -137,8 +137,7 @@
|
|||||||
dashboard-ctx="vm.dashboardCtx"
|
dashboard-ctx="vm.dashboardCtx"
|
||||||
is-edit="vm.isEdit"
|
is-edit="vm.isEdit"
|
||||||
is-mobile="vm.forceDashboardMobileMode"
|
is-mobile="vm.forceDashboardMobileMode"
|
||||||
widget-edit-mode="vm.widgetEditMode"
|
widget-edit-mode="vm.widgetEditMode">
|
||||||
get-st-diff="vm.getServerTimeDiff()">
|
|
||||||
</tb-dashboard-layout>
|
</tb-dashboard-layout>
|
||||||
</div>
|
</div>
|
||||||
<md-sidenav ng-if="vm.layouts.right.show"
|
<md-sidenav ng-if="vm.layouts.right.show"
|
||||||
@ -157,8 +156,7 @@
|
|||||||
dashboard-ctx="vm.dashboardCtx"
|
dashboard-ctx="vm.dashboardCtx"
|
||||||
is-edit="vm.isEdit"
|
is-edit="vm.isEdit"
|
||||||
is-mobile="vm.forceDashboardMobileMode"
|
is-mobile="vm.forceDashboardMobileMode"
|
||||||
widget-edit-mode="vm.widgetEditMode"
|
widget-edit-mode="vm.widgetEditMode">
|
||||||
get-st-diff="vm.getServerTimeDiff()">
|
|
||||||
</tb-dashboard-layout>
|
</tb-dashboard-layout>
|
||||||
</md-sidenav>
|
</md-sidenav>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -29,8 +29,7 @@ export default function DashboardLayout() {
|
|||||||
dashboardCtx: '=',
|
dashboardCtx: '=',
|
||||||
isEdit: '=',
|
isEdit: '=',
|
||||||
isMobile: '=',
|
isMobile: '=',
|
||||||
widgetEditMode: '=',
|
widgetEditMode: '='
|
||||||
getStDiff: '&?'
|
|
||||||
},
|
},
|
||||||
controller: DashboardLayoutController,
|
controller: DashboardLayoutController,
|
||||||
controllerAs: 'vm',
|
controllerAs: 'vm',
|
||||||
|
|||||||
@ -64,7 +64,6 @@
|
|||||||
prepare-dashboard-context-menu="vm.prepareDashboardContextMenu()"
|
prepare-dashboard-context-menu="vm.prepareDashboardContextMenu()"
|
||||||
prepare-widget-context-menu="vm.prepareWidgetContextMenu(widget)"
|
prepare-widget-context-menu="vm.prepareWidgetContextMenu(widget)"
|
||||||
on-remove-widget="vm.removeWidget(event, widget)"
|
on-remove-widget="vm.removeWidget(event, widget)"
|
||||||
get-st-diff="vm.getStDiff()"
|
|
||||||
on-init="vm.dashboardInited(dashboard)"
|
on-init="vm.dashboardInited(dashboard)"
|
||||||
on-init-failed="vm.dashboardInitFailed(e)"
|
on-init-failed="vm.dashboardInitFailed(e)"
|
||||||
ignore-loading="vm.layoutCtx.ignoreLoading">
|
ignore-loading="vm.layoutCtx.ignoreLoading">
|
||||||
|
|||||||
@ -31,7 +31,7 @@ import AliasController from '../../api/alias-controller';
|
|||||||
/*@ngInject*/
|
/*@ngInject*/
|
||||||
export default function AttributeTableDirective($compile, $templateCache, $rootScope, $q, $mdEditDialog, $mdDialog,
|
export default function AttributeTableDirective($compile, $templateCache, $rootScope, $q, $mdEditDialog, $mdDialog,
|
||||||
$mdUtil, $document, $translate, $filter, utils, types, dashboardUtils,
|
$mdUtil, $document, $translate, $filter, utils, types, dashboardUtils,
|
||||||
dashboardService, entityService, attributeService, widgetService) {
|
entityService, attributeService, widgetService) {
|
||||||
|
|
||||||
var linker = function (scope, element, attrs) {
|
var linker = function (scope, element, attrs) {
|
||||||
|
|
||||||
@ -407,10 +407,6 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
|
|||||||
scope.getEntityAttributes(true);
|
scope.getEntityAttributes(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
scope.getServerTimeDiff = function() {
|
|
||||||
return dashboardService.getServerTimeDiff();
|
|
||||||
}
|
|
||||||
|
|
||||||
scope.addWidgetToDashboard = function($event) {
|
scope.addWidgetToDashboard = function($event) {
|
||||||
if (scope.mode === 'widget' && scope.widgetsListCache.length > 0) {
|
if (scope.mode === 'widget' && scope.widgetsListCache.length > 0) {
|
||||||
var widget = scope.widgetsListCache[scope.widgetsCarousel.index][0];
|
var widget = scope.widgetsListCache[scope.widgetsCarousel.index][0];
|
||||||
|
|||||||
@ -158,7 +158,6 @@
|
|||||||
<tb-dashboard
|
<tb-dashboard
|
||||||
alias-controller="aliasController"
|
alias-controller="aliasController"
|
||||||
widgets="widgets"
|
widgets="widgets"
|
||||||
get-st-diff="getServerTimeDiff()"
|
|
||||||
columns="20"
|
columns="20"
|
||||||
is-edit="false"
|
is-edit="false"
|
||||||
is-mobile-disabled="true"
|
is-mobile-disabled="true"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user