[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/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
};

View File

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

View File

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

View File

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

View File

@ -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