mirror of
https://github.com/nasa/openmct.git
synced 2025-06-25 10:44:21 +00:00
Compare commits
4 Commits
tables-rem
...
open305b
Author | SHA1 | Date | |
---|---|---|---|
9c466cb89c | |||
a47760cea5 | |||
8b4dd7fe1e | |||
eba1421df8 |
@ -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,
|
||||
|
@ -49,6 +49,7 @@ define(
|
||||
// domain objects), and it should be idempotent
|
||||
var capability = new EditableLookupCapability(
|
||||
contextCapability,
|
||||
[ "getRoot", "getPath", "getParent" ],
|
||||
editableObject,
|
||||
domainObject,
|
||||
cache,
|
||||
|
@ -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
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
@ -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;
|
||||
};
|
||||
|
@ -50,6 +50,7 @@ define(
|
||||
// specific value every time (composition may change)
|
||||
return new EditableLookupCapability(
|
||||
relationshipCapability,
|
||||
[ "getRelatedObjects" ],
|
||||
editableObject,
|
||||
domainObject,
|
||||
cache,
|
||||
|
@ -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
|
||||
};
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user