mirror of
https://github.com/nasa/openmct.git
synced 2025-06-06 01:11:41 +00:00
Merge pull request #946 from nasa/open636
[New Edit Mode] #636 Removed edit concerns from DropGesture
This commit is contained in:
commit
1419ff86e8
@ -26,7 +26,7 @@ define([
|
|||||||
"./src/controllers/ElementsController",
|
"./src/controllers/ElementsController",
|
||||||
"./src/controllers/EditObjectController",
|
"./src/controllers/EditObjectController",
|
||||||
"./src/directives/MCTBeforeUnload",
|
"./src/directives/MCTBeforeUnload",
|
||||||
"./src/actions/LinkAction",
|
"./src/actions/EditAndComposeAction",
|
||||||
"./src/actions/EditAction",
|
"./src/actions/EditAction",
|
||||||
"./src/actions/PropertiesAction",
|
"./src/actions/PropertiesAction",
|
||||||
"./src/actions/RemoveAction",
|
"./src/actions/RemoveAction",
|
||||||
@ -55,7 +55,7 @@ define([
|
|||||||
ElementsController,
|
ElementsController,
|
||||||
EditObjectController,
|
EditObjectController,
|
||||||
MCTBeforeUnload,
|
MCTBeforeUnload,
|
||||||
LinkAction,
|
EditAndComposeAction,
|
||||||
EditAction,
|
EditAction,
|
||||||
PropertiesAction,
|
PropertiesAction,
|
||||||
RemoveAction,
|
RemoveAction,
|
||||||
@ -126,7 +126,7 @@ define([
|
|||||||
"actions": [
|
"actions": [
|
||||||
{
|
{
|
||||||
"key": "compose",
|
"key": "compose",
|
||||||
"implementation": LinkAction
|
"implementation": EditAndComposeAction
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "edit",
|
"key": "edit",
|
||||||
|
@ -31,13 +31,14 @@ define(
|
|||||||
* @memberof platform/commonUI/edit
|
* @memberof platform/commonUI/edit
|
||||||
* @implements {Action}
|
* @implements {Action}
|
||||||
*/
|
*/
|
||||||
function LinkAction(context) {
|
function EditAndComposeAction(context) {
|
||||||
this.domainObject = (context || {}).domainObject;
|
this.domainObject = (context || {}).domainObject;
|
||||||
this.selectedObject = (context || {}).selectedObject;
|
this.selectedObject = (context || {}).selectedObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
LinkAction.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,9 +55,13 @@ define(
|
|||||||
.then(doPersist);
|
.then(doPersist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (editAction) {
|
||||||
|
editAction.perform();
|
||||||
|
}
|
||||||
|
|
||||||
return this.selectedObject && doLink();
|
return this.selectedObject && doLink();
|
||||||
};
|
};
|
||||||
|
|
||||||
return LinkAction;
|
return EditAndComposeAction;
|
||||||
}
|
}
|
||||||
);
|
);
|
@ -81,18 +81,15 @@ 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
|
|
||||||
if (category === 'view-control') {
|
|
||||||
// Restrict 'edit' to cases where there are editable
|
// Restrict 'edit' to cases where there are editable
|
||||||
// views (similarly, restrict 'properties' to when
|
// views (similarly, restrict 'properties' to when
|
||||||
// the converse is true), and where the domain object is not
|
// the converse is true), and where the domain object is not
|
||||||
// already being edited.
|
// already being edited.
|
||||||
if (key === 'edit') {
|
if (key === 'edit') {
|
||||||
return this.countEditableViews(context) > 0 && !isEditing(context);
|
return this.countEditableViews(context) > 0 && !isEditing(context);
|
||||||
} else if (key === 'properties') {
|
} else if (key === 'properties' && category === 'view-control') {
|
||||||
return this.countEditableViews(context) < 1 && !isEditing(context);
|
return this.countEditableViews(context) < 1 && !isEditing(context);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Like all policies, allow by default.
|
// Like all policies, allow by default.
|
||||||
return true;
|
return true;
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
define(
|
define(
|
||||||
["../../src/actions/LinkAction"],
|
["../../src/actions/EditAndComposeAction"],
|
||||||
function (LinkAction) {
|
function (EditAndComposeAction) {
|
||||||
|
|
||||||
describe("The Link action", function () {
|
describe("The Link action", function () {
|
||||||
var mockQ,
|
var mockQ,
|
||||||
@ -31,6 +31,8 @@ define(
|
|||||||
mockContext,
|
mockContext,
|
||||||
mockComposition,
|
mockComposition,
|
||||||
mockPersistence,
|
mockPersistence,
|
||||||
|
mockActionCapability,
|
||||||
|
mockEditAction,
|
||||||
mockType,
|
mockType,
|
||||||
actionContext,
|
actionContext,
|
||||||
model,
|
model,
|
||||||
@ -67,18 +69,23 @@ define(
|
|||||||
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||||
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" ]);
|
mockType = jasmine.createSpyObj("type", [ "hasFeature", "getKey" ]);
|
||||||
|
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);
|
||||||
mockContext.getParent.andReturn(mockParent);
|
mockContext.getParent.andReturn(mockParent);
|
||||||
mockType.hasFeature.andReturn(true);
|
mockType.hasFeature.andReturn(true);
|
||||||
|
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,
|
||||||
persistence: mockPersistence,
|
persistence: mockPersistence,
|
||||||
|
action: mockActionCapability,
|
||||||
type: mockType
|
type: mockType
|
||||||
};
|
};
|
||||||
model = {
|
model = {
|
||||||
@ -90,7 +97,7 @@ define(
|
|||||||
selectedObject: mockDomainObject
|
selectedObject: mockDomainObject
|
||||||
};
|
};
|
||||||
|
|
||||||
action = new LinkAction(actionContext);
|
action = new EditAndComposeAction(actionContext);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -105,6 +112,21 @@ define(
|
|||||||
expect(mockPersistence.persist).toHaveBeenCalled();
|
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("enables edit mode for objects that have an edit action", function () {
|
||||||
|
mockActionCapability.getActions.andReturn([mockEditAction]);
|
||||||
|
action.perform();
|
||||||
|
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);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
@ -54,9 +54,6 @@ define(
|
|||||||
// ...and broadcast the event. This allows specific
|
// ...and broadcast the event. This allows specific
|
||||||
// views to have post-drop behavior which depends on
|
// views to have post-drop behavior which depends on
|
||||||
// drop position.
|
// drop position.
|
||||||
// Also broadcast the editableDomainObject to
|
|
||||||
// avoid race condition against non-editable
|
|
||||||
// version in EditRepresenter
|
|
||||||
scope.$broadcast(
|
scope.$broadcast(
|
||||||
GestureConstants.MCT_DROP_EVENT,
|
GestureConstants.MCT_DROP_EVENT,
|
||||||
id,
|
id,
|
||||||
@ -93,21 +90,13 @@ define(
|
|||||||
|
|
||||||
function drop(e) {
|
function drop(e) {
|
||||||
var event = (e || {}).originalEvent || e,
|
var event = (e || {}).originalEvent || e,
|
||||||
id = event.dataTransfer.getData(GestureConstants.MCT_DRAG_TYPE),
|
id = event.dataTransfer.getData(GestureConstants.MCT_DRAG_TYPE);
|
||||||
domainObjectType = domainObject.getModel().type;
|
|
||||||
|
|
||||||
// Handle the drop; add the dropped identifier to the
|
// Handle the drop; add the dropped identifier to the
|
||||||
// destination domain object's composition, and persist
|
// destination domain object's composition, and persist
|
||||||
// the change.
|
// the change.
|
||||||
if (id) {
|
if (id) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
//Use scope.apply, drop event is outside digest cycle
|
|
||||||
scope.$apply(function () {
|
|
||||||
if (domainObjectType !== 'folder') {
|
|
||||||
domainObject.getCapability('action').perform('edit');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
$q.when(action && action.perform()).then(function () {
|
$q.when(action && action.perform()).then(function () {
|
||||||
broadcastDrop(id, event);
|
broadcastDrop(id, event);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user