Merge branch 'open-master' into open1256

This commit is contained in:
Victor Woeltjen
2015-06-23 13:14:17 -07:00
46 changed files with 1228 additions and 160 deletions

View File

@@ -93,15 +93,18 @@ define(
function link($scope, element, attrs) {
var activeRepresenters = representers.map(function (Representer) {
return new Representer($scope, element, attrs);
});
return new Representer($scope, element, attrs);
}),
toClear = [], // Properties to clear out of scope on change
counter = 0;
// Populate scope with any capabilities indicated by the
// representation's extension definition
function refreshCapabilities() {
var domainObject = $scope.domainObject,
representation = lookup($scope.key, domainObject),
uses = ((representation || {}).uses || []);
uses = ((representation || {}).uses || []),
myCounter = counter;
if (domainObject) {
// Update model
@@ -115,10 +118,16 @@ define(
" for representation ",
$scope.key
].join(""));
$q.when(
domainObject.useCapability(used)
).then(function (c) {
$scope[used] = c;
// Avoid clobbering capabilities from
// subsequent representations;
// Angular reuses scopes.
if (counter === myCounter) {
$scope[used] = c;
}
});
});
}
@@ -130,8 +139,7 @@ define(
function refresh() {
var domainObject = $scope.domainObject,
representation = lookup($scope.key, domainObject),
uses = ((representation || {}).uses || []),
gestureKeys = ((representation || {}).gestures || []);
uses = ((representation || {}).uses || []);
// Create an empty object named "representation", for this
// representation to store local variables into.
@@ -152,9 +160,19 @@ define(
$log.warn("No representation found for " + $scope.key);
}
// Clear out the scope from the last representation
toClear.forEach(function (property) {
delete $scope[property];
});
// Populate scope with fields associated with the current
// domain object (if one has been passed in)
if (domainObject) {
// Track how many representations we've made in this scope,
// to ensure that the correct representations are matched to
// the correct object/key pairs.
counter += 1;
// Initialize any capabilities
refreshCapabilities();
@@ -168,6 +186,10 @@ define(
activeRepresenters.forEach(function (representer) {
representer.represent(representation, domainObject);
});
// Track which properties we want to clear from scope
// next change object/key pair changes
toClear = uses.concat(['model']);
}
}

View File

@@ -43,7 +43,7 @@ define(
function DropGesture(dndService, $q, element, domainObject) {
var actionCapability = domainObject.getCapability('action'),
action; // Action for the drop, when it occurs
function broadcastDrop(id, event) {
// Find the relevant scope...
var scope = element && element.scope && element.scope(),
@@ -92,17 +92,24 @@ define(
function drop(e) {
var event = (e || {}).originalEvent || e,
id = event.dataTransfer.getData(GestureConstants.MCT_DRAG_TYPE);
// Handle the drop; add the dropped identifier to the
// destination domain object's composition, and persist
// the change.
if (id) {
$q.when(action && action.perform()).then(function (result) {
broadcastDrop(id, event);
});
id = event.dataTransfer.getData(GestureConstants.MCT_DRAG_TYPE),
domainObjectType = domainObject.getModel().type;
// If currently in edit mode allow drag and drop gestures to the
// domain object. An exception to this is folders which have drop
// gestures in browse mode.
if (domainObjectType === 'folder' || domainObject.hasCapability('editor')) {
// Handle the drop; add the dropped identifier to the
// destination domain object's composition, and persist
// the change.
if (id) {
$q.when(action && action.perform()).then(function (result) {
broadcastDrop(id, event);
});
}
}
// TODO: Alert user if drag and drop is not allowed
}
// We can only handle drops if we have access to actions...

View File

@@ -212,6 +212,25 @@ define(
// Should have gotten a warning - that's an unknown key
expect(mockLog.warn).toHaveBeenCalled();
});
it("clears out obsolete peroperties from scope", function () {
mctRepresentation.link(mockScope, mockElement);
mockScope.key = "def";
mockScope.domainObject = mockDomainObject;
mockDomainObject.useCapability.andReturn("some value");
// Trigger the watch
mockScope.$watch.calls[0].args[1]();
expect(mockScope.testCapability).toBeDefined();
// Change the view
mockScope.key = "xyz";
// Trigger the watch again; should clear capability from scope
mockScope.$watch.calls[0].args[1]();
expect(mockScope.testCapability).toBeUndefined();
});
});
}
);

View File

@@ -131,8 +131,11 @@ define(
expect(mockEvent.preventDefault).toHaveBeenCalled();
expect(mockEvent.dataTransfer.dropEffect).toBeDefined();
});
it("invokes compose on drop", function () {
it("invokes compose on drop in edit mode", function () {
// Set the mockDomainObject to have the editor capability
mockDomainObject.hasCapability.andReturn(true);
callbacks.dragover(mockEvent);
expect(mockAction.getActions).toHaveBeenCalledWith({
key: 'compose',
@@ -141,9 +144,43 @@ define(
callbacks.drop(mockEvent);
expect(mockCompose.perform).toHaveBeenCalled();
});
it("does not invoke compose on drop in browse mode for non-folders", function () {
// Set the mockDomainObject to not have the editor capability
mockDomainObject.hasCapability.andReturn(false);
// Set the mockDomainObject to not have a type of folder
mockDomainObject.getModel.andReturn({type: 'notAFolder'});
callbacks.dragover(mockEvent);
expect(mockAction.getActions).toHaveBeenCalledWith({
key: 'compose',
selectedObject: mockDraggedObject
});
callbacks.drop(mockEvent);
expect(mockCompose.perform).not.toHaveBeenCalled();
});
it("invokes compose on drop in browse mode for folders", function () {
// Set the mockDomainObject to not have the editor capability
mockDomainObject.hasCapability.andReturn(false);
// Set the mockDomainObject to have a type of folder
mockDomainObject.getModel.andReturn({type: 'folder'});
it("broadcasts drop position", function () {
callbacks.dragover(mockEvent);
expect(mockAction.getActions).toHaveBeenCalledWith({
key: 'compose',
selectedObject: mockDraggedObject
});
callbacks.drop(mockEvent);
expect(mockCompose.perform).toHaveBeenCalled();
});
it("broadcasts drop position (in edit mode)", function () {
// Set the mockDomainObject to have the editor capability
mockDomainObject.hasCapability.andReturn(true);
testRect.left = 42;
testRect.top = 36;
mockEvent.pageX = 52;