mirror of
https://github.com/nasa/openmct.git
synced 2024-12-22 06:27:48 +00:00
[Edit Mode] #794 Modified policy to show remove action in context for non-editable domain object types
This commit is contained in:
parent
8b7af43d6c
commit
06436c488a
@ -207,7 +207,7 @@ define([
|
|||||||
{
|
{
|
||||||
"category": "action",
|
"category": "action",
|
||||||
"implementation": EditContextualActionPolicy,
|
"implementation": EditContextualActionPolicy,
|
||||||
"depends": ["navigationService"]
|
"depends": ["navigationService", "editModeBlacklist", "nonEditContextBlacklist"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"category": "action",
|
"category": "action",
|
||||||
@ -274,6 +274,16 @@ define([
|
|||||||
{
|
{
|
||||||
"implementation": EditToolbarRepresenter
|
"implementation": EditToolbarRepresenter
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"constants": [
|
||||||
|
{
|
||||||
|
"key":"editModeBlacklist",
|
||||||
|
"value": ["copy", "follow", "window", "link", "locate"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "nonEditContextBlacklist",
|
||||||
|
"value": ["copy", "follow", "properties", "move", "link", "remove", "locate"]
|
||||||
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -29,17 +29,27 @@ define(
|
|||||||
/**
|
/**
|
||||||
* Policy controlling whether the context menu is visible when
|
* Policy controlling whether the context menu is visible when
|
||||||
* objects are being edited
|
* objects are being edited
|
||||||
* @memberof platform/commonUI/edit
|
* @param navigationService
|
||||||
|
* @param editModeBlacklist A blacklist of actions disallowed from
|
||||||
|
* context menu when navigated object is being edited
|
||||||
|
* @param nonEditContextBlacklist A blacklist of actions disallowed
|
||||||
|
* from context menu of non-editable objects, when navigated object
|
||||||
|
* is being edited
|
||||||
* @constructor
|
* @constructor
|
||||||
* @implements {Policy.<Action, ActionContext>}
|
|
||||||
*/
|
*/
|
||||||
function EditContextualActionPolicy(navigationService) {
|
function EditContextualActionPolicy(navigationService, editModeBlacklist, nonEditContextBlacklist) {
|
||||||
this.navigationService = navigationService;
|
this.navigationService = navigationService;
|
||||||
|
|
||||||
//The list of objects disallowed on target object when in edit mode
|
//The list of objects disallowed on target object when in edit mode
|
||||||
this.editBlacklist = ["copy", "follow", "window"];
|
this.editModeBlacklist = editModeBlacklist;
|
||||||
//The list of objects disallowed on target object that is not in
|
//The list of objects disallowed on target object that is not in
|
||||||
// edit mode (ie. the context menu in the tree on the LHS).
|
// edit mode (ie. the context menu in the tree on the LHS).
|
||||||
this.nonEditBlacklist = ["copy", "follow", "properties", "move", "link", "remove"];
|
this.nonEditContextBlacklist = nonEditContextBlacklist;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isParentEditable(object) {
|
||||||
|
var parent = object.hasCapability("context") && object.getCapability("context").getParent();
|
||||||
|
return !!parent && parent.hasCapability("editor");
|
||||||
}
|
}
|
||||||
|
|
||||||
EditContextualActionPolicy.prototype.allow = function (action, context) {
|
EditContextualActionPolicy.prototype.allow = function (action, context) {
|
||||||
@ -48,11 +58,11 @@ define(
|
|||||||
actionMetadata = action.getMetadata ? action.getMetadata() : {};
|
actionMetadata = action.getMetadata ? action.getMetadata() : {};
|
||||||
|
|
||||||
if (navigatedObject.hasCapability('editor')) {
|
if (navigatedObject.hasCapability('editor')) {
|
||||||
if (!selectedObject.hasCapability('editor')){
|
if (selectedObject.hasCapability('editor') || isParentEditable(selectedObject)){
|
||||||
//Target is in the context menu
|
return this.editModeBlacklist.indexOf(actionMetadata.key) === -1;
|
||||||
return this.nonEditBlacklist.indexOf(actionMetadata.key) === -1;
|
|
||||||
} else {
|
} else {
|
||||||
return this.editBlacklist.indexOf(actionMetadata.key) === -1;
|
//Target is in the context menu
|
||||||
|
return this.nonEditContextBlacklist.indexOf(actionMetadata.key) === -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return true;
|
return true;
|
||||||
|
@ -33,13 +33,15 @@ define(
|
|||||||
context,
|
context,
|
||||||
navigatedObject,
|
navigatedObject,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
metadata;
|
metadata,
|
||||||
|
editModeBlacklist = ["copy", "follow", "window", "link", "locate"],
|
||||||
|
nonEditContextBlacklist = ["copy", "follow", "properties", "move", "link", "remove", "locate"];
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
navigatedObject = jasmine.createSpyObj("navigatedObject", ["hasCapability"]);
|
navigatedObject = jasmine.createSpyObj("navigatedObject", ["hasCapability"]);
|
||||||
navigatedObject.hasCapability.andReturn(false);
|
navigatedObject.hasCapability.andReturn(false);
|
||||||
|
|
||||||
mockDomainObject = jasmine.createSpyObj("domainObject", ["hasCapability"]);
|
mockDomainObject = jasmine.createSpyObj("domainObject", ["hasCapability", "getCapability"]);
|
||||||
mockDomainObject.hasCapability.andReturn(false);
|
mockDomainObject.hasCapability.andReturn(false);
|
||||||
|
|
||||||
navigationService = jasmine.createSpyObj("navigationService", ["getNavigation"]);
|
navigationService = jasmine.createSpyObj("navigationService", ["getNavigation"]);
|
||||||
@ -51,7 +53,7 @@ define(
|
|||||||
|
|
||||||
context = {domainObject: mockDomainObject};
|
context = {domainObject: mockDomainObject};
|
||||||
|
|
||||||
policy = new EditContextualActionPolicy(navigationService);
|
policy = new EditContextualActionPolicy(navigationService, editModeBlacklist, nonEditContextBlacklist);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Allows all actions when navigated object not in edit mode', function() {
|
it('Allows all actions when navigated object not in edit mode', function() {
|
||||||
@ -65,6 +67,28 @@ define(
|
|||||||
expect(policy.allow(mockAction, context)).toBe(true);
|
expect(policy.allow(mockAction, context)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Allows "remove" action when navigated object in edit mode,' +
|
||||||
|
' and selected object not editable, but its parent is.',
|
||||||
|
function() {
|
||||||
|
var mockParent = jasmine.createSpyObj("parentObject", ["hasCapability"]),
|
||||||
|
mockContextCapability = jasmine.createSpyObj("contextCapability", ["getParent"]);
|
||||||
|
|
||||||
|
mockParent.hasCapability.andReturn(true);
|
||||||
|
mockContextCapability.getParent.andReturn(mockParent);
|
||||||
|
navigatedObject.hasCapability.andReturn(true);
|
||||||
|
|
||||||
|
mockDomainObject.getCapability.andReturn(mockContextCapability);
|
||||||
|
mockDomainObject.hasCapability.andCallFake(function (capability) {
|
||||||
|
switch (capability) {
|
||||||
|
case "editor": return false;
|
||||||
|
case "context": return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
metadata.key = "remove";
|
||||||
|
|
||||||
|
expect(policy.allow(mockAction, context)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it('Disallows "move" action when navigated object in edit mode,' +
|
it('Disallows "move" action when navigated object in edit mode,' +
|
||||||
' but selected object not in edit mode ', function() {
|
' but selected object not in edit mode ', function() {
|
||||||
navigatedObject.hasCapability.andReturn(true);
|
navigatedObject.hasCapability.andReturn(true);
|
||||||
|
Loading…
Reference in New Issue
Block a user