From a16e5319a4997da9fd0744f921252ab22ee2da92 Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Wed, 11 Oct 2017 16:12:12 +0300 Subject: [PATCH] Minor UI improvements. --- .../alarm/alarm-details-dialog.controller.js | 7 +++- .../app/alarm/alarm-details-dialog.tpl.html | 4 +- ui/src/app/alarm/alarm-row.directive.js | 1 + .../states/default-state-controller.js | 39 +++++++----------- .../states/entity-state-controller.js | 41 ++++++++----------- ui/src/app/widget/lib/alarms-table-widget.js | 1 + 6 files changed, 40 insertions(+), 53 deletions(-) diff --git a/ui/src/app/alarm/alarm-details-dialog.controller.js b/ui/src/app/alarm/alarm-details-dialog.controller.js index 6c82e2086c..d97d299008 100644 --- a/ui/src/app/alarm/alarm-details-dialog.controller.js +++ b/ui/src/app/alarm/alarm-details-dialog.controller.js @@ -24,20 +24,23 @@ const js_beautify = beautify.js; /*@ngInject*/ export default function AlarmDetailsDialogController($mdDialog, $filter, $translate, types, - alarmService, alarmId, allowAcknowledgment, allowClear, showingCallback) { + alarmService, alarmId, allowAcknowledgment, allowClear, displayDetails, showingCallback) { var vm = this; vm.alarmId = alarmId; vm.allowAcknowledgment = allowAcknowledgment; vm.allowClear = allowClear; + vm.displayDetails = displayDetails; vm.types = types; vm.alarm = null; vm.alarmUpdated = false; showingCallback.onShowing = function(scope, element) { - updateEditorSize(element); + if (vm.displayDetails) { + updateEditorSize(element); + } } vm.alarmDetailsOptions = { diff --git a/ui/src/app/alarm/alarm-details-dialog.tpl.html b/ui/src/app/alarm/alarm-details-dialog.tpl.html index 48f991c52a..c09a1fc8b1 100644 --- a/ui/src/app/alarm/alarm-details-dialog.tpl.html +++ b/ui/src/app/alarm/alarm-details-dialog.tpl.html @@ -74,8 +74,8 @@ -
alarm.details
-
+
alarm.details
+
diff --git a/ui/src/app/alarm/alarm-row.directive.js b/ui/src/app/alarm/alarm-row.directive.js index 09c04f9594..62bed1117a 100644 --- a/ui/src/app/alarm/alarm-row.directive.js +++ b/ui/src/app/alarm/alarm-row.directive.js @@ -44,6 +44,7 @@ export default function AlarmRowDirective($compile, $templateCache, types, $mdDi alarmId: scope.alarm.id.id, allowAcknowledgment: true, allowClear: true, + displayDetails: true, showingCallback: onShowingCallback }, parent: angular.element($document[0].body), diff --git a/ui/src/app/dashboard/states/default-state-controller.js b/ui/src/app/dashboard/states/default-state-controller.js index 8d85c59aeb..6f5172417d 100644 --- a/ui/src/app/dashboard/states/default-state-controller.js +++ b/ui/src/app/dashboard/states/default-state-controller.js @@ -22,6 +22,8 @@ export default function DefaultStateController($scope, $timeout, $location, $sta vm.inited = false; + vm.skipStateChange = false; + vm.openState = openState; vm.updateState = updateState; vm.resetState = resetState; @@ -48,10 +50,9 @@ export default function DefaultStateController($scope, $timeout, $location, $sta params: params } //append new state - stopWatchStateObject(); vm.stateObject[0] = newState; gotoState(vm.stateObject[0].id, true, openRightLayout); - watchStateObject(); + vm.skipStateChange = true; } } @@ -68,10 +69,9 @@ export default function DefaultStateController($scope, $timeout, $location, $sta params: params } //replace with new state - stopWatchStateObject(); vm.stateObject[0] = newState; gotoState(vm.stateObject[0].id, true, openRightLayout); - watchStateObject(); + vm.skipStateChange = true; } } @@ -87,10 +87,9 @@ export default function DefaultStateController($scope, $timeout, $location, $sta function navigatePrevState(index) { if (index < vm.stateObject.length-1) { - stopWatchStateObject(); vm.stateObject.splice(index+1, vm.stateObject.length-index-1); gotoState(vm.stateObject[vm.stateObject.length-1].id, true); - watchStateObject(); + vm.skipStateChange = true; } } @@ -221,31 +220,23 @@ export default function DefaultStateController($scope, $timeout, $location, $sta $scope.$watch('vm.dashboardCtrl.dashboardCtx.state', function () { if (vm.stateObject[0].id !== vm.dashboardCtrl.dashboardCtx.state) { - stopWatchStateObject(); vm.stateObject[0].id = vm.dashboardCtrl.dashboardCtx.state; updateLocation(); - watchStateObject(); + vm.skipStateChange = true; } }); - watchStateObject(); + $scope.$watch('vm.stateObject', function(newVal, prevVal) { + if (!angular.equals(newVal, prevVal) && newVal) { + if (vm.skipStateChange) { + vm.skipStateChange = false; + } else { + gotoState(vm.stateObject[0].id, true); + } + } + }, true); }); } - function stopWatchStateObject() { - if (vm.stateObjectWatcher) { - vm.stateObjectWatcher(); - vm.stateObjectWatcher = null; - } - } - - function watchStateObject() { - vm.stateObjectWatcher = $scope.$watch('vm.stateObject', function(newVal, prevVal) { - if (!angular.equals(newVal, prevVal) && newVal) { - gotoState(vm.stateObject[0].id, true); - } - }, true); - } - function gotoState(stateId, update, openRightLayout) { if (vm.dashboardCtrl.dashboardCtx.state != stateId) { vm.dashboardCtrl.openDashboardState(stateId, openRightLayout); diff --git a/ui/src/app/dashboard/states/entity-state-controller.js b/ui/src/app/dashboard/states/entity-state-controller.js index ba2bc64149..527cd08f54 100644 --- a/ui/src/app/dashboard/states/entity-state-controller.js +++ b/ui/src/app/dashboard/states/entity-state-controller.js @@ -24,6 +24,8 @@ export default function EntityStateController($scope, $timeout, $location, $stat vm.inited = false; + vm.skipStateChange = false; + vm.openState = openState; vm.updateState = updateState; vm.resetState = resetState; @@ -50,11 +52,10 @@ export default function EntityStateController($scope, $timeout, $location, $stat params: params } //append new state - stopWatchStateObject(); vm.stateObject.push(newState); vm.selectedStateIndex = vm.stateObject.length-1; gotoState(vm.stateObject[vm.stateObject.length-1].id, true, openRightLayout); - watchStateObject(); + vm.skipStateChange = true; } ); } @@ -73,10 +74,9 @@ export default function EntityStateController($scope, $timeout, $location, $stat params: params } //replace with new state - stopWatchStateObject(); vm.stateObject[vm.stateObject.length - 1] = newState; gotoState(vm.stateObject[vm.stateObject.length - 1].id, true, openRightLayout); - watchStateObject(); + vm.skipStateChange = true; } ); } @@ -94,11 +94,10 @@ export default function EntityStateController($scope, $timeout, $location, $stat function navigatePrevState(index) { if (index < vm.stateObject.length-1) { - stopWatchStateObject(); vm.stateObject.splice(index+1, vm.stateObject.length-index-1); vm.selectedStateIndex = vm.stateObject.length-1; gotoState(vm.stateObject[vm.stateObject.length-1].id, true); - watchStateObject(); + vm.skipStateChange = true; } } @@ -266,14 +265,22 @@ export default function EntityStateController($scope, $timeout, $location, $stat $scope.$watch('vm.dashboardCtrl.dashboardCtx.state', function () { if (vm.stateObject[vm.stateObject.length - 1].id !== vm.dashboardCtrl.dashboardCtx.state) { - stopWatchStateObject(); vm.stateObject[vm.stateObject.length - 1].id = vm.dashboardCtrl.dashboardCtx.state; updateLocation(); - watchStateObject(); + vm.skipStateChange = true; } }); - watchStateObject(); + $scope.$watch('vm.stateObject', function(newVal, prevVal) { + if (!angular.equals(newVal, prevVal) && newVal) { + if (vm.skipStateChange) { + vm.skipStateChange = false; + } else { + vm.selectedStateIndex = vm.stateObject.length - 1; + gotoState(vm.stateObject[vm.stateObject.length - 1].id, true); + } + } + }, true); if (vm.dashboardCtrl.isMobile) { watchSelectedStateIndex(); @@ -292,22 +299,6 @@ export default function EntityStateController($scope, $timeout, $location, $stat } - function stopWatchStateObject() { - if (vm.stateObjectWatcher) { - vm.stateObjectWatcher(); - vm.stateObjectWatcher = null; - } - } - - function watchStateObject() { - vm.stateObjectWatcher = $scope.$watch('vm.stateObject', function(newVal, prevVal) { - if (!angular.equals(newVal, prevVal) && newVal) { - vm.selectedStateIndex = vm.stateObject.length-1; - gotoState(vm.stateObject[vm.stateObject.length-1].id, true); - } - }, true); - } - function stopWatchSelectedStateIndex() { if (vm.selectedStateIndexWatcher) { vm.selectedStateIndexWatcher(); diff --git a/ui/src/app/widget/lib/alarms-table-widget.js b/ui/src/app/widget/lib/alarms-table-widget.js index 10e7aa3bc1..3af7ac7e8d 100644 --- a/ui/src/app/widget/lib/alarms-table-widget.js +++ b/ui/src/app/widget/lib/alarms-table-widget.js @@ -333,6 +333,7 @@ function AlarmsTableWidgetController($element, $scope, $filter, $mdMedia, $mdDia alarmId: alarm.id.id, allowAcknowledgment: vm.allowAcknowledgment, allowClear: vm.allowClear, + displayDetails: true, showingCallback: onShowingCallback }, parent: angular.element($document[0].body),