mirror of
https://github.com/nasa/openmct.git
synced 2025-06-25 18:50:11 +00:00
Compare commits
131 Commits
api-proto
...
api-tutori
Author | SHA1 | Date | |
---|---|---|---|
d475d767d5 | |||
a63e053399 | |||
5de7a96ccc | |||
09a833f524 | |||
9c4e17bfab | |||
d3e5d95d6b | |||
c70793ac2d | |||
a6ef1d3423 | |||
c4fec1af6a | |||
a6996df3df | |||
0c660238f2 | |||
b73b824e55 | |||
1954d98628 | |||
7aa034ce23 | |||
385dc5d298 | |||
a88b4b31a1 | |||
04112956cf | |||
f1113fda24 | |||
33c208d8fe | |||
c557fb6cd5 | |||
bde2bc7709 | |||
5fe759aa91 | |||
a5b7badb95 | |||
eefd4c8669 | |||
7c11f2db4f | |||
7501f679f7 | |||
52e087d8f8 | |||
c5cd495fce | |||
37a417051d | |||
97d819739c | |||
3935378b0c | |||
952f95aa4c | |||
0a75a5be1f | |||
70b593e28a | |||
ed69a65f9b | |||
05b4f5401e | |||
2ff0c7b06a | |||
2330f1d135 | |||
ff92d3acab | |||
32d7187db6 | |||
00534f8af7 | |||
3795570938 | |||
362248a02e | |||
16d20eabd2 | |||
eb5566f041 | |||
757da1dff4 | |||
85432af187 | |||
f0ab817e87 | |||
96af931c0b | |||
9a5209f7c2 | |||
0818a7cda0 | |||
f35947361c | |||
9a8bcc0550 | |||
eff46b076c | |||
ab64b682c3 | |||
1c007ea256 | |||
6c1412784b | |||
6e7f4df5e3 | |||
5b6ea600ba | |||
fd9d766913 | |||
b6502e9ea1 | |||
25a2321578 | |||
6fb36374f6 | |||
9861e63589 | |||
bce5643994 | |||
ad5691142e | |||
e468080373 | |||
c98c36753c | |||
1419ff86e8 | |||
601bc03ba2 | |||
ea454d65bb | |||
776586ae25 | |||
78bf804e02 | |||
2a4004fd5b | |||
b5229d7786 | |||
20ecf168f2 | |||
dc348f33c5 | |||
b7cfaf6b63 | |||
34d5bc4f28 | |||
e4b192001f | |||
516b8c9e38 | |||
f9631ff4c5 | |||
fa77139077 | |||
f12b9704d9 | |||
edb158f2d3 | |||
b2c6db6207 | |||
bcdd835275 | |||
5b4952d4c6 | |||
de43aa81be | |||
5eff4e45c9 | |||
70a13a75d5 | |||
dcf26d3863 | |||
a729edd399 | |||
69cc1086df | |||
18fa9aeaf6 | |||
96892722a4 | |||
54a0de4a08 | |||
a11dba88b2 | |||
d08cdfba49 | |||
031a46aa8e | |||
ffacf6e1ae | |||
69c4c3a2c8 | |||
c305fba0a7 | |||
44f4a82fa1 | |||
5bf750c90c | |||
836b5db8cf | |||
1753a5473c | |||
d00e13e4ee | |||
4b786d3536 | |||
e6bbc3442b | |||
433dd87e51 | |||
cf9eb3f602 | |||
bd686790dc | |||
e5ef7c0c22 | |||
3d891073da | |||
116c6e57ed | |||
a39ce566d1 | |||
671ba66354 | |||
a5ba72582c | |||
73c2c01def | |||
7c82e31b66 | |||
a58fe1f81c | |||
2829b8d495 | |||
3727b287a1 | |||
c448753bab | |||
7ade873365 | |||
8788523c25 | |||
c301523156 | |||
2e8604e18d | |||
cae85f3e30 | |||
ab6ef22363 |
4
.jscsrc
4
.jscsrc
@ -1,3 +1,5 @@
|
||||
{
|
||||
"preset": "crockford"
|
||||
"preset": "crockford",
|
||||
"requireMultipleVarDecl": false,
|
||||
"requireVarDeclFirst": false
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
"eqeqeq": true,
|
||||
"forin": true,
|
||||
"freeze": true,
|
||||
"funcscope": true,
|
||||
"funcscope": false,
|
||||
"futurehostile": true,
|
||||
"latedef": true,
|
||||
"noarg": true,
|
||||
@ -16,6 +16,7 @@
|
||||
"define",
|
||||
"Promise"
|
||||
],
|
||||
"shadow": "outer",
|
||||
"strict": "implied",
|
||||
"undef": true,
|
||||
"unused": "vars"
|
||||
|
@ -18,6 +18,8 @@
|
||||
"node-uuid": "^1.4.7",
|
||||
"comma-separated-values": "^3.6.4",
|
||||
"FileSaver.js": "^0.0.2",
|
||||
"zepto": "^1.1.6"
|
||||
"zepto": "^1.1.6",
|
||||
"eventemitter3": "^1.2.0",
|
||||
"lodash": "3.10.1"
|
||||
}
|
||||
}
|
||||
|
@ -22,17 +22,19 @@
|
||||
#* at runtime from the About dialog for additional information.
|
||||
#*****************************************************************************
|
||||
|
||||
# Script to build and deploy docs to github pages.
|
||||
# Script to build and deploy docs.
|
||||
|
||||
OUTPUT_DIRECTORY="target/docs"
|
||||
REPOSITORY_URL="git@github.com:nasa/openmctweb.git"
|
||||
# Docs, once built, are pushed to the private website repo
|
||||
REPOSITORY_URL="git@github.com:nasa/openmct-website.git"
|
||||
WEBSITE_DIRECTORY="website"
|
||||
|
||||
BUILD_SHA=`git rev-parse head`
|
||||
BUILD_SHA=`git rev-parse HEAD`
|
||||
|
||||
# A remote will be created for the git repository we are pushing to.
|
||||
# Don't worry, as this entire directory will get trashed inbetween builds.
|
||||
REMOTE_NAME="documentation"
|
||||
WEBSITE_BRANCH="gh-pages"
|
||||
WEBSITE_BRANCH="master"
|
||||
|
||||
# Clean output directory, JSDOC will recreate
|
||||
if [ -d $OUTPUT_DIRECTORY ]; then
|
||||
@ -40,23 +42,21 @@ if [ -d $OUTPUT_DIRECTORY ]; then
|
||||
fi
|
||||
|
||||
npm run docs
|
||||
cd $OUTPUT_DIRECTORY || exit 1
|
||||
|
||||
echo "git init"
|
||||
git init
|
||||
echo "git clone $REPOSITORY_URL website"
|
||||
git clone $REPOSITORY_URL website || exit 1
|
||||
echo "cp -r $OUTPUT_DIRECTORY $WEBSITE_DIRECTORY/docs"
|
||||
cp -r $OUTPUT_DIRECTORY $WEBSITE_DIRECTORY/docs
|
||||
echo "cd $WEBSITE_DIRECTORY"
|
||||
cd $WEBSITE_DIRECTORY || exit 1
|
||||
|
||||
# Configure github for CircleCI user.
|
||||
git config user.email "buildbot@circleci.com"
|
||||
git config user.name "BuildBot"
|
||||
|
||||
echo "git remote add $REMOTE_NAME $REPOSITORY_URL"
|
||||
git remote add $REMOTE_NAME $REPOSITORY_URL
|
||||
echo "git add ."
|
||||
git add .
|
||||
echo "git commit -m \"Generate docs from build $BUILD_SHA\""
|
||||
git commit -m "Generate docs from build $BUILD_SHA"
|
||||
|
||||
echo "git push $REMOTE_NAME HEAD:$WEBSITE_BRANCH -f"
|
||||
git push $REMOTE_NAME HEAD:$WEBSITE_BRANCH -f
|
||||
|
||||
echo "Documentation pushed to gh-pages branch."
|
||||
echo "git commit -m \"Docs updated from build $BUILD_SHA\""
|
||||
git commit -m "Docs updated from build $BUILD_SHA"
|
||||
# Push to the website repo
|
||||
git push
|
||||
|
13
circle.yml
13
circle.yml
@ -1,8 +1,11 @@
|
||||
deployment:
|
||||
production:
|
||||
branch: master
|
||||
heroku:
|
||||
appname: openmctweb-demo
|
||||
commands:
|
||||
- npm install canvas nomnoml
|
||||
- ./build-docs.sh
|
||||
- git fetch --unshallow
|
||||
- git push git@heroku.com:openmctweb-demo.git $CIRCLE_SHA1:refs/heads/master
|
||||
openmct-demo:
|
||||
branch: live_demo
|
||||
heroku:
|
||||
@ -14,3 +17,9 @@ deployment:
|
||||
test:
|
||||
post:
|
||||
- gulp lint
|
||||
- gulp checkstyle
|
||||
|
||||
general:
|
||||
branches:
|
||||
ignore:
|
||||
- gh-pages
|
||||
|
@ -1,9 +1,3 @@
|
||||
<hr>
|
||||
<cite>
|
||||
This document is styled using
|
||||
<a href="https://github.com/jasonm23/markdown-css-themes">
|
||||
https://github.com/jasonm23/markdown-css-themes
|
||||
</a>.
|
||||
</cite>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,7 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
<link rel="stylesheet"
|
||||
href="http://jasonm23.github.io/markdown-css-themes/avenir-white.css">
|
||||
href="//nasa.github.io/openmct/static/res/css/styles.css">
|
||||
<link rel="stylesheet"
|
||||
href="//nasa.github.io/openmct/static/res/css/documentation.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
58
example/eventGenerator/data/transcript.json
Normal file
58
example/eventGenerator/data/transcript.json
Normal file
@ -0,0 +1,58 @@
|
||||
[
|
||||
"CC: Eagle, Houston. You're GO for landing. Over.",
|
||||
"LMP: Roger. Understand. GO for landing. 3000 feet. PROGRAM ALARM.",
|
||||
"CC: Copy.",
|
||||
"LMP: 1201",
|
||||
"CDR: 1201.",
|
||||
"CC: Roger. 1201 alarm. We're GO. Same type. We're GO.",
|
||||
"LMP: 2000 feet. 2000 feet, Into the AGS, 47 degrees.",
|
||||
"CC: Roger.",
|
||||
"LMP: 47 degrees.",
|
||||
"CC: Eagle, looking great. You're GO.",
|
||||
"CC: Roger. 1202. We copy it.",
|
||||
"O1: LMP 35 degrees. 35 degrees. 750. Coming aown to 23.fl",
|
||||
"LMP: 700 feet, 21 down, 33 degrees.",
|
||||
"LMP: 600 feet, down at 19.",
|
||||
"LMP: 540 feet, down at - 30. Down at 15.",
|
||||
"LMP: At 400 feet, down at 9.",
|
||||
"LMP: ...forward.",
|
||||
"LMP: 350 feet, down at 4.",
|
||||
"LMP: 30, ... one-half down.",
|
||||
"LMP: We're pegged on horizontal velocity.",
|
||||
"LMP: 300 feet, down 3 1/2, 47 forward.",
|
||||
"LMP: ... up.",
|
||||
"LMP: On 1 a minute, 1 1/2 down.",
|
||||
"CDR: 70.",
|
||||
"LMP: Watch your shadow out there.",
|
||||
"LMP: 50, down at 2 1/2, 19 forward.",
|
||||
"LMP: Altitude-velocity light.",
|
||||
"LMP: 3 1/2 down s 220 feet, 13 forward.",
|
||||
"LMP: 1t forward. Coming down nicely.",
|
||||
"LMP: 200 feet, 4 1/2 down.",
|
||||
"LMP: 5 1/2 down.",
|
||||
"LMP: 160, 6 - 6 1/2 down.",
|
||||
"LMP: 5 1/2 down, 9 forward. That's good.",
|
||||
"LMP: 120 feet.",
|
||||
"LMP: 100 feet, 3 1/2 down, 9 forward. Five percent.",
|
||||
"LMP: ...",
|
||||
"LMP: Okay. 75 feet. There's looking good. Down a half, 6 forward.",
|
||||
"CC: 60 seconds.",
|
||||
"LMP: Lights on. ...",
|
||||
"LMP: Down 2 1/2. Forward. Forward. Good.",
|
||||
"LMP: 40 feet, down 2 1/2. Kicking up some dust.",
|
||||
"LMP: 30 feet, 2 1/2 down. Faint shadow.",
|
||||
"LMP: 4 forward. 4 forward. Drifting to the right a little. Okay. Down a half.",
|
||||
"CC: 30 seconds.",
|
||||
"CDR: Forward drift?",
|
||||
"LMP: Yes.",
|
||||
"LMP: Okay.",
|
||||
"LMP: CONTACT LIGHT.",
|
||||
"LMP: Okay. ENGINE STOP.",
|
||||
"LMP: ACA - out of DETENT.",
|
||||
"CDR: Out of DETENT.",
|
||||
"LMP: MODE CONTROL - both AUTO. DESCENT ENGINE COMMAND OVERRIDE - OFF. ENGINE ARM - OFF.",
|
||||
"LMP: 413 is in.",
|
||||
"CC: We copy you down, Eagle.",
|
||||
"CDR: Houston, Tranquility Base here.",
|
||||
"CDR: THE EAGLE HAS LANDED."
|
||||
]
|
@ -27,45 +27,12 @@
|
||||
* Modified by shale on 06/23/2015.
|
||||
*/
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
['text!../data/transcript.json'],
|
||||
function (transcript) {
|
||||
"use strict";
|
||||
|
||||
var
|
||||
firstObservedTime = Date.now(),
|
||||
messages = [];
|
||||
|
||||
messages.push(["CMD: SYS- MSG: Open the pod bay doors, please, Hal...Open the pod bay doors, please, Hal...Hullo, Hal, do you read me?...Hullo, Hal, do you read me?...Do you read me, Hal?"]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: Affirmative, Dave, I read you."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: Open the pod bay doors, Hal."]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: I'm sorry, Dave, I'm afraid I can't do that."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: What's the problem?"]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: I think you know what the problem is just as well as I do."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: What're you talking about, Hal?"]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: This mission is too important for me to allow you to jeopardise it."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: I don't know what you're talking about, Hal."]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: I know that you and Frank were planning to disconnect me, and I'm afraid that's something I cannot allow to happen."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: Where the hell'd you get that idea, Hal?"]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: Dave, although you took very thorough precautions in the pod against my hearing you, I could see your lips move."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: Alright, I'll go in through the emergency airlock."]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: Without your space-helmet, Dave, you're going to find that rather difficult."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: Hal, I won't argue with you any more. Open the doors."]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: Dave, this conversation can serve no purpose any more. Goodbye."]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: I hope the two of you are not concerned about this."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: No, I'm not, Hal."]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: Are you quite sure?"]);
|
||||
messages.push(["CMD: SYS-COMM MSG: Yeh. I'd like to ask you a question, though."]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: Of course."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: How would you account for this discrepancy between you and the twin 9000?"]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: Well, I don't think there is any question about it. It can only be attributable to human error. This sort of thing has cropped up before, and it has always been due to human error."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: Listen, There's never been any instance at all of a computer error occurring in the 9000 series, has there?"]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: None whatsoever, The 9000 series has a perfect operational record."]);
|
||||
messages.push(["CMD: SYS-COMM MSG: Well, of course, I know all the wonderful achievements of the 9000 series, but - er - huh - are you certain there's never been any case of even the most insignificant computer error?"]);
|
||||
messages.push(["RESP: SYS-HAL9K MSG: None whatsoever, Quite honestly, I wouldn't worry myself about that."]);
|
||||
messages.push(["RESP: SYS-COMM MSG: (Pause) Well, I'm sure you're right, Umm - fine, thanks very much. Oh, Frank, I'm having a bit of trouble with my transmitter in C-pod, I wonder if you'd come down and take a look at it with me?"]);
|
||||
messages.push(["CMD: SYS-HAL9K MSG: Sure."]);
|
||||
messages.push(["RESP: SYS-COMM MSG: See you later, Hal."]);
|
||||
|
||||
var firstObservedTime = Date.now(),
|
||||
messages = JSON.parse(transcript);
|
||||
|
||||
function EventTelemetry(request, interval) {
|
||||
|
||||
@ -85,8 +52,7 @@ define(
|
||||
generatorData.getRangeValue = function (i, range) {
|
||||
var domainDelta = this.getDomainValue(i) - firstObservedTime,
|
||||
ind = i % messages.length;
|
||||
return "TEMP " + i.toString() + "-" + messages[ind][0] + "[" + domainDelta.toString() + "]";
|
||||
// TODO: Unsure why we are prepeding 'TEMP'
|
||||
return messages[ind] + " - [" + domainDelta.toString() + "]";
|
||||
};
|
||||
|
||||
return generatorData;
|
||||
|
@ -45,11 +45,12 @@ define(
|
||||
function buildTaxonomy(dictionary){
|
||||
var models = {};
|
||||
|
||||
function addMeasurement(measurement){
|
||||
function addMeasurement(measurement, parent){
|
||||
var format = FORMAT_MAPPINGS[measurement.type];
|
||||
models[makeId(measurement)] = {
|
||||
type: "msl.measurement",
|
||||
name: measurement.name,
|
||||
location: parent,
|
||||
telemetry: {
|
||||
key: measurement.identifier,
|
||||
ranges: [{
|
||||
@ -62,17 +63,24 @@ define(
|
||||
};
|
||||
}
|
||||
|
||||
function addInstrument(subsystem) {
|
||||
var measurements = (subsystem.measurements || []);
|
||||
models[makeId(subsystem)] = {
|
||||
function addInstrument(subsystem, spacecraftId) {
|
||||
var measurements = (subsystem.measurements || []),
|
||||
instrumentId = makeId(subsystem);
|
||||
|
||||
models[instrumentId] = {
|
||||
type: "msl.instrument",
|
||||
name: subsystem.name,
|
||||
location: spacecraftId,
|
||||
composition: measurements.map(makeId)
|
||||
};
|
||||
measurements.forEach(addMeasurement);
|
||||
measurements.forEach(function(measurement) {
|
||||
addMeasurement(measurement, instrumentId);
|
||||
});
|
||||
}
|
||||
|
||||
(dictionary.instruments || []).forEach(addInstrument);
|
||||
(dictionary.instruments || []).forEach(function(instrument) {
|
||||
addInstrument(instrument, "msl:curiosity");
|
||||
});
|
||||
return models;
|
||||
}
|
||||
|
||||
|
@ -147,6 +147,6 @@ gulp.task('develop', ['serve', 'stylesheets', 'watch']);
|
||||
|
||||
gulp.task('install', [ 'static', 'scripts' ]);
|
||||
|
||||
gulp.task('verify', [ 'lint', 'test' ]);
|
||||
gulp.task('verify', [ 'lint', 'test', 'checkstyle' ]);
|
||||
|
||||
gulp.task('build', [ 'verify', 'install' ]);
|
||||
|
11
index.html
11
index.html
@ -31,10 +31,17 @@
|
||||
<script type="text/javascript">
|
||||
require(['main'], function (mct) {
|
||||
require([
|
||||
'./tutorials/grootprovider/groots',
|
||||
'./tutorials/todo/todo',
|
||||
'./tutorials/todo/bundle',
|
||||
'./example/imagery/bundle',
|
||||
'./example/eventGenerator/bundle',
|
||||
'./example/generator/bundle'
|
||||
], mct.run.bind(mct));
|
||||
'./example/generator/bundle',
|
||||
], function (grootify, todoPlugin) {
|
||||
grootify(mct);
|
||||
todoPlugin(mct);
|
||||
mct.start();
|
||||
})
|
||||
});
|
||||
</script>
|
||||
<link rel="stylesheet" href="platform/commonUI/general/res/css/startup-base.css">
|
||||
|
29
main.js
29
main.js
@ -28,23 +28,28 @@ requirejs.config({
|
||||
"angular-route": "bower_components/angular-route/angular-route.min",
|
||||
"csv": "bower_components/comma-separated-values/csv.min",
|
||||
"es6-promise": "bower_components/es6-promise/promise.min",
|
||||
"EventEmitter": "bower_components/eventemitter3/index",
|
||||
"moment": "bower_components/moment/moment",
|
||||
"moment-duration-format": "bower_components/moment-duration-format/lib/moment-duration-format",
|
||||
"saveAs": "bower_components/FileSaver.js/FileSaver.min",
|
||||
"screenfull": "bower_components/screenfull/dist/screenfull.min",
|
||||
"text": "bower_components/text/text",
|
||||
"uuid": "bower_components/node-uuid/uuid",
|
||||
"zepto": "bower_components/zepto/zepto.min"
|
||||
"zepto": "bower_components/zepto/zepto.min",
|
||||
"lodash": "bower_components/lodash/lodash"
|
||||
},
|
||||
"shim": {
|
||||
"angular": {
|
||||
"exports": "angular"
|
||||
},
|
||||
"angular-route": {
|
||||
"deps": [ "angular" ]
|
||||
"deps": ["angular"]
|
||||
},
|
||||
"EventEmitter": {
|
||||
"exports": "EventEmitter"
|
||||
},
|
||||
"moment-duration-format": {
|
||||
"deps": [ "moment" ]
|
||||
"deps": ["moment"]
|
||||
},
|
||||
"screenfull": {
|
||||
"exports": "screenfull"
|
||||
@ -58,6 +63,7 @@ requirejs.config({
|
||||
define([
|
||||
'./platform/framework/src/Main',
|
||||
'legacyRegistry',
|
||||
'./src/MCT',
|
||||
|
||||
'./platform/framework/bundle',
|
||||
'./platform/core/bundle',
|
||||
@ -93,11 +99,14 @@ define([
|
||||
'./platform/search/bundle',
|
||||
'./platform/status/bundle',
|
||||
'./platform/commonUI/regions/bundle'
|
||||
], function (Main, legacyRegistry) {
|
||||
return {
|
||||
legacyRegistry: legacyRegistry,
|
||||
run: function () {
|
||||
return new Main().run(legacyRegistry);
|
||||
}
|
||||
};
|
||||
], function (Main, legacyRegistry, MCT) {
|
||||
var mct = new MCT();
|
||||
|
||||
mct.legacyRegistry = legacyRegistry;
|
||||
mct.run = mct.start;
|
||||
mct.on('start', function () {
|
||||
return new Main().run(legacyRegistry);
|
||||
});
|
||||
|
||||
return mct;
|
||||
});
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "openmct",
|
||||
"version": "0.10.1-SNAPSHOT",
|
||||
"version": "0.10.2-SNAPSHOT",
|
||||
"description": "The Open MCT core platform",
|
||||
"dependencies": {
|
||||
"express": "^4.13.1",
|
||||
|
@ -55,4 +55,4 @@ define(
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -46,4 +46,4 @@ define(
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -48,4 +48,4 @@ define(
|
||||
});
|
||||
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -24,23 +24,14 @@ define([
|
||||
"./src/BrowseController",
|
||||
"./src/PaneController",
|
||||
"./src/BrowseObjectController",
|
||||
"./src/creation/CreateMenuController",
|
||||
"./src/creation/LocatorController",
|
||||
"./src/MenuArrowController",
|
||||
"./src/navigation/NavigationService",
|
||||
"./src/creation/CreationPolicy",
|
||||
"./src/navigation/NavigateAction",
|
||||
"./src/windowing/NewTabAction",
|
||||
"./src/windowing/FullscreenAction",
|
||||
"./src/creation/CreateActionProvider",
|
||||
"./src/creation/AddActionProvider",
|
||||
"./src/creation/CreationService",
|
||||
"./src/windowing/WindowTitler",
|
||||
"text!./res/templates/browse.html",
|
||||
"text!./res/templates/create/locator.html",
|
||||
"text!./res/templates/browse-object.html",
|
||||
"text!./res/templates/create/create-button.html",
|
||||
"text!./res/templates/create/create-menu.html",
|
||||
"text!./res/templates/items/grid-item.html",
|
||||
"text!./res/templates/browse/object-header.html",
|
||||
"text!./res/templates/menu-arrow.html",
|
||||
@ -53,23 +44,14 @@ define([
|
||||
BrowseController,
|
||||
PaneController,
|
||||
BrowseObjectController,
|
||||
CreateMenuController,
|
||||
LocatorController,
|
||||
MenuArrowController,
|
||||
NavigationService,
|
||||
CreationPolicy,
|
||||
NavigateAction,
|
||||
NewTabAction,
|
||||
FullscreenAction,
|
||||
CreateActionProvider,
|
||||
AddActionProvider,
|
||||
CreationService,
|
||||
WindowTitler,
|
||||
browseTemplate,
|
||||
locatorTemplate,
|
||||
browseObjectTemplate,
|
||||
createButtonTemplate,
|
||||
createMenuTemplate,
|
||||
gridItemTemplate,
|
||||
objectHeaderTemplate,
|
||||
menuArrowTemplate,
|
||||
@ -136,22 +118,6 @@ define([
|
||||
"$route"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "CreateMenuController",
|
||||
"implementation": CreateMenuController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "LocatorController",
|
||||
"implementation": LocatorController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout",
|
||||
"objectService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "MenuArrowController",
|
||||
"implementation": MenuArrowController,
|
||||
@ -160,12 +126,6 @@ define([
|
||||
]
|
||||
}
|
||||
],
|
||||
"controls": [
|
||||
{
|
||||
"key": "locator",
|
||||
"template": locatorTemplate
|
||||
}
|
||||
],
|
||||
"representations": [
|
||||
{
|
||||
"key": "view-object",
|
||||
@ -181,17 +141,6 @@ define([
|
||||
"view"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "create-button",
|
||||
"template": createButtonTemplate
|
||||
},
|
||||
{
|
||||
"key": "create-menu",
|
||||
"template": createMenuTemplate,
|
||||
"uses": [
|
||||
"action"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "grid-item",
|
||||
"template": gridItemTemplate,
|
||||
@ -244,12 +193,6 @@ define([
|
||||
"implementation": NavigationService
|
||||
}
|
||||
],
|
||||
"policies": [
|
||||
{
|
||||
"implementation": CreationPolicy,
|
||||
"category": "creation"
|
||||
}
|
||||
],
|
||||
"actions": [
|
||||
{
|
||||
"key": "navigate",
|
||||
@ -302,42 +245,6 @@ define([
|
||||
"editable": false
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"key": "CreateActionProvider",
|
||||
"provides": "actionService",
|
||||
"type": "provider",
|
||||
"implementation": CreateActionProvider,
|
||||
"depends": [
|
||||
"$q",
|
||||
"typeService",
|
||||
"navigationService",
|
||||
"policyService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "AddActionProvider",
|
||||
"provides": "actionService",
|
||||
"type": "provider",
|
||||
"implementation": AddActionProvider,
|
||||
"depends": [
|
||||
"$q",
|
||||
"typeService",
|
||||
"dialogService",
|
||||
"policyService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "CreationService",
|
||||
"provides": "creationService",
|
||||
"type": "provider",
|
||||
"implementation": CreationService,
|
||||
"depends": [
|
||||
"$q",
|
||||
"$log"
|
||||
]
|
||||
}
|
||||
],
|
||||
"runs": [
|
||||
{
|
||||
"implementation": WindowTitler,
|
||||
|
@ -26,5 +26,5 @@
|
||||
<mct-representation
|
||||
key="'menu-arrow'"
|
||||
mct-object='domainObject'
|
||||
class="flex-elem"></mct-representation>
|
||||
class="flex-elem context-available-w"></mct-representation>
|
||||
</span>
|
@ -41,13 +41,13 @@ define(
|
||||
* @constructor
|
||||
*/
|
||||
function BrowseController(
|
||||
$scope,
|
||||
$route,
|
||||
$location,
|
||||
$window,
|
||||
objectService,
|
||||
navigationService,
|
||||
urlService,
|
||||
$scope,
|
||||
$route,
|
||||
$location,
|
||||
$window,
|
||||
objectService,
|
||||
navigationService,
|
||||
urlService,
|
||||
policyService,
|
||||
defaultPath
|
||||
) {
|
||||
@ -80,12 +80,12 @@ define(
|
||||
function setNavigation(domainObject) {
|
||||
var navigationAllowed = true;
|
||||
|
||||
if (domainObject === $scope.navigatedObject){
|
||||
if (domainObject === $scope.navigatedObject) {
|
||||
//do nothing;
|
||||
return;
|
||||
}
|
||||
|
||||
policyService.allow("navigation", $scope.navigatedObject, domainObject, function(message){
|
||||
policyService.allow("navigation", $scope.navigatedObject, domainObject, function (message) {
|
||||
navigationAllowed = $window.confirm(message + "\r\n\r\n" +
|
||||
" Are you sure you want to continue?");
|
||||
});
|
||||
|
@ -33,7 +33,7 @@ define(
|
||||
function BrowseObjectController($scope, $location, $route) {
|
||||
var navigatedObject;
|
||||
function setViewForDomainObject(domainObject) {
|
||||
|
||||
|
||||
var locationViewKey = $location.search().view;
|
||||
|
||||
function selectViewIfMatching(view) {
|
||||
@ -70,7 +70,7 @@ define(
|
||||
$scope.$watch('domainObject', setViewForDomainObject);
|
||||
$scope.$watch('representation.selected.key', updateQueryParam);
|
||||
|
||||
$scope.doAction = function (action){
|
||||
$scope.doAction = function (action) {
|
||||
return $scope[action] && $scope[action]();
|
||||
};
|
||||
|
||||
|
@ -45,7 +45,7 @@ define(
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
InspectorRegion.prototype.buildRegion = function() {
|
||||
InspectorRegion.prototype.buildRegion = function () {
|
||||
var metadataRegion = {
|
||||
name: 'metadata',
|
||||
title: 'Metadata Region',
|
||||
|
@ -26,11 +26,11 @@
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
|
||||
|
||||
/**
|
||||
* A left-click on the menu arrow should display a
|
||||
* context menu. This controller launches the context
|
||||
* menu.
|
||||
* A left-click on the menu arrow should display a
|
||||
* context menu. This controller launches the context
|
||||
* menu.
|
||||
* @memberof platform/commonUI/browse
|
||||
* @constructor
|
||||
*/
|
||||
|
@ -78,12 +78,12 @@ define(
|
||||
|
||||
mockScope = jasmine.createSpyObj(
|
||||
"$scope",
|
||||
[ "$on", "$watch" ]
|
||||
["$on", "$watch"]
|
||||
);
|
||||
mockRoute = { current: { params: {} } };
|
||||
mockLocation = jasmine.createSpyObj(
|
||||
"$location",
|
||||
[ "path" ]
|
||||
["path"]
|
||||
);
|
||||
mockUrlService = jasmine.createSpyObj(
|
||||
"urlService",
|
||||
@ -91,7 +91,7 @@ define(
|
||||
);
|
||||
mockObjectService = jasmine.createSpyObj(
|
||||
"objectService",
|
||||
[ "getObjects" ]
|
||||
["getObjects"]
|
||||
);
|
||||
mockNavigationService = jasmine.createSpyObj(
|
||||
"navigationService",
|
||||
@ -104,15 +104,15 @@ define(
|
||||
);
|
||||
mockRootObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getCapability", "getModel", "useCapability" ]
|
||||
["getId", "getCapability", "getModel", "useCapability"]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getCapability", "getModel", "useCapability" ]
|
||||
["getId", "getCapability", "getModel", "useCapability"]
|
||||
);
|
||||
mockNextObject = jasmine.createSpyObj(
|
||||
"nextObject",
|
||||
[ "getId", "getCapability", "getModel", "useCapability" ]
|
||||
["getId", "getCapability", "getModel", "useCapability"]
|
||||
);
|
||||
|
||||
mockObjectService.getObjects.andReturn(mockPromise({
|
||||
@ -255,7 +255,7 @@ define(
|
||||
" object", function () {
|
||||
mockScope.navigatedObject = mockDomainObject;
|
||||
mockWindow.confirm.andReturn(false);
|
||||
mockPolicyService.allow.andCallFake(function(category, object, context, callback){
|
||||
mockPolicyService.allow.andCallFake(function (category, object, context, callback) {
|
||||
callback("unsaved changes");
|
||||
return false;
|
||||
});
|
||||
|
@ -44,12 +44,12 @@ define(
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj(
|
||||
"$scope",
|
||||
[ "$on", "$watch" ]
|
||||
["$on", "$watch"]
|
||||
);
|
||||
mockRoute = { current: { params: {} } };
|
||||
mockLocation = jasmine.createSpyObj(
|
||||
"$location",
|
||||
[ "path", "search" ]
|
||||
["path", "search"]
|
||||
);
|
||||
mockUnlisten = jasmine.createSpy("unlisten");
|
||||
|
||||
@ -69,7 +69,7 @@ define(
|
||||
// Allows the path index to be checked
|
||||
// prior to setting $route.current
|
||||
mockLocation.path.andReturn("/browse/");
|
||||
|
||||
|
||||
// Exercise the Angular workaround
|
||||
mockScope.$on.mostRecentCall.args[1]();
|
||||
expect(mockUnlisten).toHaveBeenCalled();
|
||||
|
@ -40,4 +40,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -26,7 +26,7 @@
|
||||
define(
|
||||
["../src/MenuArrowController"],
|
||||
function (MenuArrowController) {
|
||||
|
||||
|
||||
describe("The menu arrow controller ", function () {
|
||||
var mockScope,
|
||||
mockDomainObject,
|
||||
@ -34,43 +34,43 @@ define(
|
||||
mockContextMenuAction,
|
||||
mockActionContext,
|
||||
controller;
|
||||
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj(
|
||||
"$scope",
|
||||
[ "" ]
|
||||
[""]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getCapability" ]
|
||||
["getCapability"]
|
||||
);
|
||||
mockEvent = jasmine.createSpyObj(
|
||||
"event",
|
||||
[ "preventDefault" ]
|
||||
["preventDefault"]
|
||||
);
|
||||
mockContextMenuAction = jasmine.createSpyObj(
|
||||
"action",
|
||||
[ "perform", "getActions" ]
|
||||
["perform", "getActions"]
|
||||
);
|
||||
mockActionContext = jasmine.createSpyObj(
|
||||
"actionContext",
|
||||
[ "" ]
|
||||
[""]
|
||||
);
|
||||
|
||||
|
||||
mockActionContext.domainObject = mockDomainObject;
|
||||
mockActionContext.event = mockEvent;
|
||||
mockScope.domainObject = mockDomainObject;
|
||||
mockDomainObject.getCapability.andReturn(mockContextMenuAction);
|
||||
mockContextMenuAction.perform.andReturn(jasmine.any(Function));
|
||||
|
||||
|
||||
controller = new MenuArrowController(mockScope);
|
||||
});
|
||||
|
||||
|
||||
it("calls the context menu action when clicked", function () {
|
||||
// Simulate a click on the menu arrow
|
||||
controller.showMenu(mockEvent);
|
||||
|
||||
// Expect the menu action to be performed
|
||||
|
||||
// Expect the menu action to be performed
|
||||
expect(mockDomainObject.getCapability).toHaveBeenCalledWith('action');
|
||||
expect(mockContextMenuAction.perform).toHaveBeenCalled();
|
||||
});
|
||||
|
@ -42,11 +42,11 @@ define(
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj("$scope", [ "$on" ]);
|
||||
mockScope = jasmine.createSpyObj("$scope", ["$on"]);
|
||||
mockDomainObjects = ['a', 'b'].map(function (id) {
|
||||
var mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject-' + id,
|
||||
[ 'getId', 'getModel', 'getCapability' ]
|
||||
['getId', 'getModel', 'getCapability']
|
||||
);
|
||||
|
||||
mockDomainObject.getId.andReturn(id);
|
||||
@ -56,7 +56,7 @@ define(
|
||||
});
|
||||
mockAgentService = jasmine.createSpyObj(
|
||||
"agentService",
|
||||
[ "isMobile", "isPhone", "isTablet", "isPortrait", "isLandscape" ]
|
||||
["isMobile", "isPhone", "isTablet", "isPortrait", "isLandscape"]
|
||||
);
|
||||
mockWindow = jasmine.createSpyObj("$window", ["open"]);
|
||||
});
|
||||
|
@ -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.
|
||||
*****************************************************************************/
|
||||
|
||||
/**
|
||||
* MCTRepresentationSpec. Created by vwoeltje on 11/6/14.
|
||||
*/
|
||||
define(
|
||||
["../../src/creation/CreateAction"],
|
||||
function (CreateAction) {
|
||||
|
||||
describe("The create action", function () {
|
||||
var mockType,
|
||||
mockParent,
|
||||
mockContext,
|
||||
mockDialogService,
|
||||
mockCreationService,
|
||||
action;
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockType = jasmine.createSpyObj(
|
||||
"type",
|
||||
[
|
||||
"getKey",
|
||||
"getGlyph",
|
||||
"getName",
|
||||
"getDescription",
|
||||
"getProperties",
|
||||
"getInitialModel"
|
||||
]
|
||||
);
|
||||
mockParent = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[
|
||||
"getId",
|
||||
"getModel",
|
||||
"getCapability"
|
||||
]
|
||||
);
|
||||
mockContext = {
|
||||
domainObject: mockParent
|
||||
};
|
||||
mockDialogService = jasmine.createSpyObj(
|
||||
"dialogService",
|
||||
[ "getUserInput" ]
|
||||
);
|
||||
mockCreationService = jasmine.createSpyObj(
|
||||
"creationService",
|
||||
[ "createObject" ]
|
||||
);
|
||||
|
||||
mockType.getKey.andReturn("test");
|
||||
mockType.getGlyph.andReturn("T");
|
||||
mockType.getDescription.andReturn("a test type");
|
||||
mockType.getName.andReturn("Test");
|
||||
mockType.getProperties.andReturn([]);
|
||||
mockType.getInitialModel.andReturn({});
|
||||
|
||||
mockDialogService.getUserInput.andReturn(mockPromise({}));
|
||||
|
||||
action = new CreateAction(
|
||||
mockType,
|
||||
mockParent,
|
||||
mockContext,
|
||||
mockDialogService,
|
||||
mockCreationService
|
||||
);
|
||||
});
|
||||
|
||||
it("exposes type-appropriate metadata", function () {
|
||||
var metadata = action.getMetadata();
|
||||
|
||||
expect(metadata.name).toEqual("Test");
|
||||
expect(metadata.description).toEqual("a test type");
|
||||
expect(metadata.glyph).toEqual("T");
|
||||
});
|
||||
|
||||
//TODO: Disabled for NEM Beta
|
||||
xit("invokes the creation service when performed", function () {
|
||||
action.perform();
|
||||
expect(mockCreationService.createObject).toHaveBeenCalledWith(
|
||||
{ type: "test" },
|
||||
mockParent
|
||||
);
|
||||
});
|
||||
|
||||
//TODO: Disabled for NEM Beta
|
||||
xit("does not create an object if the user cancels", function () {
|
||||
mockDialogService.getUserInput.andReturn({
|
||||
then: function (callback, fail) {
|
||||
fail();
|
||||
}
|
||||
});
|
||||
|
||||
action.perform();
|
||||
|
||||
expect(mockCreationService.createObject)
|
||||
.not.toHaveBeenCalled();
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -44,12 +44,12 @@ define(
|
||||
beforeEach(function () {
|
||||
mockNavigationService = jasmine.createSpyObj(
|
||||
"navigationService",
|
||||
[ "setNavigation" ]
|
||||
["setNavigation"]
|
||||
);
|
||||
mockQ = { when: mockPromise };
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability" ]
|
||||
["getId", "getModel", "getCapability"]
|
||||
);
|
||||
|
||||
action = new NavigateAction(
|
||||
@ -74,4 +74,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -56,4 +56,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -23,7 +23,7 @@
|
||||
define(
|
||||
["../../src/windowing/NewTabAction"],
|
||||
function (NewTabAction) {
|
||||
|
||||
|
||||
describe("The new tab action", function () {
|
||||
var actionSelected,
|
||||
actionCurrent,
|
||||
@ -37,39 +37,39 @@ define(
|
||||
|
||||
// Context if the current object is selected
|
||||
// For example, when the top right new tab
|
||||
// button is clicked, the user is using the
|
||||
// button is clicked, the user is using the
|
||||
// current domainObject
|
||||
mockContextCurrent = jasmine.createSpyObj("context", ["domainObject"]);
|
||||
|
||||
|
||||
// Context if the selected object is selected
|
||||
// For example, when an object in the left
|
||||
// tree is opened in a new tab using the
|
||||
// context menu
|
||||
mockContextSelected = jasmine.createSpyObj("context", ["selectedObject",
|
||||
"domainObject"]);
|
||||
|
||||
|
||||
// Mocks the urlService used to make the new tab's url from a
|
||||
// domainObject and mode
|
||||
mockUrlService = jasmine.createSpyObj("urlService", ["urlForNewTab"]);
|
||||
|
||||
|
||||
// Action done using the current context or mockContextCurrent
|
||||
actionCurrent = new NewTabAction(mockUrlService, mockWindow,
|
||||
mockContextCurrent);
|
||||
|
||||
|
||||
// Action done using the selected context or mockContextSelected
|
||||
actionSelected = new NewTabAction(mockUrlService, mockWindow,
|
||||
mockContextSelected);
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
it("new tab with current url is opened", function () {
|
||||
actionCurrent.perform();
|
||||
});
|
||||
|
||||
|
||||
it("new tab with a selected url is opened", function () {
|
||||
actionSelected.perform();
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -37,11 +37,11 @@ define(
|
||||
beforeEach(function () {
|
||||
mockNavigationService = jasmine.createSpyObj(
|
||||
'navigationService',
|
||||
[ 'getNavigation' ]
|
||||
['getNavigation']
|
||||
);
|
||||
mockRootScope = jasmine.createSpyObj(
|
||||
'$rootScope',
|
||||
[ '$watch' ]
|
||||
['$watch']
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
@ -75,4 +75,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -155,8 +155,8 @@ define(
|
||||
* @returns {boolean} true if dialog is currently visible, false
|
||||
* otherwise
|
||||
*/
|
||||
DialogService.prototype.canShowDialog = function(dialogModel){
|
||||
if (this.dialogVisible){
|
||||
DialogService.prototype.canShowDialog = function (dialogModel) {
|
||||
if (this.dialogVisible) {
|
||||
// Only one dialog should be shown at a time.
|
||||
// The application design should be such that
|
||||
// we never even try to do this.
|
||||
@ -224,7 +224,7 @@ define(
|
||||
* @param {typeClass} string tells overlayService that this overlay should use appropriate CSS class
|
||||
* @returns {boolean}
|
||||
*/
|
||||
DialogService.prototype.showBlockingMessage = function(dialogModel) {
|
||||
DialogService.prototype.showBlockingMessage = function (dialogModel) {
|
||||
if (this.canShowDialog(dialogModel)) {
|
||||
// Add the overlay using the OverlayService, which
|
||||
// will handle actual insertion into the DOM
|
||||
|
@ -38,23 +38,23 @@ define(
|
||||
beforeEach(function () {
|
||||
mockOverlayService = jasmine.createSpyObj(
|
||||
"overlayService",
|
||||
[ "createOverlay" ]
|
||||
["createOverlay"]
|
||||
);
|
||||
mockQ = jasmine.createSpyObj(
|
||||
"$q",
|
||||
[ "defer" ]
|
||||
["defer"]
|
||||
);
|
||||
mockLog = jasmine.createSpyObj(
|
||||
"$log",
|
||||
[ "warn", "info", "debug" ]
|
||||
["warn", "info", "debug"]
|
||||
);
|
||||
mockOverlay = jasmine.createSpyObj(
|
||||
"overlay",
|
||||
[ "dismiss" ]
|
||||
["dismiss"]
|
||||
);
|
||||
mockDeferred = jasmine.createSpyObj(
|
||||
"deferred",
|
||||
[ "resolve", "reject"]
|
||||
["resolve", "reject"]
|
||||
);
|
||||
mockDeferred.promise = "mock promise";
|
||||
|
||||
@ -120,7 +120,7 @@ define(
|
||||
});
|
||||
|
||||
it("invokes the overlay service with the correct parameters when" +
|
||||
" a blocking dialog is requested", function() {
|
||||
" a blocking dialog is requested", function () {
|
||||
var dialogModel = {};
|
||||
expect(dialogService.showBlockingMessage(dialogModel)).toBe(true);
|
||||
expect(mockOverlayService.createOverlay).toHaveBeenCalledWith(
|
||||
|
@ -38,13 +38,13 @@ define(
|
||||
overlayService;
|
||||
|
||||
beforeEach(function () {
|
||||
mockDocument = jasmine.createSpyObj("$document", [ "find" ]);
|
||||
mockDocument = jasmine.createSpyObj("$document", ["find"]);
|
||||
mockCompile = jasmine.createSpy("$compile");
|
||||
mockRootScope = jasmine.createSpyObj("$rootScope", [ "$new" ]);
|
||||
mockBody = jasmine.createSpyObj("body", [ "prepend" ]);
|
||||
mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]);
|
||||
mockBody = jasmine.createSpyObj("body", ["prepend"]);
|
||||
mockTemplate = jasmine.createSpy("template");
|
||||
mockElement = jasmine.createSpyObj("element", [ "remove" ]);
|
||||
mockScope = jasmine.createSpyObj("scope", [ "$destroy" ]);
|
||||
mockElement = jasmine.createSpyObj("element", ["remove"]);
|
||||
mockScope = jasmine.createSpyObj("scope", ["$destroy"]);
|
||||
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockCompile.andReturn(mockTemplate);
|
||||
@ -96,4 +96,4 @@ define(
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -26,7 +26,7 @@ define([
|
||||
"./src/controllers/ElementsController",
|
||||
"./src/controllers/EditObjectController",
|
||||
"./src/directives/MCTBeforeUnload",
|
||||
"./src/actions/LinkAction",
|
||||
"./src/actions/EditAndComposeAction",
|
||||
"./src/actions/EditAction",
|
||||
"./src/actions/PropertiesAction",
|
||||
"./src/actions/RemoveAction",
|
||||
@ -40,6 +40,18 @@ define([
|
||||
"./src/policies/EditContextualActionPolicy",
|
||||
"./src/representers/EditRepresenter",
|
||||
"./src/representers/EditToolbarRepresenter",
|
||||
"./src/capabilities/EditorCapability",
|
||||
"./src/capabilities/TransactionCapabilityDecorator",
|
||||
"./src/services/TransactionService",
|
||||
"./src/creation/CreateMenuController",
|
||||
"./src/creation/LocatorController",
|
||||
"./src/creation/CreationPolicy",
|
||||
"./src/creation/CreateActionProvider",
|
||||
"./src/creation/AddActionProvider",
|
||||
"./src/creation/CreationService",
|
||||
"text!./res/templates/create/locator.html",
|
||||
"text!./res/templates/create/create-button.html",
|
||||
"text!./res/templates/create/create-menu.html",
|
||||
"text!./res/templates/library.html",
|
||||
"text!./res/templates/edit-object.html",
|
||||
"text!./res/templates/edit-action-buttons.html",
|
||||
@ -52,7 +64,7 @@ define([
|
||||
ElementsController,
|
||||
EditObjectController,
|
||||
MCTBeforeUnload,
|
||||
LinkAction,
|
||||
EditAndComposeAction,
|
||||
EditAction,
|
||||
PropertiesAction,
|
||||
RemoveAction,
|
||||
@ -66,6 +78,18 @@ define([
|
||||
EditContextualActionPolicy,
|
||||
EditRepresenter,
|
||||
EditToolbarRepresenter,
|
||||
EditorCapability,
|
||||
TransactionCapabilityDecorator,
|
||||
TransactionService,
|
||||
CreateMenuController,
|
||||
LocatorController,
|
||||
CreationPolicy,
|
||||
CreateActionProvider,
|
||||
AddActionProvider,
|
||||
CreationService,
|
||||
locatorTemplate,
|
||||
createButtonTemplate,
|
||||
createMenuTemplate,
|
||||
libraryTemplate,
|
||||
editObjectTemplate,
|
||||
editActionButtonsTemplate,
|
||||
@ -106,6 +130,22 @@ define([
|
||||
"$location",
|
||||
"policyService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "CreateMenuController",
|
||||
"implementation": CreateMenuController,
|
||||
"depends": [
|
||||
"$scope"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "LocatorController",
|
||||
"implementation": LocatorController,
|
||||
"depends": [
|
||||
"$scope",
|
||||
"$timeout",
|
||||
"objectService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"directives": [
|
||||
@ -120,7 +160,7 @@ define([
|
||||
"actions": [
|
||||
{
|
||||
"key": "compose",
|
||||
"implementation": LinkAction
|
||||
"implementation": EditAndComposeAction
|
||||
},
|
||||
{
|
||||
"key": "edit",
|
||||
@ -128,8 +168,7 @@ define([
|
||||
"depends": [
|
||||
"$location",
|
||||
"navigationService",
|
||||
"$log",
|
||||
"$q"
|
||||
"$log"
|
||||
],
|
||||
"description": "Edit this object.",
|
||||
"category": "view-control",
|
||||
@ -191,10 +230,7 @@ define([
|
||||
"implementation": CancelAction,
|
||||
"name": "Cancel",
|
||||
"description": "Discard changes made to these objects.",
|
||||
"depends": [
|
||||
"$injector",
|
||||
"navigationService"
|
||||
]
|
||||
"depends": []
|
||||
}
|
||||
],
|
||||
"policies": [
|
||||
@ -217,10 +253,13 @@ define([
|
||||
},
|
||||
{
|
||||
"category": "navigation",
|
||||
"message": "There are unsaved changes.",
|
||||
"message": "Continuing will cause the loss of any unsaved changes.",
|
||||
"implementation": EditNavigationPolicy
|
||||
},
|
||||
{
|
||||
"implementation": CreationPolicy,
|
||||
"category": "creation"
|
||||
}
|
||||
|
||||
],
|
||||
"templates": [
|
||||
{
|
||||
@ -259,8 +298,73 @@ define([
|
||||
{
|
||||
"key": "topbar-edit",
|
||||
"template": topbarEditTemplate
|
||||
},
|
||||
{
|
||||
"key": "create-button",
|
||||
"template": createButtonTemplate
|
||||
},
|
||||
{
|
||||
"key": "create-menu",
|
||||
"template": createMenuTemplate,
|
||||
"uses": [
|
||||
"action"
|
||||
]
|
||||
}
|
||||
],
|
||||
"components": [
|
||||
{
|
||||
"type": "decorator",
|
||||
"provides": "capabilityService",
|
||||
"implementation": TransactionCapabilityDecorator,
|
||||
"depends": [
|
||||
"$q",
|
||||
"transactionService"
|
||||
],
|
||||
"priority": "fallback"
|
||||
},
|
||||
{
|
||||
"type": "provider",
|
||||
"provides": "transactionService",
|
||||
"implementation": TransactionService,
|
||||
"depends": [
|
||||
"$q",
|
||||
"$log"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "CreateActionProvider",
|
||||
"provides": "actionService",
|
||||
"type": "provider",
|
||||
"implementation": CreateActionProvider,
|
||||
"depends": [
|
||||
"typeService",
|
||||
"policyService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "AddActionProvider",
|
||||
"provides": "actionService",
|
||||
"type": "provider",
|
||||
"implementation": AddActionProvider,
|
||||
"depends": [
|
||||
"$q",
|
||||
"typeService",
|
||||
"dialogService",
|
||||
"policyService"
|
||||
]
|
||||
},
|
||||
{
|
||||
"key": "CreationService",
|
||||
"provides": "creationService",
|
||||
"type": "provider",
|
||||
"implementation": CreationService,
|
||||
"depends": [
|
||||
"$q",
|
||||
"$log"
|
||||
]
|
||||
}
|
||||
|
||||
],
|
||||
"representers": [
|
||||
{
|
||||
"implementation": EditRepresenter,
|
||||
@ -275,13 +379,30 @@ define([
|
||||
],
|
||||
"constants": [
|
||||
{
|
||||
"key":"editModeBlacklist",
|
||||
"key": "editModeBlacklist",
|
||||
"value": ["copy", "follow", "window", "link", "locate"]
|
||||
},
|
||||
{
|
||||
"key": "nonEditContextBlacklist",
|
||||
"value": ["copy", "follow", "properties", "move", "link", "remove", "locate"]
|
||||
}
|
||||
],
|
||||
"capabilities": [
|
||||
{
|
||||
"key": "editor",
|
||||
"name": "Editor Capability",
|
||||
"description": "Provides transactional editing capabilities",
|
||||
"implementation": EditorCapability,
|
||||
"depends": [
|
||||
"transactionService"
|
||||
]
|
||||
}
|
||||
],
|
||||
"controls": [
|
||||
{
|
||||
"key": "locator",
|
||||
"template": locatorTemplate
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,30 +42,25 @@ define(
|
||||
* cancellation has completed
|
||||
*/
|
||||
CancelAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject,
|
||||
self = this;
|
||||
var domainObject = this.domainObject;
|
||||
|
||||
// Look up the object's "editor.completion" capability;
|
||||
// this is introduced by EditableDomainObject which is
|
||||
// used to insulate underlying objects from changes made
|
||||
// during editing.
|
||||
function getEditorCapability() {
|
||||
return domainObject.getCapability("editor");
|
||||
}
|
||||
|
||||
// Invoke any save behavior introduced by the editor.completion
|
||||
// capability.
|
||||
function doCancel(editor) {
|
||||
return editor.cancel();
|
||||
}
|
||||
|
||||
//Discard current 'editable' object, and retrieve original
|
||||
// un-edited object.
|
||||
function returnToBrowse() {
|
||||
return self.navigationService.setNavigation(self.domainObject.getOriginalObject());
|
||||
}
|
||||
var parent;
|
||||
|
||||
return doCancel(getEditorCapability())
|
||||
//If the object existed already, navigate to refresh view
|
||||
// with previous object state.
|
||||
if (domainObject.getModel().persisted) {
|
||||
domainObject.getCapability("action").perform("navigate");
|
||||
} else {
|
||||
//If the object was new, and user has cancelled, then
|
||||
//navigate back to parent because nothing to show.
|
||||
domainObject.getCapability("location").getOriginal().then(function (original) {
|
||||
parent = original.getCapability("context").getParent();
|
||||
parent.getCapability("action").perform("navigate");
|
||||
});
|
||||
}
|
||||
}
|
||||
return this.domainObject.getCapability("editor").cancel()
|
||||
.then(returnToBrowse);
|
||||
};
|
||||
|
||||
@ -80,7 +73,8 @@ define(
|
||||
CancelAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
return domainObject !== undefined &&
|
||||
domainObject.hasCapability("editor");
|
||||
domainObject.hasCapability('editor') &&
|
||||
domainObject.getCapability('editor').isEditContextRoot();
|
||||
};
|
||||
|
||||
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.
|
||||
@ -44,7 +44,7 @@ define(
|
||||
* @constructor
|
||||
* @implements {Action}
|
||||
*/
|
||||
function EditAction($location, navigationService, $log, $q, context) {
|
||||
function EditAction($location, navigationService, $log, context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
|
||||
// We cannot enter Edit mode if we have no domain object to
|
||||
@ -63,7 +63,6 @@ define(
|
||||
this.domainObject = domainObject;
|
||||
this.$location = $location;
|
||||
this.navigationService = navigationService;
|
||||
this.$q = $q;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,25 +70,18 @@ define(
|
||||
*/
|
||||
EditAction.prototype.perform = function () {
|
||||
var self = this;
|
||||
if (!this.domainObject.hasCapability("editor")) {
|
||||
//TODO: This is only necessary because the drop gesture is
|
||||
// wrapping the object itself, need to refactor this later.
|
||||
// All responsibility for switching into edit mode should be
|
||||
// in the edit action, and not duplicated in the gesture
|
||||
this.domainObject = new EditableDomainObject(this.domainObject, this.$q);
|
||||
function cancelEditing() {
|
||||
self.domainObject.getCapability('editor').cancel();
|
||||
self.navigationService.removeListener(cancelEditing);
|
||||
}
|
||||
//If this is not the currently navigated object, then navigate
|
||||
// to it.
|
||||
if (this.navigationService.getNavigation() !== this.domainObject) {
|
||||
this.navigationService.setNavigation(this.domainObject);
|
||||
}
|
||||
this.navigationService.setNavigation(this.domainObject);
|
||||
this.domainObject.getCapability('status').set('editing', true);
|
||||
|
||||
//Register a listener to automatically cancel this edit action
|
||||
//if the user navigates away from this object.
|
||||
function cancelEditing(navigatedTo){
|
||||
if (!navigatedTo || navigatedTo.getId() !== self.domainObject.getId()) {
|
||||
self.domainObject.getCapability('editor').cancel();
|
||||
self.navigationService.removeListener(cancelEditing);
|
||||
}
|
||||
}
|
||||
this.navigationService.addListener(cancelEditing);
|
||||
this.domainObject.useCapability("editor");
|
||||
};
|
||||
|
||||
/**
|
||||
@ -100,11 +92,13 @@ define(
|
||||
*/
|
||||
EditAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject,
|
||||
type = domainObject && domainObject.getCapability('type'),
|
||||
isEditMode = domainObject && domainObject.getDomainObject ? true : false;
|
||||
type = domainObject && domainObject.getCapability('type');
|
||||
|
||||
// Only allow creatable types to be edited
|
||||
return type && type.hasFeature('creation') && !isEditMode;
|
||||
// Only allow editing of types that support it and are not already
|
||||
// being edited
|
||||
return type && type.hasFeature('creation') &&
|
||||
domainObject.hasCapability('editor') &&
|
||||
!domainObject.getCapability('editor').isEditContextRoot();
|
||||
};
|
||||
|
||||
return EditAction;
|
||||
|
@ -31,13 +31,14 @@ define(
|
||||
* @memberof platform/commonUI/edit
|
||||
* @implements {Action}
|
||||
*/
|
||||
function LinkAction(context) {
|
||||
function EditAndComposeAction(context) {
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.selectedObject = (context || {}).selectedObject;
|
||||
}
|
||||
|
||||
LinkAction.prototype.perform = function () {
|
||||
var self = this;
|
||||
EditAndComposeAction.prototype.perform = function () {
|
||||
var self = this,
|
||||
editAction = this.domainObject.getCapability('action').getActions("edit")[0];
|
||||
|
||||
// Persist changes to the domain object
|
||||
function doPersist() {
|
||||
@ -54,9 +55,13 @@ define(
|
||||
.then(doPersist);
|
||||
}
|
||||
|
||||
if (editAction) {
|
||||
editAction.perform();
|
||||
}
|
||||
|
||||
return this.selectedObject && doLink();
|
||||
};
|
||||
|
||||
return LinkAction;
|
||||
return EditAndComposeAction;
|
||||
}
|
||||
);
|
@ -63,10 +63,10 @@ define(
|
||||
});
|
||||
}
|
||||
|
||||
function showDialog(type) {
|
||||
function showDialog(objType) {
|
||||
// Create a dialog object to generate the form structure, etc.
|
||||
var dialog =
|
||||
new PropertiesDialog(type, domainObject.getModel());
|
||||
new PropertiesDialog(objType, domainObject.getModel());
|
||||
|
||||
// Show the dialog
|
||||
return dialogService.getUserInput(
|
||||
|
@ -75,8 +75,8 @@ define(
|
||||
* Invoke persistence on a domain object. This will be called upon
|
||||
* the removed object's parent (as its composition will have changed.)
|
||||
*/
|
||||
function doPersist(domainObject) {
|
||||
var persistence = domainObject.getCapability('persistence');
|
||||
function doPersist(domainObj) {
|
||||
var persistence = domainObj.getCapability('persistence');
|
||||
return persistence && persistence.persist();
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ define(
|
||||
SaveAction.prototype.perform = function () {
|
||||
var domainObject = this.domainObject;
|
||||
|
||||
function resolveWith(object){
|
||||
function resolveWith(object) {
|
||||
return function () {
|
||||
return object;
|
||||
};
|
||||
@ -60,7 +60,7 @@ define(
|
||||
// during editing.
|
||||
function doSave() {
|
||||
return domainObject.getCapability("editor").save()
|
||||
.then(resolveWith(domainObject.getOriginalObject()));
|
||||
.then(resolveWith(domainObject));
|
||||
}
|
||||
|
||||
// Discard the current root view (which will be the editing
|
||||
@ -85,7 +85,8 @@ define(
|
||||
SaveAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
return domainObject !== undefined &&
|
||||
domainObject.hasCapability("editor") &&
|
||||
domainObject.hasCapability('editor') &&
|
||||
domainObject.getCapability('editor').isEditContextRoot() &&
|
||||
domainObject.getModel().persisted !== undefined;
|
||||
};
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
|
||||
|
||||
define(
|
||||
['../../../browse/src/creation/CreateWizard'],
|
||||
['../creation/CreateWizard'],
|
||||
function (CreateWizard) {
|
||||
|
||||
/**
|
||||
@ -42,7 +42,7 @@ define(
|
||||
context
|
||||
) {
|
||||
this.domainObject = (context || {}).domainObject;
|
||||
this.injectObjectService = function(){
|
||||
this.injectObjectService = function () {
|
||||
this.objectService = $injector.get("objectService");
|
||||
};
|
||||
this.policyService = policyService;
|
||||
@ -65,7 +65,7 @@ define(
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
SaveAsAction.prototype.getObjectService = function(){
|
||||
SaveAsAction.prototype.getObjectService = function () {
|
||||
// Lazily acquire object service (avoids cyclical dependency)
|
||||
if (!this.objectService) {
|
||||
this.injectObjectService();
|
||||
@ -73,7 +73,7 @@ define(
|
||||
return this.objectService;
|
||||
};
|
||||
|
||||
function resolveWith(object){
|
||||
function resolveWith(object) {
|
||||
return function () {
|
||||
return object;
|
||||
};
|
||||
@ -116,13 +116,13 @@ define(
|
||||
).then(wizard.populateObjectFromInput.bind(wizard));
|
||||
}
|
||||
|
||||
function fetchObject(objectId){
|
||||
return self.getObjectService().getObjects([objectId]).then(function(objects){
|
||||
function fetchObject(objectId) {
|
||||
return self.getObjectService().getObjects([objectId]).then(function (objects) {
|
||||
return objects[objectId];
|
||||
});
|
||||
}
|
||||
|
||||
function getParent(object){
|
||||
function getParent(object) {
|
||||
return fetchObject(object.getModel().location);
|
||||
}
|
||||
|
||||
@ -135,8 +135,8 @@ define(
|
||||
return copyService.perform(domainObject, parent, allowClone);
|
||||
}
|
||||
|
||||
function cancelEditingAfterClone(clonedObject) {
|
||||
return domainObject.getCapability("editor").cancel()
|
||||
function commitEditingAfterClone(clonedObject) {
|
||||
return domainObject.getCapability("editor").save()
|
||||
.then(resolveWith(clonedObject));
|
||||
}
|
||||
|
||||
@ -144,7 +144,7 @@ define(
|
||||
.then(doWizardSave)
|
||||
.then(getParent)
|
||||
.then(cloneIntoParent)
|
||||
.then(cancelEditingAfterClone)
|
||||
.then(commitEditingAfterClone)
|
||||
.catch(resolveWith(false));
|
||||
};
|
||||
|
||||
@ -157,7 +157,8 @@ define(
|
||||
SaveAsAction.appliesTo = function (context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
return domainObject !== undefined &&
|
||||
domainObject.hasCapability("editor") &&
|
||||
domainObject.hasCapability('editor') &&
|
||||
domainObject.getCapability('editor').isEditContextRoot() &&
|
||||
domainObject.getModel().persisted === undefined;
|
||||
};
|
||||
|
||||
|
@ -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,115 +24,95 @@ define(
|
||||
[],
|
||||
function () {
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* A capability that implements an editing 'session' for a domain
|
||||
* object. An editing session is initiated via a call to .edit().
|
||||
* Once initiated, any persist operations will be queued pending a
|
||||
* subsequent call to [.save()](@link #save) or [.cancel()](@link
|
||||
* #cancel).
|
||||
* @param transactionService
|
||||
* @param domainObject
|
||||
* @constructor
|
||||
* @memberof platform/commonUI/edit
|
||||
*/
|
||||
function EditorCapability(
|
||||
persistenceCapability,
|
||||
editableObject,
|
||||
domainObject,
|
||||
cache
|
||||
transactionService,
|
||||
domainObject
|
||||
) {
|
||||
this.editableObject = editableObject;
|
||||
this.transactionService = transactionService;
|
||||
this.domainObject = domainObject;
|
||||
this.cache = cache;
|
||||
}
|
||||
|
||||
// Simulate Promise.resolve (or $q.when); the former
|
||||
// causes a delayed reaction from Angular (since it
|
||||
// does not trigger a digest) and the latter is not
|
||||
// readily accessible, since we're a few classes
|
||||
// removed from the layer which gets dependency
|
||||
// injection.
|
||||
function resolvePromise(value) {
|
||||
return (value && value.then) ? value : {
|
||||
then: function (callback) {
|
||||
return resolvePromise(callback(value));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Save any changes that have been made to this domain object
|
||||
* (as well as to others that might have been retrieved and
|
||||
* modified during the editing session)
|
||||
* @param {boolean} nonrecursive if true, save only this
|
||||
* object (and not other objects with associated changes)
|
||||
* @returns {Promise} a promise that will be fulfilled after
|
||||
* persistence has completed.
|
||||
* @memberof platform/commonUI/edit.EditorCapability#
|
||||
* Initiate an editing session. This will start a transaction during
|
||||
* which any persist operations will be deferred until either save()
|
||||
* or cancel() are called.
|
||||
*/
|
||||
EditorCapability.prototype.save = function (nonrecursive) {
|
||||
var domainObject = this.domainObject,
|
||||
editableObject = this.editableObject,
|
||||
self = this,
|
||||
cache = this.cache,
|
||||
returnPromise;
|
||||
EditorCapability.prototype.edit = function () {
|
||||
this.transactionService.startTransaction();
|
||||
this.domainObject.getCapability('status').set('editing', true);
|
||||
};
|
||||
|
||||
// Update the underlying, "real" domain object's model
|
||||
// with changes made to the copy used for editing.
|
||||
function doMutate() {
|
||||
return domainObject.useCapability('mutation', function () {
|
||||
return editableObject.getModel();
|
||||
});
|
||||
}
|
||||
function isEditContextRoot(domainObject) {
|
||||
return domainObject.getCapability('status').get('editing');
|
||||
}
|
||||
|
||||
// Persist the underlying domain object
|
||||
function doPersist() {
|
||||
return domainObject.getCapability('persistence').persist();
|
||||
}
|
||||
function isEditing(domainObject) {
|
||||
return isEditContextRoot(domainObject) ||
|
||||
domainObject.hasCapability('context') &&
|
||||
isEditing(domainObject.getCapability('context').getParent());
|
||||
}
|
||||
|
||||
editableObject.getCapability("status").set("editing", false);
|
||||
/**
|
||||
* Determines whether this object, or any of its ancestors are
|
||||
* currently being edited.
|
||||
* @returns boolean
|
||||
*/
|
||||
EditorCapability.prototype.inEditContext = function () {
|
||||
return isEditing(this.domainObject);
|
||||
};
|
||||
|
||||
if (nonrecursive) {
|
||||
returnPromise = resolvePromise(doMutate())
|
||||
.then(doPersist)
|
||||
.then(function(){
|
||||
self.cancel();
|
||||
});
|
||||
} else {
|
||||
returnPromise = resolvePromise(cache.saveAll());
|
||||
}
|
||||
//Return the original (non-editable) object
|
||||
return returnPromise.then(function() {
|
||||
return domainObject.getOriginalObject ? domainObject.getOriginalObject() : domainObject;
|
||||
/**
|
||||
* Is this the root editing object (ie. the object that the user
|
||||
* clicked 'edit' on)?
|
||||
* @returns {*}
|
||||
*/
|
||||
EditorCapability.prototype.isEditContextRoot = function () {
|
||||
return isEditContextRoot(this.domainObject);
|
||||
};
|
||||
|
||||
/**
|
||||
* Save any changes from this editing session. This will flush all
|
||||
* pending persists and end the current transaction
|
||||
* @returns {*}
|
||||
*/
|
||||
EditorCapability.prototype.save = function () {
|
||||
var domainObject = this.domainObject;
|
||||
return this.transactionService.commit().then(function () {
|
||||
domainObject.getCapability('status').set('editing', false);
|
||||
});
|
||||
};
|
||||
|
||||
EditorCapability.prototype.invoke = EditorCapability.prototype.edit;
|
||||
|
||||
/**
|
||||
* Cancel the current editing session. This will discard any pending
|
||||
* persist operations
|
||||
* @returns {*}
|
||||
*/
|
||||
EditorCapability.prototype.cancel = function () {
|
||||
var domainObject = this.domainObject;
|
||||
return this.transactionService.cancel().then(function () {
|
||||
domainObject.getCapability("status").set("editing", false);
|
||||
return domainObject;
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Cancel editing; Discard any changes that have been made to
|
||||
* this domain object (as well as to others that might have
|
||||
* been retrieved and modified during the editing session)
|
||||
* @returns {Promise} a promise that will be fulfilled after
|
||||
* cancellation has completed.
|
||||
* @memberof platform/commonUI/edit.EditorCapability#
|
||||
*/
|
||||
EditorCapability.prototype.cancel = function () {
|
||||
this.editableObject.getCapability("status").set("editing", false);
|
||||
this.cache.markClean();
|
||||
return resolvePromise(undefined);
|
||||
};
|
||||
|
||||
/**
|
||||
* Check if there are any unsaved changes.
|
||||
* @returns {boolean} true if there are unsaved changes
|
||||
* @memberof platform/commonUI/edit.EditorCapability#
|
||||
* @returns {boolean} true if there have been any domain model
|
||||
* modifications since the last persist, false otherwise.
|
||||
*/
|
||||
EditorCapability.prototype.dirty = function () {
|
||||
return this.cache.dirty();
|
||||
return this.transactionService.size() > 0;
|
||||
};
|
||||
|
||||
return EditorCapability;
|
||||
|
@ -0,0 +1,73 @@
|
||||
/*****************************************************************************
|
||||
* 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(
|
||||
['./TransactionalPersistenceCapability'],
|
||||
function (TransactionalPersistenceCapability) {
|
||||
|
||||
/**
|
||||
* Wraps the [PersistenceCapability]{@link PersistenceCapability} with
|
||||
* transactional capabilities.
|
||||
* @param $q
|
||||
* @param transactionService
|
||||
* @param capabilityService
|
||||
* @see TransactionalPersistenceCapability
|
||||
* @constructor
|
||||
*/
|
||||
function TransactionCapabilityDecorator(
|
||||
$q,
|
||||
transactionService,
|
||||
capabilityService
|
||||
) {
|
||||
this.capabilityService = capabilityService;
|
||||
this.transactionService = transactionService;
|
||||
this.$q = $q;
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate PersistenceCapability to queue persistence calls when a
|
||||
* transaction is in progress.
|
||||
*/
|
||||
TransactionCapabilityDecorator.prototype.getCapabilities = function (model) {
|
||||
var self = this,
|
||||
capabilities = this.capabilityService.getCapabilities(model),
|
||||
persistenceCapability = capabilities.persistence;
|
||||
|
||||
capabilities.persistence = function (domainObject) {
|
||||
var original =
|
||||
(typeof persistenceCapability === 'function') ?
|
||||
persistenceCapability(domainObject) :
|
||||
persistenceCapability;
|
||||
return new TransactionalPersistenceCapability(
|
||||
self.$q,
|
||||
self.transactionService,
|
||||
original,
|
||||
domainObject
|
||||
);
|
||||
};
|
||||
return capabilities;
|
||||
};
|
||||
|
||||
return TransactionCapabilityDecorator;
|
||||
}
|
||||
);
|
@ -0,0 +1,98 @@
|
||||
/*****************************************************************************
|
||||
* 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(
|
||||
[],
|
||||
function () {
|
||||
|
||||
/**
|
||||
* Wraps persistence capability to enable transactions. Transactions
|
||||
* will cause persist calls not to be invoked immediately, but
|
||||
* rather queued until [EditorCapability.save()]{@link EditorCapability#save}
|
||||
* or [EditorCapability.cancel()]{@link EditorCapability#cancel} are
|
||||
* called.
|
||||
* @memberof platform/commonUI/edit/capabilities
|
||||
* @param $q
|
||||
* @param transactionService
|
||||
* @param persistenceCapability
|
||||
* @param domainObject
|
||||
* @constructor
|
||||
*/
|
||||
function TransactionalPersistenceCapability(
|
||||
$q,
|
||||
transactionService,
|
||||
persistenceCapability,
|
||||
domainObject
|
||||
) {
|
||||
this.transactionService = transactionService;
|
||||
this.persistenceCapability = persistenceCapability;
|
||||
this.domainObject = domainObject;
|
||||
this.$q = $q;
|
||||
this.persistPending = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* The wrapped persist function. If a transaction is active, persist
|
||||
* will be queued until the transaction is committed or cancelled.
|
||||
* @returns {*}
|
||||
*/
|
||||
TransactionalPersistenceCapability.prototype.persist = function () {
|
||||
var self = this;
|
||||
|
||||
function onCommit() {
|
||||
return self.persistenceCapability.persist().then(function (result) {
|
||||
self.persistPending = false;
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
function onCancel() {
|
||||
return self.persistenceCapability.refresh().then(function (result) {
|
||||
self.persistPending = false;
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
if (this.transactionService.isActive()) {
|
||||
if (!this.persistPending) {
|
||||
this.transactionService.addToTransaction(onCommit, onCancel);
|
||||
this.persistPending = true;
|
||||
}
|
||||
//Need to return a promise from this function
|
||||
return this.$q.when(true);
|
||||
} else {
|
||||
return this.persistenceCapability.persist();
|
||||
}
|
||||
};
|
||||
|
||||
TransactionalPersistenceCapability.prototype.refresh = function () {
|
||||
return this.persistenceCapability.refresh();
|
||||
};
|
||||
|
||||
TransactionalPersistenceCapability.prototype.getSpace = function () {
|
||||
return this.persistenceCapability.getSpace();
|
||||
};
|
||||
|
||||
return TransactionalPersistenceCapability;
|
||||
}
|
||||
);
|
@ -59,7 +59,7 @@ define(
|
||||
|
||||
$scope.$watch('domainObject', setViewForDomainObject);
|
||||
|
||||
$scope.doAction = function (action){
|
||||
$scope.doAction = function (action) {
|
||||
return $scope[action] && $scope[action]();
|
||||
};
|
||||
}
|
||||
@ -74,8 +74,8 @@ define(
|
||||
var navigatedObject = this.scope.domainObject,
|
||||
policyMessage;
|
||||
|
||||
this.policyService.allow("navigation", navigatedObject, undefined, function(message) {
|
||||
policyMessage = message;
|
||||
this.policyService.allow("navigation", navigatedObject, undefined, function (message) {
|
||||
policyMessage = message;
|
||||
});
|
||||
|
||||
return policyMessage;
|
||||
|
@ -30,7 +30,7 @@ define(
|
||||
* @constructor
|
||||
*/
|
||||
function ElementsController($scope) {
|
||||
function filterBy(text){
|
||||
function filterBy(text) {
|
||||
if (typeof text === 'undefined') {
|
||||
return $scope.searchText;
|
||||
} else {
|
||||
|
@ -81,13 +81,13 @@ define(
|
||||
|
||||
newModel.type = this.type.getKey();
|
||||
newObject = parentObject.getCapability('instantiation').instantiate(newModel);
|
||||
newObject.useCapability('mutation', function(model){
|
||||
newObject.useCapability('mutation', function (model) {
|
||||
model.location = parentObject.getId();
|
||||
});
|
||||
|
||||
wizard = new CreateWizard(newObject, this.parent, this.policyService);
|
||||
|
||||
function populateObjectFromInput (formValue) {
|
||||
function populateObjectFromInput(formValue) {
|
||||
return wizard.populateObjectFromInput(formValue, newObject);
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ define(
|
||||
});
|
||||
}
|
||||
|
||||
function addToParent (populatedObject) {
|
||||
function addToParent(populatedObject) {
|
||||
parentObject.getCapability('composition').add(populatedObject);
|
||||
return persistAndReturn(parentObject);
|
||||
}
|
||||
@ -125,7 +125,7 @@ define(
|
||||
* @returns {AddActionMetadata} metadata about this action
|
||||
*/
|
||||
AddAction.prototype.getMetadata = function () {
|
||||
return this.metadata;
|
||||
return this.metadata;
|
||||
};
|
||||
|
||||
return AddAction;
|
@ -24,11 +24,8 @@
|
||||
* Module defining CreateAction. Created by vwoeltje on 11/10/14.
|
||||
*/
|
||||
define(
|
||||
[
|
||||
'./CreateWizard',
|
||||
'../../../edit/src/objects/EditableDomainObject'
|
||||
],
|
||||
function (CreateWizard, EditableDomainObject) {
|
||||
[],
|
||||
function () {
|
||||
|
||||
/**
|
||||
* The Create Action is performed to create new instances of
|
||||
@ -46,11 +43,8 @@ define(
|
||||
* override this)
|
||||
* @param {ActionContext} context the context in which the
|
||||
* action is being performed
|
||||
* @param {NavigationService} navigationService the navigation service,
|
||||
* which handles changes in navigation. It allows the object
|
||||
* being browsed/edited to be set.
|
||||
*/
|
||||
function CreateAction(type, parent, context, $q, navigationService) {
|
||||
function CreateAction(type, parent, context) {
|
||||
this.metadata = {
|
||||
key: 'create',
|
||||
glyph: type.getGlyph(),
|
||||
@ -59,24 +53,8 @@ define(
|
||||
description: type.getDescription(),
|
||||
context: context
|
||||
};
|
||||
|
||||
this.type = type;
|
||||
this.parent = parent;
|
||||
this.navigationService = navigationService;
|
||||
this.$q = $q;
|
||||
}
|
||||
|
||||
// Get a count of views which are not flagged as non-editable.
|
||||
function countEditableViews(domainObject) {
|
||||
var views = domainObject && domainObject.useCapability('view'),
|
||||
count = 0;
|
||||
|
||||
// A view is editable unless explicitly flagged as not
|
||||
(views || []).forEach(function (view) {
|
||||
count += (view.editable !== false) ? 1 : 0;
|
||||
});
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -85,23 +63,31 @@ define(
|
||||
*/
|
||||
CreateAction.prototype.perform = function () {
|
||||
var newModel = this.type.getInitialModel(),
|
||||
parentObject = this.navigationService.getNavigation(),
|
||||
newObject,
|
||||
editableObject;
|
||||
editAction,
|
||||
editorCapability;
|
||||
|
||||
function onSave() {
|
||||
return editorCapability.save();
|
||||
}
|
||||
|
||||
function onCancel() {
|
||||
return editorCapability.cancel();
|
||||
}
|
||||
|
||||
newModel.type = this.type.getKey();
|
||||
newObject = parentObject.useCapability('instantiation', newModel);
|
||||
editableObject = new EditableDomainObject(newObject, this.$q);
|
||||
editableObject.setOriginalObject(parentObject);
|
||||
editableObject.getCapability('status').set('editing', true);
|
||||
editableObject.useCapability('mutation', function(model){
|
||||
model.location = parentObject.getId();
|
||||
});
|
||||
newModel.location = this.parent.getId();
|
||||
newObject = this.parent.useCapability('instantiation', newModel);
|
||||
editorCapability = newObject.hasCapability('editor') && newObject.getCapability("editor");
|
||||
|
||||
if (countEditableViews(editableObject) > 0 && editableObject.hasCapability('composition')) {
|
||||
this.navigationService.setNavigation(editableObject);
|
||||
} else {
|
||||
return editableObject.getCapability('action').perform('save');
|
||||
editAction = newObject.getCapability("action").getActions("edit")[0];
|
||||
//If an edit action is available, perform it
|
||||
if (editAction) {
|
||||
return editAction.perform();
|
||||
} else if (editorCapability) {
|
||||
//otherwise, use the save action
|
||||
editorCapability.edit();
|
||||
return newObject.getCapability("action").perform("save").then(onSave, onCancel);
|
||||
}
|
||||
};
|
||||
|
||||
@ -118,7 +104,7 @@ define(
|
||||
* @returns {CreateActionMetadata} metadata about this action
|
||||
*/
|
||||
CreateAction.prototype.getMetadata = function () {
|
||||
return this.metadata;
|
||||
return this.metadata;
|
||||
};
|
||||
|
||||
return CreateAction;
|
@ -44,10 +44,8 @@ define(
|
||||
* introduced in this bundle), responsible for handling actual
|
||||
* object creation.
|
||||
*/
|
||||
function CreateActionProvider($q, typeService, navigationService, policyService) {
|
||||
function CreateActionProvider(typeService, policyService) {
|
||||
this.typeService = typeService;
|
||||
this.navigationService = navigationService;
|
||||
this.$q = $q;
|
||||
this.policyService = policyService;
|
||||
}
|
||||
|
||||
@ -72,9 +70,7 @@ define(
|
||||
return new CreateAction(
|
||||
type,
|
||||
destination,
|
||||
context,
|
||||
self.$q,
|
||||
self.navigationService
|
||||
context
|
||||
);
|
||||
});
|
||||
};
|
@ -111,12 +111,12 @@ define(
|
||||
* @param formValue
|
||||
* @returns {DomainObject}
|
||||
*/
|
||||
CreateWizard.prototype.populateObjectFromInput = function(formValue) {
|
||||
CreateWizard.prototype.populateObjectFromInput = function (formValue) {
|
||||
var parent = this.getLocation(formValue),
|
||||
formModel = this.createModel(formValue);
|
||||
|
||||
formModel.location = parent.getId();
|
||||
this.domainObject.useCapability("mutation", function(){
|
||||
this.domainObject.useCapability("mutation", function () {
|
||||
return formModel;
|
||||
});
|
||||
return this.domainObject;
|
@ -40,4 +40,4 @@ define(
|
||||
|
||||
return CreationPolicy;
|
||||
}
|
||||
);
|
||||
);
|
@ -50,14 +50,14 @@ define(
|
||||
$scope.rootObject =
|
||||
(context && context.getRoot()) || $scope.rootObject;
|
||||
}, 0);
|
||||
} else if (!contextRoot){
|
||||
} else if (!contextRoot) {
|
||||
//If no context root is available, default to the root
|
||||
// object
|
||||
$scope.rootObject = undefined;
|
||||
// Update the displayed tree on a timeout to avoid
|
||||
// an infinite digest exception.
|
||||
objectService.getObjects(['ROOT'])
|
||||
.then(function(objects){
|
||||
.then(function (objects) {
|
||||
$timeout(function () {
|
||||
$scope.rootObject = objects.ROOT;
|
||||
}, 0);
|
@ -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;
|
||||
}
|
||||
);
|
@ -45,7 +45,7 @@ define(
|
||||
count = 0,
|
||||
type, views;
|
||||
|
||||
if (!domainObject){
|
||||
if (!domainObject) {
|
||||
return count;
|
||||
}
|
||||
|
||||
@ -56,7 +56,10 @@ define(
|
||||
// A view is editable unless explicitly flagged as not
|
||||
(views || []).forEach(function (view) {
|
||||
if (view.editable === true ||
|
||||
(view.key === 'plot' && type.getKey() === 'telemetry.panel')) {
|
||||
(view.key === 'plot' && type.getKey() === 'telemetry.panel') ||
|
||||
(view.key === 'table' && type.getKey() === 'table') ||
|
||||
(view.key === 'rt-table' && type.getKey() === 'rttable')
|
||||
) {
|
||||
count++;
|
||||
}
|
||||
});
|
||||
@ -73,25 +76,22 @@ define(
|
||||
function isEditing(context) {
|
||||
var domainObject = (context || {}).domainObject;
|
||||
return domainObject &&
|
||||
domainObject.hasCapability('status') &&
|
||||
domainObject.getCapability('status').get('editing');
|
||||
domainObject.hasCapability('editor') &&
|
||||
domainObject.getCapability('editor').isEditContextRoot();
|
||||
}
|
||||
|
||||
EditActionPolicy.prototype.allow = function (action, context) {
|
||||
var key = action.getMetadata().key,
|
||||
category = (context || {}).category;
|
||||
|
||||
// Only worry about actions in the view-control category
|
||||
if (category === 'view-control') {
|
||||
// Restrict 'edit' to cases where there are editable
|
||||
// views (similarly, restrict 'properties' to when
|
||||
// the converse is true), and where the domain object is not
|
||||
// already being edited.
|
||||
if (key === 'edit') {
|
||||
return this.countEditableViews(context) > 0 && !isEditing(context);
|
||||
} else if (key === 'properties') {
|
||||
return this.countEditableViews(context) < 1 && !isEditing(context);
|
||||
}
|
||||
// Restrict 'edit' to cases where there are editable
|
||||
// views (similarly, restrict 'properties' to when
|
||||
// the converse is true), and where the domain object is not
|
||||
// already being edited.
|
||||
if (key === 'edit') {
|
||||
return this.countEditableViews(context) > 0 && !isEditing(context);
|
||||
} else if (key === 'properties' && category === 'view-control') {
|
||||
return this.countEditableViews(context) < 1 && !isEditing(context);
|
||||
}
|
||||
|
||||
// Like all policies, allow by default.
|
||||
|
@ -34,6 +34,11 @@ define(
|
||||
* from context menu of non-editable objects, when navigated object
|
||||
* is being edited
|
||||
* @constructor
|
||||
* @param editModeBlacklist A blacklist of actions disallowed from
|
||||
* context menu when navigated object is being edited
|
||||
* @param nonEditContextBlacklist A blacklist of actions disallowed
|
||||
* from context menu of non-editable objects, when navigated object
|
||||
* @implements {Policy.<Action, ActionContext>}
|
||||
*/
|
||||
function EditContextualActionPolicy(navigationService, editModeBlacklist, nonEditContextBlacklist) {
|
||||
this.navigationService = navigationService;
|
||||
@ -45,18 +50,13 @@ define(
|
||||
this.nonEditContextBlacklist = nonEditContextBlacklist;
|
||||
}
|
||||
|
||||
function isParentEditable(object) {
|
||||
var parent = object.hasCapability("context") && object.getCapability("context").getParent();
|
||||
return !!parent && parent.hasCapability("editor");
|
||||
}
|
||||
|
||||
EditContextualActionPolicy.prototype.allow = function (action, context) {
|
||||
var selectedObject = context.domainObject,
|
||||
navigatedObject = this.navigationService.getNavigation(),
|
||||
actionMetadata = action.getMetadata ? action.getMetadata() : {};
|
||||
|
||||
if (navigatedObject.hasCapability('editor')) {
|
||||
if (selectedObject.hasCapability('editor') || isParentEditable(selectedObject)){
|
||||
if (navigatedObject.hasCapability("editor") && navigatedObject.getCapability("editor").isEditContextRoot()) {
|
||||
if (selectedObject.hasCapability("editor") && selectedObject.getCapability("editor").inEditContext()) {
|
||||
return this.editModeBlacklist.indexOf(actionMetadata.key) === -1;
|
||||
} else {
|
||||
//Target is in the context menu
|
||||
|
@ -38,15 +38,14 @@ define(
|
||||
/**
|
||||
* @private
|
||||
*/
|
||||
EditNavigationPolicy.prototype.isDirty = function(domainObject) {
|
||||
EditNavigationPolicy.prototype.isDirty = function (domainObject) {
|
||||
var navigatedObject = domainObject,
|
||||
editorCapability = navigatedObject &&
|
||||
navigatedObject.getCapability("editor"),
|
||||
statusCapability = navigatedObject &&
|
||||
navigatedObject.getCapability("status");
|
||||
navigatedObject.getCapability("editor");
|
||||
|
||||
return statusCapability && statusCapability.get('editing') &&
|
||||
editorCapability && editorCapability.dirty();
|
||||
return editorCapability &&
|
||||
editorCapability.isEditContextRoot() &&
|
||||
editorCapability.dirty();
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -35,11 +35,12 @@ define([], function () {
|
||||
}
|
||||
|
||||
EditableLinkPolicy.prototype.allow = function (action, context) {
|
||||
var key = action.getMetadata().key;
|
||||
var key = action.getMetadata().key,
|
||||
object;
|
||||
|
||||
if (key === 'link') {
|
||||
return !((context.selectedObject || context.domainObject)
|
||||
.hasCapability('editor'));
|
||||
object = context.selectedObject || context.domainObject;
|
||||
return !(object.hasCapability("editor") && object.getCapability("editor").inEditContext());
|
||||
}
|
||||
|
||||
// Like all policies, allow by default.
|
||||
|
@ -35,10 +35,13 @@ define([], function () {
|
||||
EditableMovePolicy.prototype.allow = function (action, context) {
|
||||
var domainObject = context.domainObject,
|
||||
selectedObject = context.selectedObject,
|
||||
key = action.getMetadata().key;
|
||||
key = action.getMetadata().key,
|
||||
isDomainObjectEditing = domainObject.hasCapability('editor') &&
|
||||
domainObject.getCapability('editor').inEditContext();
|
||||
|
||||
if (key === 'move' && domainObject.hasCapability('editor')) {
|
||||
return !!selectedObject && selectedObject.hasCapability('editor');
|
||||
if (key === 'move' && isDomainObjectEditing) {
|
||||
return !!selectedObject && selectedObject.hasCapability('editor') &&
|
||||
selectedObject.getCapability('editor').inEditContext();
|
||||
}
|
||||
|
||||
// Like all policies, allow by default.
|
||||
|
@ -37,7 +37,7 @@ define(
|
||||
// If a view is flagged as non-editable, only allow it
|
||||
// while we're not in Edit mode.
|
||||
if ((view || {}).editable === false) {
|
||||
return !domainObject.hasCapability('editor');
|
||||
return !(domainObject.hasCapability('editor') && domainObject.getCapability('editor').inEditContext());
|
||||
}
|
||||
|
||||
// Like all policies, allow by default.
|
||||
|
@ -91,14 +91,8 @@ define(
|
||||
}
|
||||
}
|
||||
|
||||
function setEditable(editableDomainObject) {
|
||||
self.domainObject = editableDomainObject;
|
||||
scope.model = editableDomainObject.getModel();
|
||||
}
|
||||
|
||||
// Place the "commit" method in the scope
|
||||
scope.commit = commit;
|
||||
scope.setEditable = setEditable;
|
||||
|
||||
// Clean up when the scope is destroyed
|
||||
scope.$on("$destroy", function () {
|
||||
@ -119,7 +113,7 @@ define(
|
||||
// Ensure existing watches are released
|
||||
this.destroy();
|
||||
|
||||
function setEditing(){
|
||||
function setEditing() {
|
||||
scope.viewObjectTemplate = 'edit-object';
|
||||
}
|
||||
|
||||
@ -128,15 +122,15 @@ define(
|
||||
* editable then change the view and inspector regions
|
||||
* object representation accordingly
|
||||
*/
|
||||
this.listenHandle = this.domainObject.getCapability('status').listen(function(statuses){
|
||||
if (statuses.indexOf('editing') !== -1){
|
||||
this.listenHandle = this.domainObject.getCapability('status').listen(function (statuses) {
|
||||
if (statuses.indexOf('editing') !== -1) {
|
||||
setEditing();
|
||||
} else {
|
||||
delete scope.viewObjectTemplate;
|
||||
}
|
||||
});
|
||||
|
||||
if (representedObject.getCapability('status').get('editing')){
|
||||
if (representedObject.hasCapability('editor') && representedObject.getCapability('editor').isEditContextRoot()) {
|
||||
setEditing();
|
||||
}
|
||||
};
|
||||
|
@ -24,8 +24,12 @@ define(
|
||||
function () {
|
||||
|
||||
// Utility functions for reducing truth arrays
|
||||
function and(a, b) { return a && b; }
|
||||
function or(a, b) { return a || b; }
|
||||
function and(a, b) {
|
||||
return a && b;
|
||||
}
|
||||
function or(a, b) {
|
||||
return a || b;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@ -219,7 +223,7 @@ define(
|
||||
|
||||
// Update value for this property in all elements of the
|
||||
// selection which have this property.
|
||||
function updateProperties(property, value) {
|
||||
function updateProperties(property, val) {
|
||||
var changed = false;
|
||||
|
||||
// Update property in a selected element
|
||||
@ -229,12 +233,12 @@ define(
|
||||
// Check if this is a setter, or just assignable
|
||||
if (typeof selected[property] === 'function') {
|
||||
changed =
|
||||
changed || (selected[property]() !== value);
|
||||
selected[property](value);
|
||||
changed || (selected[property]() !== val);
|
||||
selected[property](val);
|
||||
} else {
|
||||
changed =
|
||||
changed || (selected[property] !== value);
|
||||
selected[property] = value;
|
||||
changed || (selected[property] !== val);
|
||||
selected[property] = val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,11 +133,11 @@ define(
|
||||
self = this;
|
||||
|
||||
// Initialize toolbar (expose object to parent scope)
|
||||
function initialize(definition) {
|
||||
function initialize(def) {
|
||||
// If we have been asked to expose toolbar state...
|
||||
if (self.attrs.toolbar) {
|
||||
// Initialize toolbar object
|
||||
self.toolbar = new EditToolbar(definition, self.commit);
|
||||
self.toolbar = new EditToolbar(def, self.commit);
|
||||
// Ensure toolbar state is exposed
|
||||
self.exposeToolbar();
|
||||
}
|
||||
|
148
platform/commonUI/edit/src/services/TransactionService.js
Normal file
148
platform/commonUI/edit/src/services/TransactionService.js
Normal file
@ -0,0 +1,148 @@
|
||||
/*****************************************************************************
|
||||
* 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(
|
||||
[],
|
||||
function () {
|
||||
/**
|
||||
* Implements an application-wide transaction state. Once a
|
||||
* transaction is started, calls to
|
||||
* [PersistenceCapability.persist()]{@link PersistenceCapability#persist}
|
||||
* will be deferred until a subsequent call to
|
||||
* [TransactionService.commit]{@link TransactionService#commit} is made.
|
||||
*
|
||||
* @memberof platform/commonUI/edit/services
|
||||
* @param $q
|
||||
* @constructor
|
||||
*/
|
||||
function TransactionService($q, $log) {
|
||||
this.$q = $q;
|
||||
this.$log = $log;
|
||||
this.transaction = false;
|
||||
|
||||
this.onCommits = [];
|
||||
this.onCancels = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a transaction. While a transaction is active all calls to
|
||||
* [PersistenceCapability.persist](@link PersistenceCapability#persist)
|
||||
* will be queued until [commit]{@link #commit} or [cancel]{@link
|
||||
* #cancel} are called
|
||||
*/
|
||||
TransactionService.prototype.startTransaction = function () {
|
||||
if (this.transaction) {
|
||||
//Log error because this is a programming error if it occurs.
|
||||
this.$log.error("Transaction already in progress");
|
||||
}
|
||||
this.transaction = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* @returns {boolean} If true, indicates that a transaction is in progress
|
||||
*/
|
||||
TransactionService.prototype.isActive = function () {
|
||||
return this.transaction;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds provided functions to a queue to be called on
|
||||
* [.commit()]{@link #commit} or
|
||||
* [.cancel()]{@link #commit}
|
||||
* @param onCommit A function to call on commit
|
||||
* @param onCancel A function to call on cancel
|
||||
*/
|
||||
TransactionService.prototype.addToTransaction = function (onCommit, onCancel) {
|
||||
if (this.transaction) {
|
||||
this.onCommits.push(onCommit);
|
||||
if (onCancel) {
|
||||
this.onCancels.push(onCancel);
|
||||
}
|
||||
} else {
|
||||
//Log error because this is a programming error if it occurs.
|
||||
this.$log.error("No transaction in progress");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* All persist calls deferred since the beginning of the transaction
|
||||
* will be committed.
|
||||
*
|
||||
* @returns {Promise} resolved when all persist operations have
|
||||
* completed. Will reject if any commit operations fail
|
||||
*/
|
||||
TransactionService.prototype.commit = function () {
|
||||
var self = this,
|
||||
promises = [],
|
||||
onCommit;
|
||||
|
||||
while (this.onCommits.length > 0) { // ...using a while in case some onCommit adds to transaction
|
||||
onCommit = this.onCommits.pop();
|
||||
try { // ...also don't want to fail mid-loop...
|
||||
promises.push(onCommit());
|
||||
} catch (e) {
|
||||
this.$log.error("Error committing transaction.");
|
||||
}
|
||||
}
|
||||
return this.$q.all(promises).then(function () {
|
||||
self.transaction = false;
|
||||
|
||||
self.onCommits = [];
|
||||
self.onCancels = [];
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Cancel the current transaction, replacing any dirty objects from
|
||||
* persistence. Not a true rollback, as it cannot be used to undo any
|
||||
* persist calls that were successful in the event one of a batch of
|
||||
* persists failing.
|
||||
*
|
||||
* @returns {*}
|
||||
*/
|
||||
TransactionService.prototype.cancel = function () {
|
||||
var self = this,
|
||||
results = [],
|
||||
onCancel;
|
||||
|
||||
while (this.onCancels.length > 0) {
|
||||
onCancel = this.onCancels.pop();
|
||||
try {
|
||||
results.push(onCancel());
|
||||
} catch (error) {
|
||||
this.$log.error("Error committing transaction.");
|
||||
}
|
||||
}
|
||||
return this.$q.all(results).then(function () {
|
||||
self.transaction = false;
|
||||
|
||||
self.onCommits = [];
|
||||
self.onCancels = [];
|
||||
});
|
||||
};
|
||||
|
||||
TransactionService.prototype.size = function () {
|
||||
return this.onCommits.length;
|
||||
};
|
||||
|
||||
return TransactionService;
|
||||
});
|
@ -44,15 +44,15 @@ define(
|
||||
beforeEach(function () {
|
||||
mockLocation = jasmine.createSpyObj(
|
||||
"$location",
|
||||
[ "path" ]
|
||||
["path"]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getCapability", "hasCapability" ]
|
||||
["getCapability", "hasCapability"]
|
||||
);
|
||||
mockEditorCapability = jasmine.createSpyObj(
|
||||
"editor",
|
||||
[ "save", "cancel" ]
|
||||
["save", "cancel"]
|
||||
);
|
||||
mockUrlService = jasmine.createSpyObj(
|
||||
"urlService",
|
||||
@ -100,4 +100,4 @@ define(
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -30,32 +30,46 @@ define(
|
||||
mockLog,
|
||||
mockDomainObject,
|
||||
mockType,
|
||||
mockEditor,
|
||||
actionContext,
|
||||
capabilities,
|
||||
action;
|
||||
|
||||
beforeEach(function () {
|
||||
mockLocation = jasmine.createSpyObj(
|
||||
"$location",
|
||||
[ "path" ]
|
||||
["path"]
|
||||
);
|
||||
mockNavigationService = jasmine.createSpyObj(
|
||||
"navigationService",
|
||||
[ "setNavigation", "getNavigation" ]
|
||||
["setNavigation", "getNavigation", "addListener", "removeListener"]
|
||||
);
|
||||
mockLog = jasmine.createSpyObj(
|
||||
"$log",
|
||||
[ "error", "warn", "info", "debug" ]
|
||||
["error", "warn", "info", "debug"]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability" ]
|
||||
["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
|
||||
);
|
||||
mockType = jasmine.createSpyObj(
|
||||
"type",
|
||||
[ "hasFeature" ]
|
||||
["hasFeature"]
|
||||
);
|
||||
mockEditor = jasmine.createSpyObj(
|
||||
"editorCapability",
|
||||
["edit", "isEditContextRoot", "cancel"]
|
||||
);
|
||||
|
||||
mockDomainObject.getCapability.andReturn(mockType);
|
||||
capabilities = {
|
||||
type: mockType,
|
||||
editor: mockEditor
|
||||
};
|
||||
|
||||
mockDomainObject.getCapability.andCallFake(function (name) {
|
||||
return capabilities[name];
|
||||
});
|
||||
mockDomainObject.hasCapability.andReturn(true);
|
||||
mockType.hasFeature.andReturn(true);
|
||||
|
||||
actionContext = { domainObject: mockDomainObject };
|
||||
@ -68,51 +82,34 @@ define(
|
||||
);
|
||||
});
|
||||
|
||||
it("is only applicable when a domain object is present", function () {
|
||||
it("is only applicable when an editable domain object is present", function () {
|
||||
expect(EditAction.appliesTo(actionContext)).toBeTruthy();
|
||||
expect(EditAction.appliesTo({})).toBeFalsy();
|
||||
|
||||
expect(mockDomainObject.hasCapability).toHaveBeenCalledWith('editor');
|
||||
// Should have checked for creatability
|
||||
expect(mockType.hasFeature).toHaveBeenCalledWith('creation');
|
||||
});
|
||||
|
||||
//TODO: Disabled for NEM Beta
|
||||
xit("changes URL path to edit mode when performed", function () {
|
||||
it("is only applicable to objects not already in edit mode", function () {
|
||||
mockEditor.isEditContextRoot.andReturn(false);
|
||||
expect(EditAction.appliesTo(actionContext)).toBe(true);
|
||||
mockEditor.isEditContextRoot.andReturn(true);
|
||||
expect(EditAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
|
||||
it ("cancels editing when user navigates away", function () {
|
||||
action.perform();
|
||||
expect(mockLocation.path).toHaveBeenCalledWith("/edit");
|
||||
expect(mockNavigationService.addListener).toHaveBeenCalled();
|
||||
mockNavigationService.addListener.mostRecentCall.args[0]();
|
||||
expect(mockEditor.cancel).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
//TODO: Disabled for NEM Beta
|
||||
xit("ensures that the edited object is navigated-to", function () {
|
||||
it ("invokes the Edit capability on the object", function () {
|
||||
action.perform();
|
||||
expect(mockNavigationService.setNavigation)
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
expect(mockDomainObject.useCapability).toHaveBeenCalledWith("editor");
|
||||
});
|
||||
|
||||
//TODO: Disabled for NEM Beta
|
||||
xit("logs a warning if constructed when inapplicable", function () {
|
||||
// Verify precondition (ensure warn wasn't called during setup)
|
||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||
|
||||
// Should not have hit an exception...
|
||||
new EditAction(
|
||||
mockLocation,
|
||||
mockNavigationService,
|
||||
mockLog,
|
||||
{}
|
||||
).perform();
|
||||
|
||||
// ...but should have logged a warning
|
||||
expect(mockLog.warn).toHaveBeenCalled();
|
||||
|
||||
// And should not have had other interactions
|
||||
expect(mockLocation.path)
|
||||
.not.toHaveBeenCalled();
|
||||
expect(mockNavigationService.setNavigation)
|
||||
.not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -21,8 +21,8 @@
|
||||
*****************************************************************************/
|
||||
|
||||
define(
|
||||
["../../src/actions/LinkAction"],
|
||||
function (LinkAction) {
|
||||
["../../src/actions/EditAndComposeAction"],
|
||||
function (EditAndComposeAction) {
|
||||
|
||||
describe("The Link action", function () {
|
||||
var mockQ,
|
||||
@ -31,6 +31,8 @@ define(
|
||||
mockContext,
|
||||
mockComposition,
|
||||
mockPersistence,
|
||||
mockActionCapability,
|
||||
mockEditAction,
|
||||
mockType,
|
||||
actionContext,
|
||||
model,
|
||||
@ -50,7 +52,7 @@ define(
|
||||
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getCapability" ]
|
||||
["getId", "getCapability"]
|
||||
);
|
||||
mockQ = { when: mockPromise };
|
||||
mockParent = {
|
||||
@ -64,25 +66,30 @@ define(
|
||||
return capabilities[k].invoke(v);
|
||||
}
|
||||
};
|
||||
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||
mockComposition = jasmine.createSpyObj("composition", [ "invoke", "add" ]);
|
||||
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
|
||||
mockType = jasmine.createSpyObj("type", [ "hasFeature" ]);
|
||||
mockContext = jasmine.createSpyObj("context", ["getParent"]);
|
||||
mockComposition = jasmine.createSpyObj("composition", ["invoke", "add"]);
|
||||
mockPersistence = jasmine.createSpyObj("persistence", ["persist"]);
|
||||
mockType = jasmine.createSpyObj("type", ["hasFeature", "getKey"]);
|
||||
mockActionCapability = jasmine.createSpyObj("actionCapability", ["getActions"]);
|
||||
mockEditAction = jasmine.createSpyObj("editAction", ["perform"]);
|
||||
|
||||
mockDomainObject.getId.andReturn("test");
|
||||
mockDomainObject.getCapability.andReturn(mockContext);
|
||||
mockContext.getParent.andReturn(mockParent);
|
||||
mockType.hasFeature.andReturn(true);
|
||||
mockType.getKey.andReturn("layout");
|
||||
mockComposition.invoke.andReturn(mockPromise(true));
|
||||
mockComposition.add.andReturn(mockPromise(true));
|
||||
mockActionCapability.getActions.andReturn([]);
|
||||
|
||||
capabilities = {
|
||||
composition: mockComposition,
|
||||
persistence: mockPersistence,
|
||||
action: mockActionCapability,
|
||||
type: mockType
|
||||
};
|
||||
model = {
|
||||
composition: [ "a", "b", "c" ]
|
||||
composition: ["a", "b", "c"]
|
||||
};
|
||||
|
||||
actionContext = {
|
||||
@ -90,7 +97,7 @@ define(
|
||||
selectedObject: mockDomainObject
|
||||
};
|
||||
|
||||
action = new LinkAction(actionContext);
|
||||
action = new EditAndComposeAction(actionContext);
|
||||
});
|
||||
|
||||
|
||||
@ -105,6 +112,21 @@ define(
|
||||
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("enables edit mode for objects that have an edit action", function () {
|
||||
mockActionCapability.getActions.andReturn([mockEditAction]);
|
||||
action.perform();
|
||||
expect(mockEditAction.perform).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("Does not enable edit mode for objects that do not have an" +
|
||||
" edit action", function () {
|
||||
mockActionCapability.getActions.andReturn([]);
|
||||
action.perform();
|
||||
expect(mockEditAction.perform).not.toHaveBeenCalled();
|
||||
expect(mockComposition.add)
|
||||
.toHaveBeenCalledWith(mockDomainObject);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -38,7 +38,9 @@ define(
|
||||
beforeEach(function () {
|
||||
capabilities = {
|
||||
type: {
|
||||
getProperties: function () { return []; },
|
||||
getProperties: function () {
|
||||
return [];
|
||||
},
|
||||
hasFeature: jasmine.createSpy('hasFeature')
|
||||
},
|
||||
persistence: jasmine.createSpyObj("persistence", ["persist"]),
|
||||
@ -47,11 +49,21 @@ define(
|
||||
model = {};
|
||||
input = {};
|
||||
object = {
|
||||
getId: function () { return 'test-id'; },
|
||||
getCapability: function (k) { return capabilities[k]; },
|
||||
getModel: function () { return model; },
|
||||
useCapability: function (k, v) { return capabilities[k](v); },
|
||||
hasCapability: function () { return true; }
|
||||
getId: function () {
|
||||
return 'test-id';
|
||||
},
|
||||
getCapability: function (k) {
|
||||
return capabilities[k];
|
||||
},
|
||||
getModel: function () {
|
||||
return model;
|
||||
},
|
||||
useCapability: function (k, v) {
|
||||
return capabilities[k](v);
|
||||
},
|
||||
hasCapability: function () {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
context = { someKey: "some value", domainObject: object };
|
||||
dialogService = {
|
||||
|
@ -30,14 +30,22 @@ define(
|
||||
|
||||
beforeEach(function () {
|
||||
type = {
|
||||
getProperties: function () { return properties; }
|
||||
getProperties: function () {
|
||||
return properties;
|
||||
}
|
||||
};
|
||||
model = { x: "initial value" };
|
||||
properties = ["x", "y", "z"].map(function (k) {
|
||||
return {
|
||||
getValue: function (model) { return model[k]; },
|
||||
setValue: function (model, v) { model[k] = v; },
|
||||
getDefinition: function () { return { control: 'textfield '}; }
|
||||
getValue: function (m) {
|
||||
return m[k];
|
||||
},
|
||||
setValue: function (m, v) {
|
||||
m[k] = v;
|
||||
},
|
||||
getDefinition: function () {
|
||||
return { control: 'textfield '};
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
|
@ -57,19 +57,19 @@ define(
|
||||
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getCapability" ]
|
||||
["getId", "getCapability"]
|
||||
);
|
||||
mockChildObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getCapability" ]
|
||||
["getId", "getCapability"]
|
||||
);
|
||||
mockGrandchildObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getCapability" ]
|
||||
["getId", "getCapability"]
|
||||
);
|
||||
mockRootObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getCapability" ]
|
||||
["getId", "getCapability"]
|
||||
);
|
||||
mockQ = { when: mockPromise };
|
||||
mockParent = {
|
||||
@ -83,13 +83,13 @@ define(
|
||||
return capabilities[k].invoke(v);
|
||||
}
|
||||
};
|
||||
mockContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||
mockChildContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||
mockGrandchildContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||
mockRootContext = jasmine.createSpyObj("context", [ "getParent" ]);
|
||||
mockMutation = jasmine.createSpyObj("mutation", [ "invoke" ]);
|
||||
mockPersistence = jasmine.createSpyObj("persistence", [ "persist" ]);
|
||||
mockType = jasmine.createSpyObj("type", [ "hasFeature" ]);
|
||||
mockContext = jasmine.createSpyObj("context", ["getParent"]);
|
||||
mockChildContext = jasmine.createSpyObj("context", ["getParent"]);
|
||||
mockGrandchildContext = jasmine.createSpyObj("context", ["getParent"]);
|
||||
mockRootContext = jasmine.createSpyObj("context", ["getParent"]);
|
||||
mockMutation = jasmine.createSpyObj("mutation", ["invoke"]);
|
||||
mockPersistence = jasmine.createSpyObj("persistence", ["persist"]);
|
||||
mockType = jasmine.createSpyObj("type", ["hasFeature"]);
|
||||
mockNavigationService = jasmine.createSpyObj(
|
||||
"navigationService",
|
||||
[
|
||||
@ -100,8 +100,8 @@ define(
|
||||
]
|
||||
);
|
||||
mockNavigationService.getNavigation.andReturn(mockDomainObject);
|
||||
|
||||
|
||||
|
||||
|
||||
mockDomainObject.getId.andReturn("test");
|
||||
mockDomainObject.getCapability.andReturn(mockContext);
|
||||
mockContext.getParent.andReturn(mockParent);
|
||||
@ -113,7 +113,7 @@ define(
|
||||
type: mockType
|
||||
};
|
||||
model = {
|
||||
composition: [ "a", "test", "b" ]
|
||||
composition: ["a", "test", "b"]
|
||||
};
|
||||
|
||||
actionContext = { domainObject: mockDomainObject };
|
||||
@ -158,60 +158,60 @@ define(
|
||||
// Finally, should have persisted
|
||||
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
it("removes parent of object currently navigated to", function () {
|
||||
// Navigates to child object
|
||||
mockNavigationService.getNavigation.andReturn(mockChildObject);
|
||||
|
||||
|
||||
// Test is id of object being removed
|
||||
// Child object has different id
|
||||
mockDomainObject.getId.andReturn("test");
|
||||
mockChildObject.getId.andReturn("not test");
|
||||
|
||||
|
||||
// Sets context for the child and domainObject
|
||||
mockDomainObject.getCapability.andReturn(mockContext);
|
||||
mockChildObject.getCapability.andReturn(mockChildContext);
|
||||
|
||||
|
||||
// Parents of child and domainObject are set
|
||||
mockContext.getParent.andReturn(mockParent);
|
||||
mockChildContext.getParent.andReturn(mockDomainObject);
|
||||
|
||||
|
||||
mockType.hasFeature.andReturn(true);
|
||||
|
||||
|
||||
action.perform();
|
||||
|
||||
|
||||
// Expects navigation to parent of domainObject (removed object)
|
||||
expect(mockNavigationService.setNavigation).toHaveBeenCalledWith(mockParent);
|
||||
});
|
||||
|
||||
|
||||
it("checks if removing object not in ascendent path (reaches ROOT)", function () {
|
||||
// Navigates to grandchild of ROOT
|
||||
mockNavigationService.getNavigation.andReturn(mockGrandchildObject);
|
||||
|
||||
|
||||
// domainObject (grandparent) is set as ROOT, child and grandchild
|
||||
// are set objects not being removed
|
||||
mockDomainObject.getId.andReturn("test 1");
|
||||
mockRootObject.getId.andReturn("ROOT");
|
||||
mockChildObject.getId.andReturn("not test 2");
|
||||
mockGrandchildObject.getId.andReturn("not test 3");
|
||||
|
||||
|
||||
// Sets context for the grandchild, child, and domainObject
|
||||
mockRootObject.getCapability.andReturn(mockRootContext);
|
||||
mockChildObject.getCapability.andReturn(mockChildContext);
|
||||
mockGrandchildObject.getCapability.andReturn(mockGrandchildContext);
|
||||
|
||||
|
||||
// Parents of grandchild and child are set
|
||||
mockChildContext.getParent.andReturn(mockRootObject);
|
||||
mockGrandchildContext.getParent.andReturn(mockChildObject);
|
||||
|
||||
|
||||
mockType.hasFeature.andReturn(true);
|
||||
|
||||
|
||||
action.perform();
|
||||
|
||||
|
||||
// Expects no navigation to occur
|
||||
expect(mockNavigationService.setNavigation).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -52,11 +52,11 @@ define(
|
||||
);
|
||||
mockEditorCapability = jasmine.createSpyObj(
|
||||
"editor",
|
||||
[ "save", "cancel" ]
|
||||
["save", "cancel", "isEditContextRoot"]
|
||||
);
|
||||
mockActionCapability = jasmine.createSpyObj(
|
||||
"actionCapability",
|
||||
[ "perform"]
|
||||
["perform"]
|
||||
);
|
||||
capabilities.editor = mockEditorCapability;
|
||||
capabilities.action = mockActionCapability;
|
||||
@ -71,7 +71,7 @@ define(
|
||||
});
|
||||
mockDomainObject.getModel.andReturn({persisted: 0});
|
||||
mockEditorCapability.save.andReturn(mockPromise(true));
|
||||
mockDomainObject.getOriginalObject.andReturn(mockDomainObject);
|
||||
mockEditorCapability.isEditContextRoot.andReturn(true);
|
||||
|
||||
action = new SaveAction(actionContext);
|
||||
|
||||
@ -90,13 +90,20 @@ define(
|
||||
function () {
|
||||
mockDomainObject.getModel.andReturn({persisted: undefined});
|
||||
expect(SaveAction.appliesTo(actionContext)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
it("uses the editor capability to save the object",
|
||||
function () {
|
||||
action.perform();
|
||||
expect(mockEditorCapability.save).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("navigates to the object after saving",
|
||||
function () {
|
||||
action.perform();
|
||||
expect(mockActionCapability.perform).toHaveBeenCalledWith("navigate");
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -38,7 +38,7 @@ define(
|
||||
capabilities = {},
|
||||
action;
|
||||
|
||||
function noop () {}
|
||||
function noop() {}
|
||||
|
||||
function mockPromise(value) {
|
||||
return (value || {}).then ? value :
|
||||
@ -49,7 +49,7 @@ define(
|
||||
catch: function (callback) {
|
||||
return mockPromise(callback(value));
|
||||
}
|
||||
} ;
|
||||
} ;
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
@ -78,10 +78,11 @@ define(
|
||||
|
||||
mockEditorCapability = jasmine.createSpyObj(
|
||||
"editor",
|
||||
[ "save", "cancel" ]
|
||||
["save", "cancel", "isEditContextRoot"]
|
||||
);
|
||||
mockEditorCapability.cancel.andReturn(mockPromise(undefined));
|
||||
mockEditorCapability.save.andReturn(mockPromise(true));
|
||||
mockEditorCapability.isEditContextRoot.andReturn(true);
|
||||
capabilities.editor = mockEditorCapability;
|
||||
|
||||
mockActionCapability = jasmine.createSpyObj(
|
||||
@ -129,7 +130,7 @@ define(
|
||||
action.createWizard.andReturn({
|
||||
getFormStructure: noop,
|
||||
getInitialFormValue: noop,
|
||||
populateObjectFromInput: function() {
|
||||
populateObjectFromInput: function () {
|
||||
return mockDomainObject;
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -25,94 +25,149 @@ define(
|
||||
function (EditorCapability) {
|
||||
|
||||
describe("The editor capability", function () {
|
||||
var mockPersistence,
|
||||
mockEditableObject,
|
||||
mockDomainObject,
|
||||
mockCache,
|
||||
mockCallback,
|
||||
model,
|
||||
var mockDomainObject,
|
||||
capabilities,
|
||||
mockParentObject,
|
||||
mockTransactionService,
|
||||
mockStatusCapability,
|
||||
mockParentStatus,
|
||||
mockContextCapability,
|
||||
capability;
|
||||
|
||||
beforeEach(function () {
|
||||
mockPersistence = jasmine.createSpyObj(
|
||||
"persistence",
|
||||
[ "persist" ]
|
||||
);
|
||||
mockEditableObject = {
|
||||
getModel: function () { return model; }
|
||||
function fastPromise(val) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return callback(val);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability", "useCapability" ]
|
||||
["getId", "getModel", "hasCapability", "getCapability", "useCapability"]
|
||||
);
|
||||
mockCache = jasmine.createSpyObj(
|
||||
"cache",
|
||||
[ "saveAll", "markClean" ]
|
||||
mockParentObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
["getId", "getModel", "hasCapability", "getCapability", "useCapability"]
|
||||
);
|
||||
mockCallback = jasmine.createSpy("callback");
|
||||
mockTransactionService = jasmine.createSpyObj(
|
||||
"transactionService",
|
||||
[
|
||||
"startTransaction",
|
||||
"size",
|
||||
"commit",
|
||||
"cancel"
|
||||
]
|
||||
);
|
||||
mockTransactionService.commit.andReturn(fastPromise());
|
||||
mockTransactionService.cancel.andReturn(fastPromise());
|
||||
|
||||
mockDomainObject.getCapability.andReturn(mockPersistence);
|
||||
mockStatusCapability = jasmine.createSpyObj(
|
||||
"statusCapability",
|
||||
["get", "set"]
|
||||
);
|
||||
mockParentStatus = jasmine.createSpyObj(
|
||||
"statusCapability",
|
||||
["get", "set"]
|
||||
);
|
||||
mockContextCapability = jasmine.createSpyObj(
|
||||
"contextCapability",
|
||||
["getParent"]
|
||||
);
|
||||
mockContextCapability.getParent.andReturn(mockParentObject);
|
||||
|
||||
model = { someKey: "some value", x: 42 };
|
||||
capabilities = {
|
||||
context: mockContextCapability,
|
||||
status: mockStatusCapability
|
||||
};
|
||||
|
||||
mockDomainObject.hasCapability.andCallFake(function (name) {
|
||||
return capabilities[name] !== undefined;
|
||||
});
|
||||
|
||||
mockDomainObject.getCapability.andCallFake(function (name) {
|
||||
return capabilities[name];
|
||||
});
|
||||
|
||||
mockParentObject.getCapability.andReturn(mockParentStatus);
|
||||
mockParentObject.hasCapability.andReturn(false);
|
||||
|
||||
capability = new EditorCapability(
|
||||
mockPersistence,
|
||||
mockEditableObject,
|
||||
mockDomainObject,
|
||||
mockCache
|
||||
mockTransactionService,
|
||||
mockDomainObject
|
||||
);
|
||||
});
|
||||
|
||||
//TODO: Disabled for NEM Beta
|
||||
xit("mutates the real domain object on nonrecursive save", function () {
|
||||
capability.save(true).then(mockCallback);
|
||||
it("starts a transaction when edit is invoked", function () {
|
||||
capability.edit();
|
||||
expect(mockTransactionService.startTransaction).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Wait for promise to resolve
|
||||
waitsFor(function () {
|
||||
return mockCallback.calls.length > 0;
|
||||
}, 250);
|
||||
it("sets editing status on object", function () {
|
||||
capability.edit();
|
||||
expect(mockStatusCapability.set).toHaveBeenCalledWith("editing", true);
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
expect(mockDomainObject.useCapability)
|
||||
.toHaveBeenCalledWith("mutation", jasmine.any(Function));
|
||||
// We should get the model from the editable object back
|
||||
expect(
|
||||
mockDomainObject.useCapability.mostRecentCall.args[1]()
|
||||
).toEqual(model);
|
||||
it("uses editing status to determine editing context root", function () {
|
||||
capability.edit();
|
||||
mockStatusCapability.get.andReturn(false);
|
||||
expect(capability.isEditContextRoot()).toBe(false);
|
||||
mockStatusCapability.get.andReturn(true);
|
||||
expect(capability.isEditContextRoot()).toBe(true);
|
||||
});
|
||||
|
||||
it("inEditingContext returns true if parent object is being" +
|
||||
" edited", function () {
|
||||
mockStatusCapability.get.andReturn(false);
|
||||
mockParentStatus.get.andReturn(false);
|
||||
expect(capability.inEditContext()).toBe(false);
|
||||
mockParentStatus.get.andReturn(true);
|
||||
expect(capability.inEditContext()).toBe(true);
|
||||
});
|
||||
|
||||
describe("save", function () {
|
||||
beforeEach(function () {
|
||||
capability.edit();
|
||||
capability.save();
|
||||
});
|
||||
it("commits the transaction", function () {
|
||||
expect(mockTransactionService.commit).toHaveBeenCalled();
|
||||
});
|
||||
it("resets the edit state", function () {
|
||||
expect(mockStatusCapability.set).toHaveBeenCalledWith('editing', false);
|
||||
});
|
||||
});
|
||||
|
||||
//TODO: Disabled for NEM Beta
|
||||
xit("tells the cache to save others", function () {
|
||||
capability.save().then(mockCallback);
|
||||
|
||||
// Wait for promise to resolve
|
||||
waitsFor(function () {
|
||||
return mockCallback.calls.length > 0;
|
||||
}, 250);
|
||||
|
||||
runs(function () {
|
||||
expect(mockCache.saveAll).toHaveBeenCalled();
|
||||
describe("cancel", function () {
|
||||
beforeEach(function () {
|
||||
capability.edit();
|
||||
capability.cancel();
|
||||
});
|
||||
it("cancels the transaction", function () {
|
||||
expect(mockTransactionService.cancel).toHaveBeenCalled();
|
||||
});
|
||||
it("resets the edit state", function () {
|
||||
expect(mockStatusCapability.set).toHaveBeenCalledWith('editing', false);
|
||||
});
|
||||
});
|
||||
|
||||
//TODO: Disabled for NEM Beta
|
||||
xit("has no interactions on cancel", function () {
|
||||
capability.cancel().then(mockCallback);
|
||||
describe("dirty", function () {
|
||||
var model = {};
|
||||
|
||||
// Wait for promise to resolve
|
||||
waitsFor(function () {
|
||||
return mockCallback.calls.length > 0;
|
||||
}, 250);
|
||||
|
||||
runs(function () {
|
||||
expect(mockDomainObject.useCapability).not.toHaveBeenCalled();
|
||||
expect(mockCache.markClean).not.toHaveBeenCalled();
|
||||
expect(mockCache.saveAll).not.toHaveBeenCalled();
|
||||
beforeEach(function () {
|
||||
mockDomainObject.getModel.andReturn(model);
|
||||
capability.edit();
|
||||
capability.cancel();
|
||||
});
|
||||
it("returns true if the object has been modified since it" +
|
||||
" was last persisted", function () {
|
||||
mockTransactionService.size.andReturn(0);
|
||||
expect(capability.dirty()).toBe(false);
|
||||
mockTransactionService.size.andReturn(1);
|
||||
expect(capability.dirty()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -20,36 +20,35 @@
|
||||
* 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);
|
||||
[
|
||||
"../../src/capabilities/TransactionalPersistenceCapability",
|
||||
"../../src/capabilities/TransactionCapabilityDecorator"
|
||||
],
|
||||
function (TransactionalPersistenceCapability, TransactionCapabilityDecorator) {
|
||||
|
||||
action.getActions = function(domainObject) {
|
||||
return actionCapability.getActions(domainObject).filter(function(action){
|
||||
return DISALLOWED_ACTIONS.indexOf(action.getMetadata().key) === -1;
|
||||
describe("The transaction capability decorator", function () {
|
||||
var mockQ,
|
||||
mockTransactionService,
|
||||
mockCapabilityService,
|
||||
provider;
|
||||
|
||||
beforeEach(function () {
|
||||
mockQ = {};
|
||||
mockTransactionService = {};
|
||||
mockCapabilityService = jasmine.createSpyObj("capabilityService", ["getCapabilities"]);
|
||||
mockCapabilityService.getCapabilities.andReturn({
|
||||
persistence: function () {}
|
||||
});
|
||||
};
|
||||
|
||||
return action;
|
||||
}
|
||||
provider = new TransactionCapabilityDecorator(mockQ, mockTransactionService, mockCapabilityService);
|
||||
|
||||
return EditableActionCapability;
|
||||
});
|
||||
it("decorates the persistence capability", function () {
|
||||
var capabilities = provider.getCapabilities();
|
||||
expect(capabilities.persistence({}) instanceof TransactionalPersistenceCapability).toBe(true);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -0,0 +1,92 @@
|
||||
/*****************************************************************************
|
||||
* 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,describe,it,expect,beforeEach,jasmine*/
|
||||
|
||||
define(
|
||||
[
|
||||
"../../src/capabilities/TransactionalPersistenceCapability"
|
||||
],
|
||||
function (TransactionalPersistenceCapability) {
|
||||
|
||||
function fastPromise(val) {
|
||||
return {
|
||||
then: function (callback) {
|
||||
return callback(val);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
describe("The transactional persistence decorator", function () {
|
||||
var mockQ,
|
||||
mockTransactionService,
|
||||
mockPersistence,
|
||||
mockDomainObject,
|
||||
capability;
|
||||
|
||||
beforeEach(function () {
|
||||
mockQ = jasmine.createSpyObj("$q", ["when"]);
|
||||
mockQ.when.andCallFake(function (val) {
|
||||
return fastPromise(val);
|
||||
});
|
||||
mockTransactionService = jasmine.createSpyObj(
|
||||
"transactionService",
|
||||
["isActive", "addToTransaction"]
|
||||
);
|
||||
mockPersistence = jasmine.createSpyObj(
|
||||
"persistenceCapability",
|
||||
["persist", "refresh"]
|
||||
);
|
||||
mockPersistence.persist.andReturn(fastPromise());
|
||||
mockPersistence.refresh.andReturn(fastPromise());
|
||||
capability = new TransactionalPersistenceCapability(mockQ, mockTransactionService, mockPersistence, mockDomainObject);
|
||||
});
|
||||
|
||||
it("if no transaction is active, passes through to persistence" +
|
||||
" provider", function () {
|
||||
mockTransactionService.isActive.andReturn(false);
|
||||
capability.persist();
|
||||
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("if transaction is active, persist and cancel calls are" +
|
||||
" queued", function () {
|
||||
mockTransactionService.isActive.andReturn(true);
|
||||
capability.persist();
|
||||
expect(mockTransactionService.addToTransaction).toHaveBeenCalled();
|
||||
mockTransactionService.addToTransaction.mostRecentCall.args[0]();
|
||||
expect(mockPersistence.persist).toHaveBeenCalled();
|
||||
mockTransactionService.addToTransaction.mostRecentCall.args[1]();
|
||||
expect(mockPersistence.refresh).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("persist call is only added to transaction once", function () {
|
||||
mockTransactionService.isActive.andReturn(true);
|
||||
capability.persist();
|
||||
expect(mockTransactionService.addToTransaction).toHaveBeenCalled();
|
||||
capability.persist();
|
||||
expect(mockTransactionService.addToTransaction.calls.length).toBe(1);
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -56,4 +56,4 @@ define(
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
@ -52,15 +52,15 @@ define(
|
||||
);
|
||||
mockScope = jasmine.createSpyObj(
|
||||
"$scope",
|
||||
[ "$on", "$watch" ]
|
||||
["$on", "$watch"]
|
||||
);
|
||||
mockObject = jasmine.createSpyObj(
|
||||
"domainObject",
|
||||
[ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ]
|
||||
["getId", "getModel", "getCapability", "hasCapability", "useCapability"]
|
||||
);
|
||||
mockType = jasmine.createSpyObj(
|
||||
"type",
|
||||
[ "hasFeature" ]
|
||||
["hasFeature"]
|
||||
);
|
||||
mockStatusCapability = jasmine.createSpyObj('statusCapability',
|
||||
["get"]
|
||||
@ -99,8 +99,8 @@ define(
|
||||
expect(controller.getUnloadWarning()).toBeUndefined();
|
||||
|
||||
// Override the policy service to prevent navigation
|
||||
mockPolicyService.allow.andCallFake(function(category, object, context, callback){
|
||||
callback(errorMessage);
|
||||
mockPolicyService.allow.andCallFake(function (category, object, context, callback) {
|
||||
callback(errorMessage);
|
||||
});
|
||||
|
||||
// Should have some warning message here now
|
||||
|
@ -34,11 +34,11 @@ define(
|
||||
mockScope = jasmine.createSpyObj("$scope", ["$watch"]);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
[ 'getId', 'getCapability' ]
|
||||
['getId', 'getCapability']
|
||||
);
|
||||
mockContext = jasmine.createSpyObj(
|
||||
'context',
|
||||
[ 'getTrueRoot' ]
|
||||
['getTrueRoot']
|
||||
);
|
||||
|
||||
mockDomainObject.getId.andReturn('test-id');
|
||||
@ -110,4 +110,4 @@ define(
|
||||
});
|
||||
});
|
||||
}
|
||||
);
|
||||
);
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user