mirror of
https://github.com/nasa/openmct.git
synced 2024-12-19 13:17:53 +00:00
[New Edit Mode] #636 Modified EditAndCompose action to rely on a slightly refactored EditActionPolicy to remove folder specific logic
This commit is contained in:
parent
54a0de4a08
commit
601bc03ba2
@ -37,7 +37,8 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
EditAndComposeAction.prototype.perform = function () {
|
EditAndComposeAction.prototype.perform = function () {
|
||||||
var self = this;
|
var self = this,
|
||||||
|
editAction = this.domainObject.getCapability('action').getActions("edit")[0];
|
||||||
|
|
||||||
// Persist changes to the domain object
|
// Persist changes to the domain object
|
||||||
function doPersist() {
|
function doPersist() {
|
||||||
@ -54,8 +55,8 @@ define(
|
|||||||
.then(doPersist);
|
.then(doPersist);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.domainObject.getCapability('type').getKey() !== 'folder') {
|
if (editAction) {
|
||||||
this.domainObject.getCapability('action').perform('edit');
|
editAction.perform();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.selectedObject && doLink();
|
return this.selectedObject && doLink();
|
||||||
|
@ -81,17 +81,14 @@ define(
|
|||||||
var key = action.getMetadata().key,
|
var key = action.getMetadata().key,
|
||||||
category = (context || {}).category;
|
category = (context || {}).category;
|
||||||
|
|
||||||
// Only worry about actions in the view-control category
|
// Restrict 'edit' to cases where there are editable
|
||||||
if (category === 'view-control') {
|
// views (similarly, restrict 'properties' to when
|
||||||
// Restrict 'edit' to cases where there are editable
|
// the converse is true), and where the domain object is not
|
||||||
// views (similarly, restrict 'properties' to when
|
// already being edited.
|
||||||
// the converse is true), and where the domain object is not
|
if (key === 'edit') {
|
||||||
// already being edited.
|
return this.countEditableViews(context) > 0 && !isEditing(context);
|
||||||
if (key === 'edit') {
|
} else if (key === 'properties' && category === 'view-control') {
|
||||||
return this.countEditableViews(context) > 0 && !isEditing(context);
|
return this.countEditableViews(context) < 1 && !isEditing(context);
|
||||||
} else if (key === 'properties') {
|
|
||||||
return this.countEditableViews(context) < 1 && !isEditing(context);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Like all policies, allow by default.
|
// Like all policies, allow by default.
|
||||||
|
@ -32,6 +32,7 @@ define(
|
|||||||
mockComposition,
|
mockComposition,
|
||||||
mockPersistence,
|
mockPersistence,
|
||||||
mockActionCapability,
|
mockActionCapability,
|
||||||
|
mockEditAction,
|
||||||
mockType,
|
mockType,
|
||||||
actionContext,
|
actionContext,
|
||||||
model,
|
model,
|
||||||
@ -69,7 +70,8 @@ define(
|
|||||||
mockComposition = jasmine.createSpyObj("composition", [ "invoke", "add" ]);
|
mockComposition = jasmine.createSpyObj("composition", [ "invoke", "add" ]);
|
||||||
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
|
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
|
||||||
mockType = jasmine.createSpyObj("type", [ "hasFeature", "getKey" ]);
|
mockType = jasmine.createSpyObj("type", [ "hasFeature", "getKey" ]);
|
||||||
mockActionCapability = jasmine.createSpyObj("actionCapability", [ "perform"]);
|
mockActionCapability = jasmine.createSpyObj("actionCapability", [ "getActions"]);
|
||||||
|
mockEditAction = jasmine.createSpyObj("editAction", ["perform"]);
|
||||||
|
|
||||||
mockDomainObject.getId.andReturn("test");
|
mockDomainObject.getId.andReturn("test");
|
||||||
mockDomainObject.getCapability.andReturn(mockContext);
|
mockDomainObject.getCapability.andReturn(mockContext);
|
||||||
@ -78,6 +80,7 @@ define(
|
|||||||
mockType.getKey.andReturn("layout");
|
mockType.getKey.andReturn("layout");
|
||||||
mockComposition.invoke.andReturn(mockPromise(true));
|
mockComposition.invoke.andReturn(mockPromise(true));
|
||||||
mockComposition.add.andReturn(mockPromise(true));
|
mockComposition.add.andReturn(mockPromise(true));
|
||||||
|
mockActionCapability.getActions.andReturn([]);
|
||||||
|
|
||||||
capabilities = {
|
capabilities = {
|
||||||
composition: mockComposition,
|
composition: mockComposition,
|
||||||
@ -109,9 +112,19 @@ define(
|
|||||||
expect(mockPersistence.persist).toHaveBeenCalled();
|
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("enables edit mode", function () {
|
it("enables edit mode for objects that have an edit action", function () {
|
||||||
|
mockActionCapability.getActions.andReturn([mockEditAction]);
|
||||||
action.perform();
|
action.perform();
|
||||||
expect(mockActionCapability.perform).toHaveBeenCalledWith("edit");
|
expect(mockEditAction.perform).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Does not enable edit mode for objects that do not have an" +
|
||||||
|
" edit action", function () {
|
||||||
|
mockActionCapability.getActions.andReturn([]);
|
||||||
|
action.perform();
|
||||||
|
expect(mockEditAction.perform).not.toHaveBeenCalled();
|
||||||
|
expect(mockComposition.add)
|
||||||
|
.toHaveBeenCalledWith(mockDomainObject);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user