mirror of
https://github.com/nasa/openmct.git
synced 2025-06-13 04:38:15 +00:00
[Creation] Store location of new objects
The creation service stores the location (the full path) to the domain object as "model.location"
This commit is contained in:
@ -112,12 +112,37 @@ define(
|
||||
return $q.when(
|
||||
uuid()
|
||||
).then(function (id) {
|
||||
model = addLocationToModel(id, model, parent);
|
||||
return doPersist(persistence.getSpace(), id, model);
|
||||
}).then(function (id) {
|
||||
return addToComposition(id, parent, persistence);
|
||||
});
|
||||
}
|
||||
|
||||
// Store the location of an object relative to it's parent.
|
||||
function addLocationToModel(modelId, model, parent) {
|
||||
var context = parent.getCapability("context"),
|
||||
pathObjects,
|
||||
pathIds;
|
||||
|
||||
if (!context) {
|
||||
$log.warn('No parent context, location will not be set.');
|
||||
return model;
|
||||
}
|
||||
|
||||
pathObjects = context.getPath();
|
||||
if (!pathObjects || !pathObjects.length) {
|
||||
pathObjects = [];
|
||||
}
|
||||
pathIds = pathObjects.map(function (object) {
|
||||
return object.getId();
|
||||
});
|
||||
pathIds.push(modelId);
|
||||
|
||||
model.location = pathIds.join('/');
|
||||
return model;
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Create a new domain object with the provided model, as
|
||||
|
Reference in New Issue
Block a user