mirror of
https://github.com/nasa/openmct.git
synced 2025-05-15 15:02:51 +00:00
Merge branch 'undirty-on-refresh-1046' into transaction-clearing-1059
Conflicts: platform/commonUI/edit/src/actions/SaveAsAction.js
This commit is contained in:
commit
4c7ad6d93a
@ -111,7 +111,8 @@ define([
|
|||||||
var self = this,
|
var self = this,
|
||||||
domainObject = this.domainObject,
|
domainObject = this.domainObject,
|
||||||
copyService = this.copyService,
|
copyService = this.copyService,
|
||||||
dialog = new SaveInProgressDialog(this.dialogService);
|
dialog = new SaveInProgressDialog(this.dialogService),
|
||||||
|
toUndirty = [];
|
||||||
|
|
||||||
function doWizardSave(parent) {
|
function doWizardSave(parent) {
|
||||||
var wizard = self.createWizard(parent);
|
var wizard = self.createWizard(parent);
|
||||||
@ -143,14 +144,28 @@ define([
|
|||||||
}
|
}
|
||||||
|
|
||||||
function allowClone(objectToClone) {
|
function allowClone(objectToClone) {
|
||||||
return (objectToClone.getId() === domainObject.getId()) ||
|
var allowed =
|
||||||
|
(objectToClone.getId() === domainObject.getId()) ||
|
||||||
objectToClone.getCapability('location').isOriginal();
|
objectToClone.getCapability('location').isOriginal();
|
||||||
|
if (allowed) {
|
||||||
|
toUndirty.push(objectToClone);
|
||||||
|
}
|
||||||
|
return allowed;
|
||||||
}
|
}
|
||||||
|
|
||||||
function cloneIntoParent(parent) {
|
function cloneIntoParent(parent) {
|
||||||
return copyService.perform(domainObject, parent, allowClone);
|
return copyService.perform(domainObject, parent, allowClone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function undirty(object) {
|
||||||
|
return object.getCapability('persistence').refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
function undirtyOriginals(object) {
|
||||||
|
return Promise.all(toUndirty.map(undirty))
|
||||||
|
.then(resolveWith(object));
|
||||||
|
}
|
||||||
|
|
||||||
function commitEditingAfterClone(clonedObject) {
|
function commitEditingAfterClone(clonedObject) {
|
||||||
return domainObject.getCapability("editor").save()
|
return domainObject.getCapability("editor").save()
|
||||||
.then(resolveWith(clonedObject));
|
.then(resolveWith(clonedObject));
|
||||||
@ -166,6 +181,7 @@ define([
|
|||||||
.then(showBlockingDialog)
|
.then(showBlockingDialog)
|
||||||
.then(getParent)
|
.then(getParent)
|
||||||
.then(cloneIntoParent)
|
.then(cloneIntoParent)
|
||||||
|
.then(undirtyOriginals)
|
||||||
.then(commitEditingAfterClone)
|
.then(commitEditingAfterClone)
|
||||||
.then(hideBlockingDialog)
|
.then(hideBlockingDialog)
|
||||||
.catch(onFailure);
|
.catch(onFailure);
|
||||||
|
@ -49,6 +49,7 @@ define(
|
|||||||
this.domainObject = domainObject;
|
this.domainObject = domainObject;
|
||||||
this.$q = $q;
|
this.$q = $q;
|
||||||
this.persistPending = false;
|
this.persistPending = false;
|
||||||
|
this.removeFromTransaction = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -75,6 +76,7 @@ define(
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
self.persistPending = false;
|
self.persistPending = false;
|
||||||
|
self.removeFromTransaction = undefined;
|
||||||
//Model is undefined in persistence, so return undefined.
|
//Model is undefined in persistence, so return undefined.
|
||||||
return self.$q.when(undefined);
|
return self.$q.when(undefined);
|
||||||
}
|
}
|
||||||
@ -82,7 +84,8 @@ define(
|
|||||||
|
|
||||||
if (this.transactionService.isActive()) {
|
if (this.transactionService.isActive()) {
|
||||||
if (!this.persistPending) {
|
if (!this.persistPending) {
|
||||||
this.transactionService.addToTransaction(onCommit, onCancel);
|
this.removeFromTransaction = this.transactionService
|
||||||
|
.addToTransaction(onCommit, onCancel);
|
||||||
this.persistPending = true;
|
this.persistPending = true;
|
||||||
}
|
}
|
||||||
//Need to return a promise from this function
|
//Need to return a promise from this function
|
||||||
@ -93,6 +96,11 @@ define(
|
|||||||
};
|
};
|
||||||
|
|
||||||
TransactionalPersistenceCapability.prototype.refresh = function () {
|
TransactionalPersistenceCapability.prototype.refresh = function () {
|
||||||
|
if (this.persistPending) {
|
||||||
|
this.persistPending = false;
|
||||||
|
this.removeFromTransaction();
|
||||||
|
this.removeFromTransaction = undefined;
|
||||||
|
}
|
||||||
return this.persistenceCapability.refresh();
|
return this.persistenceCapability.refresh();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,6 +81,15 @@ define(
|
|||||||
//Log error because this is a programming error if it occurs.
|
//Log error because this is a programming error if it occurs.
|
||||||
this.$log.error("No transaction in progress");
|
this.$log.error("No transaction in progress");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return function () {
|
||||||
|
this.onCommits = this.onCommits.filter(function (callback) {
|
||||||
|
return callback !== onCommit;
|
||||||
|
});
|
||||||
|
this.onCancels = this.onCancels.filter(function (callback) {
|
||||||
|
return callback !== onCancel;
|
||||||
|
});
|
||||||
|
}.bind(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -152,6 +152,10 @@ define(
|
|||||||
}, modified);
|
}, modified);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (domainObject.getModel().persisted === undefined) {
|
||||||
|
return this.$q.when(true);
|
||||||
|
}
|
||||||
|
|
||||||
return this.persistenceService.readObject(
|
return this.persistenceService.readObject(
|
||||||
this.getSpace(),
|
this.getSpace(),
|
||||||
this.getKey()
|
this.getKey()
|
||||||
|
@ -74,7 +74,7 @@ define(
|
|||||||
);
|
);
|
||||||
mockQ = jasmine.createSpyObj(
|
mockQ = jasmine.createSpyObj(
|
||||||
"$q",
|
"$q",
|
||||||
["reject"]
|
["reject", "when"]
|
||||||
);
|
);
|
||||||
mockNofificationService = jasmine.createSpyObj(
|
mockNofificationService = jasmine.createSpyObj(
|
||||||
"notificationService",
|
"notificationService",
|
||||||
@ -103,6 +103,7 @@ define(
|
|||||||
mockIdentifierService.parse.andReturn(mockIdentifier);
|
mockIdentifierService.parse.andReturn(mockIdentifier);
|
||||||
mockIdentifier.getSpace.andReturn(SPACE);
|
mockIdentifier.getSpace.andReturn(SPACE);
|
||||||
mockIdentifier.getKey.andReturn(key);
|
mockIdentifier.getKey.andReturn(key);
|
||||||
|
mockQ.when.andCallFake(asPromise);
|
||||||
persistence = new PersistenceCapability(
|
persistence = new PersistenceCapability(
|
||||||
mockCacheService,
|
mockCacheService,
|
||||||
mockPersistenceService,
|
mockPersistenceService,
|
||||||
@ -156,6 +157,7 @@ define(
|
|||||||
});
|
});
|
||||||
it("refreshes the domain object model from persistence", function () {
|
it("refreshes the domain object model from persistence", function () {
|
||||||
var refreshModel = {someOtherKey: "some other value"};
|
var refreshModel = {someOtherKey: "some other value"};
|
||||||
|
model.persisted = 1;
|
||||||
mockPersistenceService.readObject.andReturn(asPromise(refreshModel));
|
mockPersistenceService.readObject.andReturn(asPromise(refreshModel));
|
||||||
persistence.refresh();
|
persistence.refresh();
|
||||||
expect(model).toEqual(refreshModel);
|
expect(model).toEqual(refreshModel);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user