Merge pull request #172 from thingsboard/feature/TB-63

TB-63: Minor fixes.
This commit is contained in:
Igor Kulikov 2017-06-16 10:59:41 +03:00 committed by GitHub
commit 0bfbbd95ec
8 changed files with 77 additions and 35 deletions

View File

@ -296,6 +296,21 @@ export default class Subscription {
} }
} }
resetData() {
for (var i=0;i<this.data.length;i++) {
this.data[i].data = [];
this.hiddenData[i].data = [];
if (this.displayLegend) {
this.legendData.data[i].min = null;
this.legendData.data[i].max = null;
this.legendData.data[i].avg = null;
this.legendData.data[i].total = null;
this.legendData.data[i].hidden = false;
}
}
this.onDataUpdated();
}
startWatchingTimewindow() { startWatchingTimewindow() {
var subscription = this; var subscription = this;
this.timeWindowWatchRegistration = this.ctx.$scope.$watch(function () { this.timeWindowWatchRegistration = this.ctx.$scope.$watch(function () {
@ -720,6 +735,7 @@ export default class Subscription {
this.ctx.datasourceService.unsubscribeFromDatasource(listener); this.ctx.datasourceService.unsubscribeFromDatasource(listener);
} }
this.datasourceListeners = []; this.datasourceListeners = [];
this.resetData();
} }
} }
} }

View File

@ -16,6 +16,7 @@
import './dashboard.scss'; import './dashboard.scss';
import $ from 'jquery'; import $ from 'jquery';
import 'javascript-detect-element-resize/detect-element-resize';
import angularGridster from 'angular-gridster'; import angularGridster from 'angular-gridster';
import thingsboardTypes from '../common/types.constant'; import thingsboardTypes from '../common/types.constant';
import thingsboardApiWidget from '../api/widget.service'; import thingsboardApiWidget from '../api/widget.service';
@ -225,6 +226,18 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
} }
}; };
addResizeListener(gridsterParent[0], onGirdsterParentResize); // eslint-disable-line no-undef
$scope.$on("$destroy", function () {
removeResizeListener(gridsterParent[0], onGirdsterParentResize); // eslint-disable-line no-undef
});
function onGirdsterParentResize() {
if (gridsterParent.height() && vm.autofillHeight) {
updateMobileOpts();
}
}
$scope.$watchCollection('vm.widgets', function () { $scope.$watchCollection('vm.widgets', function () {
var ids = []; var ids = [];
for (var i=0;i<vm.widgets.length;i++) { for (var i=0;i<vm.widgets.length;i++) {
@ -262,6 +275,9 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
delete vm.widgetLayoutInfo[widgetId]; delete vm.widgetLayoutInfo[widgetId];
} }
} }
if (vm.autofillHeight) {
updateMobileOpts();
}
}); });
//TODO: widgets visibility //TODO: widgets visibility
@ -316,31 +332,7 @@ function DashboardController($scope, $rootScope, $element, $timeout, $mdMedia, $
}); });
$scope.$watch('vm.autofillHeight', function () { $scope.$watch('vm.autofillHeight', function () {
if (vm.autofillHeight) { updateMobileOpts();
//if (gridsterParent.height()) {
// updateMobileOpts();
//} else {
if ($scope.parentHeighWatcher) {
$scope.parentHeighWatcher();
}
if (gridsterParent.height()) {
updateMobileOpts();
}
$scope.parentHeighWatcher = $scope.$watch(function() { return gridsterParent.height(); },
function(newHeight) {
if (newHeight) {
updateMobileOpts();
}
}
);
} else {
if ($scope.parentHeighWatcher) {
$scope.parentHeighWatcher();
$scope.parentHeighWatcher = null;
}
updateMobileOpts();
}
}); });
$scope.$watch('vm.isMobileDisabled', function () { $scope.$watch('vm.isMobileDisabled', function () {

View File

@ -562,6 +562,9 @@ export default function WidgetController($scope, $timeout, $window, $element, $q
} }
function onInit(skipSizeCheck) { function onInit(skipSizeCheck) {
if (!widgetContext.$containerParent) {
return;
}
if (!skipSizeCheck) { if (!skipSizeCheck) {
checkSize(); checkSize();
} }

View File

@ -72,6 +72,12 @@ export default function DashboardController(types, utils, dashboardUtils, widget
set: function() { } set: function() { }
}); });
Object.defineProperty(vm, 'rightLayoutOpened', {
get: function() {
return !vm.isMobile || vm.isRightLayoutOpened; },
set: function() { }
});
vm.layouts = { vm.layouts = {
main: { main: {
show: false, show: false,

View File

@ -150,7 +150,7 @@
zIndex: 1}" zIndex: 1}"
md-component-id="right-dashboard-layout" md-component-id="right-dashboard-layout"
aria-label="Right dashboard layout" aria-label="Right dashboard layout"
md-is-open="!vm.isMobile || vm.isRightLayoutOpened" md-is-open="vm.rightLayoutOpened"
md-is-locked-open="!vm.isMobile"> md-is-locked-open="!vm.isMobile">
<tb-dashboard-layout style="height: 100%;" <tb-dashboard-layout style="height: 100%;"
layout-ctx="vm.layouts.right.layoutCtx" layout-ctx="vm.layouts.right.layoutCtx"

View File

@ -42,8 +42,10 @@ export default function DefaultStateController($scope, $location, $state, $state
params: params params: params
} }
//append new state //append new state
stopWatchStateObject();
vm.stateObject[0] = newState; vm.stateObject[0] = newState;
gotoState(vm.stateObject[0].id, true, openRightLayout); gotoState(vm.stateObject[0].id, true, openRightLayout);
watchStateObject();
} }
} }
@ -57,24 +59,36 @@ export default function DefaultStateController($scope, $location, $state, $state
params: params params: params
} }
//replace with new state //replace with new state
stopWatchStateObject();
vm.stateObject[0] = newState; vm.stateObject[0] = newState;
gotoState(vm.stateObject[0].id, true, openRightLayout); gotoState(vm.stateObject[0].id, true, openRightLayout);
watchStateObject();
} }
} }
function navigatePrevState(index) { function navigatePrevState(index) {
if (index < vm.stateObject.length-1) { if (index < vm.stateObject.length-1) {
stopWatchStateObject();
vm.stateObject.splice(index+1, vm.stateObject.length-index-1); vm.stateObject.splice(index+1, vm.stateObject.length-index-1);
gotoState(vm.stateObject[vm.stateObject.length-1].id, true); gotoState(vm.stateObject[vm.stateObject.length-1].id, true);
watchStateObject();
} }
} }
function getStateId() { function getStateId() {
return vm.stateObject[vm.stateObject.length-1].id; if (vm.stateObject && vm.stateObject.length) {
return vm.stateObject[vm.stateObject.length-1].id;
} else {
return '';
}
} }
function getStateParams() { function getStateParams() {
return vm.stateObject[vm.stateObject.length-1].params; if (vm.stateObject && vm.stateObject.length) {
return vm.stateObject[vm.stateObject.length - 1].params;
} else {
return {};
}
} }
function getStateParamsByStateId(stateId) { function getStateParamsByStateId(stateId) {
@ -102,7 +116,7 @@ export default function DefaultStateController($scope, $location, $state, $state
if (translation != translationId) { if (translation != translationId) {
result = translation + ''; result = translation + '';
} else { } else {
result = state.name; result = id;
} }
return result; return result;
} }
@ -194,7 +208,4 @@ export default function DefaultStateController($scope, $location, $state, $state
$location.search({state : angular.toJson(vm.stateObject)}); $location.search({state : angular.toJson(vm.stateObject)});
} }
} }
} }

View File

@ -44,9 +44,11 @@ export default function EntityStateController($scope, $location, $state, $stateP
params: params params: params
} }
//append new state //append new state
stopWatchStateObject();
vm.stateObject.push(newState); vm.stateObject.push(newState);
vm.selectedStateIndex = vm.stateObject.length-1; vm.selectedStateIndex = vm.stateObject.length-1;
gotoState(vm.stateObject[vm.stateObject.length-1].id, true, openRightLayout); gotoState(vm.stateObject[vm.stateObject.length-1].id, true, openRightLayout);
watchStateObject();
} }
); );
} }
@ -62,8 +64,10 @@ export default function EntityStateController($scope, $location, $state, $stateP
params: params params: params
} }
//replace with new state //replace with new state
stopWatchStateObject();
vm.stateObject[vm.stateObject.length - 1] = newState; vm.stateObject[vm.stateObject.length - 1] = newState;
gotoState(vm.stateObject[vm.stateObject.length - 1].id, true, openRightLayout); gotoState(vm.stateObject[vm.stateObject.length - 1].id, true, openRightLayout);
watchStateObject();
} }
); );
} }
@ -71,18 +75,28 @@ export default function EntityStateController($scope, $location, $state, $stateP
function navigatePrevState(index) { function navigatePrevState(index) {
if (index < vm.stateObject.length-1) { if (index < vm.stateObject.length-1) {
stopWatchStateObject();
vm.stateObject.splice(index+1, vm.stateObject.length-index-1); vm.stateObject.splice(index+1, vm.stateObject.length-index-1);
vm.selectedStateIndex = vm.stateObject.length-1; vm.selectedStateIndex = vm.stateObject.length-1;
gotoState(vm.stateObject[vm.stateObject.length-1].id, true); gotoState(vm.stateObject[vm.stateObject.length-1].id, true);
watchStateObject();
} }
} }
function getStateId() { function getStateId() {
return vm.stateObject[vm.stateObject.length-1].id; if (vm.stateObject && vm.stateObject.length) {
return vm.stateObject[vm.stateObject.length-1].id;
} else {
return '';
}
} }
function getStateParams() { function getStateParams() {
return vm.stateObject[vm.stateObject.length-1].params; if (vm.stateObject && vm.stateObject.length) {
return vm.stateObject[vm.stateObject.length - 1].params;
} else {
return {};
}
} }
function getStateParamsByStateId(stateId) { function getStateParamsByStateId(stateId) {

View File

@ -122,7 +122,7 @@ export default function ManageDashboardStatesController($scope, $mdDialog, $filt
} }
function getStateIndex(id) { function getStateIndex(id) {
var result = $filter('filter')(vm.allStates, {id: id}); var result = $filter('filter')(vm.allStates, {id: id}, true);
if (result && result.length) { if (result && result.length) {
return vm.allStates.indexOf(result[0]); return vm.allStates.indexOf(result[0]);
} }