[Edit Mode] Limit context menu options available for objects in edit mode

[Edit Mode] Edit mode on objects that do not have a view supporting editing should edit properties instead. #320
This commit is contained in:
Henry
2015-12-09 17:05:11 -08:00
parent 2ca414d2a4
commit 39b3e6c4a9
6 changed files with 100 additions and 18 deletions

View File

@@ -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;
}
);

View File

@@ -37,6 +37,7 @@ define(
'../capabilities/EditableCompositionCapability', '../capabilities/EditableCompositionCapability',
'../capabilities/EditableRelationshipCapability', '../capabilities/EditableRelationshipCapability',
'../capabilities/EditorCapability', '../capabilities/EditorCapability',
'../capabilities/EditableActionCapability',
'./EditableDomainObjectCache' './EditableDomainObjectCache'
], ],
function ( function (
@@ -45,6 +46,7 @@ define(
EditableCompositionCapability, EditableCompositionCapability,
EditableRelationshipCapability, EditableRelationshipCapability,
EditorCapability, EditorCapability,
EditableActionCapability,
EditableDomainObjectCache EditableDomainObjectCache
) { ) {
"use strict"; "use strict";
@@ -54,6 +56,7 @@ define(
context: EditableContextCapability, context: EditableContextCapability,
composition: EditableCompositionCapability, composition: EditableCompositionCapability,
relationship: EditableRelationshipCapability, relationship: EditableRelationshipCapability,
action: EditableActionCapability,
editor: EditorCapability editor: EditorCapability
}; };

View File

@@ -54,11 +54,13 @@
{ {
"key": "clock", "key": "clock",
"type": "clock", "type": "clock",
"editable": false,
"templateUrl": "templates/clock.html" "templateUrl": "templates/clock.html"
}, },
{ {
"key": "timer", "key": "timer",
"type": "timer", "type": "timer",
"editable": false,
"templateUrl": "templates/timer.html" "templateUrl": "templates/timer.html"
} }
], ],

View File

@@ -8,7 +8,8 @@
"glyph": "\u00E3", "glyph": "\u00E3",
"templateUrl": "templates/imagery.html", "templateUrl": "templates/imagery.html",
"priority": "preferred", "priority": "preferred",
"needs": [ "telemetry" ] "needs": [ "telemetry" ],
"editable": false
} }
], ],
"policies": [ "policies": [

View File

@@ -23,7 +23,8 @@
"templateUrl": "iframe.html", "templateUrl": "iframe.html",
"name": "Page", "name": "Page",
"type": "example.page", "type": "example.page",
"key": "example.page" "key": "example.page",
"editable": false
} }
], ],
"controllers": [ "controllers": [

View File

@@ -59,6 +59,9 @@ define(
// ...and broadcast the event. This allows specific // ...and broadcast the event. This allows specific
// views to have post-drop behavior which depends on // views to have post-drop behavior which depends on
// drop position. // drop position.
// Also broadcast the editableDomainObject to
// avoid race condition against non-editable
// version in EditRepresenter
scope.$broadcast( scope.$broadcast(
GestureConstants.MCT_DROP_EVENT, GestureConstants.MCT_DROP_EVENT,
id, id,
@@ -70,11 +73,18 @@ define(
); );
} }
} }
function canCompose(domainObject, selectedObject){
return domainObject.getCapability("action").getActions({
key: 'compose',
selectedObject: selectedObject
}).length > 0;
}
function shouldCreateVirtualPanel(domainObject){ function shouldCreateVirtualPanel(domainObject){
return domainObject.useCapability('view').filter(function (view){ return domainObject.useCapability('view').filter(function (view){
return view.key==='plot' && domainObject.getModel().type!== 'telemetry.panel'; return (view.key==='plot' || view.key==='scrolling') && domainObject.getModel().type!== 'telemetry.panel';
}).length > 0; }).length > 0;
} }
function dragOver(e) { function dragOver(e) {
@@ -97,7 +107,7 @@ define(
})[0]; })[0];
//TODO: Fix this. Define an action for creating new //TODO: Fix this. Define an action for creating new
// virtual panel // virtual panel
if (action || shouldCreateVirtualPanel(domainObject)) { if (action || shouldCreateVirtualPanel(domainObject, selectedObject)) {
event.dataTransfer.dropEffect = 'move'; event.dataTransfer.dropEffect = 'move';
// Indicate that we will accept the drag // Indicate that we will accept the drag
@@ -107,18 +117,21 @@ define(
} }
} }
function createVirtualPanel(base, overlayId){ function createVirtualPanel(base, selectedObject){
var typeKey = 'telemetry.panel', var typeKey = 'telemetry.panel',
type = typeService.getType(typeKey), type = typeService.getType(typeKey),
model = type.getInitialModel(), model = type.getInitialModel(),
id = uuid(), id = uuid(),
newPanel; newPanel,
composeAction;
model.type = typeKey; model.type = typeKey;
newPanel = new EditableDomainObject(instantiate(model, id), $q); 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); newPanel.getCapability('composition').add(id);
}); });
@@ -135,7 +148,10 @@ define(
function drop(e) { function drop(e) {
var event = (e || {}).originalEvent || e, var event = (e || {}).originalEvent || e,
id = event.dataTransfer.getData(GestureConstants.MCT_DRAG_TYPE), 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 // If currently in edit mode allow drag and drop gestures to the
// domain object. An exception to this is folders which have drop // domain object. An exception to this is folders which have drop
@@ -146,13 +162,12 @@ define(
// destination domain object's composition, and persist // destination domain object's composition, and persist
// the change. // the change.
if (id) { if (id) {
if (shouldCreateVirtualPanel(domainObject)){ if (shouldCreateVirtualPanel(domainObject, selectedObject)){
editableDomainObject = createVirtualPanel(domainObject, id); if (editableDomainObject = createVirtualPanel(domainObject, selectedObject)) {
navigationService.setNavigation(editableDomainObject); navigationService.setNavigation(editableDomainObject);
//Also broadcast the editableDomainObject to broadcastDrop(id, event);
// avoid race condition against non-editable editableDomainObject.getCapability('status').set('editing', true);
// version in EditRepresenter }
broadcastDrop(id, event);
} else { } else {
$q.when(action && action.perform()).then(function (result) { $q.when(action && action.perform()).then(function (result) {
//Don't go into edit mode for folders //Don't go into edit mode for folders
@@ -160,9 +175,9 @@ define(
navigationService.setNavigation(editableDomainObject); navigationService.setNavigation(editableDomainObject);
} }
broadcastDrop(id, event); 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 // TODO: Alert user if drag and drop is not allowed