mirror of
https://github.com/nasa/openmct.git
synced 2025-06-19 07:38:15 +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:
@ -133,7 +133,7 @@ define(['lodash'], function (_) {
|
|||||||
copyOfChild.location = parentId;
|
copyOfChild.location = parentId;
|
||||||
parent.composition[index] = copyOfChild.identifier;
|
parent.composition[index] = copyOfChild.identifier;
|
||||||
this.tree[newIdString] = copyOfChild;
|
this.tree[newIdString] = copyOfChild;
|
||||||
this.tree[parentId].composition[index] = newIdString;
|
this.tree[parentId].composition[index] = copyOfChild.identifier;
|
||||||
|
|
||||||
return copyOfChild;
|
return copyOfChild;
|
||||||
};
|
};
|
||||||
|
@ -79,16 +79,18 @@ define(['zepto'], function ($) {
|
|||||||
var parentModel = parent.getModel();
|
var parentModel = parent.getModel();
|
||||||
var newObj;
|
var newObj;
|
||||||
|
|
||||||
seen.push(parent.getId());
|
seen.push(this.getKeyString(parent.getId()));
|
||||||
parentModel.composition.forEach(function (childId, index) {
|
parentModel.composition.forEach(function (childId, index) {
|
||||||
if (!tree[childId] || seen.includes(childId)) {
|
var childIdString = this.getKeyString(childId);
|
||||||
|
if (!tree[childIdString] || seen.includes(childIdString)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
newObj = this.instantiate(tree[childId], childId);
|
newObj = this.instantiate(tree[childIdString], childIdString);
|
||||||
parent.getCapability("composition").add(newObj);
|
// New object has not been persisted yet so clear persisted
|
||||||
newObj.getCapability("location")
|
// timestamp from copied model.
|
||||||
.setPrimaryLocation(tree[childId].location);
|
delete newObj.getModel().persisted;
|
||||||
|
newObj.getCapability('persistence').persist();
|
||||||
this.deepInstantiate(newObj, tree, seen);
|
this.deepInstantiate(newObj, tree, seen);
|
||||||
}, this);
|
}, this);
|
||||||
}
|
}
|
||||||
@ -103,6 +105,10 @@ define(['zepto'], function ($) {
|
|||||||
return tree;
|
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
|
* Rewrites all instances of a given id in the tree with a newly generated
|
||||||
* replacement to prevent collision.
|
* replacement to prevent collision.
|
||||||
|
@ -47,7 +47,12 @@ define(
|
|||||||
uniqueId = 0;
|
uniqueId = 0;
|
||||||
newObjects = [];
|
newObjects = [];
|
||||||
openmct = {
|
openmct = {
|
||||||
$injector: jasmine.createSpyObj('$injector', ['get'])
|
$injector: jasmine.createSpyObj('$injector', ['get']),
|
||||||
|
objects: {
|
||||||
|
makeKeyString: function (identifier) {
|
||||||
|
return identifier.key;
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
mockInstantiate = jasmine.createSpy('instantiate').and.callFake(
|
mockInstantiate = jasmine.createSpy('instantiate').and.callFake(
|
||||||
function (model, id) {
|
function (model, id) {
|
||||||
@ -154,7 +159,7 @@ define(
|
|||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"openmct": {
|
"openmct": {
|
||||||
"infiniteParent": {
|
"infiniteParent": {
|
||||||
"composition": ["infinteChild"],
|
"composition": [{key: "infinteChild", namespace: ""}],
|
||||||
"name": "1",
|
"name": "1",
|
||||||
"type": "folder",
|
"type": "folder",
|
||||||
"modified": 1503598129176,
|
"modified": 1503598129176,
|
||||||
@ -162,7 +167,7 @@ define(
|
|||||||
"persisted": 1503598129176
|
"persisted": 1503598129176
|
||||||
},
|
},
|
||||||
"infinteChild": {
|
"infinteChild": {
|
||||||
"composition": ["infiniteParent"],
|
"composition": [{key: "infinteParent", namespace: ""}],
|
||||||
"name": "2",
|
"name": "2",
|
||||||
"type": "folder",
|
"type": "folder",
|
||||||
"modified": 1503598132428,
|
"modified": 1503598132428,
|
||||||
|
Reference in New Issue
Block a user