[Time Conductor] Prevent route change when time conductor values change (#1342)
* [Time Conductor] Prevent route change on setting search parameters. fixes #1341 * [Inspector] Fixed incorrect listener deregistration which was causing errors on scope destruction * Bare route is redirect to browse * [Browse] handle routing without breaking $route Manage route transitions such that route changes are properly prevented and navigation events occur while still updating the url. Resolves a number of issues where path and search updates had to be supported in a very hacky manner. https://github.com/nasa/openmct/pull/1342 * [URL] Set search without hacks Changes in previous commit allow the search parameters to be modified without accidentally triggering a page reload. https://github.com/nasa/openmct/pull/1342 * [Views] Update on location changes If the user has a bookmark or tries to change the current view of an object by specifying view=someView as a search parameter, the change would not previously take effect. This resolves that bug. https://github.com/nasa/openmct/pull/1342 * [TC] Set query params to undefined Instead of setting params to null, which would eventually result in those parameters equaling undefined, set them to undefined to skip the extra step. https://github.com/nasa/openmct/pull/1342 * [Instantiate] Instantiate objects with context Add context to instantiate objects so that they can be navigated to for editing. https://github.com/nasa/openmct/pull/1342 * [Tests] Update specs Update specs to match new expectations. * [Style] Fix style * [TC] Remove unused dependency Remove $route dependency from time conductor controller as it was not being used. Resolves review comments. https://github.com/nasa/openmct/pull/1342#pullrequestreview-11449260
This commit is contained in:
@@ -96,6 +96,19 @@ define(
|
||||
this.conductor.on('timeSystem', this.changeTimeSystem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used as a url search param setter in place of $location.search(...)
|
||||
*
|
||||
* Invokes $location.search(...) but prevents an Angular route
|
||||
* change from occurring as a consequence which will cause
|
||||
* controllers to reload and strangeness to ensue.
|
||||
*
|
||||
* @private
|
||||
*/
|
||||
TimeConductorController.prototype.setParam = function (name, value) {
|
||||
this.$location.search(name, value);
|
||||
};
|
||||
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
@@ -185,8 +198,8 @@ define(
|
||||
this.setFormFromBounds(bounds);
|
||||
if (this.conductorViewService.mode() === 'fixed') {
|
||||
//Set bounds in URL on change
|
||||
this.$location.search(SEARCH.START_BOUND, bounds.start);
|
||||
this.$location.search(SEARCH.END_BOUND, bounds.end);
|
||||
this.setParam(SEARCH.START_BOUND, bounds.start);
|
||||
this.setParam(SEARCH.END_BOUND, bounds.end);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -299,8 +312,8 @@ define(
|
||||
this.conductorViewService.deltas(deltas);
|
||||
|
||||
//Set Deltas in URL on change
|
||||
this.$location.search(SEARCH.START_DELTA, deltas.start);
|
||||
this.$location.search(SEARCH.END_DELTA, deltas.end);
|
||||
this.setParam(SEARCH.START_DELTA, deltas.start);
|
||||
this.setParam(SEARCH.END_DELTA, deltas.end);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -315,23 +328,23 @@ define(
|
||||
*/
|
||||
TimeConductorController.prototype.setMode = function (newModeKey, oldModeKey) {
|
||||
//Set mode in URL on change
|
||||
this.$location.search(SEARCH.MODE, newModeKey);
|
||||
this.setParam(SEARCH.MODE, newModeKey);
|
||||
|
||||
if (newModeKey !== oldModeKey) {
|
||||
this.conductorViewService.mode(newModeKey);
|
||||
this.setFormFromMode(newModeKey);
|
||||
|
||||
if (newModeKey === "fixed") {
|
||||
this.$location.search(SEARCH.START_DELTA, null);
|
||||
this.$location.search(SEARCH.END_DELTA, null);
|
||||
this.setParam(SEARCH.START_DELTA, undefined);
|
||||
this.setParam(SEARCH.END_DELTA, undefined);
|
||||
} else {
|
||||
this.$location.search(SEARCH.START_BOUND, null);
|
||||
this.$location.search(SEARCH.END_BOUND, null);
|
||||
this.setParam(SEARCH.START_BOUND, undefined);
|
||||
this.setParam(SEARCH.END_BOUND, undefined);
|
||||
|
||||
var deltas = this.conductorViewService.deltas();
|
||||
if (deltas) {
|
||||
this.$location.search(SEARCH.START_DELTA, deltas.start);
|
||||
this.$location.search(SEARCH.END_DELTA, deltas.end);
|
||||
this.setParam(SEARCH.START_DELTA, deltas.start);
|
||||
this.setParam(SEARCH.END_DELTA, deltas.end);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -363,7 +376,7 @@ define(
|
||||
*/
|
||||
TimeConductorController.prototype.changeTimeSystem = function (newTimeSystem) {
|
||||
//Set time system in URL on change
|
||||
this.$location.search(SEARCH.TIME_SYSTEM, newTimeSystem.metadata.key);
|
||||
this.setParam(SEARCH.TIME_SYSTEM, newTimeSystem.metadata.key);
|
||||
|
||||
if (newTimeSystem && (newTimeSystem !== this.$scope.timeSystemModel.selected)) {
|
||||
this.setFormFromTimeSystem(newTimeSystem);
|
||||
|
||||
@@ -37,6 +37,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
"$watch",
|
||||
"$on"
|
||||
]);
|
||||
|
||||
mockWindow = jasmine.createSpyObj("$window", ["requestAnimationFrame"]);
|
||||
mockTimeConductor = jasmine.createSpyObj(
|
||||
"TimeConductor",
|
||||
@@ -258,9 +259,7 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
return mockTimeSystem;
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("sets the mode on scope", function () {
|
||||
controller = new TimeConductorController(
|
||||
mockScope,
|
||||
mockWindow,
|
||||
@@ -270,7 +269,9 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
mockTimeSystemConstructors,
|
||||
mockFormatService
|
||||
);
|
||||
});
|
||||
|
||||
it("sets the mode on scope", function () {
|
||||
mockConductorViewService.availableTimeSystems.andReturn(mockTimeSystems);
|
||||
controller.setMode(mode);
|
||||
|
||||
@@ -278,16 +279,6 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
});
|
||||
|
||||
it("sets available time systems on scope when mode changes", function () {
|
||||
controller = new TimeConductorController(
|
||||
mockScope,
|
||||
mockWindow,
|
||||
mockLocation,
|
||||
{conductor: mockTimeConductor},
|
||||
mockConductorViewService,
|
||||
mockTimeSystemConstructors,
|
||||
mockFormatService
|
||||
);
|
||||
|
||||
mockConductorViewService.availableTimeSystems.andReturn(mockTimeSystems);
|
||||
controller.setMode(mode);
|
||||
|
||||
@@ -303,16 +294,6 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
end: 10
|
||||
};
|
||||
|
||||
controller = new TimeConductorController(
|
||||
mockScope,
|
||||
mockWindow,
|
||||
mockLocation,
|
||||
{conductor: mockTimeConductor},
|
||||
mockConductorViewService,
|
||||
mockTimeSystemConstructors,
|
||||
mockFormatService
|
||||
);
|
||||
|
||||
controller.setBounds(formModel);
|
||||
expect(mockTimeConductor.bounds).toHaveBeenCalledWith(formModel);
|
||||
});
|
||||
@@ -327,16 +308,6 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
endDelta: deltas.end
|
||||
};
|
||||
|
||||
controller = new TimeConductorController(
|
||||
mockScope,
|
||||
mockWindow,
|
||||
mockLocation,
|
||||
{conductor: mockTimeConductor},
|
||||
mockConductorViewService,
|
||||
mockTimeSystemConstructors,
|
||||
mockFormatService
|
||||
);
|
||||
|
||||
controller.setDeltas(formModel);
|
||||
expect(mockConductorViewService.deltas).toHaveBeenCalledWith(deltas);
|
||||
});
|
||||
@@ -347,32 +318,17 @@ define(['./TimeConductorController'], function (TimeConductorController) {
|
||||
end: 6
|
||||
};
|
||||
var timeSystem = {
|
||||
metadata: {
|
||||
key: 'testTimeSystem'
|
||||
},
|
||||
defaults: function () {
|
||||
return {
|
||||
bounds: defaultBounds
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
mockTimeSystems = [
|
||||
// Wrap as constructor function
|
||||
function () {
|
||||
return timeSystem;
|
||||
metadata: {
|
||||
key: 'testTimeSystem'
|
||||
},
|
||||
defaults: function () {
|
||||
return {
|
||||
bounds: defaultBounds
|
||||
};
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
controller = new TimeConductorController(
|
||||
mockScope,
|
||||
mockWindow,
|
||||
mockLocation,
|
||||
{conductor: mockTimeConductor},
|
||||
mockConductorViewService,
|
||||
mockTimeSystems,
|
||||
mockFormatService
|
||||
);
|
||||
controller.timeSystems = [timeSystem];
|
||||
|
||||
controller.selectTimeSystemByKey('testTimeSystem');
|
||||
expect(mockTimeConductor.timeSystem).toHaveBeenCalledWith(timeSystem, defaultBounds);
|
||||
|
||||
Reference in New Issue
Block a user