thingsboard-memoizeit
Changes
ui/src/app/api/dashboard.service.js 38(+25 -13)
ui/src/app/api/subscription.js 90(+56 -34)
ui/src/app/components/dashboard.directive.js 28(+2 -26)
Details
ui/src/app/api/dashboard.service.js 38(+25 -13)
diff --git a/ui/src/app/api/dashboard.service.js b/ui/src/app/api/dashboard.service.js
index 743fbe9..74b68d0 100644
--- a/ui/src/app/api/dashboard.service.js
+++ b/ui/src/app/api/dashboard.service.js
@@ -17,7 +17,14 @@ export default angular.module('thingsboard.api.dashboard', [])
.factory('dashboardService', DashboardService).name;
/*@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 = {
assignDashboardToCustomer: assignDashboardToCustomer,
@@ -113,18 +120,23 @@ function DashboardService($http, $q, $location, customerService) {
}
function getServerTimeDiff() {
- var deferred = $q.defer();
- var url = '/api/dashboard/serverTime';
- var ct1 = Date.now();
- $http.get(url, { ignoreLoading: true }).then(function success(response) {
- var ct2 = Date.now();
- var st = response.data;
- var stDiff = Math.ceil(st - (ct1+ct2)/2);
- deferred.resolve(stDiff);
- }, function fail() {
- deferred.reject();
- });
- return deferred.promise;
+ if (stDiffPromise) {
+ return stDiffPromise;
+ } else {
+ var deferred = $q.defer();
+ stDiffPromise = deferred.promise;
+ var url = '/api/dashboard/serverTime';
+ var ct1 = Date.now();
+ $http.get(url, {ignoreLoading: true}).then(function success(response) {
+ var ct2 = Date.now();
+ var st = response.data;
+ var stDiff = Math.ceil(st - (ct1 + ct2) / 2);
+ deferred.resolve(stDiff);
+ }, function fail() {
+ deferred.reject();
+ });
+ }
+ return stDiffPromise;
}
function getDashboard(dashboardId) {
ui/src/app/api/subscription.js 90(+56 -34)
diff --git a/ui/src/app/api/subscription.js b/ui/src/app/api/subscription.js
index ac8cefe..7334165 100644
--- a/ui/src/app/api/subscription.js
+++ b/ui/src/app/api/subscription.js
@@ -80,9 +80,7 @@ export default class Subscription {
this.alarms = [];
this.originalTimewindow = null;
- this.timeWindow = {
- stDiff: this.ctx.stDiff
- }
+ this.timeWindow = {};
this.useDashboardTimewindow = options.useDashboardTimewindow;
if (this.useDashboardTimewindow) {
@@ -124,9 +122,7 @@ export default class Subscription {
this.data = [];
this.hiddenData = [];
this.originalTimewindow = null;
- this.timeWindow = {
- stDiff: this.ctx.stDiff
- }
+ this.timeWindow = {};
this.useDashboardTimewindow = options.useDashboardTimewindow;
this.stateData = options.stateData;
if (this.useDashboardTimewindow) {
@@ -213,27 +209,51 @@ export default class Subscription {
}
}
- initAlarmSubscription() {
+ loadStDiff() {
var deferred = this.ctx.$q.defer();
- if (!this.ctx.aliasController) {
- this.configureAlarmsData();
- deferred.resolve();
- } else {
- var subscription = this;
- this.ctx.aliasController.resolveAlarmSource(this.alarmSource).then(
- function success(alarmSource) {
- subscription.alarmSource = alarmSource;
- subscription.configureAlarmsData();
+ if (this.ctx.getStDiff && this.timeWindow) {
+ this.ctx.getStDiff().then(
+ (stDiff) => {
+ this.timeWindow.stDiff = stDiff;
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;
}
+ 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() {
var subscription = this;
var registration;
@@ -252,22 +272,24 @@ export default class Subscription {
initDataSubscription() {
var deferred = this.ctx.$q.defer();
- if (!this.ctx.aliasController) {
- this.configureData();
- deferred.resolve();
- } else {
- var subscription = this;
- this.ctx.aliasController.resolveDatasources(this.datasources).then(
- function success(datasources) {
- subscription.datasources = datasources;
- subscription.configureData();
- deferred.resolve();
- },
- function fail() {
- deferred.reject();
- }
- );
- }
+ var subscription = this;
+ this.loadStDiff().then(() => {
+ if (!subscription.ctx.aliasController) {
+ subscription.configureData();
+ deferred.resolve();
+ } else {
+ subscription.ctx.aliasController.resolveDatasources(subscription.datasources).then(
+ function success(datasources) {
+ subscription.datasources = datasources;
+ subscription.configureData();
+ deferred.resolve();
+ },
+ function fail() {
+ deferred.reject();
+ }
+ );
+ }
+ });
return deferred.promise;
}
ui/src/app/components/dashboard.directive.js 28(+2 -26)
diff --git a/ui/src/app/components/dashboard.directive.js b/ui/src/app/components/dashboard.directive.js
index 1a675ce..417ddb1 100644
--- a/ui/src/app/components/dashboard.directive.js
+++ b/ui/src/app/components/dashboard.directive.js
@@ -75,7 +75,6 @@ function Dashboard() {
prepareDashboardContextMenu: '&?',
prepareWidgetContextMenu: '&?',
loadWidgets: '&?',
- getStDiff: '&?',
onInit: '&?',
onInitFailed: '&?',
dashboardStyle: '=?',
@@ -102,8 +101,6 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
vm.gridster = null;
- vm.stDiff = 0;
-
vm.isMobileDisabled = angular.isDefined(vm.isMobileDisabled) ? vm.isMobileDisabled : false;
vm.isMobileSize = false;
@@ -500,7 +497,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
sortWidgets();
});
- loadStDiff();
+ loadDashboard();
function sortWidgets() {
vm.widgets.sort(function (widget1, widget2) {
@@ -515,28 +512,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
}
function reload() {
- loadStDiff();
- }
-
- 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();
- }
+ loadDashboard();
}
function loadDashboard() {
diff --git a/ui/src/app/components/dashboard.tpl.html b/ui/src/app/components/dashboard.tpl.html
index 2887419..0fe24de 100644
--- a/ui/src/app/components/dashboard.tpl.html
+++ b/ui/src/app/components/dashboard.tpl.html
@@ -113,7 +113,6 @@
stateController: vm.stateController,
isEdit: vm.isEdit,
isMobile: vm.isMobileSize,
- stDiff: vm.stDiff,
dashboardTimewindow: vm.dashboardTimewindow,
dashboardTimewindowApi: vm.dashboardTimewindowApi }">
</div>
diff --git a/ui/src/app/components/widget/widget.controller.js b/ui/src/app/components/widget/widget.controller.js
index a4846be..e81854c 100644
--- a/ui/src/app/components/widget/widget.controller.js
+++ b/ui/src/app/components/widget/widget.controller.js
@@ -21,7 +21,7 @@ import Subscription from '../../api/subscription';
/*@ngInject*/
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) {
var vm = this;
@@ -159,7 +159,7 @@ export default function WidgetController($scope, $state, $timeout, $window, $ele
widgetUtils: widgetContext.utils,
dashboardTimewindowApi: dashboardTimewindowApi,
types: types,
- stDiff: stDiff,
+ getStDiff: dashboardService.getServerTimeDiff,
aliasController: aliasController
};
diff --git a/ui/src/app/dashboard/dashboard.controller.js b/ui/src/app/dashboard/dashboard.controller.js
index 8319a9d..160223c 100644
--- a/ui/src/app/dashboard/dashboard.controller.js
+++ b/ui/src/app/dashboard/dashboard.controller.js
@@ -170,7 +170,6 @@ export default function DashboardController(types, utils, dashboardUtils, widget
}
}
- vm.getServerTimeDiff = getServerTimeDiff;
vm.addWidget = addWidget;
vm.addWidgetFromType = addWidgetFromType;
vm.exportDashboard = exportDashboard;
@@ -334,10 +333,6 @@ export default function DashboardController(types, utils, dashboardUtils, widget
}
}
- function getServerTimeDiff() {
- return dashboardService.getServerTimeDiff();
- }
-
function loadDashboard() {
if (vm.widgetEditMode) {
var widget = {
diff --git a/ui/src/app/dashboard/dashboard.tpl.html b/ui/src/app/dashboard/dashboard.tpl.html
index 394a601..71fbc66 100644
--- a/ui/src/app/dashboard/dashboard.tpl.html
+++ b/ui/src/app/dashboard/dashboard.tpl.html
@@ -137,8 +137,7 @@
dashboard-ctx="vm.dashboardCtx"
is-edit="vm.isEdit"
is-mobile="vm.forceDashboardMobileMode"
- widget-edit-mode="vm.widgetEditMode"
- get-st-diff="vm.getServerTimeDiff()">
+ widget-edit-mode="vm.widgetEditMode">
</tb-dashboard-layout>
</div>
<md-sidenav ng-if="vm.layouts.right.show"
@@ -157,8 +156,7 @@
dashboard-ctx="vm.dashboardCtx"
is-edit="vm.isEdit"
is-mobile="vm.forceDashboardMobileMode"
- widget-edit-mode="vm.widgetEditMode"
- get-st-diff="vm.getServerTimeDiff()">
+ widget-edit-mode="vm.widgetEditMode">
</tb-dashboard-layout>
</md-sidenav>
</div>
diff --git a/ui/src/app/dashboard/layouts/dashboard-layout.directive.js b/ui/src/app/dashboard/layouts/dashboard-layout.directive.js
index 18926c3..9ce569f 100644
--- a/ui/src/app/dashboard/layouts/dashboard-layout.directive.js
+++ b/ui/src/app/dashboard/layouts/dashboard-layout.directive.js
@@ -29,8 +29,7 @@ export default function DashboardLayout() {
dashboardCtx: '=',
isEdit: '=',
isMobile: '=',
- widgetEditMode: '=',
- getStDiff: '&?'
+ widgetEditMode: '='
},
controller: DashboardLayoutController,
controllerAs: 'vm',
diff --git a/ui/src/app/dashboard/layouts/dashboard-layout.tpl.html b/ui/src/app/dashboard/layouts/dashboard-layout.tpl.html
index 90a10b1..d9c7c23 100644
--- a/ui/src/app/dashboard/layouts/dashboard-layout.tpl.html
+++ b/ui/src/app/dashboard/layouts/dashboard-layout.tpl.html
@@ -64,7 +64,6 @@
prepare-dashboard-context-menu="vm.prepareDashboardContextMenu()"
prepare-widget-context-menu="vm.prepareWidgetContextMenu(widget)"
on-remove-widget="vm.removeWidget(event, widget)"
- get-st-diff="vm.getStDiff()"
on-init="vm.dashboardInited(dashboard)"
on-init-failed="vm.dashboardInitFailed(e)"
ignore-loading="vm.layoutCtx.ignoreLoading">
diff --git a/ui/src/app/entity/attribute/attribute-table.directive.js b/ui/src/app/entity/attribute/attribute-table.directive.js
index 62d2081..bb138ed 100644
--- a/ui/src/app/entity/attribute/attribute-table.directive.js
+++ b/ui/src/app/entity/attribute/attribute-table.directive.js
@@ -31,7 +31,7 @@ import AliasController from '../../api/alias-controller';
/*@ngInject*/
export default function AttributeTableDirective($compile, $templateCache, $rootScope, $q, $mdEditDialog, $mdDialog,
$mdUtil, $document, $translate, $filter, utils, types, dashboardUtils,
- dashboardService, entityService, attributeService, widgetService) {
+ entityService, attributeService, widgetService) {
var linker = function (scope, element, attrs) {
@@ -407,10 +407,6 @@ export default function AttributeTableDirective($compile, $templateCache, $rootS
scope.getEntityAttributes(true);
}
- scope.getServerTimeDiff = function() {
- return dashboardService.getServerTimeDiff();
- }
-
scope.addWidgetToDashboard = function($event) {
if (scope.mode === 'widget' && scope.widgetsListCache.length > 0) {
var widget = scope.widgetsListCache[scope.widgetsCarousel.index][0];
diff --git a/ui/src/app/entity/attribute/attribute-table.tpl.html b/ui/src/app/entity/attribute/attribute-table.tpl.html
index 3dfad59..6f862ba 100644
--- a/ui/src/app/entity/attribute/attribute-table.tpl.html
+++ b/ui/src/app/entity/attribute/attribute-table.tpl.html
@@ -158,7 +158,6 @@
<tb-dashboard
alias-controller="aliasController"
widgets="widgets"
- get-st-diff="getServerTimeDiff()"
columns="20"
is-edit="false"
is-mobile-disabled="true"