Commit 0e6053795515c53443b4e6f7f2638547593df38c
1 parent
88877cb0
UI: Preserve dashboard state when switching to edit mode.
Showing
5 changed files
with
105 additions
and
55 deletions
@@ -993,6 +993,7 @@ export default function DashboardController(types, utils, dashboardUtils, widget | @@ -993,6 +993,7 @@ export default function DashboardController(types, utils, dashboardUtils, widget | ||
993 | function setEditMode(isEdit, revert) { | 993 | function setEditMode(isEdit, revert) { |
994 | vm.isEdit = isEdit; | 994 | vm.isEdit = isEdit; |
995 | if (vm.isEdit) { | 995 | if (vm.isEdit) { |
996 | + vm.dashboardCtx.stateController.preserveState(); | ||
996 | vm.prevDashboard = angular.copy(vm.dashboard); | 997 | vm.prevDashboard = angular.copy(vm.dashboard); |
997 | } else { | 998 | } else { |
998 | if (vm.widgetEditMode) { | 999 | if (vm.widgetEditMode) { |
@@ -1009,7 +1010,6 @@ export default function DashboardController(types, utils, dashboardUtils, widget | @@ -1009,7 +1010,6 @@ export default function DashboardController(types, utils, dashboardUtils, widget | ||
1009 | } else { | 1010 | } else { |
1010 | vm.dashboard.configuration.timewindow = vm.dashboardCtx.dashboardTimewindow; | 1011 | vm.dashboard.configuration.timewindow = vm.dashboardCtx.dashboardTimewindow; |
1011 | } | 1012 | } |
1012 | - vm.dashboardCtx.stateController.resetState(); | ||
1013 | } | 1013 | } |
1014 | } | 1014 | } |
1015 | } | 1015 | } |
@@ -15,7 +15,8 @@ | @@ -15,7 +15,8 @@ | ||
15 | */ | 15 | */ |
16 | 16 | ||
17 | /*@ngInject*/ | 17 | /*@ngInject*/ |
18 | -export default function DefaultStateController($scope, $location, $state, $stateParams, utils, types, dashboardUtils) { | 18 | +export default function DefaultStateController($scope, $timeout, $location, $state, |
19 | + $stateParams, utils, types, dashboardUtils, preservedState) { | ||
19 | 20 | ||
20 | var vm = this; | 21 | var vm = this; |
21 | 22 | ||
@@ -24,6 +25,7 @@ export default function DefaultStateController($scope, $location, $state, $state | @@ -24,6 +25,7 @@ export default function DefaultStateController($scope, $location, $state, $state | ||
24 | vm.openState = openState; | 25 | vm.openState = openState; |
25 | vm.updateState = updateState; | 26 | vm.updateState = updateState; |
26 | vm.resetState = resetState; | 27 | vm.resetState = resetState; |
28 | + vm.getStateObject = getStateObject; | ||
27 | vm.navigatePrevState = navigatePrevState; | 29 | vm.navigatePrevState = navigatePrevState; |
28 | vm.getStateId = getStateId; | 30 | vm.getStateId = getStateId; |
29 | vm.getStateParams = getStateParams; | 31 | vm.getStateParams = getStateParams; |
@@ -77,6 +79,10 @@ export default function DefaultStateController($scope, $location, $state, $state | @@ -77,6 +79,10 @@ export default function DefaultStateController($scope, $location, $state, $state | ||
77 | gotoState(rootStateId, true); | 79 | gotoState(rootStateId, true); |
78 | } | 80 | } |
79 | 81 | ||
82 | + function getStateObject() { | ||
83 | + return vm.stateObject; | ||
84 | + } | ||
85 | + | ||
80 | function navigatePrevState(index) { | 86 | function navigatePrevState(index) { |
81 | if (index < vm.stateObject.length-1) { | 87 | if (index < vm.stateObject.length-1) { |
82 | stopWatchStateObject(); | 88 | stopWatchStateObject(); |
@@ -168,27 +174,33 @@ export default function DefaultStateController($scope, $location, $state, $state | @@ -168,27 +174,33 @@ export default function DefaultStateController($scope, $location, $state, $state | ||
168 | } | 174 | } |
169 | 175 | ||
170 | function init() { | 176 | function init() { |
171 | - var initialState = $stateParams.state; | ||
172 | - vm.stateObject = parseState(initialState); | ||
173 | - | ||
174 | - gotoState(vm.stateObject[0].id, false); | ||
175 | - | ||
176 | - $scope.$watchCollection(function(){ | ||
177 | - return $state.params; | ||
178 | - }, function(){ | ||
179 | - var currentState = $state.params.state; | ||
180 | - vm.stateObject = parseState(currentState); | ||
181 | - }); | ||
182 | - | ||
183 | - $scope.$watch('vm.dashboardCtrl.dashboardCtx.state', function() { | ||
184 | - if (vm.stateObject[0].id !== vm.dashboardCtrl.dashboardCtx.state) { | ||
185 | - stopWatchStateObject(); | ||
186 | - vm.stateObject[0].id = vm.dashboardCtrl.dashboardCtx.state; | ||
187 | - updateLocation(); | ||
188 | - watchStateObject(); | ||
189 | - } | 177 | + if (preservedState) { |
178 | + vm.stateObject = preservedState; | ||
179 | + gotoState(vm.stateObject[0].id, true); | ||
180 | + } else { | ||
181 | + var initialState = $stateParams.state; | ||
182 | + vm.stateObject = parseState(initialState); | ||
183 | + gotoState(vm.stateObject[0].id, false); | ||
184 | + } | ||
185 | + | ||
186 | + $timeout(() => { | ||
187 | + $scope.$watchCollection(function () { | ||
188 | + return $state.params; | ||
189 | + }, function () { | ||
190 | + var currentState = $state.params.state; | ||
191 | + vm.stateObject = parseState(currentState); | ||
192 | + }); | ||
193 | + | ||
194 | + $scope.$watch('vm.dashboardCtrl.dashboardCtx.state', function () { | ||
195 | + if (vm.stateObject[0].id !== vm.dashboardCtrl.dashboardCtx.state) { | ||
196 | + stopWatchStateObject(); | ||
197 | + vm.stateObject[0].id = vm.dashboardCtrl.dashboardCtx.state; | ||
198 | + updateLocation(); | ||
199 | + watchStateObject(); | ||
200 | + } | ||
201 | + }); | ||
202 | + watchStateObject(); | ||
190 | }); | 203 | }); |
191 | - watchStateObject(); | ||
192 | } | 204 | } |
193 | 205 | ||
194 | function stopWatchStateObject() { | 206 | function stopWatchStateObject() { |
@@ -17,7 +17,8 @@ | @@ -17,7 +17,8 @@ | ||
17 | import './entity-state-controller.scss'; | 17 | import './entity-state-controller.scss'; |
18 | 18 | ||
19 | /*@ngInject*/ | 19 | /*@ngInject*/ |
20 | -export default function EntityStateController($scope, $location, $state, $stateParams, $q, $translate, utils, types, dashboardUtils, entityService) { | 20 | +export default function EntityStateController($scope, $timeout, $location, $state, $stateParams, |
21 | + $q, $translate, utils, types, dashboardUtils, entityService, preservedState) { | ||
21 | 22 | ||
22 | var vm = this; | 23 | var vm = this; |
23 | 24 | ||
@@ -26,6 +27,7 @@ export default function EntityStateController($scope, $location, $state, $stateP | @@ -26,6 +27,7 @@ export default function EntityStateController($scope, $location, $state, $stateP | ||
26 | vm.openState = openState; | 27 | vm.openState = openState; |
27 | vm.updateState = updateState; | 28 | vm.updateState = updateState; |
28 | vm.resetState = resetState; | 29 | vm.resetState = resetState; |
30 | + vm.getStateObject = getStateObject; | ||
29 | vm.navigatePrevState = navigatePrevState; | 31 | vm.navigatePrevState = navigatePrevState; |
30 | vm.getStateId = getStateId; | 32 | vm.getStateId = getStateId; |
31 | vm.getStateParams = getStateParams; | 33 | vm.getStateParams = getStateParams; |
@@ -84,6 +86,10 @@ export default function EntityStateController($scope, $location, $state, $stateP | @@ -84,6 +86,10 @@ export default function EntityStateController($scope, $location, $state, $stateP | ||
84 | gotoState(rootStateId, true); | 86 | gotoState(rootStateId, true); |
85 | } | 87 | } |
86 | 88 | ||
89 | + function getStateObject() { | ||
90 | + return vm.stateObject; | ||
91 | + } | ||
92 | + | ||
87 | function navigatePrevState(index) { | 93 | function navigatePrevState(index) { |
88 | if (index < vm.stateObject.length-1) { | 94 | if (index < vm.stateObject.length-1) { |
89 | stopWatchStateObject(); | 95 | stopWatchStateObject(); |
@@ -212,41 +218,49 @@ export default function EntityStateController($scope, $location, $state, $stateP | @@ -212,41 +218,49 @@ export default function EntityStateController($scope, $location, $state, $stateP | ||
212 | }); | 218 | }); |
213 | 219 | ||
214 | function init() { | 220 | function init() { |
215 | - var initialState = $stateParams.state; | ||
216 | - vm.stateObject = parseState(initialState); | ||
217 | - vm.selectedStateIndex = vm.stateObject.length-1; | ||
218 | - gotoState(vm.stateObject[vm.stateObject.length-1].id, false); | ||
219 | - | ||
220 | - $scope.$watchCollection(function() { | ||
221 | - return $state.params; | ||
222 | - }, function(){ | ||
223 | - var currentState = $state.params.state; | ||
224 | - vm.stateObject = parseState(currentState); | ||
225 | - }); | 221 | + if (preservedState) { |
222 | + vm.stateObject = preservedState; | ||
223 | + vm.selectedStateIndex = vm.stateObject.length-1; | ||
224 | + gotoState(vm.stateObject[vm.stateObject.length-1].id, true); | ||
225 | + } else { | ||
226 | + var initialState = $stateParams.state; | ||
227 | + vm.stateObject = parseState(initialState); | ||
228 | + vm.selectedStateIndex = vm.stateObject.length-1; | ||
229 | + gotoState(vm.stateObject[vm.stateObject.length-1].id, false); | ||
230 | + } | ||
226 | 231 | ||
227 | - $scope.$watch('vm.dashboardCtrl.dashboardCtx.state', function() { | ||
228 | - if (vm.stateObject[vm.stateObject.length-1].id !== vm.dashboardCtrl.dashboardCtx.state) { | ||
229 | - stopWatchStateObject(); | ||
230 | - vm.stateObject[vm.stateObject.length-1].id = vm.dashboardCtrl.dashboardCtx.state; | ||
231 | - updateLocation(); | ||
232 | - watchStateObject(); | ||
233 | - } | ||
234 | - }); | 232 | + $timeout(() => { |
233 | + $scope.$watchCollection(function () { | ||
234 | + return $state.params; | ||
235 | + }, function () { | ||
236 | + var currentState = $state.params.state; | ||
237 | + vm.stateObject = parseState(currentState); | ||
238 | + }); | ||
235 | 239 | ||
236 | - watchStateObject(); | 240 | + $scope.$watch('vm.dashboardCtrl.dashboardCtx.state', function () { |
241 | + if (vm.stateObject[vm.stateObject.length - 1].id !== vm.dashboardCtrl.dashboardCtx.state) { | ||
242 | + stopWatchStateObject(); | ||
243 | + vm.stateObject[vm.stateObject.length - 1].id = vm.dashboardCtrl.dashboardCtx.state; | ||
244 | + updateLocation(); | ||
245 | + watchStateObject(); | ||
246 | + } | ||
247 | + }); | ||
237 | 248 | ||
238 | - if (vm.dashboardCtrl.isMobile) { | ||
239 | - watchSelectedStateIndex(); | ||
240 | - } | 249 | + watchStateObject(); |
241 | 250 | ||
242 | - $scope.$watch('vm.dashboardCtrl.isMobile', function(newVal, prevVal) { | ||
243 | - if (!angular.equals(newVal, prevVal)) { | ||
244 | - if (vm.dashboardCtrl.isMobile) { | ||
245 | - watchSelectedStateIndex(); | ||
246 | - } else { | ||
247 | - stopWatchSelectedStateIndex(); | ||
248 | - } | 251 | + if (vm.dashboardCtrl.isMobile) { |
252 | + watchSelectedStateIndex(); | ||
249 | } | 253 | } |
254 | + | ||
255 | + $scope.$watch('vm.dashboardCtrl.isMobile', function (newVal, prevVal) { | ||
256 | + if (!angular.equals(newVal, prevVal)) { | ||
257 | + if (vm.dashboardCtrl.isMobile) { | ||
258 | + watchSelectedStateIndex(); | ||
259 | + } else { | ||
260 | + stopWatchSelectedStateIndex(); | ||
261 | + } | ||
262 | + } | ||
263 | + }); | ||
250 | }); | 264 | }); |
251 | 265 | ||
252 | } | 266 | } |
@@ -47,6 +47,13 @@ export default function StatesComponent($compile, $templateCache, $controller, s | @@ -47,6 +47,13 @@ export default function StatesComponent($compile, $templateCache, $controller, s | ||
47 | } | 47 | } |
48 | } | 48 | } |
49 | 49 | ||
50 | + stateController.preserveState = function() { | ||
51 | + if (scope.statesController) { | ||
52 | + var state = scope.statesController.getStateObject(); | ||
53 | + statesControllerService.preserveStateControllerState(scope.statesControllerId, state); | ||
54 | + } | ||
55 | + } | ||
56 | + | ||
50 | stateController.navigatePrevState = function(index) { | 57 | stateController.navigatePrevState = function(index) { |
51 | if (scope.statesController) { | 58 | if (scope.statesController) { |
52 | scope.statesController.navigatePrevState(index); | 59 | scope.statesController.navigatePrevState(index); |
@@ -109,7 +116,12 @@ export default function StatesComponent($compile, $templateCache, $controller, s | @@ -109,7 +116,12 @@ export default function StatesComponent($compile, $templateCache, $controller, s | ||
109 | } | 116 | } |
110 | var template = $templateCache.get(statesControllerInfo.templateUrl); | 117 | var template = $templateCache.get(statesControllerInfo.templateUrl); |
111 | element.html(template); | 118 | element.html(template); |
112 | - var locals = {}; | 119 | + |
120 | + var preservedState = statesControllerService.withdrawStateControllerState(scope.statesControllerId); | ||
121 | + | ||
122 | + var locals = { | ||
123 | + preservedState: preservedState | ||
124 | + }; | ||
113 | angular.extend(locals, {$scope: scope, $element: element}); | 125 | angular.extend(locals, {$scope: scope, $element: element}); |
114 | var controller = $controller(statesControllerInfo.controller, locals, true, 'vm'); | 126 | var controller = $controller(statesControllerInfo.controller, locals, true, 'vm'); |
115 | controller.instance = controller(); | 127 | controller.instance = controller(); |
@@ -40,7 +40,9 @@ export default function StatesControllerService() { | @@ -40,7 +40,9 @@ export default function StatesControllerService() { | ||
40 | var service = { | 40 | var service = { |
41 | registerStatesController: registerStatesController, | 41 | registerStatesController: registerStatesController, |
42 | getStateControllers: getStateControllers, | 42 | getStateControllers: getStateControllers, |
43 | - getStateController: getStateController | 43 | + getStateController: getStateController, |
44 | + preserveStateControllerState: preserveStateControllerState, | ||
45 | + withdrawStateControllerState: withdrawStateControllerState | ||
44 | }; | 46 | }; |
45 | 47 | ||
46 | return service; | 48 | return service; |
@@ -57,4 +59,14 @@ export default function StatesControllerService() { | @@ -57,4 +59,14 @@ export default function StatesControllerService() { | ||
57 | return statesControllers[id]; | 59 | return statesControllers[id]; |
58 | } | 60 | } |
59 | 61 | ||
62 | + function preserveStateControllerState(id, state) { | ||
63 | + statesControllers[id].state = angular.copy(state); | ||
64 | + } | ||
65 | + | ||
66 | + function withdrawStateControllerState(id) { | ||
67 | + var state = statesControllers[id].state; | ||
68 | + statesControllers[id].state = null; | ||
69 | + return state; | ||
70 | + } | ||
71 | + | ||
60 | } | 72 | } |