Use mutable object for plans (#3712)

* Use mutable object for plans so that they can sync even in time strip views
Allow the name of couch search folder to be configurable

* Move observing of couchdb changes to the _toMutable function

* Fix unit tests

Co-authored-by: Jamie V <jamie.j.vigliotta@nasa.gov>
This commit is contained in:
Shefali Joshi 2021-02-25 15:14:31 -08:00 committed by GitHub
parent 16249c3790
commit 3571004f5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 56 additions and 28 deletions

View File

@ -29,9 +29,22 @@ describe('The ActionCollection', () => {
let mockApplicableActions;
let mockObjectPath;
let mockView;
let mockIdentifierService;
beforeEach(() => {
openmct = createOpenMct();
openmct.$injector = jasmine.createSpyObj('$injector', ['get']);
mockIdentifierService = jasmine.createSpyObj(
'identifierService',
['parse']
);
mockIdentifierService.parse.and.returnValue({
getSpace: () => {
return '';
}
});
openmct.$injector.get.and.returnValue(mockIdentifierService);
mockObjectPath = [
{
name: 'mock folder',

View File

@ -228,29 +228,13 @@ ObjectAPI.prototype.search = function (query, options) {
* @returns {Promise.<MutableDomainObject>} a promise that will resolve with a MutableDomainObject if
* the object can be mutated.
*/
ObjectAPI.prototype.getMutable = function (idOrKeyString) {
if (!this.supportsMutation(idOrKeyString)) {
throw new Error(`Object "${this.makeKeyString(idOrKeyString)}" does not support mutation.`);
ObjectAPI.prototype.getMutable = function (identifier) {
if (!this.supportsMutation(identifier)) {
throw new Error(`Object "${this.makeKeyString(identifier)}" does not support mutation.`);
}
return this.get(idOrKeyString).then((object) => {
const mutableDomainObject = this._toMutable(object);
// Check if provider supports realtime updates
let identifier = utils.parseKeyString(idOrKeyString);
let provider = this.getProvider(identifier);
if (provider !== undefined
&& provider.observe !== undefined) {
let unobserve = provider.observe(identifier, (updatedModel) => {
mutableDomainObject.$refresh(updatedModel);
});
mutableDomainObject.$on('$destroy', () => {
unobserve();
});
}
return mutableDomainObject;
return this.get(identifier).then((object) => {
return this._toMutable(object);
});
};
@ -389,11 +373,29 @@ ObjectAPI.prototype.mutate = function (domainObject, path, value) {
* @private
*/
ObjectAPI.prototype._toMutable = function (object) {
let mutableObject;
if (object.isMutable) {
return object;
mutableObject = object;
} else {
return MutableDomainObject.createMutable(object, this.eventEmitter);
mutableObject = MutableDomainObject.createMutable(object, this.eventEmitter);
}
// Check if provider supports realtime updates
let identifier = utils.parseKeyString(mutableObject.identifier);
let provider = this.getProvider(identifier);
if (provider !== undefined
&& provider.observe !== undefined) {
let unobserve = provider.observe(identifier, (updatedModel) => {
mutableObject.$refresh(updatedModel);
});
mutableObject.$on('$destroy', () => {
unobserve();
});
}
return mutableObject;
};
/**

View File

@ -1,4 +1,4 @@
export default function (couchPlugin, searchFilter) {
export default function (folderName, couchPlugin, searchFilter) {
return function install(openmct) {
const couchProvider = couchPlugin.couchProvider;
@ -15,7 +15,7 @@ export default function (couchPlugin, searchFilter) {
return Promise.resolve({
identifier,
type: 'folder',
name: "CouchDB Documents"
name: folderName || "CouchDB Documents"
});
}
}

View File

@ -39,7 +39,7 @@ describe('the plugin', function () {
let couchPlugin = openmct.plugins.CouchDB(testPath);
openmct.install(couchPlugin);
openmct.install(new CouchDBSearchFolderPlugin(couchPlugin, {
openmct.install(new CouchDBSearchFolderPlugin('CouchDB Documents', couchPlugin, {
"selector": {
"model": {
"type": "plan"

View File

@ -56,11 +56,24 @@ const notebookStorage = {
}
};
let openmct = createOpenMct();
let openmct;
let mockIdentifierService;
describe('Notebook Storage:', () => {
beforeEach((done) => {
openmct = createOpenMct();
openmct.$injector = jasmine.createSpyObj('$injector', ['get']);
mockIdentifierService = jasmine.createSpyObj(
'identifierService',
['parse']
);
mockIdentifierService.parse.and.returnValue({
getSpace: () => {
return '';
}
});
openmct.$injector.get.and.returnValue(mockIdentifierService);
window.localStorage.setItem('notebook-storage', null);
openmct.objects.addProvider('', jasmine.createSpyObj('mockNotebookProvider', [
'create',

View File

@ -85,7 +85,7 @@ export default {
this.resizeTimer = setInterval(this.resize, RESIZE_POLL_INTERVAL);
this.unlisten = this.openmct.objects.observe(this.domainObject, '*', this.observeForChanges);
},
destroyed() {
beforeDestroy() {
clearInterval(this.resizeTimer);
this.openmct.time.off("timeSystem", this.setScaleAndPlotActivities);
this.openmct.time.off("bounds", this.updateViewBounds);