mirror of
https://github.com/nasa/openmct.git
synced 2025-05-11 04:52:57 +00:00
[Edit Mode] Fixed issue with save dialog not being displayed for new objects after mutation. Fixes 1080
This commit is contained in:
parent
e0b6986851
commit
3548cde9c4
@ -48,20 +48,34 @@ define(
|
|||||||
*/
|
*/
|
||||||
NavigateAction.prototype.perform = function () {
|
NavigateAction.prototype.perform = function () {
|
||||||
var self = this,
|
var self = this,
|
||||||
navigationAllowed = true;
|
navigateTo = this.domainObject,
|
||||||
|
currentObject = self.navigationService.getNavigation(),
|
||||||
|
editing = currentObject.hasCapability('editor') &&
|
||||||
|
currentObject.getCapability('editor').isEditContextRoot();
|
||||||
|
|
||||||
function allow() {
|
function allow() {
|
||||||
self.policyService.allow("navigation", self.navigationService.getNavigation(), self.domainObject, function (message) {
|
var navigationAllowed = true;
|
||||||
|
self.policyService.allow("navigation", currentObject, navigateTo, function (message) {
|
||||||
navigationAllowed = self.$window.confirm(message + "\r\n\r\n" +
|
navigationAllowed = self.$window.confirm(message + "\r\n\r\n" +
|
||||||
" Are you sure you want to continue?");
|
" Are you sure you want to continue?");
|
||||||
});
|
});
|
||||||
return navigationAllowed;
|
return navigationAllowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set navigation, and wrap like a promise
|
function cancelIfEditing() {
|
||||||
return this.$q.when(
|
return self.$q.when(editing && currentObject.getCapability("editor").cancel());
|
||||||
allow() && this.navigationService.setNavigation(this.domainObject)
|
}
|
||||||
);
|
|
||||||
|
function navigate() {
|
||||||
|
return self.navigationService.setNavigation(navigateTo);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (allow()) {
|
||||||
|
return cancelIfEditing().then(navigate);
|
||||||
|
} else {
|
||||||
|
return this.$q.when(false);
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,7 +32,9 @@ define(
|
|||||||
mockQ,
|
mockQ,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
mockPolicyService,
|
mockPolicyService,
|
||||||
|
mockNavigatedObject,
|
||||||
mockWindow,
|
mockWindow,
|
||||||
|
capabilities,
|
||||||
action;
|
action;
|
||||||
|
|
||||||
function mockPromise(value) {
|
function mockPromise(value) {
|
||||||
@ -44,6 +46,29 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
|
capabilities = {};
|
||||||
|
|
||||||
|
mockQ = { when: mockPromise };
|
||||||
|
mockNavigatedObject = jasmine.createSpyObj(
|
||||||
|
"domainObject",
|
||||||
|
[
|
||||||
|
"getId",
|
||||||
|
"getModel",
|
||||||
|
"hasCapability",
|
||||||
|
"getCapability"
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
capabilities.editor = jasmine.createSpyObj("editorCapability", [
|
||||||
|
"isEditContextRoot",
|
||||||
|
"cancel"
|
||||||
|
]);
|
||||||
|
|
||||||
|
mockNavigatedObject.getCapability.andCallFake(function (capability) {
|
||||||
|
return capabilities[capability];
|
||||||
|
});
|
||||||
|
mockNavigatedObject.hasCapability.andReturn(false);
|
||||||
|
|
||||||
mockNavigationService = jasmine.createSpyObj(
|
mockNavigationService = jasmine.createSpyObj(
|
||||||
"navigationService",
|
"navigationService",
|
||||||
[
|
[
|
||||||
@ -51,11 +76,14 @@ define(
|
|||||||
"getNavigation"
|
"getNavigation"
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
mockNavigationService.getNavigation.andReturn({});
|
mockNavigationService.getNavigation.andReturn(mockNavigatedObject);
|
||||||
mockQ = { when: mockPromise };
|
|
||||||
mockDomainObject = jasmine.createSpyObj(
|
mockDomainObject = jasmine.createSpyObj(
|
||||||
"domainObject",
|
"domainObject",
|
||||||
["getId", "getModel", "getCapability"]
|
[
|
||||||
|
"getId",
|
||||||
|
"getModel"
|
||||||
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
mockPolicyService = jasmine.createSpyObj("policyService",
|
mockPolicyService = jasmine.createSpyObj("policyService",
|
||||||
@ -112,6 +140,21 @@ define(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("in edit more", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
mockNavigatedObject.hasCapability.andCallFake(function (capability) {
|
||||||
|
return capability === "editor";
|
||||||
|
});
|
||||||
|
capabilities.editor.isEditContextRoot.andReturn(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("cancels editing if in edit mode", function () {
|
||||||
|
action.perform();
|
||||||
|
expect(capabilities.editor.cancel)
|
||||||
|
.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it("is only applicable when a domain object is in context", function () {
|
it("is only applicable when a domain object is in context", function () {
|
||||||
expect(NavigateAction.appliesTo({})).toBeFalsy();
|
expect(NavigateAction.appliesTo({})).toBeFalsy();
|
||||||
expect(NavigateAction.appliesTo({
|
expect(NavigateAction.appliesTo({
|
||||||
|
@ -69,18 +69,14 @@ define(
|
|||||||
* Enter edit mode.
|
* Enter edit mode.
|
||||||
*/
|
*/
|
||||||
EditAction.prototype.perform = function () {
|
EditAction.prototype.perform = function () {
|
||||||
var self = this;
|
|
||||||
function cancelEditing() {
|
|
||||||
self.domainObject.getCapability('editor').cancel();
|
|
||||||
self.navigationService.removeListener(cancelEditing);
|
|
||||||
}
|
|
||||||
//If this is not the currently navigated object, then navigate
|
//If this is not the currently navigated object, then navigate
|
||||||
// to it.
|
// to it.
|
||||||
if (this.navigationService.getNavigation() !== this.domainObject) {
|
if (this.navigationService.getNavigation() !== this.domainObject) {
|
||||||
this.navigationService.setNavigation(this.domainObject);
|
this.navigationService.setNavigation(this.domainObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.navigationService.addListener(cancelEditing);
|
//this.navigationService.addListener(cancelEditing);
|
||||||
this.domainObject.useCapability("editor");
|
this.domainObject.useCapability("editor");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ define(
|
|||||||
try {
|
try {
|
||||||
results.push(onCancel());
|
results.push(onCancel());
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$log.error("Error committing transaction.");
|
this.$log.error("Error cancelling transaction.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.$q.all(results).then(function () {
|
return this.$q.all(results).then(function () {
|
||||||
|
@ -98,13 +98,6 @@ define(
|
|||||||
expect(EditAction.appliesTo(actionContext)).toBe(false);
|
expect(EditAction.appliesTo(actionContext)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it ("cancels editing when user navigates away", function () {
|
|
||||||
action.perform();
|
|
||||||
expect(mockNavigationService.addListener).toHaveBeenCalled();
|
|
||||||
mockNavigationService.addListener.mostRecentCall.args[0]();
|
|
||||||
expect(mockEditor.cancel).toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it ("invokes the Edit capability on the object", function () {
|
it ("invokes the Edit capability on the object", function () {
|
||||||
action.perform();
|
action.perform();
|
||||||
expect(mockDomainObject.useCapability).toHaveBeenCalledWith("editor");
|
expect(mockDomainObject.useCapability).toHaveBeenCalledWith("editor");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user