mirror of
https://github.com/nasa/openmct.git
synced 2025-02-21 17:57:04 +00:00
Fixes #2144. Identifiers for objects and links now exported as identifier objects.
Use keystring as map key on import. Also removed redundant step to re-add imported objects to parent composition.
This commit is contained in:
parent
9582fb2b06
commit
6a9cf3389d
@ -133,7 +133,7 @@ define(['lodash'], function (_) {
|
||||
copyOfChild.location = parentId;
|
||||
parent.composition[index] = copyOfChild.identifier;
|
||||
this.tree[newIdString] = copyOfChild;
|
||||
this.tree[parentId].composition[index] = newIdString;
|
||||
this.tree[parentId].composition[index] = copyOfChild.identifier;
|
||||
|
||||
return copyOfChild;
|
||||
};
|
||||
|
@ -79,16 +79,18 @@ define(['zepto'], function ($) {
|
||||
var parentModel = parent.getModel();
|
||||
var newObj;
|
||||
|
||||
seen.push(parent.getId());
|
||||
seen.push(this.getKeyString(parent.getId()));
|
||||
parentModel.composition.forEach(function (childId, index) {
|
||||
if (!tree[childId] || seen.includes(childId)) {
|
||||
var childIdString = this.getKeyString(childId);
|
||||
if (!tree[childIdString] || seen.includes(childIdString)) {
|
||||
return;
|
||||
}
|
||||
|
||||
newObj = this.instantiate(tree[childId], childId);
|
||||
parent.getCapability("composition").add(newObj);
|
||||
newObj.getCapability("location")
|
||||
.setPrimaryLocation(tree[childId].location);
|
||||
newObj = this.instantiate(tree[childIdString], childIdString);
|
||||
// New object has not been persisted yet so clear persisted
|
||||
// timestamp from copied model.
|
||||
delete newObj.getModel().persisted;
|
||||
newObj.getCapability('persistence').persist();
|
||||
this.deepInstantiate(newObj, tree, seen);
|
||||
}, this);
|
||||
}
|
||||
@ -103,6 +105,10 @@ define(['zepto'], function ($) {
|
||||
return tree;
|
||||
};
|
||||
|
||||
ImportAsJSONAction.prototype.getKeyString = function (identifier) {
|
||||
return this.openmct.objects.makeKeyString(identifier);
|
||||
};
|
||||
|
||||
/**
|
||||
* Rewrites all instances of a given id in the tree with a newly generated
|
||||
* replacement to prevent collision.
|
||||
|
@ -47,7 +47,12 @@ define(
|
||||
uniqueId = 0;
|
||||
newObjects = [];
|
||||
openmct = {
|
||||
$injector: jasmine.createSpyObj('$injector', ['get'])
|
||||
$injector: jasmine.createSpyObj('$injector', ['get']),
|
||||
objects: {
|
||||
makeKeyString: function (identifier) {
|
||||
return identifier.key;
|
||||
}
|
||||
}
|
||||
};
|
||||
mockInstantiate = jasmine.createSpy('instantiate').and.callFake(
|
||||
function (model, id) {
|
||||
@ -154,7 +159,7 @@ define(
|
||||
body: JSON.stringify({
|
||||
"openmct": {
|
||||
"infiniteParent": {
|
||||
"composition": ["infinteChild"],
|
||||
"composition": [{key: "infinteChild", namespace: ""}],
|
||||
"name": "1",
|
||||
"type": "folder",
|
||||
"modified": 1503598129176,
|
||||
@ -162,7 +167,7 @@ define(
|
||||
"persisted": 1503598129176
|
||||
},
|
||||
"infinteChild": {
|
||||
"composition": ["infiniteParent"],
|
||||
"composition": [{key: "infinteParent", namespace: ""}],
|
||||
"name": "2",
|
||||
"type": "folder",
|
||||
"modified": 1503598132428,
|
||||
|
Loading…
x
Reference in New Issue
Block a user