mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 14:07:50 +00:00
Defers legacy mutation of object till after a creation happens. (#3379)
* Defers legacy mutation of object till after a creation happens. * Fixes display layout to defer actions until objects.save returns * Revert back to localStorage... big oops!
This commit is contained in:
parent
67749dd2bb
commit
08b2940eb6
@ -192,6 +192,7 @@ define([
|
||||
*/
|
||||
ObjectAPI.prototype.save = function (domainObject) {
|
||||
let provider = this.getProvider(domainObject.identifier);
|
||||
let savedResolve;
|
||||
let result;
|
||||
|
||||
if (!this.isPersistable(domainObject)) {
|
||||
@ -200,8 +201,14 @@ define([
|
||||
result = Promise.resolve(true);
|
||||
} else {
|
||||
if (domainObject.persisted === undefined) {
|
||||
domainObject.persisted = domainObject.modified;
|
||||
result = new Promise((resolve) => {
|
||||
savedResolve = resolve;
|
||||
});
|
||||
provider.create(domainObject).then((response) => {
|
||||
this.mutate(domainObject, 'persisted', domainObject.modified);
|
||||
result = provider.create(domainObject);
|
||||
savedResolve(response);
|
||||
});
|
||||
} else {
|
||||
this.mutate(domainObject, 'persisted', domainObject.modified);
|
||||
result = provider.update(domainObject);
|
||||
|
@ -32,6 +32,7 @@ describe("The Object API", () => {
|
||||
"create",
|
||||
"update"
|
||||
]);
|
||||
mockProvider.create.and.returnValue(Promise.resolve(true));
|
||||
objectAPI.addProvider(TEST_NAMESPACE, mockProvider);
|
||||
});
|
||||
it("Calls 'create' on provider if object is new", () => {
|
||||
|
@ -630,9 +630,14 @@ export default {
|
||||
object.identifier = identifier;
|
||||
object.location = parentKeyString;
|
||||
|
||||
this.openmct.objects.save(object);
|
||||
let savedResolve;
|
||||
this.openmct.objects.save(object).then(() => {
|
||||
savedResolve(object);
|
||||
});
|
||||
|
||||
return object;
|
||||
return new Promise((resolve) => {
|
||||
savedResolve = resolve;
|
||||
});
|
||||
},
|
||||
convertToTelemetryView(identifier, position) {
|
||||
this.openmct.objects.get(identifier).then((domainObject) => {
|
||||
@ -679,10 +684,10 @@ export default {
|
||||
}
|
||||
|
||||
if (copy.type === 'subobject-view') {
|
||||
let newDomainObject = this.createNewDomainObject(domainObject, domainObject.composition, domainObject.type, 'duplicate', domainObject);
|
||||
|
||||
this.createNewDomainObject(domainObject, domainObject.composition, domainObject.type, 'duplicate', domainObject).then((newDomainObject) => {
|
||||
newDomainObjectsArray.push(newDomainObject);
|
||||
copy.identifier = newDomainObject.identifier;
|
||||
});
|
||||
}
|
||||
|
||||
offsetKeys.forEach(key => {
|
||||
@ -719,12 +724,12 @@ export default {
|
||||
name: 'Merged Telemetry Views',
|
||||
identifier: firstDomainObject.identifier
|
||||
};
|
||||
let newDomainObject = this.createNewDomainObject(mockDomainObject, identifiers, viewType);
|
||||
|
||||
this.createNewDomainObject(mockDomainObject, identifiers, viewType).then((newDomainObject) => {
|
||||
this.composition.add(newDomainObject);
|
||||
this.addItem('subobject-view', newDomainObject, position);
|
||||
this.removeItem(selection);
|
||||
this.initSelectIndex = this.layoutItems.length - 1;
|
||||
});
|
||||
},
|
||||
mergeMultipleOverlayPlots(selection, viewType) {
|
||||
let overlayPlots = selection.map(selectedItem => selectedItem[0].context.item);
|
||||
@ -736,7 +741,7 @@ export default {
|
||||
name: 'Merged Overlay Plots',
|
||||
identifier: firstOverlayPlot.identifier
|
||||
};
|
||||
let newDomainObject = this.createNewDomainObject(mockDomainObject, overlayPlotIdentifiers, viewType);
|
||||
this.createNewDomainObject(mockDomainObject, overlayPlotIdentifiers, viewType).then((newDomainObject) => {
|
||||
let newDomainObjectKeyString = this.openmct.objects.makeKeyString(newDomainObject.identifier);
|
||||
let internalDomainObjectKeyString = this.openmct.objects.makeKeyString(this.internalDomainObject.identifier);
|
||||
|
||||
@ -751,6 +756,7 @@ export default {
|
||||
|
||||
this.removeItem(selection);
|
||||
this.initSelectIndex = this.layoutItems.length - 1;
|
||||
});
|
||||
},
|
||||
getTelemetryIdentifiers(domainObject) {
|
||||
let method = TELEMETRY_IDENTIFIER_FUNCTIONS[domainObject.type];
|
||||
@ -768,10 +774,10 @@ export default {
|
||||
let layoutType = 'subobject-view';
|
||||
|
||||
if (layoutItem.type === 'telemetry-view') {
|
||||
let newDomainObject = this.createNewDomainObject(domainObject, [domainObject.identifier], viewType);
|
||||
|
||||
this.createNewDomainObject(domainObject, [domainObject.identifier], viewType).then((newDomainObject) => {
|
||||
this.composition.add(newDomainObject);
|
||||
this.addItem(layoutType, newDomainObject, position);
|
||||
});
|
||||
} else {
|
||||
this.getTelemetryIdentifiers(domainObject).then((identifiers) => {
|
||||
if (viewType === 'telemetry-view') {
|
||||
@ -782,10 +788,10 @@ export default {
|
||||
this.convertToTelemetryView(identifier, [positionX, positionY]);
|
||||
});
|
||||
} else {
|
||||
let newDomainObject = this.createNewDomainObject(domainObject, identifiers, viewType);
|
||||
|
||||
this.createNewDomainObject(domainObject, identifiers, viewType).then((newDomainObject) => {
|
||||
this.composition.add(newDomainObject);
|
||||
this.addItem(layoutType, newDomainObject, position);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -71,11 +71,13 @@ export default class NewFolderAction {
|
||||
|
||||
folderType.definition.initialize(objectModel);
|
||||
objectModel.name = name || 'New Folder';
|
||||
objectModel.modified = Date.now();
|
||||
|
||||
this._openmct.objects.save(objectModel);
|
||||
|
||||
this._openmct.objects.save(objectModel).then(() => {
|
||||
composition.add(objectModel);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
appliesTo(objectPath) {
|
||||
let domainObject = objectPath[0];
|
||||
|
@ -79,7 +79,7 @@ describe("the plugin", () => {
|
||||
|
||||
spyOn(openmct.$injector, 'get').and.returnValue(mockDialogService);
|
||||
spyOn(compositionAPI, 'get').and.returnValue(mockComposition);
|
||||
spyOn(openmct.objects, 'save');
|
||||
spyOn(openmct.objects, 'save').and.returnValue(Promise.resolve(true));
|
||||
|
||||
newFolderAction.invoke(mockObjectPath);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user