[Mobile] Merge

Merged with master, getting the
RemoveAction changes.
This commit is contained in:
Shivam Dave
2015-08-27 12:15:48 -07:00
3 changed files with 35 additions and 23 deletions

View File

@@ -55,9 +55,7 @@ define(
RemoveAction.prototype.perform = function () { RemoveAction.prototype.perform = function () {
var $q = this.$q, var $q = this.$q,
navigationService = this.navigationService, navigationService = this.navigationService,
domainObject = this.domainObject, domainObject = this.domainObject;
ROOT_ID = "ROOT";
/* /*
* Check whether an object ID matches the ID of the object being * Check whether an object ID matches the ID of the object being
* removed (used to filter a parent's composition to handle the * removed (used to filter a parent's composition to handle the
@@ -84,35 +82,44 @@ define(
return persistence && persistence.persist(); return persistence && persistence.persist();
} }
// Checks current object and ascendants of current /*
// object with object being removed, if the current * Checks current object and ascendants of current
// object or any in the current object's path is being removed, * object with object being removed, if the current
// navigate back to parent of removed object. * object or any in the current object's path is being removed,
* navigate back to parent of removed object.
*/
function checkObjectNavigation(object, parentObject) { function checkObjectNavigation(object, parentObject) {
// Traverse object starts at current location // Traverse object starts at current location
var traverseObject = (navigationService).getNavigation(); var traverseObject = (navigationService).getNavigation();
// Stop at ROOT of folder path // Stop when object is not defined (above ROOT)
while (traverseObject.getId() !== ROOT_ID) { while (traverseObject) {
// If traverse object is object being removed
// navigate to parent of removed object // If object currently traversed to is object being removed
// navigate to parent of current object and then exit loop
if (traverseObject.getId() === object.getId()) { if (traverseObject.getId() === object.getId()) {
navigationService.setNavigation(parentObject); navigationService.setNavigation(parentObject);
return; return;
} }
// Traverses to parent // Traverses to parent of current object, moving
// up the ascendant path
traverseObject = traverseObject.getCapability('context').getParent(); traverseObject = traverseObject.getCapability('context').getParent();
} }
} }
/* /*
* Remove the object from its parent, as identified by its context * Remove the object from its parent, as identified by its context
* capability. * capability. Based on object's location and selected object's location
* user may be navigated to existing parent object
*/ */
function removeFromContext(object) { function removeFromContext(object) {
var contextCapability = object.getCapability('context'), var contextCapability = object.getCapability('context'),
parent = contextCapability.getParent(); parent = contextCapability.getParent();
// If currently within path of removed object(s),
// navigates to existing object up tree
checkObjectNavigation(object, parent); checkObjectNavigation(object, parent);
return $q.when( return $q.when(
parent.useCapability('mutation', doMutate) parent.useCapability('mutation', doMutate)
).then(function () { ).then(function () {

View File

@@ -33,9 +33,11 @@ define(
mockParent, mockParent,
mockChildObject, mockChildObject,
mockGrandchildObject, mockGrandchildObject,
mockRootObject,
mockContext, mockContext,
mockChildContext, mockChildContext,
mockGrandchildContext, mockGrandchildContext,
mockRootContext,
mockMutation, mockMutation,
mockPersistence, mockPersistence,
mockType, mockType,
@@ -67,6 +69,10 @@ define(
"domainObject", "domainObject",
[ "getId", "getCapability" ] [ "getId", "getCapability" ]
); );
mockRootObject = jasmine.createSpyObj(
"domainObject",
[ "getId", "getCapability" ]
);
mockQ = { when: mockPromise }; mockQ = { when: mockPromise };
mockParent = { mockParent = {
getModel: function () { getModel: function () {
@@ -82,6 +88,7 @@ define(
mockContext = jasmine.createSpyObj("context", [ "getParent" ]); mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
mockChildContext = jasmine.createSpyObj("context", [ "getParent" ]); mockChildContext = jasmine.createSpyObj("context", [ "getParent" ]);
mockGrandchildContext = jasmine.createSpyObj("context", [ "getParent" ]); mockGrandchildContext = jasmine.createSpyObj("context", [ "getParent" ]);
mockRootContext = jasmine.createSpyObj("context", [ "getParent" ]);
mockMutation = jasmine.createSpyObj("mutation", [ "invoke" ]); mockMutation = jasmine.createSpyObj("mutation", [ "invoke" ]);
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]); mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
mockType = jasmine.createSpyObj("type", [ "hasFeature" ]); mockType = jasmine.createSpyObj("type", [ "hasFeature" ]);
@@ -155,8 +162,6 @@ define(
}); });
it("removes parent of object currently navigated to", function () { it("removes parent of object currently navigated to", function () {
var mutator, result;
// Navigates to child object // Navigates to child object
mockNavigationService.getNavigation.andReturn(mockChildObject); mockNavigationService.getNavigation.andReturn(mockChildObject);
@@ -187,18 +192,18 @@ define(
// domainObject (grandparent) is set as ROOT, child and grandchild // domainObject (grandparent) is set as ROOT, child and grandchild
// are set objects not being removed // are set objects not being removed
mockDomainObject.getId.andReturn("ROOT"); mockDomainObject.getId.andReturn("test 1");
mockChildObject.getId.andReturn("not test"); mockRootObject.getId.andReturn("ROOT");
mockGrandchildObject.getId.andReturn("not test"); mockChildObject.getId.andReturn("not test 2");
mockGrandchildObject.getId.andReturn("not test 3");
// Sets context for the grandchild, child, and domainObject // Sets context for the grandchild, child, and domainObject
mockDomainObject.getCapability.andReturn(mockContext); mockRootObject.getCapability.andReturn(mockRootContext);
mockChildObject.getCapability.andReturn(mockChildContext); mockChildObject.getCapability.andReturn(mockChildContext);
mockGrandchildObject.getCapability.andReturn(mockGrandchildContext); mockGrandchildObject.getCapability.andReturn(mockGrandchildContext);
// Parents of grandchild, child, and domainObject are set // Parents of grandchild and child are set
mockContext.getParent.andReturn(mockParent); mockChildContext.getParent.andReturn(mockRootObject);
mockChildContext.getParent.andReturn(mockDomainObject);
mockGrandchildContext.getParent.andReturn(mockChildObject); mockGrandchildContext.getParent.andReturn(mockChildObject);
mockType.hasFeature.andReturn(true); mockType.hasFeature.andReturn(true);

View File

@@ -23,7 +23,7 @@
}, },
{ {
"key": "ELASTIC_ROOT", "key": "ELASTIC_ROOT",
"value": "/elastic", "value": "http://localhost:9200",
"priority": "fallback" "priority": "fallback"
}, },
{ {