Compare commits

...

4 Commits

Author SHA1 Message Date
9c466cb89c [Edit] Override instantiation capability
https://github.com/nasa/openmctweb/issues/305
2015-12-03 10:55:02 -08:00
a47760cea5 [Edit] Don't clone models of ineditable objects
Avoids regression on WTD-1291 after changes for
https://github.com/nasa/openmctweb/issues/368
cause ineditable objects to be wrapped for
editability.
2015-12-03 10:52:17 -08:00
8b4dd7fe1e [Edit] Remove faulty logic
Remove faulty check for editability; ineditable objects need
to be wrapped too, because they may be used to reach editable
objects (via composition and/or context)
2015-12-03 10:45:26 -08:00
eba1421df8 [Edit] Specify methods to wrap
Specify which methods need to be wrapped in Edit mode
to ensure that only editable objects are retrieved via
the capabilities of other editable objects.
2015-12-03 10:17:55 -08:00
8 changed files with 88 additions and 13 deletions

View File

@ -40,7 +40,7 @@ define(
* @implements {CompositionCapability}
*/
return function EditableCompositionCapability(
contextCapability,
compositionCapability,
editableObject,
domainObject,
cache
@ -49,7 +49,8 @@ define(
// domain objects), but we do not want to return the same
// specific value every time (composition may change)
return new EditableLookupCapability(
contextCapability,
compositionCapability,
[ "invoke", "add" ],
editableObject,
domainObject,
cache,

View File

@ -49,6 +49,7 @@ define(
// domain objects), and it should be idempotent
var capability = new EditableLookupCapability(
contextCapability,
[ "getRoot", "getPath", "getParent" ],
editableObject,
domainObject,
cache,

View File

@ -0,0 +1,61 @@
/*****************************************************************************
* 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.
*****************************************************************************/
/*global define*/
define(
['./EditableLookupCapability'],
function (EditableLookupCapability) {
'use strict';
/**
* 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 {InstantiationCapability}
*/
return function EditableInstantiationCapability(
instantiationCapability,
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(
instantiationCapability,
[ "invoke", "instantiate" ],
editableObject,
domainObject,
cache,
false // Not idempotent
);
};
}
);

View File

@ -39,13 +39,14 @@ define(
* @memberof platform/commonUI/edit
*/
return function EditableLookupCapability(
contextCapability,
capabilityToWrap,
methods,
editableObject,
domainObject,
cache,
idempotent
) {
var capability = Object.create(contextCapability);
var capability = Object.create(capabilityToWrap);
// Check for domain object interface. If something has these
// three methods, we assume it's a domain object.
@ -87,7 +88,7 @@ define(
// all results are editable domain objects.
function wrapFunction(fn) {
return function () {
return wrapResult(contextCapability[fn].apply(
return wrapResult(capabilityToWrap[fn].apply(
capability,
arguments
));
@ -114,7 +115,7 @@ define(
}
// Wrap all methods; return only editable domain objects.
Object.keys(contextCapability).forEach(wrapMethod);
methods.forEach(wrapMethod);
return capability;
};

View File

@ -50,6 +50,7 @@ define(
// specific value every time (composition may change)
return new EditableLookupCapability(
relationshipCapability,
[ "getRelatedObjects" ],
editableObject,
domainObject,
cache,

View File

@ -35,6 +35,7 @@ define(
'../capabilities/EditablePersistenceCapability',
'../capabilities/EditableContextCapability',
'../capabilities/EditableCompositionCapability',
'../capabilities/EditableInstantiationCapability',
'../capabilities/EditableRelationshipCapability',
'../capabilities/EditorCapability',
'./EditableDomainObjectCache'
@ -43,6 +44,7 @@ define(
EditablePersistenceCapability,
EditableContextCapability,
EditableCompositionCapability,
EditableInstantiationCapability,
EditableRelationshipCapability,
EditorCapability,
EditableDomainObjectCache
@ -53,6 +55,7 @@ define(
persistence: EditablePersistenceCapability,
context: EditableContextCapability,
composition: EditableCompositionCapability,
instantiation: EditableInstantiationCapability,
relationship: EditableRelationshipCapability,
editor: EditorCapability
};

View File

@ -80,11 +80,6 @@ define(
return domainObject;
}
// Don't bother wrapping non-editable objects
if (!type || !type.hasFeature('creation')) {
return domainObject;
}
// Provide an editable form of the object
return new EditableDomainObject(
domainObject,

View File

@ -44,6 +44,12 @@ define(
return JSON.parse(JSON.stringify(model));
}
function isEditable(domainObject) {
// Presently, creatability is synonymous with editability
return domainObject.hasCapability('type') &&
domainObject.getCapability('type').hasFeature('creation');
}
/**
* Get this domain object's model from the cache (or
* place it in the cache if it isn't in the cache yet)
@ -53,8 +59,14 @@ define(
var id = domainObject.getId(),
cache = this.cache;
return (cache[id] =
cache[id] || clone(domainObject.getModel()));
if (!cache[id]) {
// Only need to clone models for editable objects.
cache[id] = isEditable(domainObject) ?
clone(domainObject.getModel()) :
domainObject.getModel();
}
return cache[id];
};
return EditableModelCache;