[New Edit Mode] Fixed positioning of dropped objects #386

This commit is contained in:
Henry 2015-12-09 09:51:00 -08:00
parent aae8f1575d
commit 49579378dd
6 changed files with 25 additions and 5 deletions

View File

@ -92,8 +92,14 @@ define(
} }
} }
function setEditable(editableDomainObject) {
self.domainObject = editableDomainObject;
scope.model = editableDomainObject.getModel();
}
// Place the "commit" method in the scope // Place the "commit" method in the scope
scope.commit = commit; scope.commit = commit;
scope.setEditable = setEditable;
} }
// Handle a specific representation of a specific domain object // Handle a specific representation of a specific domain object

View File

@ -19,6 +19,7 @@
"type": "telemetry.panel", "type": "telemetry.panel",
"templateUrl": "templates/fixed.html", "templateUrl": "templates/fixed.html",
"uses": [ "composition" ], "uses": [ "composition" ],
"gestures": [ "drop" ],
"toolbar": { "toolbar": {
"sections": [ "sections": [
{ {

View File

@ -273,12 +273,15 @@ define(
} }
// Position a panel after a drop event // Position a panel after a drop event
function handleDrop(e, id, position) { function handleDrop(e, id, position, editableDomainObject) {
// Don't handle this event if it has already been handled // Don't handle this event if it has already been handled
// color is set to "" to let the CSS theme determine the default color // color is set to "" to let the CSS theme determine the default color
if (e.defaultPrevented) { if (e.defaultPrevented) {
return; return;
} }
if (editableDomainObject){
$scope.setEditable(editableDomainObject);
}
e.preventDefault(); e.preventDefault();
// Store the position of this element. // Store the position of this element.
addElement({ addElement({

View File

@ -62,10 +62,15 @@ define(
} }
// Position a panel after a drop event // Position a panel after a drop event
function handleDrop(e, id, position) { //An editableDomainObject is provided, as the drop may have
// triggered a transition to edit mode.
function handleDrop(e, id, position, editableDomainObject) {
if (e.defaultPrevented) { if (e.defaultPrevented) {
return; return;
} }
if (editableDomainObject){
$scope.setEditable(editableDomainObject);
}
// Ensure that configuration field is populated // Ensure that configuration field is populated
$scope.configuration = $scope.configuration || {}; $scope.configuration = $scope.configuration || {};
// Make sure there is a "panels" field in the // Make sure there is a "panels" field in the

View File

@ -8,6 +8,7 @@
"glyph": "6", "glyph": "6",
"templateUrl": "templates/plot.html", "templateUrl": "templates/plot.html",
"needs": [ "telemetry" ], "needs": [ "telemetry" ],
"gestures": [ "drop" ],
"priority": "preferred", "priority": "preferred",
"delegation": true "delegation": true
} }

View File

@ -45,12 +45,12 @@ define(
function DropGesture(dndService, $q, navigationService, objectService, instantiate, typeService, element, domainObject) { function DropGesture(dndService, $q, navigationService, objectService, instantiate, typeService, element, domainObject) {
var actionCapability = domainObject.getCapability('action'), var actionCapability = domainObject.getCapability('action'),
editableDomainObject, editableDomainObject,
scope = element && element.scope && element.scope(),
action; // Action for the drop, when it occurs action; // Action for the drop, when it occurs
function broadcastDrop(id, event) { function broadcastDrop(id, event) {
// Find the relevant scope... // Find the relevant scope...
var scope = element && element.scope && element.scope(), var rect;
rect;
if (scope && scope.$broadcast) { if (scope && scope.$broadcast) {
// Get the representation's bounds, to convert // Get the representation's bounds, to convert
// drop position // drop position
@ -65,7 +65,8 @@ define(
{ {
x: event.pageX - rect.left, x: event.pageX - rect.left,
y: event.pageY - rect.top y: event.pageY - rect.top
} },
editableDomainObject
); );
} }
} }
@ -148,6 +149,9 @@ define(
if (shouldCreateVirtualPanel(domainObject)){ if (shouldCreateVirtualPanel(domainObject)){
editableDomainObject = createVirtualPanel(domainObject, id); editableDomainObject = createVirtualPanel(domainObject, id);
navigationService.setNavigation(editableDomainObject); navigationService.setNavigation(editableDomainObject);
//Also broadcast the editableDomainObject to
// avoid race condition against non-editable
// version in EditRepresenter
broadcastDrop(id, event); broadcastDrop(id, event);
} else { } else {
$q.when(action && action.perform()).then(function (result) { $q.when(action && action.perform()).then(function (result) {