mirror of
https://github.com/nasa/openmct.git
synced 2025-06-27 03:22:04 +00:00
Compare commits
4 Commits
code-walkt
...
open305b
Author | SHA1 | Date | |
---|---|---|---|
9c466cb89c | |||
a47760cea5 | |||
8b4dd7fe1e | |||
eba1421df8 |
@ -40,7 +40,7 @@ define(
|
|||||||
* @implements {CompositionCapability}
|
* @implements {CompositionCapability}
|
||||||
*/
|
*/
|
||||||
return function EditableCompositionCapability(
|
return function EditableCompositionCapability(
|
||||||
contextCapability,
|
compositionCapability,
|
||||||
editableObject,
|
editableObject,
|
||||||
domainObject,
|
domainObject,
|
||||||
cache
|
cache
|
||||||
@ -49,7 +49,8 @@ define(
|
|||||||
// domain objects), but we do not want to return the same
|
// domain objects), but we do not want to return the same
|
||||||
// specific value every time (composition may change)
|
// specific value every time (composition may change)
|
||||||
return new EditableLookupCapability(
|
return new EditableLookupCapability(
|
||||||
contextCapability,
|
compositionCapability,
|
||||||
|
[ "invoke", "add" ],
|
||||||
editableObject,
|
editableObject,
|
||||||
domainObject,
|
domainObject,
|
||||||
cache,
|
cache,
|
||||||
|
@ -49,6 +49,7 @@ define(
|
|||||||
// domain objects), and it should be idempotent
|
// domain objects), and it should be idempotent
|
||||||
var capability = new EditableLookupCapability(
|
var capability = new EditableLookupCapability(
|
||||||
contextCapability,
|
contextCapability,
|
||||||
|
[ "getRoot", "getPath", "getParent" ],
|
||||||
editableObject,
|
editableObject,
|
||||||
domainObject,
|
domainObject,
|
||||||
cache,
|
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
|
* @memberof platform/commonUI/edit
|
||||||
*/
|
*/
|
||||||
return function EditableLookupCapability(
|
return function EditableLookupCapability(
|
||||||
contextCapability,
|
capabilityToWrap,
|
||||||
|
methods,
|
||||||
editableObject,
|
editableObject,
|
||||||
domainObject,
|
domainObject,
|
||||||
cache,
|
cache,
|
||||||
idempotent
|
idempotent
|
||||||
) {
|
) {
|
||||||
var capability = Object.create(contextCapability);
|
var capability = Object.create(capabilityToWrap);
|
||||||
|
|
||||||
// Check for domain object interface. If something has these
|
// Check for domain object interface. If something has these
|
||||||
// three methods, we assume it's a domain object.
|
// three methods, we assume it's a domain object.
|
||||||
@ -87,7 +88,7 @@ define(
|
|||||||
// all results are editable domain objects.
|
// all results are editable domain objects.
|
||||||
function wrapFunction(fn) {
|
function wrapFunction(fn) {
|
||||||
return function () {
|
return function () {
|
||||||
return wrapResult(contextCapability[fn].apply(
|
return wrapResult(capabilityToWrap[fn].apply(
|
||||||
capability,
|
capability,
|
||||||
arguments
|
arguments
|
||||||
));
|
));
|
||||||
@ -114,7 +115,7 @@ define(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Wrap all methods; return only editable domain objects.
|
// Wrap all methods; return only editable domain objects.
|
||||||
Object.keys(contextCapability).forEach(wrapMethod);
|
methods.forEach(wrapMethod);
|
||||||
|
|
||||||
return capability;
|
return capability;
|
||||||
};
|
};
|
||||||
|
@ -50,6 +50,7 @@ define(
|
|||||||
// specific value every time (composition may change)
|
// specific value every time (composition may change)
|
||||||
return new EditableLookupCapability(
|
return new EditableLookupCapability(
|
||||||
relationshipCapability,
|
relationshipCapability,
|
||||||
|
[ "getRelatedObjects" ],
|
||||||
editableObject,
|
editableObject,
|
||||||
domainObject,
|
domainObject,
|
||||||
cache,
|
cache,
|
||||||
|
@ -35,6 +35,7 @@ define(
|
|||||||
'../capabilities/EditablePersistenceCapability',
|
'../capabilities/EditablePersistenceCapability',
|
||||||
'../capabilities/EditableContextCapability',
|
'../capabilities/EditableContextCapability',
|
||||||
'../capabilities/EditableCompositionCapability',
|
'../capabilities/EditableCompositionCapability',
|
||||||
|
'../capabilities/EditableInstantiationCapability',
|
||||||
'../capabilities/EditableRelationshipCapability',
|
'../capabilities/EditableRelationshipCapability',
|
||||||
'../capabilities/EditorCapability',
|
'../capabilities/EditorCapability',
|
||||||
'./EditableDomainObjectCache'
|
'./EditableDomainObjectCache'
|
||||||
@ -43,6 +44,7 @@ define(
|
|||||||
EditablePersistenceCapability,
|
EditablePersistenceCapability,
|
||||||
EditableContextCapability,
|
EditableContextCapability,
|
||||||
EditableCompositionCapability,
|
EditableCompositionCapability,
|
||||||
|
EditableInstantiationCapability,
|
||||||
EditableRelationshipCapability,
|
EditableRelationshipCapability,
|
||||||
EditorCapability,
|
EditorCapability,
|
||||||
EditableDomainObjectCache
|
EditableDomainObjectCache
|
||||||
@ -53,6 +55,7 @@ define(
|
|||||||
persistence: EditablePersistenceCapability,
|
persistence: EditablePersistenceCapability,
|
||||||
context: EditableContextCapability,
|
context: EditableContextCapability,
|
||||||
composition: EditableCompositionCapability,
|
composition: EditableCompositionCapability,
|
||||||
|
instantiation: EditableInstantiationCapability,
|
||||||
relationship: EditableRelationshipCapability,
|
relationship: EditableRelationshipCapability,
|
||||||
editor: EditorCapability
|
editor: EditorCapability
|
||||||
};
|
};
|
||||||
|
@ -80,11 +80,6 @@ define(
|
|||||||
return domainObject;
|
return domainObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't bother wrapping non-editable objects
|
|
||||||
if (!type || !type.hasFeature('creation')) {
|
|
||||||
return domainObject;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Provide an editable form of the object
|
// Provide an editable form of the object
|
||||||
return new EditableDomainObject(
|
return new EditableDomainObject(
|
||||||
domainObject,
|
domainObject,
|
||||||
|
@ -44,6 +44,12 @@ define(
|
|||||||
return JSON.parse(JSON.stringify(model));
|
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
|
* Get this domain object's model from the cache (or
|
||||||
* place it in the cache if it isn't in the cache yet)
|
* place it in the cache if it isn't in the cache yet)
|
||||||
@ -53,8 +59,14 @@ define(
|
|||||||
var id = domainObject.getId(),
|
var id = domainObject.getId(),
|
||||||
cache = this.cache;
|
cache = this.cache;
|
||||||
|
|
||||||
return (cache[id] =
|
if (!cache[id]) {
|
||||||
cache[id] || clone(domainObject.getModel()));
|
// Only need to clone models for editable objects.
|
||||||
|
cache[id] = isEditable(domainObject) ?
|
||||||
|
clone(domainObject.getModel()) :
|
||||||
|
domainObject.getModel();
|
||||||
|
}
|
||||||
|
|
||||||
|
return cache[id];
|
||||||
};
|
};
|
||||||
|
|
||||||
return EditableModelCache;
|
return EditableModelCache;
|
||||||
|
Reference in New Issue
Block a user