diff --git a/platform/commonUI/edit/src/capabilities/EditableActionCapability.js b/platform/commonUI/edit/src/capabilities/EditableActionCapability.js new file mode 100644 index 0000000000..d7bbf48274 --- /dev/null +++ b/platform/commonUI/edit/src/capabilities/EditableActionCapability.js @@ -0,0 +1,60 @@ +/***************************************************************************** + * Open MCT Web, Copyright (c) 2014-2015, United States Government + * as represented by the Administrator of the National Aeronautics and Space + * Administration. All rights reserved. + * + * Open MCT Web is licensed under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Open MCT Web includes source code licensed under additional open source + * licenses. See the Open Source Licenses file (LICENSES.md) included with + * this source code distribution or the Licensing information page available + * at runtime from the About dialog for additional information. + *****************************************************************************/ +/*global define*/ + + +define( + function () { + 'use strict'; + var DISALLOWED_ACTIONS = ["move", "copy", "link"]; + /** + * Editable Action Capability. Overrides the action capability + * normally exhibited by a domain object and filters out certain + * actions not applicable when an object is in edit mode. + * + * Meant specifically for use by EditableDomainObject and the + * associated cache; the constructor signature is particular + * to a pattern used there and may contain unused arguments. + * @constructor + * @memberof platform/commonUI/edit + * @implements {PersistenceCapability} + */ + function EditableActionCapability( + actionCapability, + editableObject, + domainObject, + cache + ) { + var action = Object.create(actionCapability); + + action.getActions = function(domainObject) { + return actionCapability.getActions(domainObject).filter(function(action){ + return !(DISALLOWED_ACTIONS.indexOf(action.getMetadata().key) >= 0); + }); + }; + + return action; + } + + return EditableActionCapability; + } +); diff --git a/platform/commonUI/edit/src/objects/EditableDomainObject.js b/platform/commonUI/edit/src/objects/EditableDomainObject.js index bef4806040..98561e7e7d 100644 --- a/platform/commonUI/edit/src/objects/EditableDomainObject.js +++ b/platform/commonUI/edit/src/objects/EditableDomainObject.js @@ -37,6 +37,7 @@ define( '../capabilities/EditableCompositionCapability', '../capabilities/EditableRelationshipCapability', '../capabilities/EditorCapability', + '../capabilities/EditableActionCapability', './EditableDomainObjectCache' ], function ( @@ -45,6 +46,7 @@ define( EditableCompositionCapability, EditableRelationshipCapability, EditorCapability, + EditableActionCapability, EditableDomainObjectCache ) { "use strict"; @@ -54,6 +56,7 @@ define( context: EditableContextCapability, composition: EditableCompositionCapability, relationship: EditableRelationshipCapability, + action: EditableActionCapability, editor: EditorCapability }; diff --git a/platform/features/clock/bundle.json b/platform/features/clock/bundle.json index 5468c46207..ee2bf0def1 100644 --- a/platform/features/clock/bundle.json +++ b/platform/features/clock/bundle.json @@ -54,11 +54,13 @@ { "key": "clock", "type": "clock", + "editable": false, "templateUrl": "templates/clock.html" }, { "key": "timer", "type": "timer", + "editable": false, "templateUrl": "templates/timer.html" } ], diff --git a/platform/features/imagery/bundle.json b/platform/features/imagery/bundle.json index 8d8495aa3a..77d42be3c5 100644 --- a/platform/features/imagery/bundle.json +++ b/platform/features/imagery/bundle.json @@ -8,7 +8,8 @@ "glyph": "\u00E3", "templateUrl": "templates/imagery.html", "priority": "preferred", - "needs": [ "telemetry" ] + "needs": [ "telemetry" ], + "editable": false } ], "policies": [ diff --git a/platform/features/pages/bundle.json b/platform/features/pages/bundle.json index 099b96415b..5a8a3218ef 100644 --- a/platform/features/pages/bundle.json +++ b/platform/features/pages/bundle.json @@ -23,7 +23,8 @@ "templateUrl": "iframe.html", "name": "Page", "type": "example.page", - "key": "example.page" + "key": "example.page", + "editable": false } ], "controllers": [ diff --git a/platform/representation/src/gestures/DropGesture.js b/platform/representation/src/gestures/DropGesture.js index 5a8e859b3d..e7fa2de3ab 100644 --- a/platform/representation/src/gestures/DropGesture.js +++ b/platform/representation/src/gestures/DropGesture.js @@ -59,6 +59,9 @@ define( // ...and broadcast the event. This allows specific // views to have post-drop behavior which depends on // drop position. + // Also broadcast the editableDomainObject to + // avoid race condition against non-editable + // version in EditRepresenter scope.$broadcast( GestureConstants.MCT_DROP_EVENT, id, @@ -70,11 +73,18 @@ define( ); } } - + + function canCompose(domainObject, selectedObject){ + return domainObject.getCapability("action").getActions({ + key: 'compose', + selectedObject: selectedObject + }).length > 0; + } + function shouldCreateVirtualPanel(domainObject){ return domainObject.useCapability('view').filter(function (view){ - return view.key==='plot' && domainObject.getModel().type!== 'telemetry.panel'; - }).length > 0; + return (view.key==='plot' || view.key==='scrolling') && domainObject.getModel().type!== 'telemetry.panel'; + }).length > 0; } function dragOver(e) { @@ -97,7 +107,7 @@ define( })[0]; //TODO: Fix this. Define an action for creating new // virtual panel - if (action || shouldCreateVirtualPanel(domainObject)) { + if (action || shouldCreateVirtualPanel(domainObject, selectedObject)) { event.dataTransfer.dropEffect = 'move'; // Indicate that we will accept the drag @@ -107,18 +117,21 @@ define( } } - function createVirtualPanel(base, overlayId){ + function createVirtualPanel(base, selectedObject){ var typeKey = 'telemetry.panel', type = typeService.getType(typeKey), model = type.getInitialModel(), id = uuid(), - newPanel; + newPanel, + composeAction; model.type = typeKey; newPanel = new EditableDomainObject(instantiate(model, id), $q); + if (!canCompose(newPanel, selectedObject)) + return undefined; - [base.getId(), overlayId].forEach(function(id){ + [base.getId(), selectedObject.getId()].forEach(function(id){ newPanel.getCapability('composition').add(id); }); @@ -135,7 +148,10 @@ define( function drop(e) { var event = (e || {}).originalEvent || e, id = event.dataTransfer.getData(GestureConstants.MCT_DRAG_TYPE), - domainObjectType = editableDomainObject.getModel().type; + domainObjectType = editableDomainObject.getModel().type, + selectedObject = dndService.getData( + GestureConstants.MCT_EXTENDED_DRAG_TYPE + );; // If currently in edit mode allow drag and drop gestures to the // domain object. An exception to this is folders which have drop @@ -146,13 +162,12 @@ define( // destination domain object's composition, and persist // the change. if (id) { - if (shouldCreateVirtualPanel(domainObject)){ - editableDomainObject = createVirtualPanel(domainObject, id); - navigationService.setNavigation(editableDomainObject); - //Also broadcast the editableDomainObject to - // avoid race condition against non-editable - // version in EditRepresenter - broadcastDrop(id, event); + if (shouldCreateVirtualPanel(domainObject, selectedObject)){ + if (editableDomainObject = createVirtualPanel(domainObject, selectedObject)) { + navigationService.setNavigation(editableDomainObject); + broadcastDrop(id, event); + editableDomainObject.getCapability('status').set('editing', true); + } } else { $q.when(action && action.perform()).then(function (result) { //Don't go into edit mode for folders @@ -160,9 +175,9 @@ define( navigationService.setNavigation(editableDomainObject); } broadcastDrop(id, event); + editableDomainObject.getCapability('status').set('editing', true); }); } - editableDomainObject.getCapability('status').set('editing', true); } //} // TODO: Alert user if drag and drop is not allowed