mirror of
https://github.com/nasa/openmct.git
synced 2025-02-21 09:52:04 +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:
parent
16249c3790
commit
3571004f5c
@ -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',
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
|
@ -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',
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user