mirror of
https://github.com/nasa/openmct.git
synced 2025-04-16 07:26:53 +00:00
[Actions] Update to use isPersistable API Method (#4432)
* added persistance check to edit properties action * adding persistence check in browse bar as well as reverting passing in openmct in bundle and now passing it in through appliesTo method * adding other actions that need to be persistable * adding persistance check to set primary location action Co-authored-by: Andrew Henry <akhenry@gmail.com>
This commit is contained in:
parent
420edb75f8
commit
7b53cad2c5
@ -80,18 +80,15 @@ define(
|
||||
* This will ensure that a domain object is present in the
|
||||
* context.
|
||||
*/
|
||||
PropertiesAction.appliesTo = function (context) {
|
||||
PropertiesAction.appliesTo = function (context, view, openmct) {
|
||||
|
||||
var domainObject = (context || {}).domainObject,
|
||||
type = domainObject && domainObject.getCapability('type'),
|
||||
creatable = type && type.hasFeature('creation');
|
||||
let domainObject = (context || {}).domainObject;
|
||||
|
||||
if (domainObject && domainObject.model && domainObject.model.locked) {
|
||||
if (!domainObject || (domainObject.model && domainObject.model.locked)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only allow creatable types to be edited
|
||||
return domainObject && creatable;
|
||||
return openmct.objects.isPersistable(domainObject.id);
|
||||
};
|
||||
|
||||
return PropertiesAction;
|
||||
|
@ -25,7 +25,7 @@ define(
|
||||
function (PropertiesAction) {
|
||||
|
||||
describe("Properties action", function () {
|
||||
var capabilities, model, object, context, input, dialogService, action;
|
||||
var capabilities, model, object, context, input, dialogService, action, openmct;
|
||||
|
||||
function mockPromise(value) {
|
||||
return {
|
||||
@ -36,6 +36,11 @@ define(
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
openmct = {
|
||||
objects: {
|
||||
isPersistable: jasmine.createSpy('isPersistable')
|
||||
}
|
||||
};
|
||||
capabilities = {
|
||||
type: {
|
||||
getProperties: function () {
|
||||
@ -77,6 +82,8 @@ define(
|
||||
capabilities.type.hasFeature.and.returnValue(true);
|
||||
capabilities.mutation.and.returnValue(true);
|
||||
|
||||
openmct.objects.isPersistable.and.returnValue(true);
|
||||
|
||||
action = new PropertiesAction(dialogService, context);
|
||||
});
|
||||
|
||||
@ -93,11 +100,11 @@ define(
|
||||
});
|
||||
|
||||
it("is only applicable when a domain object is in context", function () {
|
||||
expect(PropertiesAction.appliesTo(context)).toBeTruthy();
|
||||
expect(PropertiesAction.appliesTo({})).toBeFalsy();
|
||||
// Make sure it checked for creatability
|
||||
expect(capabilities.type.hasFeature).toHaveBeenCalledWith('creation');
|
||||
expect(PropertiesAction.appliesTo(context, undefined, openmct)).toBeTruthy();
|
||||
expect(PropertiesAction.appliesTo({}, undefined, openmct)).toBeFalsy();
|
||||
expect(openmct.objects.isPersistable).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
|
@ -47,10 +47,16 @@ define(
|
||||
);
|
||||
};
|
||||
|
||||
SetPrimaryLocationAction.appliesTo = function (context) {
|
||||
var domainObject = context.domainObject;
|
||||
SetPrimaryLocationAction.appliesTo = function (context, view, openmct) {
|
||||
let domainObject = (context || {}).domainObject;
|
||||
|
||||
return domainObject && domainObject.hasCapability("location")
|
||||
if (!domainObject || (domainObject.model && domainObject.model.locked)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
let isPersistable = openmct.objects.isPersistable(domainObject.id);
|
||||
|
||||
return isPersistable && domainObject.hasCapability("location")
|
||||
&& (domainObject.getModel().location === undefined);
|
||||
};
|
||||
|
||||
|
@ -31,9 +31,15 @@ define(
|
||||
var testContext,
|
||||
testModel,
|
||||
testId,
|
||||
mockLocationCapability;
|
||||
mockLocationCapability,
|
||||
openmct;
|
||||
|
||||
beforeEach(function () {
|
||||
openmct = {
|
||||
objects: {
|
||||
isPersistable: jasmine.createSpy('isPersistable')
|
||||
}
|
||||
};
|
||||
testId = "some-id";
|
||||
testModel = { name: "some name" };
|
||||
|
||||
@ -42,6 +48,7 @@ define(
|
||||
['setPrimaryLocation', 'getContextualLocation']
|
||||
);
|
||||
|
||||
openmct.objects.isPersistable.and.returnValue(true);
|
||||
mockLocationCapability.getContextualLocation.and.returnValue(testId);
|
||||
|
||||
testContext = {
|
||||
@ -55,16 +62,21 @@ define(
|
||||
});
|
||||
|
||||
it("is applicable to objects with no location specified", function () {
|
||||
expect(SetPrimaryLocation.appliesTo(testContext))
|
||||
expect(SetPrimaryLocation.appliesTo(testContext, undefined, openmct))
|
||||
.toBe(true);
|
||||
testContext.domainObject.getModel.and.returnValue({
|
||||
location: "something",
|
||||
name: "some name"
|
||||
});
|
||||
expect(SetPrimaryLocation.appliesTo(testContext))
|
||||
expect(SetPrimaryLocation.appliesTo(testContext, undefined, openmct))
|
||||
.toBe(false);
|
||||
});
|
||||
|
||||
it("checks object persistability", function () {
|
||||
SetPrimaryLocation.appliesTo(testContext, undefined, openmct);
|
||||
expect(openmct.objects.isPersistable).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sets the location contextually when performed", function () {
|
||||
new SetPrimaryLocation(testContext).perform();
|
||||
expect(mockLocationCapability.setPrimaryLocation)
|
||||
|
@ -221,15 +221,17 @@ define(['zepto', 'objectUtils'], function ($, objectUtils) {
|
||||
dialog = this.dialogService.showBlockingMessage(model);
|
||||
};
|
||||
|
||||
ImportAsJSONAction.appliesTo = function (context) {
|
||||
let domainObject = context.domainObject;
|
||||
ImportAsJSONAction.appliesTo = function (context, view, openmct) {
|
||||
let domainObject = (context || {}).domainObject;
|
||||
|
||||
if (domainObject && domainObject.model.locked) {
|
||||
if (!domainObject || (domainObject.model && domainObject.model.locked)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return domainObject !== undefined
|
||||
&& domainObject.hasCapability("composition");
|
||||
let isPersistable = openmct.objects.isPersistable(domainObject.id);
|
||||
let hasComposition = domainObject.hasCapability('composition');
|
||||
|
||||
return hasComposition && isPersistable;
|
||||
};
|
||||
|
||||
return ImportAsJSONAction;
|
||||
|
@ -42,7 +42,6 @@ define(
|
||||
newObjects;
|
||||
|
||||
beforeEach(function () {
|
||||
|
||||
uniqueId = 0;
|
||||
newObjects = [];
|
||||
openmct = {
|
||||
@ -50,9 +49,11 @@ define(
|
||||
objects: {
|
||||
makeKeyString: function (identifier) {
|
||||
return identifier.key;
|
||||
}
|
||||
},
|
||||
isPersistable: jasmine.createSpy('isPersistable')
|
||||
}
|
||||
};
|
||||
openmct.objects.isPersistable.and.returnValue(true);
|
||||
mockInstantiate = jasmine.createSpy('instantiate').and.callFake(
|
||||
function (model, id) {
|
||||
var config = {
|
||||
@ -121,9 +122,22 @@ define(
|
||||
var noCompDomainObject = domainObjectFactory();
|
||||
|
||||
context.domainObject = compDomainObject;
|
||||
expect(ImportAsJSONAction.appliesTo(context)).toBe(true);
|
||||
expect(ImportAsJSONAction.appliesTo(context, undefined, openmct)).toBe(true);
|
||||
context.domainObject = noCompDomainObject;
|
||||
expect(ImportAsJSONAction.appliesTo(context)).toBe(false);
|
||||
expect(ImportAsJSONAction.appliesTo(context, undefined, openmct)).toBe(false);
|
||||
});
|
||||
|
||||
it("checks object persistability", function () {
|
||||
var compDomainObject = domainObjectFactory({
|
||||
name: 'compObject',
|
||||
model: { name: 'compObject'},
|
||||
capabilities: {"composition": compositionCapability}
|
||||
});
|
||||
|
||||
context.domainObject = compDomainObject;
|
||||
ImportAsJSONAction.appliesTo(context, undefined, openmct);
|
||||
|
||||
expect(openmct.objects.isPersistable).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("displays error dialog on invalid file choice", function () {
|
||||
|
@ -60,9 +60,10 @@ export default class LegacyContextMenuAction {
|
||||
|
||||
appliesTo(objectPath) {
|
||||
let legacyObject = this.openmct.legacyObject(objectPath);
|
||||
let view;
|
||||
|
||||
return (this.LegacyAction.appliesTo === undefined
|
||||
|| this.LegacyAction.appliesTo({domainObject: legacyObject}))
|
||||
|| this.LegacyAction.appliesTo({domainObject: legacyObject}, view, this.openmct))
|
||||
&& !this.isBlacklisted(objectPath);
|
||||
}
|
||||
|
||||
|
@ -83,7 +83,8 @@ export default class NewFolderAction {
|
||||
}
|
||||
appliesTo(objectPath) {
|
||||
let domainObject = objectPath[0];
|
||||
let isPersistable = this._openmct.objects.isPersistable(domainObject.identifier);
|
||||
|
||||
return domainObject.type === 'folder';
|
||||
return domainObject.type === 'folder' && isPersistable;
|
||||
}
|
||||
}
|
||||
|
@ -78,6 +78,7 @@ describe("the plugin", () => {
|
||||
spyOn(openmct.$injector, 'get').and.returnValue(mockDialogService);
|
||||
spyOn(compositionAPI, 'get').and.returnValue(mockComposition);
|
||||
spyOn(openmct.objects, 'save').and.returnValue(Promise.resolve(true));
|
||||
spyOn(openmct.objects, 'isPersistable').and.returnValue(true);
|
||||
|
||||
return newFolderAction.invoke(mockObjectPath);
|
||||
});
|
||||
@ -93,5 +94,11 @@ describe("the plugin", () => {
|
||||
it('adds new folder object to parent composition', () => {
|
||||
expect(mockComposition.add).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('checks if the domainObject is persistable', () => {
|
||||
newFolderAction.appliesTo(mockObjectPath);
|
||||
|
||||
expect(openmct.objects.isPersistable).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -20,8 +20,8 @@
|
||||
</div>
|
||||
<span
|
||||
class="l-browse-bar__object-name c-object-label__name"
|
||||
:class="{ 'c-input-inline' : type.creatable}"
|
||||
:contenteditable="type.creatable"
|
||||
:class="{ 'c-input-inline' : isPersistable}"
|
||||
:contenteditable="isPersistable"
|
||||
@blur="updateName"
|
||||
@keydown.enter.prevent
|
||||
@keyup.enter.prevent="updateNameOnEnterKeyPress"
|
||||
@ -194,6 +194,11 @@ export default {
|
||||
|
||||
return objectType.definition;
|
||||
},
|
||||
isPersistable() {
|
||||
let persistable = this.openmct.objects.isPersistable(this.domainObject.identifier);
|
||||
|
||||
return persistable;
|
||||
},
|
||||
isViewEditable() {
|
||||
let currentViewKey = this.currentView.key;
|
||||
if (currentViewKey !== undefined) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user