mirror of
https://github.com/nasa/openmct.git
synced 2025-02-20 17:33:23 +00:00
Resolved Merge conflicts, removed previously deleted files
This commit is contained in:
parent
bd686790dc
commit
cf9eb3f602
@ -199,11 +199,7 @@ define([
|
||||
"implementation": CancelAction,
|
||||
"name": "Cancel",
|
||||
"description": "Discard changes made to these objects.",
|
||||
"depends": [
|
||||
"$injector",
|
||||
"navigationService",
|
||||
"$window"
|
||||
]
|
||||
"depends": []
|
||||
}
|
||||
],
|
||||
"policies": [
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
);
|
@ -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
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
@ -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;
|
||||
};
|
||||
}
|
||||
);
|
@ -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
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
@ -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;
|
||||
};
|
||||
}
|
||||
);
|
@ -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;
|
||||
}
|
||||
);
|
@ -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
|
||||
);
|
||||
};
|
||||
}
|
||||
);
|
@ -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,
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
);
|
@ -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<DomainObject>} 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;
|
||||
}
|
||||
);
|
||||
|
@ -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;
|
||||
}
|
||||
);
|
@ -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;
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -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);
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
@ -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.
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -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));
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -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);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
);
|
@ -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();
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
@ -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));
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
);
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user