From cf9eb3f602dfef420235986583dcbac52034b485 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 12 May 2016 16:05:27 -0700 Subject: [PATCH] Resolved Merge conflicts, removed previously deleted files --- platform/commonUI/edit/bundle.js | 6 +- .../commonUI/edit/src/actions/CancelAction.js | 6 +- .../commonUI/edit/src/actions/EditAction.js | 4 +- .../commonUI/edit/src/actions/SaveAction.js | 4 +- .../capabilities/EditableActionCapability.js | 55 ------ .../EditableCompositionCapability.js | 58 ------ .../capabilities/EditableContextCapability.js | 76 -------- .../EditableInstantiationCapability.js | 58 ------ .../capabilities/EditableLookupCapability.js | 123 ------------ .../EditablePersistenceCapability.js | 66 ------- .../EditableRelationshipCapability.js | 58 ------ .../edit/src/capabilities/EditorCapability.js | 14 -- .../src/capabilities/TransactionDecorator.js | 15 -- .../TransactionalPersistenceCapability.js | 2 +- .../edit/src/objects/EditableDomainObject.js | 130 ------------- .../src/objects/EditableDomainObjectCache.js | 170 ----------------- .../edit/src/objects/EditableModelCache.js | 60 ------ .../edit/src/services/TransactionService.js | 11 ++ .../EditableCompositionCapabilitySpec.js | 73 -------- .../EditableContextCapabilitySpec.js | 87 --------- .../EditableLookupCapabilitySpec.js | 144 -------------- .../EditablePersistenceCapabilitySpec.js | 94 ---------- .../EditableRelationshipCapabilitySpec.js | 73 -------- .../objects/EditableDomainObjectCacheSpec.js | 177 ------------------ .../test/objects/EditableDomainObjectSpec.js | 35 ---- .../test/objects/EditableModelCacheSpec.js | 79 -------- .../swimlane/TimelineSwimlaneDropHandler.js | 14 +- 27 files changed, 28 insertions(+), 1664 deletions(-) delete mode 100644 platform/commonUI/edit/src/capabilities/EditableActionCapability.js delete mode 100644 platform/commonUI/edit/src/capabilities/EditableCompositionCapability.js delete mode 100644 platform/commonUI/edit/src/capabilities/EditableContextCapability.js delete mode 100644 platform/commonUI/edit/src/capabilities/EditableInstantiationCapability.js delete mode 100644 platform/commonUI/edit/src/capabilities/EditableLookupCapability.js delete mode 100644 platform/commonUI/edit/src/capabilities/EditablePersistenceCapability.js delete mode 100644 platform/commonUI/edit/src/capabilities/EditableRelationshipCapability.js delete mode 100644 platform/commonUI/edit/src/objects/EditableDomainObject.js delete mode 100644 platform/commonUI/edit/src/objects/EditableDomainObjectCache.js delete mode 100644 platform/commonUI/edit/src/objects/EditableModelCache.js delete mode 100644 platform/commonUI/edit/test/capabilities/EditableCompositionCapabilitySpec.js delete mode 100644 platform/commonUI/edit/test/capabilities/EditableContextCapabilitySpec.js delete mode 100644 platform/commonUI/edit/test/capabilities/EditableLookupCapabilitySpec.js delete mode 100644 platform/commonUI/edit/test/capabilities/EditablePersistenceCapabilitySpec.js delete mode 100644 platform/commonUI/edit/test/capabilities/EditableRelationshipCapabilitySpec.js delete mode 100644 platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js delete mode 100644 platform/commonUI/edit/test/objects/EditableDomainObjectSpec.js delete mode 100644 platform/commonUI/edit/test/objects/EditableModelCacheSpec.js diff --git a/platform/commonUI/edit/bundle.js b/platform/commonUI/edit/bundle.js index b710952ec2..35818bd477 100644 --- a/platform/commonUI/edit/bundle.js +++ b/platform/commonUI/edit/bundle.js @@ -199,11 +199,7 @@ define([ "implementation": CancelAction, "name": "Cancel", "description": "Discard changes made to these objects.", - "depends": [ - "$injector", - "navigationService", - "$window" - ] + "depends": [] } ], "policies": [ diff --git a/platform/commonUI/edit/src/actions/CancelAction.js b/platform/commonUI/edit/src/actions/CancelAction.js index 937b339085..550516360a 100644 --- a/platform/commonUI/edit/src/actions/CancelAction.js +++ b/platform/commonUI/edit/src/actions/CancelAction.js @@ -31,10 +31,8 @@ define( * @memberof platform/commonUI/edit * @implements {Action} */ - function CancelAction($injector, navigationService, context) { + function CancelAction(context) { this.domainObject = context.domainObject; - this.navigationService = navigationService; - this.objectService = $injector.get('objectService'); } /** @@ -66,7 +64,7 @@ define( CancelAction.appliesTo = function (context) { var domainObject = (context || {}).domainObject; return domainObject !== undefined && - domainObject.hasCapability("editor"); + domainObject.getCapability("status").get("editing"); }; return CancelAction; diff --git a/platform/commonUI/edit/src/actions/EditAction.js b/platform/commonUI/edit/src/actions/EditAction.js index 068acfa6b7..5931a02a52 100644 --- a/platform/commonUI/edit/src/actions/EditAction.js +++ b/platform/commonUI/edit/src/actions/EditAction.js @@ -24,8 +24,8 @@ * Module defining EditAction. Created by vwoeltje on 11/14/14. */ define( - ['../objects/EditableDomainObject'], - function (EditableDomainObject) { + [], + function () { // A no-op action to return in the event that the action cannot // be completed. diff --git a/platform/commonUI/edit/src/actions/SaveAction.js b/platform/commonUI/edit/src/actions/SaveAction.js index 3c5bb86e77..cf8675682e 100644 --- a/platform/commonUI/edit/src/actions/SaveAction.js +++ b/platform/commonUI/edit/src/actions/SaveAction.js @@ -85,8 +85,8 @@ define( SaveAction.appliesTo = function (context) { var domainObject = (context || {}).domainObject; return domainObject !== undefined && - domainObject.hasCapability("editor") && - domainObject.getModel().persisted !== undefined; + domainObject.getModel().persisted !== undefined && + domainObject.getCapability("status").get("editing"); }; return SaveAction; diff --git a/platform/commonUI/edit/src/capabilities/EditableActionCapability.js b/platform/commonUI/edit/src/capabilities/EditableActionCapability.js deleted file mode 100644 index bdfa4d3f59..0000000000 --- a/platform/commonUI/edit/src/capabilities/EditableActionCapability.js +++ /dev/null @@ -1,55 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - - -define( - function () { - var DISALLOWED_ACTIONS = ["move", "copy", "link", "window", "follow"]; - /** - * Editable Action Capability. Overrides the action capability - * normally exhibited by a domain object and filters out certain - * actions not applicable when an object is in edit mode. - * - * Meant specifically for use by EditableDomainObject and the - * associated cache; the constructor signature is particular - * to a pattern used there and may contain unused arguments. - * @constructor - * @memberof platform/commonUI/edit - * @implements {PersistenceCapability} - */ - function EditableActionCapability( - actionCapability - ) { - var action = Object.create(actionCapability); - - action.getActions = function(domainObject) { - return actionCapability.getActions(domainObject).filter(function(action){ - return DISALLOWED_ACTIONS.indexOf(action.getMetadata().key) === -1; - }); - }; - - return action; - } - - return EditableActionCapability; - } -); diff --git a/platform/commonUI/edit/src/capabilities/EditableCompositionCapability.js b/platform/commonUI/edit/src/capabilities/EditableCompositionCapability.js deleted file mode 100644 index 343c6a03a2..0000000000 --- a/platform/commonUI/edit/src/capabilities/EditableCompositionCapability.js +++ /dev/null @@ -1,58 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - - -define( - ['./EditableLookupCapability'], - function (EditableLookupCapability) { - - /** - * Wrapper for the "composition" capability; - * ensures that any domain objects reachable in Edit mode - * are also wrapped as EditableDomainObjects. - * - * Meant specifically for use by EditableDomainObject and the - * associated cache; the constructor signature is particular - * to a pattern used there and may contain unused arguments. - * @constructor - * @memberof platform/commonUI/edit - * @implements {CompositionCapability} - */ - return function EditableCompositionCapability( - contextCapability, - editableObject, - domainObject, - cache - ) { - // This is a "lookup" style capability (it looks up other - // domain objects), but we do not want to return the same - // specific value every time (composition may change) - return new EditableLookupCapability( - contextCapability, - editableObject, - domainObject, - cache, - false // Not idempotent - ); - }; - } -); diff --git a/platform/commonUI/edit/src/capabilities/EditableContextCapability.js b/platform/commonUI/edit/src/capabilities/EditableContextCapability.js deleted file mode 100644 index d20971fb04..0000000000 --- a/platform/commonUI/edit/src/capabilities/EditableContextCapability.js +++ /dev/null @@ -1,76 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - - -define( - ['./EditableLookupCapability'], - function (EditableLookupCapability) { - - /** - * Wrapper for the "context" capability; - * ensures that any domain objects reachable in Edit mode - * are also wrapped as EditableDomainObjects. - * - * Meant specifically for use by EditableDomainObject and the - * associated cache; the constructor signature is particular - * to a pattern used there and may contain unused arguments. - * @constructor - * @memberof platform/commonUI/edit - * @implements {ContextCapability} - */ - return function EditableContextCapability( - contextCapability, - editableObject, - domainObject, - cache - ) { - // This is a "lookup" style capability (it looks up other - // domain objects), and it should be idempotent - var capability = new EditableLookupCapability( - contextCapability, - editableObject, - domainObject, - cache, - true // Idempotent - ), - // Track the real root object for the Elements pane - trueRoot = capability.getRoot(); - - // Provide access to the real root, for the Elements pane. - capability.getTrueRoot = function () { - return trueRoot; - }; - - // Hide ancestry after the root of this subgraph - if (cache.isRoot(domainObject)) { - capability.getRoot = function () { - return editableObject; - }; - capability.getPath = function () { - return [editableObject]; - }; - } - - return capability; - }; - } -); diff --git a/platform/commonUI/edit/src/capabilities/EditableInstantiationCapability.js b/platform/commonUI/edit/src/capabilities/EditableInstantiationCapability.js deleted file mode 100644 index 4376a9310e..0000000000 --- a/platform/commonUI/edit/src/capabilities/EditableInstantiationCapability.js +++ /dev/null @@ -1,58 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - - -define( - ['./EditableLookupCapability'], - function (EditableLookupCapability) { - - /** - * Wrapper for the "instantiation" capability; - * ensures that any domain objects instantiated in Edit mode - * are also wrapped as EditableDomainObjects. - * - * Meant specifically for use by EditableDomainObject and the - * associated cache; the constructor signature is particular - * to a pattern used there and may contain unused arguments. - * @constructor - * @memberof platform/commonUI/edit - * @implements {CompositionCapability} - */ - return function EditableInstantiationCapability( - contextCapability, - editableObject, - domainObject, - cache - ) { - // This is a "lookup" style capability (it looks up other - // domain objects), but we do not want to return the same - // specific value every time (composition may change) - return new EditableLookupCapability( - contextCapability, - editableObject, - domainObject, - cache, - false // Not idempotent - ); - }; - } -); diff --git a/platform/commonUI/edit/src/capabilities/EditableLookupCapability.js b/platform/commonUI/edit/src/capabilities/EditableLookupCapability.js deleted file mode 100644 index 0abde97c5a..0000000000 --- a/platform/commonUI/edit/src/capabilities/EditableLookupCapability.js +++ /dev/null @@ -1,123 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - - -define( - [], - function () { - /*jshint forin:false */ - /** - * Wrapper for both "context" and "composition" capabilities; - * ensures that any domain objects reachable in Edit mode - * are also wrapped as EditableDomainObjects. - * - * Meant specifically for use by EditableDomainObject and the - * associated cache; the constructor signature is particular - * to a pattern used there and may contain unused arguments. - * @constructor - * @memberof platform/commonUI/edit - */ - return function EditableLookupCapability( - contextCapability, - editableObject, - domainObject, - cache, - idempotent - ) { - var capability = Object.create(contextCapability), - method; - - // Check for domain object interface. If something has these - // three methods, we assume it's a domain object. - function isDomainObject(obj) { - return obj !== undefined && - typeof obj.getId === 'function' && - typeof obj.getModel === 'function' && - typeof obj.getCapability === 'function'; - } - - // Check an object returned by the wrapped capability; if it - // is a domain object, we want to make it editable and/or get - // it from the cache of editable domain objects. This will - // prevent changes made in edit mode from modifying the actual - // underlying domain object. - function makeEditableObject(obj) { - return isDomainObject(obj) ? - cache.getEditableObject(obj) : - obj; - } - - // Wrap a returned value (see above); if it's an array, wrap - // all elements. - function makeEditable(returnValue) { - return Array.isArray(returnValue) ? - returnValue.map(makeEditableObject) : - makeEditableObject(returnValue); - } - - // Wrap a returned value (see above); if it's a promise, wrap - // the resolved value. - function wrapResult(result) { - return (result && result.then) ? // promise-like - result.then(makeEditable) : - makeEditable(result); - } - - // Return a wrapped version of a function, which ensures - // all results are editable domain objects. - function wrapFunction(fn) { - return function () { - return wrapResult(contextCapability[fn].apply( - capability, - arguments - )); - }; - } - - // Wrap a method such that it only delegates once. - function oneTimeFunction(fn) { - return function () { - var result = wrapFunction(fn).apply(this, arguments); - capability[fn] = function () { - return result; - }; - return result; - }; - } - - // Wrap a method of this capability - function wrapMethod(fn) { - if (typeof capability[fn] === 'function') { - capability[fn] = - (idempotent ? oneTimeFunction : wrapFunction)(fn); - } - } - - // Wrap all methods; return only editable domain objects. - for (method in contextCapability) { - wrapMethod(method); - } - - return capability; - }; - } -); diff --git a/platform/commonUI/edit/src/capabilities/EditablePersistenceCapability.js b/platform/commonUI/edit/src/capabilities/EditablePersistenceCapability.js deleted file mode 100644 index e6c32e2bf4..0000000000 --- a/platform/commonUI/edit/src/capabilities/EditablePersistenceCapability.js +++ /dev/null @@ -1,66 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - - -define( - function () { - - /** - * Editable Persistence Capability. Overrides the persistence capability - * normally exhibited by a domain object to ensure that changes made - * during edit mode are not immediately stored to the database or other - * backing storage. - * - * Meant specifically for use by EditableDomainObject and the - * associated cache; the constructor signature is particular - * to a pattern used there and may contain unused arguments. - * @constructor - * @memberof platform/commonUI/edit - * @implements {PersistenceCapability} - */ - function EditablePersistenceCapability( - persistenceCapability, - editableObject, - domainObject, - cache - ) { - var persistence = Object.create(persistenceCapability); - - // Simply trigger refresh of in-view objects; do not - // write anything to database. - persistence.persist = function () { - return cache.markDirty(editableObject); - }; - - // Delegate refresh to the original object; this avoids refreshing - // the editable instance of the object, and ensures that refresh - // correctly targets the "real" version of the object. - persistence.refresh = function () { - return domainObject.getCapability('persistence').refresh(); - }; - - return persistence; - } - - return EditablePersistenceCapability; - } -); diff --git a/platform/commonUI/edit/src/capabilities/EditableRelationshipCapability.js b/platform/commonUI/edit/src/capabilities/EditableRelationshipCapability.js deleted file mode 100644 index af8c142338..0000000000 --- a/platform/commonUI/edit/src/capabilities/EditableRelationshipCapability.js +++ /dev/null @@ -1,58 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - - -define( - ['./EditableLookupCapability'], - function (EditableLookupCapability) { - - /** - * Wrapper for the "relationship" capability; - * ensures that any domain objects reachable in Edit mode - * are also wrapped as EditableDomainObjects. - * - * Meant specifically for use by EditableDomainObject and the - * associated cache; the constructor signature is particular - * to a pattern used there and may contain unused arguments. - * @constructor - * @memberof platform/commonUI/edit - * @implements {RelationshipCapability} - */ - return function EditableRelationshipCapability( - relationshipCapability, - editableObject, - domainObject, - cache - ) { - // This is a "lookup" style capability (it looks up other - // domain objects), but we do not want to return the same - // specific value every time (composition may change) - return new EditableLookupCapability( - relationshipCapability, - editableObject, - domainObject, - cache, - false // Not idempotent - ); - }; - } -); diff --git a/platform/commonUI/edit/src/capabilities/EditorCapability.js b/platform/commonUI/edit/src/capabilities/EditorCapability.js index 98a08d5643..8f40508069 100644 --- a/platform/commonUI/edit/src/capabilities/EditorCapability.js +++ b/platform/commonUI/edit/src/capabilities/EditorCapability.js @@ -24,20 +24,6 @@ define( [], function () { - /** - * Implements "save" and "cancel" as capabilities of - * the object. In editing mode, user is seeing/using - * a copy of the object which is disconnected from persistence; the Save - * and Cancel actions can use this capability to - * propagate changes from edit mode to the underlying - * actual persistable object. - * - * Meant specifically for use by EditableDomainObject and the - * associated cache; the constructor signature is particular - * to a pattern used there and may contain unused arguments. - * @constructor - * @memberof platform/commonUI/edit - */ function EditorCapability( transactionService, dirtyModelCache, diff --git a/platform/commonUI/edit/src/capabilities/TransactionDecorator.js b/platform/commonUI/edit/src/capabilities/TransactionDecorator.js index 76213c2ac5..6121ed6faa 100644 --- a/platform/commonUI/edit/src/capabilities/TransactionDecorator.js +++ b/platform/commonUI/edit/src/capabilities/TransactionDecorator.js @@ -26,21 +26,6 @@ define( function (TransactionalPersistenceCapability) { 'use strict'; - /** - * Implements "save" and "cancel" as capabilities of - * the object. In editing mode, user is seeing/using - * a copy of the object (an EditableDomainObject) - * which is disconnected from persistence; the Save - * and Cancel actions can use this capability to - * propagate changes from edit mode to the underlying - * actual persistable object. - * - * Meant specifically for use by EditableDomainObject and the - * associated cache; the constructor signature is particular - * to a pattern used there and may contain unused arguments. - * @constructor - * @memberof platform/commonUI/edit - */ function TransactionDecorator( $q, transactionService, diff --git a/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js b/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js index 28d3f76164..b282c40e1f 100644 --- a/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js +++ b/platform/commonUI/edit/src/capabilities/TransactionalPersistenceCapability.js @@ -43,7 +43,7 @@ define( TransactionalPersistenceCapability.prototype.persist = function () { var domainObject = this.domainObject, dirtyModelCache = this.dirtyModelCache; - if (this.transactionService.isActive()) { + if (this.transactionService.isActive() && !this.transactionService.isCommitting()) { dirtyModelCache.markDirty(domainObject); //Using $q here because need to return something // from which 'catch' can be chained diff --git a/platform/commonUI/edit/src/objects/EditableDomainObject.js b/platform/commonUI/edit/src/objects/EditableDomainObject.js deleted file mode 100644 index 1eedcd563b..0000000000 --- a/platform/commonUI/edit/src/objects/EditableDomainObject.js +++ /dev/null @@ -1,130 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -/** - * Defines EditableDomainObject, which wraps domain objects - * such that user code may work with and mutate a copy of the - * domain object model; these changes may then be propagated - * up to the real domain object (or not) by way of invoking - * save or cancel behaviors of the "editor.completion" - * capability (a capability intended as internal to edit - * mode; invoked by way of the Save and Cancel actions.) - */ -define( - [ - '../capabilities/EditablePersistenceCapability', - '../capabilities/EditableContextCapability', - '../capabilities/EditableCompositionCapability', - '../capabilities/EditableRelationshipCapability', - '../capabilities/EditableInstantiationCapability', - '../capabilities/EditorCapability', - '../capabilities/EditableActionCapability', - './EditableDomainObjectCache' - ], - function ( - EditablePersistenceCapability, - EditableContextCapability, - EditableCompositionCapability, - EditableRelationshipCapability, - EditableInstantiationCapability, - EditorCapability, - EditableActionCapability, - EditableDomainObjectCache - ) { - - var capabilityFactories = { - persistence: EditablePersistenceCapability, - context: EditableContextCapability, - composition: EditableCompositionCapability, - relationship: EditableRelationshipCapability, - instantiation: EditableInstantiationCapability, - editor: EditorCapability - }; - - // Handle special case where "editor.completion" wraps persistence - // (other capability overrides wrap capabilities of the same type.) - function getDelegateArguments(name, args) { - return name === "editor" ? ['persistence'] : args; - } - - /** - * An EditableDomainObject overrides capabilities - * which need to behave differently in edit mode, - * and provides a "working copy" of the object's - * model to allow changes to be easily cancelled. - * @constructor - * @memberof platform/commonUI/edit - * @implements {DomainObject} - */ - function EditableDomainObject(domainObject, $q) { - // The cache will hold all domain objects reached from - // the initial EditableDomainObject; this ensures that - // different versions of the same editable domain object - // are not shown in different sections of the same Edit - // UI, which might thereby fall out of sync. - var cache, - originalObject = domainObject, - cachedObject; - - // Constructor for EditableDomainObject, which adheres - // to the same shared cache. - function EditableDomainObjectImpl(domainObject, model) { - var editableObject = Object.create(domainObject); - - // Only provide the cloned model. - editableObject.getModel = function () { return model; }; - - // Override certain capabilities - editableObject.getCapability = function (name) { - var delegateArguments = getDelegateArguments(name, arguments), - capability = domainObject.getCapability.apply( - this, - delegateArguments - ), - Factory = capabilityFactories[name]; - - return (Factory && capability) ? - new Factory(capability, editableObject, domainObject, cache) : - capability; - }; - - - editableObject.setOriginalObject = function(object) { - originalObject = object; - }; - - editableObject.getOriginalObject = function() { - return originalObject; - }; - - return editableObject; - } - - cache = new EditableDomainObjectCache(EditableDomainObjectImpl, $q); - cachedObject = cache.getEditableObject(domainObject); - - return cachedObject; - } - - return EditableDomainObject; - } -); diff --git a/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js b/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js deleted file mode 100644 index 774e562e61..0000000000 --- a/platform/commonUI/edit/src/objects/EditableDomainObjectCache.js +++ /dev/null @@ -1,170 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - - -/* - * An editable domain object cache stores domain objects that have been - * made editable, in a group that can be saved all-at-once. This supports - * Edit mode, which is launched for a specific object but may contain - * changes across many objects. - * - * Editable domain objects have certain specific capabilities overridden - * to ensure that changes made while in edit mode do not propagate up - * to the objects used in browse mode (or to persistence) until the user - * initiates a Save. - */ -define( - ["./EditableModelCache"], - function (EditableModelCache) { - - /** - * Construct a new cache for editable domain objects. This can be used - * to get-or-create editable objects, particularly to support wrapping - * of objects retrieved via composition or context capabilities as - * editable domain objects. - * - * @param {Constructor} EditableDomainObject a - * constructor function which takes a regular domain object as - * an argument, and returns an editable domain object as its - * result. - * @param $q Angular's $q, for promise handling - * @memberof platform/commonUI/edit - * @constructor - */ - function EditableDomainObjectCache(EditableDomainObject, $q) { - this.cache = new EditableModelCache(); - this.dirtyObjects = {}; - this.root = undefined; - this.$q = $q; - this.EditableDomainObject = EditableDomainObject; - } - - /** - * Wrap this domain object in an editable form, or pull such - * an object from the cache if one already exists. - * - * @param {DomainObject} domainObject the regular domain object - * @returns {DomainObject} the domain object in an editable form - */ - EditableDomainObjectCache.prototype.getEditableObject = function (domainObject) { - var type = domainObject.getCapability('type'), - EditableDomainObject = this.EditableDomainObject, - editableObject; - - // Track the top-level domain object; this will have - // some special behavior for its context capability. - this.root = this.root || domainObject; - - // Avoid double-wrapping (WTD-1017) - if (domainObject.hasCapability('editor')) { - return domainObject; - } - - // Don't bother wrapping non-editable objects - if (!type || !type.hasFeature('creation')) { - return domainObject; - } - - // Provide an editable form of the object - editableObject = new EditableDomainObject( - domainObject, - this.cache.getCachedModel(domainObject) - ); - - return editableObject; - }; - - /** - * Check if a domain object is (effectively) the top-level - * object in this editable subgraph. - * @returns {boolean} true if it is the root - */ - EditableDomainObjectCache.prototype.isRoot = function (domainObject) { - return domainObject === this.root; - }; - - /** - * Mark an editable domain object (presumably already cached) - * as having received modifications during editing; it should be - * included in the bulk save invoked when editing completes. - * - * @param {DomainObject} domainObject the domain object - * @memberof platform/commonUI/edit.EditableDomainObjectCache# - */ - EditableDomainObjectCache.prototype.markDirty = function (domainObject) { - this.dirtyObjects[domainObject.getId()] = domainObject; - return this.$q.when(true); - }; - - /** - * Mark an object (presumably already cached) as having had its - * changes saved (and thus no longer needing to be subject to a - * save operation.) - * - * @param {DomainObject} domainObject the domain object - */ - EditableDomainObjectCache.prototype.markClean = function (domainObject) { - var self = this; - if (!domainObject) { - Object.keys(this.dirtyObjects).forEach(function(key) { - delete self.dirtyObjects[key]; - }); - } else { - delete this.dirtyObjects[domainObject.getId()]; - } - }; - - /** - * Initiate a save on all objects that have been cached. - * @return {Promise} A promise which will resolve when all objects are - * persisted. - */ - EditableDomainObjectCache.prototype.saveAll = function () { - // Get a list of all dirty objects - var dirty = this.dirtyObjects, - objects = Object.keys(dirty).map(function (k) { - return dirty[k]; - }); - - // Clear dirty set, since we're about to save. - this.dirtyObjects = {}; - - // Most save logic is handled by the "editor.completion" - // capability, so that is delegated here. - return this.$q.all(objects.map(function (object) { - // Save; pass a nonrecursive flag to avoid looping - return object.getCapability('editor').save(true); - })); - }; - - /** - * Check if any objects have been marked dirty in this cache. - * @returns {boolean} true if objects are dirty - */ - EditableDomainObjectCache.prototype.dirty = function () { - return Object.keys(this.dirtyObjects).length > 0; - }; - - return EditableDomainObjectCache; - } -); - diff --git a/platform/commonUI/edit/src/objects/EditableModelCache.js b/platform/commonUI/edit/src/objects/EditableModelCache.js deleted file mode 100644 index 702cfbe6c7..0000000000 --- a/platform/commonUI/edit/src/objects/EditableModelCache.js +++ /dev/null @@ -1,60 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -define( - [], - function () { - - /** - * An editable model cache stores domain object models that have been - * made editable, to support a group that can be saved all-at-once. - * This is useful in Edit mode, which is launched for a specific - * object but may contain changes across many objects. - * @memberof platform/commonUI/edit - * @constructor - */ - function EditableModelCache() { - this.cache = {}; - } - - // Deep-copy a model. Models are JSONifiable, so this can be - // done by stringification then destringification - function clone(model) { - return JSON.parse(JSON.stringify(model)); - } - - /** - * Get this domain object's model from the cache (or - * place it in the cache if it isn't in the cache yet) - * @returns a clone of the domain object's model - */ - EditableModelCache.prototype.getCachedModel = function (domainObject) { - var id = domainObject.getId(), - cache = this.cache; - - return (cache[id] = - cache[id] || clone(domainObject.getModel())); - }; - - return EditableModelCache; - } -); diff --git a/platform/commonUI/edit/src/services/TransactionService.js b/platform/commonUI/edit/src/services/TransactionService.js index f9456cad77..2944d2215c 100644 --- a/platform/commonUI/edit/src/services/TransactionService.js +++ b/platform/commonUI/edit/src/services/TransactionService.js @@ -35,6 +35,7 @@ define( function TransactionService($q, dirtyModelCache) { this.$q = $q; this.transaction = false; + this.committing = false; this.cache = dirtyModelCache; } @@ -48,6 +49,10 @@ define( return this.transaction; }; + TransactionService.prototype.isCommitting = function () { + return this.committing; + }; + /** * All persist calls deferred since the beginning of the transaction * will be committed. Any failures will be reported via a promise @@ -58,6 +63,8 @@ define( var self = this; cache = this.cache.get(); + this.committing = true; + function keyToObject(key) { return cache[key]; } @@ -72,6 +79,9 @@ define( .map(objectToPromise)) .then(function () { self.transaction = false; + this.committing = false; + }).catch(function() { + return this.committing = false; }); }; @@ -100,6 +110,7 @@ define( .map(objectToPromise)) .then(function () { self.transaction = false; + this.committing = false; }); }; diff --git a/platform/commonUI/edit/test/capabilities/EditableCompositionCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/EditableCompositionCapabilitySpec.js deleted file mode 100644 index 3e4083d2e8..0000000000 --- a/platform/commonUI/edit/test/capabilities/EditableCompositionCapabilitySpec.js +++ /dev/null @@ -1,73 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -define( - ["../../src/capabilities/EditableCompositionCapability"], - function (EditableCompositionCapability) { - - describe("An editable composition capability", function () { - var mockContext, - mockEditableObject, - mockDomainObject, - mockTestObject, - someValue, - mockFactory, - capability; - - beforeEach(function () { - // EditableContextCapability should watch ALL - // methods for domain objects, so give it an - // arbitrary interface to wrap. - mockContext = - jasmine.createSpyObj("context", [ "getDomainObject" ]); - mockTestObject = jasmine.createSpyObj( - "domainObject", - [ "getId", "getModel", "getCapability" ] - ); - mockFactory = - jasmine.createSpyObj("factory", ["getEditableObject"]); - - someValue = { x: 42 }; - - mockContext.getDomainObject.andReturn(mockTestObject); - mockFactory.getEditableObject.andReturn(someValue); - - capability = new EditableCompositionCapability( - mockContext, - mockEditableObject, - mockDomainObject, - mockFactory - ); - - }); - - // Most behavior is tested for EditableLookupCapability, - // so just verify that this isse - it("presumes non-idempotence of its wrapped capability", function () { - expect(capability.getDomainObject()) - .toEqual(capability.getDomainObject()); - expect(mockContext.getDomainObject.calls.length).toEqual(2); - }); - - }); - } -); \ No newline at end of file diff --git a/platform/commonUI/edit/test/capabilities/EditableContextCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/EditableContextCapabilitySpec.js deleted file mode 100644 index b18a02e881..0000000000 --- a/platform/commonUI/edit/test/capabilities/EditableContextCapabilitySpec.js +++ /dev/null @@ -1,87 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -define( - ["../../src/capabilities/EditableContextCapability"], - function (EditableContextCapability) { - - describe("An editable context capability", function () { - var mockContext, - mockEditableObject, - mockDomainObject, - mockTestObject, - someValue, - mockFactory, - capability; - - beforeEach(function () { - // EditableContextCapability should watch ALL - // methods for domain objects, so give it an - // arbitrary interface to wrap. - mockContext = - jasmine.createSpyObj("context", [ "getDomainObject", "getRoot" ]); - mockTestObject = jasmine.createSpyObj( - "domainObject", - [ "getId", "getModel", "getCapability" ] - ); - mockFactory = jasmine.createSpyObj( - "factory", - ["getEditableObject", "isRoot"] - ); - - someValue = { x: 42 }; - - mockContext.getRoot.andReturn(mockTestObject); - mockContext.getDomainObject.andReturn(mockTestObject); - mockFactory.getEditableObject.andReturn(someValue); - mockFactory.isRoot.andReturn(true); - - capability = new EditableContextCapability( - mockContext, - mockEditableObject, - mockDomainObject, - mockFactory - ); - - }); - - it("presumes idempotence of its wrapped capability", function () { - expect(capability.getDomainObject()) - .toEqual(capability.getDomainObject()); - expect(mockContext.getDomainObject.calls.length).toEqual(1); - }); - - it("hides the root object", function () { - expect(capability.getRoot()).toEqual(mockEditableObject); - expect(capability.getPath()).toEqual([mockEditableObject]); - }); - - it("exposes the root object through a different method", function () { - // Should still go through the factory... - expect(capability.getTrueRoot()).toEqual(someValue); - // ...with value of the unwrapped capability's getRoot - expect(mockFactory.getEditableObject) - .toHaveBeenCalledWith(mockTestObject); - }); - }); - } -); \ No newline at end of file diff --git a/platform/commonUI/edit/test/capabilities/EditableLookupCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/EditableLookupCapabilitySpec.js deleted file mode 100644 index dc178da449..0000000000 --- a/platform/commonUI/edit/test/capabilities/EditableLookupCapabilitySpec.js +++ /dev/null @@ -1,144 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -define( - ["../../src/capabilities/EditableLookupCapability"], - function (EditableLookupCapability) { - - describe("An editable lookup capability", function () { - var mockContext, - mockEditableObject, - mockDomainObject, - mockTestObject, - someValue, - factory, - capability; - - beforeEach(function () { - // EditableContextCapability should watch ALL - // methods for domain objects, so give it an - // arbitrary interface to wrap. - mockContext = jasmine.createSpyObj( - "context", - [ - "getSomething", - "getDomainObject", - "getDomainObjectArray" - ] - ); - mockTestObject = jasmine.createSpyObj( - "domainObject", - [ "getId", "getModel", "getCapability" ] - ); - factory = { - getEditableObject: function (v) { - return { - isFromTestFactory: true, - calledWith: v - }; - } - }; - - someValue = { x: 42 }; - - mockContext.getSomething.andReturn(someValue); - mockContext.getDomainObject.andReturn(mockTestObject); - mockContext.getDomainObjectArray.andReturn([mockTestObject]); - - capability = new EditableLookupCapability( - mockContext, - mockEditableObject, - mockDomainObject, - factory, - false - ); - - }); - - it("wraps retrieved domain objects", function () { - var object = capability.getDomainObject(); - expect(object.isFromTestFactory).toBe(true); - expect(object.calledWith).toEqual(mockTestObject); - }); - - it("wraps retrieved domain object arrays", function () { - var object = capability.getDomainObjectArray()[0]; - expect(object.isFromTestFactory).toBe(true); - expect(object.calledWith).toEqual(mockTestObject); - }); - - it("does not wrap non-domain-objects", function () { - expect(capability.getSomething()).toEqual(someValue); - }); - - it("caches idempotent lookups", function () { - capability = new EditableLookupCapability( - mockContext, - mockEditableObject, - mockDomainObject, - factory, - true // idempotent - ); - expect(capability.getDomainObject()) - .toEqual(capability.getDomainObject()); - expect(mockContext.getDomainObject.calls.length).toEqual(1); - }); - - it("does not cache non-idempotent lookups", function () { - capability = new EditableLookupCapability( - mockContext, - mockEditableObject, - mockDomainObject, - factory, - false // Not idempotent - ); - expect(capability.getDomainObject()) - .toEqual(capability.getDomainObject()); - expect(mockContext.getDomainObject.calls.length).toEqual(2); - }); - - it("wraps inherited methods", function () { - var CapabilityClass = function(){ - }; - CapabilityClass.prototype.inheritedMethod=function () { - return "an inherited method"; - }; - - mockContext = new CapabilityClass(); - - capability = new EditableLookupCapability( - mockContext, - mockEditableObject, - mockDomainObject, - factory, - false - ); - expect(capability.inheritedMethod()).toEqual("an inherited method"); - expect(capability.hasOwnProperty('inheritedMethod')).toBe(true); - // The presence of an own property indicates that the method - // has been wrapped on the object itself and this is a valid - // test that the inherited method has been wrapped. - }); - - }); - } -); \ No newline at end of file diff --git a/platform/commonUI/edit/test/capabilities/EditablePersistenceCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/EditablePersistenceCapabilitySpec.js deleted file mode 100644 index 4ce4a2f75d..0000000000 --- a/platform/commonUI/edit/test/capabilities/EditablePersistenceCapabilitySpec.js +++ /dev/null @@ -1,94 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -define( - ["../../src/capabilities/EditablePersistenceCapability"], - function (EditablePersistenceCapability) { - - describe("An editable persistence capability", function () { - var mockPersistence, - mockEditableObject, - mockDomainObject, - mockCache, - mockPromise, - capability; - - beforeEach(function () { - mockPersistence = jasmine.createSpyObj( - "persistence", - [ "persist", "refresh" ] - ); - mockEditableObject = jasmine.createSpyObj( - "editableObject", - [ "getId", "getModel", "getCapability" ] - ); - mockDomainObject = jasmine.createSpyObj( - "editableObject", - [ "getId", "getModel", "getCapability" ] - ); - mockCache = jasmine.createSpyObj( - "cache", - [ "markDirty" ] - ); - mockPromise = jasmine.createSpyObj("promise", ["then"]); - - mockCache.markDirty.andReturn(mockPromise); - mockDomainObject.getCapability.andReturn(mockPersistence); - - capability = new EditablePersistenceCapability( - mockPersistence, - mockEditableObject, - mockDomainObject, - mockCache - ); - }); - - it("marks objects as dirty (in the cache) upon persist", function () { - capability.persist(); - expect(mockCache.markDirty) - .toHaveBeenCalledWith(mockEditableObject); - }); - - it("does not invoke the underlying persistence capability", function () { - capability.persist(); - expect(mockPersistence.persist).not.toHaveBeenCalled(); - }); - - it("refreshes using the original domain object's persistence", function () { - // Refreshing needs to delegate via the unwrapped domain object. - // Otherwise, only the editable version of the object will be updated; - // we instead want the real version of the object to receive these - // changes. - expect(mockDomainObject.getCapability).not.toHaveBeenCalled(); - expect(mockPersistence.refresh).not.toHaveBeenCalled(); - capability.refresh(); - expect(mockDomainObject.getCapability).toHaveBeenCalledWith('persistence'); - expect(mockPersistence.refresh).toHaveBeenCalled(); - }); - - it("returns a promise from persist", function () { - expect(capability.persist().then).toEqual(jasmine.any(Function)); - }); - - }); - } -); \ No newline at end of file diff --git a/platform/commonUI/edit/test/capabilities/EditableRelationshipCapabilitySpec.js b/platform/commonUI/edit/test/capabilities/EditableRelationshipCapabilitySpec.js deleted file mode 100644 index 9a6c17d944..0000000000 --- a/platform/commonUI/edit/test/capabilities/EditableRelationshipCapabilitySpec.js +++ /dev/null @@ -1,73 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -define( - ["../../src/capabilities/EditableRelationshipCapability"], - function (EditableRelationshipCapability) { - - describe("An editable relationship capability", function () { - var mockContext, - mockEditableObject, - mockDomainObject, - mockTestObject, - someValue, - mockFactory, - capability; - - beforeEach(function () { - // EditableContextCapability should watch ALL - // methods for domain objects, so give it an - // arbitrary interface to wrap. - mockContext = - jasmine.createSpyObj("context", [ "getDomainObject" ]); - mockTestObject = jasmine.createSpyObj( - "domainObject", - [ "getId", "getModel", "getCapability" ] - ); - mockFactory = - jasmine.createSpyObj("factory", ["getEditableObject"]); - - someValue = { x: 42 }; - - mockContext.getDomainObject.andReturn(mockTestObject); - mockFactory.getEditableObject.andReturn(someValue); - - capability = new EditableRelationshipCapability( - mockContext, - mockEditableObject, - mockDomainObject, - mockFactory - ); - - }); - - // Most behavior is tested for EditableLookupCapability, - // so just verify that this isse - it("presumes non-idempotence of its wrapped capability", function () { - expect(capability.getDomainObject()) - .toEqual(capability.getDomainObject()); - expect(mockContext.getDomainObject.calls.length).toEqual(2); - }); - - }); - } -); \ No newline at end of file diff --git a/platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js b/platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js deleted file mode 100644 index edbfd3edc4..0000000000 --- a/platform/commonUI/edit/test/objects/EditableDomainObjectCacheSpec.js +++ /dev/null @@ -1,177 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -define( - ["../../src/objects/EditableDomainObjectCache"], - function (EditableDomainObjectCache) { - - describe("Editable domain object cache", function () { - - var captured, - completionCapability, - mockQ, - mockType, - cache; - - - // Constructors for test objects - function TestObject(id) { - return { - getId: function () { return id; }, - getModel: function () { return {}; }, - getCapability: function (key) { - return { - editor: completionCapability, - type: mockType - }[key]; - }, - hasCapability: function () { - return false; - } - }; - } - - function WrapObject(domainObject, model) { - var result = Object.create(domainObject); - result.wrapped = true; - result.wrappedModel = model; - result.hasCapability = function (name) { - return name === 'editor'; - }; - captured.wraps = (captured.wraps || 0) + 1; - return result; - } - - beforeEach(function () { - mockQ = jasmine.createSpyObj('$q', ['when', 'all']); - mockType = jasmine.createSpyObj('type', ['hasFeature']); - mockType.hasFeature.andReturn(true); - captured = {}; - completionCapability = { - save: function () { - captured.saved = (captured.saved || 0) + 1; - } - }; - - cache = new EditableDomainObjectCache(WrapObject, mockQ); - }); - - it("wraps objects using provided constructor", function () { - var domainObject = new TestObject('test-id'), - wrappedObject = cache.getEditableObject(domainObject); - expect(wrappedObject.wrapped).toBeTruthy(); - expect(wrappedObject.getId()).toEqual(domainObject.getId()); - }); - - it("wraps objects repeatedly, wraps models once", function () { - var domainObject = new TestObject('test-id'), - wrappedObjects = []; - - // Verify precondition - expect(captured.wraps).toBeUndefined(); - - // Invoke a few more times; expect count not to increment - wrappedObjects.push(cache.getEditableObject(domainObject)); - expect(captured.wraps).toEqual(1); - wrappedObjects.push(cache.getEditableObject(domainObject)); - expect(captured.wraps).toEqual(2); - wrappedObjects.push(cache.getEditableObject(domainObject)); - expect(captured.wraps).toEqual(3); - - // Verify that the last call still gave us a wrapped object - expect(wrappedObjects[0].wrapped).toBeTruthy(); - expect(wrappedObjects[0].getId()).toEqual(domainObject.getId()); - - // Verify that objects are distinct but models are identical - expect(wrappedObjects[0].wrappedModel) - .toBe(wrappedObjects[1].wrappedModel); - expect(wrappedObjects[0]).not - .toBe(wrappedObjects[1]); - }); - - it("saves objects that have been marked dirty", function () { - var objects = ['a', 'b', 'c'].map(TestObject).map(function (domainObject) { - return cache.getEditableObject(domainObject); - }); - - cache.markDirty(objects[0]); - cache.markDirty(objects[2]); - - cache.saveAll(); - - expect(captured.saved).toEqual(2); - }); - - it("does not save objects that have been marked clean", function () { - var objects = ['a', 'b', 'c'].map(TestObject).map(function (domainObject) { - return cache.getEditableObject(domainObject); - }); - - cache.markDirty(objects[0]); - cache.markDirty(objects[2]); - cache.markClean(objects[0]); - - cache.saveAll(); - - expect(captured.saved).toEqual(1); - }); - - it("tracks the root object of the Edit mode subgraph", function () { - // Root object is the first object exposed to the cache - var domainObjects = ['a', 'b', 'c'].map(TestObject); - domainObjects.forEach(function (obj) { - cache.getEditableObject(obj); - }); - expect(cache.isRoot(domainObjects[0])).toBeTruthy(); - expect(cache.isRoot(domainObjects[1])).toBeFalsy(); - expect(cache.isRoot(domainObjects[2])).toBeFalsy(); - }); - - it("does not double-wrap objects", function () { - var domainObject = new TestObject('test-id'), - wrappedObject = cache.getEditableObject(domainObject); - - // Same instance should be returned if you try to wrap - // twice. This is necessary, since it's possible to (e.g.) - // use a context capability on an object retrieved via - // composition, in which case a result will already be - // wrapped. - expect(cache.getEditableObject(wrappedObject)) - .toBe(wrappedObject); - }); - - it("does not wrap non-editable objects", function () { - var domainObject = new TestObject('test-id'); - - mockType.hasFeature.andCallFake(function (key) { - return key !== 'creation'; - }); - - expect(cache.getEditableObject(domainObject)) - .toBe(domainObject); - }); - - - }); - } - -); diff --git a/platform/commonUI/edit/test/objects/EditableDomainObjectSpec.js b/platform/commonUI/edit/test/objects/EditableDomainObjectSpec.js deleted file mode 100644 index 9b1095f68d..0000000000 --- a/platform/commonUI/edit/test/objects/EditableDomainObjectSpec.js +++ /dev/null @@ -1,35 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -define( - ["../../src/objects/EditableDomainObject"], - function (EditableDomainObject) { - - describe("Editable domain object", function () { - var object; - - beforeEach(function () { - object = new EditableDomainObject(); - }); - }); - } -); \ No newline at end of file diff --git a/platform/commonUI/edit/test/objects/EditableModelCacheSpec.js b/platform/commonUI/edit/test/objects/EditableModelCacheSpec.js deleted file mode 100644 index 1fe8db0262..0000000000 --- a/platform/commonUI/edit/test/objects/EditableModelCacheSpec.js +++ /dev/null @@ -1,79 +0,0 @@ -/***************************************************************************** - * Open MCT Web, Copyright (c) 2014-2015, United States Government - * as represented by the Administrator of the National Aeronautics and Space - * Administration. All rights reserved. - * - * Open MCT Web is licensed under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0. - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - * - * Open MCT Web includes source code licensed under additional open source - * licenses. See the Open Source Licenses file (LICENSES.md) included with - * this source code distribution or the Licensing information page available - * at runtime from the About dialog for additional information. - *****************************************************************************/ - -define( - ["../../src/objects/EditableModelCache"], - function (EditableModelCache) { - - describe("The editable model cache", function () { - var mockObject, - mockOtherObject, - testModel, - testId, - otherModel, - otherId, - cache; - - beforeEach(function () { - testId = "test"; - testModel = { someKey: "some value" }; - otherId = "other"; - otherModel = { someKey: "some other value" }; - - mockObject = jasmine.createSpyObj( - "domainObject", - [ "getId", "getModel" ] - ); - mockOtherObject = jasmine.createSpyObj( - "domainObject", - [ "getId", "getModel" ] - ); - - mockObject.getId.andReturn(testId); - mockObject.getModel.andReturn(testModel); - mockOtherObject.getId.andReturn(otherId); - mockOtherObject.getModel.andReturn(otherModel); - - cache = new EditableModelCache(); - }); - - it("provides clones of domain object models", function () { - var model = cache.getCachedModel(mockObject); - // Should be identical... - expect(model).toEqual(testModel); - // ...but not pointer-identical - expect(model).not.toBe(testModel); - }); - - it("provides only one clone per object", function () { - var model = cache.getCachedModel(mockObject); - expect(cache.getCachedModel(mockObject)).toBe(model); - }); - - it("maintains separate caches per-object", function () { - expect(cache.getCachedModel(mockObject)) - .not.toEqual(cache.getCachedModel(mockOtherObject)); - }); - }); - - } -); \ No newline at end of file diff --git a/platform/features/timeline/src/controllers/swimlane/TimelineSwimlaneDropHandler.js b/platform/features/timeline/src/controllers/swimlane/TimelineSwimlaneDropHandler.js index 59b437d15c..7195d91895 100644 --- a/platform/features/timeline/src/controllers/swimlane/TimelineSwimlaneDropHandler.js +++ b/platform/features/timeline/src/controllers/swimlane/TimelineSwimlaneDropHandler.js @@ -39,9 +39,13 @@ define( }; } - // Check if we are in edit mode - function inEditMode() { - return swimlane.domainObject.hasCapability("editor"); + // Check if we are in edit mode (also check parents) + function inEditMode(swimlane) { + if (!swimlane.domainObject.getCapability("status").get("editing") && swimlane.parent) { + return inEditMode(swimlane.parent); + } else { + return swimlane.domainObject.getCapability("status").get("editing"); + } } // Boolean and (for reduce below) @@ -173,7 +177,7 @@ define( * @returns {boolean} true if this should be allowed */ allowDropIn: function (id, domainObject) { - return inEditMode() && + return inEditMode(swimlane) && !pathContains(swimlane, id) && !contains(swimlane, id) && canDrop(swimlane.domainObject, domainObject); @@ -188,7 +192,7 @@ define( allowDropAfter: function (id, domainObject) { var target = expandedForDropInto() ? swimlane : swimlane.parent; - return inEditMode() && + return inEditMode(swimlane) && target && !pathContains(target, id) && canDrop(target.domainObject, domainObject);