mirror of
https://github.com/nasa/openmct.git
synced 2025-06-15 05:38:12 +00:00
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:
@ -29,9 +29,22 @@ describe('The ActionCollection', () => {
|
|||||||
let mockApplicableActions;
|
let mockApplicableActions;
|
||||||
let mockObjectPath;
|
let mockObjectPath;
|
||||||
let mockView;
|
let mockView;
|
||||||
|
let mockIdentifierService;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
openmct = createOpenMct();
|
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 = [
|
mockObjectPath = [
|
||||||
{
|
{
|
||||||
name: 'mock folder',
|
name: 'mock folder',
|
||||||
|
@ -228,29 +228,13 @@ ObjectAPI.prototype.search = function (query, options) {
|
|||||||
* @returns {Promise.<MutableDomainObject>} a promise that will resolve with a MutableDomainObject if
|
* @returns {Promise.<MutableDomainObject>} a promise that will resolve with a MutableDomainObject if
|
||||||
* the object can be mutated.
|
* the object can be mutated.
|
||||||
*/
|
*/
|
||||||
ObjectAPI.prototype.getMutable = function (idOrKeyString) {
|
ObjectAPI.prototype.getMutable = function (identifier) {
|
||||||
if (!this.supportsMutation(idOrKeyString)) {
|
if (!this.supportsMutation(identifier)) {
|
||||||
throw new Error(`Object "${this.makeKeyString(idOrKeyString)}" does not support mutation.`);
|
throw new Error(`Object "${this.makeKeyString(identifier)}" does not support mutation.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.get(idOrKeyString).then((object) => {
|
return this.get(identifier).then((object) => {
|
||||||
const mutableDomainObject = this._toMutable(object);
|
return 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;
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -389,11 +373,29 @@ ObjectAPI.prototype.mutate = function (domainObject, path, value) {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
ObjectAPI.prototype._toMutable = function (object) {
|
ObjectAPI.prototype._toMutable = function (object) {
|
||||||
|
let mutableObject;
|
||||||
|
|
||||||
if (object.isMutable) {
|
if (object.isMutable) {
|
||||||
return object;
|
mutableObject = object;
|
||||||
} else {
|
} 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;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
export default function (couchPlugin, searchFilter) {
|
export default function (folderName, couchPlugin, searchFilter) {
|
||||||
return function install(openmct) {
|
return function install(openmct) {
|
||||||
const couchProvider = couchPlugin.couchProvider;
|
const couchProvider = couchPlugin.couchProvider;
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ export default function (couchPlugin, searchFilter) {
|
|||||||
return Promise.resolve({
|
return Promise.resolve({
|
||||||
identifier,
|
identifier,
|
||||||
type: 'folder',
|
type: 'folder',
|
||||||
name: "CouchDB Documents"
|
name: folderName || "CouchDB Documents"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ describe('the plugin', function () {
|
|||||||
let couchPlugin = openmct.plugins.CouchDB(testPath);
|
let couchPlugin = openmct.plugins.CouchDB(testPath);
|
||||||
openmct.install(couchPlugin);
|
openmct.install(couchPlugin);
|
||||||
|
|
||||||
openmct.install(new CouchDBSearchFolderPlugin(couchPlugin, {
|
openmct.install(new CouchDBSearchFolderPlugin('CouchDB Documents', couchPlugin, {
|
||||||
"selector": {
|
"selector": {
|
||||||
"model": {
|
"model": {
|
||||||
"type": "plan"
|
"type": "plan"
|
||||||
|
@ -56,11 +56,24 @@ const notebookStorage = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let openmct = createOpenMct();
|
let openmct;
|
||||||
|
let mockIdentifierService;
|
||||||
|
|
||||||
describe('Notebook Storage:', () => {
|
describe('Notebook Storage:', () => {
|
||||||
beforeEach((done) => {
|
beforeEach((done) => {
|
||||||
openmct = createOpenMct();
|
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);
|
window.localStorage.setItem('notebook-storage', null);
|
||||||
openmct.objects.addProvider('', jasmine.createSpyObj('mockNotebookProvider', [
|
openmct.objects.addProvider('', jasmine.createSpyObj('mockNotebookProvider', [
|
||||||
'create',
|
'create',
|
||||||
|
@ -85,7 +85,7 @@ export default {
|
|||||||
this.resizeTimer = setInterval(this.resize, RESIZE_POLL_INTERVAL);
|
this.resizeTimer = setInterval(this.resize, RESIZE_POLL_INTERVAL);
|
||||||
this.unlisten = this.openmct.objects.observe(this.domainObject, '*', this.observeForChanges);
|
this.unlisten = this.openmct.objects.observe(this.domainObject, '*', this.observeForChanges);
|
||||||
},
|
},
|
||||||
destroyed() {
|
beforeDestroy() {
|
||||||
clearInterval(this.resizeTimer);
|
clearInterval(this.resizeTimer);
|
||||||
this.openmct.time.off("timeSystem", this.setScaleAndPlotActivities);
|
this.openmct.time.off("timeSystem", this.setScaleAndPlotActivities);
|
||||||
this.openmct.time.off("bounds", this.updateViewBounds);
|
this.openmct.time.off("bounds", this.updateViewBounds);
|
||||||
|
Reference in New Issue
Block a user