1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-31 17:08:22 +01:00

Separate selection editing from selection drawing

Summary:
Currently, we draw the selection immediately after it changes. Instead, update state and then draw out of state.

Also simplify and clean up a few things. Make all the inline endpoints return data in the same format.

Test Plan: Made various inline comments.

Reviewers: chad, ljalonen

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D5085
This commit is contained in:
epriestley 2013-02-23 06:28:23 -08:00
parent 1e1ad070b6
commit 8641ef3948
6 changed files with 114 additions and 122 deletions

View file

@ -1873,7 +1873,7 @@ celerity_register_resource_map(array(
), ),
'javelin-behavior-pholio-mock-view' => 'javelin-behavior-pholio-mock-view' =>
array( array(
'uri' => '/res/a6fae7ae/rsrc/js/application/pholio/behavior-pholio-mock-view.js', 'uri' => '/res/e2778b8e/rsrc/js/application/pholio/behavior-pholio-mock-view.js',
'type' => 'js', 'type' => 'js',
'requires' => 'requires' =>
array( array(

View file

@ -37,15 +37,9 @@ final class PholioInlineController extends PholioController {
$inline_view->setEditable(true); $inline_view->setEditable(true);
} }
$inlines[] = array( $inlines[] = $inline_comment->toDictionary() + array(
'id' => $inline_comment->getID(), 'contentHTML' => $inline_view->render(),
'phid' => $inline_comment->getPHID(), );
'transactionphid' => $inline_comment->getTransactionPHID(),
'x' => $inline_comment->getX(),
'y' => $inline_comment->getY(),
'width' => $inline_comment->getWidth(),
'height' => $inline_comment->getHeight(),
'contentHTML' => $inline_view->render());
} }
return id(new AphrontAjaxResponse())->setContent($inlines); return id(new AphrontAjaxResponse())->setContent($inlines);

View file

@ -59,25 +59,18 @@ final class PholioInlineSaveController extends PholioController {
$draft->save(); $draft->save();
if ($request->isAjax()) { $inline_view = id(new PholioInlineCommentView())
$inline_view = id(new PholioInlineCommentView()) ->setInlineComment($draft)
->setInlineComment($draft) ->setEditable(true)
->setEditable(true) ->setHandle(
->setHandle( PhabricatorObjectHandleData::loadOneHandle($user->getPHID()));
PhabricatorObjectHandleData::loadOneHandle($user->getPHID()));
return id(new AphrontAjaxResponse()) return id(new AphrontAjaxResponse())
->setContent(array( ->setContent(
'success' => true, $draft->toDictionary() + array(
'phid' => $draft->getPHID(), 'contentHTML' => $inline_view->render(),
'contentHTML' => $inline_view->render() ));
)); } else {
} else {
return id(new AphrontRedirectResponse())->setUri('/M'.$mock->getID());
}
}
else {
$dialog = new PholioInlineCommentSaveView(); $dialog = new PholioInlineCommentSaveView();
$dialog->setUser($user); $dialog->setUser($user);

View file

@ -29,10 +29,8 @@ final class PholioInlineViewController extends PholioController {
} }
return id(new AphrontAjaxResponse())->setContent( return id(new AphrontAjaxResponse())->setContent(
array( $inline_comment->toDictionary() + array(
'id' => $inline_comment->getID(), 'contentHTML' => $inline_view->render(),
'phid' => $inline_comment->getPHID(),
'contentHTML' => $inline_view->render()
)); ));
} }

View file

@ -16,4 +16,16 @@ final class PholioTransactionComment
return new PholioTransaction(); return new PholioTransaction();
} }
public function toDictionary() {
return array(
'id' => $this->getID(),
'phid' => $this->getPHID(),
'transactionphid' => $this->getTransactionPHID(),
'x' => $this->getX(),
'y' => $this->getY(),
'width' => $this->getWidth(),
'height' => $this->getHeight(),
);
}
} }

View file

@ -9,11 +9,10 @@
*/ */
JX.behavior('pholio-mock-view', function(config) { JX.behavior('pholio-mock-view', function(config) {
var is_dragging = false; var is_dragging = false;
var is_typing = false;
var wrapper = JX.$('mock-wrapper'); var wrapper = JX.$('mock-wrapper');
var startPos; var drag_begin;
var endPos; var drag_end;
var selection_border; var selection_border;
var selection_fill; var selection_fill;
@ -55,72 +54,31 @@ JX.behavior('pholio-mock-view', function(config) {
// Select and show the first image. // Select and show the first image.
select_image(config.images[0].id); select_image(config.images[0].id);
function draw_rectangle(nodes, current, init) {
for (var ii = 0; ii < nodes.length; ii++) {
var node = nodes[ii];
JX.$V(
Math.abs(current.x-init.x),
Math.abs(current.y-init.y))
.setDim(node);
JX.$V(
(current.x-init.x < 0) ? current.x:init.x,
(current.y-init.y < 0) ? current.y:init.y)
.setPos(node);
}
}
function getRealXY(parent, point) {
var pos = {x: (point.x - parent.x), y: (point.y - parent.y)};
var dim = JX.Vector.getDim(JX.$(config.mainID));
pos.x = Math.max(0, Math.min(pos.x, dim.x));
pos.y = Math.max(0, Math.min(pos.y, dim.y));
return pos;
}
JX.Stratcom.listen('mousedown', 'mock-wrapper', function(e) { JX.Stratcom.listen('mousedown', 'mock-wrapper', function(e) {
if (!e.isNormalMouseEvent()) { if (!e.isNormalMouseEvent()) {
return; return;
} }
if (is_typing) { if (drag_begin) {
JX.DOM.remove(JX.$('pholio-new-inline-comment-dialog'));
JX.DOM.remove(selection_fill);
JX.DOM.remove(selection_border);
}
e.getRawEvent().target.draggable = false;
is_dragging = true;
startPos = getRealXY(JX.$V(wrapper),JX.$V(e));
selection_border = JX.$N(
'div',
{className: 'pholio-mock-select-border'});
selection_fill = JX.$N(
'div',
{className: 'pholio-mock-select-fill'});
JX.$V(startPos.x, startPos.y).setPos(selection_border);
JX.$V(startPos.x, startPos.y).setPos(selection_fill);
JX.DOM.appendContent(wrapper, [selection_border, selection_fill]);
});
JX.enableDispatch(document.body, 'mousemove');
JX.Stratcom.listen('mousemove',null, function(e) {
if (!is_dragging) {
return; return;
} }
draw_rectangle( e.kill();
[selection_border, selection_fill],
getRealXY(JX.$V(wrapper), is_dragging = true;
JX.$V(e)), startPos); drag_begin = get_image_xy(JX.$V(e));
drag_end = drag_begin;
redraw_selection();
});
JX.enableDispatch(document.body, 'mousemove');
JX.Stratcom.listen('mousemove', null, function(e) {
if (!is_dragging) {
return;
}
drag_end = get_image_xy(JX.$V(e));
redraw_selection();
}); });
JX.Stratcom.listen( JX.Stratcom.listen(
@ -145,9 +103,8 @@ JX.behavior('pholio-mock-view', function(config) {
return; return;
} }
is_dragging = false; is_dragging = false;
is_typing = true;
endPos = getRealXY(JX.$V(wrapper), JX.$V(e)); drag_end = get_image_xy(JX.$V(e));
var create_inline = new JX.Request("/pholio/inline/save/", function(r) { var create_inline = new JX.Request("/pholio/inline/save/", function(r) {
JX.DOM.appendContent(JX.$('pholio-mock-image-container'), JX.$H(r)); JX.DOM.appendContent(JX.$('pholio-mock-image-container'), JX.$H(r));
@ -158,8 +115,9 @@ JX.behavior('pholio-mock-view', function(config) {
var wrapperDimensions = JX.Vector.getDim(wrapper); var wrapperDimensions = JX.Vector.getDim(wrapper);
JX.$V( JX.$V(
wrapperVector.x + Math.max(startPos.x,endPos.x), // TODO: This is a little funky for now.
wrapperVector.y + Math.max(startPos.y,endPos.y) Math.max(drag_begin.x, drag_end.x),
Math.max(drag_begin.y, drag_end.y)
).setPos(dialog); ).setPos(dialog);
}); });
@ -206,7 +164,7 @@ JX.behavior('pholio-mock-view', function(config) {
position_inline_rectangle(inline, inlineSelection); position_inline_rectangle(inline, inlineSelection);
if (inline.transactionphid == null) { if (!inline.transactionphid) {
var inlineDraft = JX.$N( var inlineDraft = JX.$N(
'div', 'div',
@ -232,6 +190,49 @@ JX.behavior('pholio-mock-view', function(config) {
JX.$V(inline.width, inline.height).setDim(rect); JX.$V(inline.width, inline.height).setDim(rect);
} }
function get_image_xy(p) {
var main = JX.$(config.mainID);
var mainp = JX.$V(main);
var x = Math.max(0, Math.min(p.x - mainp.x, main.naturalWidth));
var y = Math.max(0, Math.min(p.y - mainp.y, main.naturalHeight));
return {
x: x,
y: y
};
}
function redraw_selection() {
selection_border = selection_border || JX.$N(
'div',
{className: 'pholio-mock-select-border'});
selection_fill = selection_fill || JX.$N(
'div',
{className: 'pholio-mock-select-fill'});
var p = JX.$V(
Math.min(drag_begin.x, drag_end.x),
Math.min(drag_begin.y, drag_end.y));
var d = JX.$V(
Math.max(drag_begin.x, drag_end.x) - p.x,
Math.max(drag_begin.y, drag_end.y) - p.y);
var nodes = [selection_border, selection_fill];
for (var ii = 0; ii < nodes.length; ii++) {
var node = nodes[ii];
wrapper.appendChild(node);
p.setPos(node);
d.setDim(node);
}
}
function clear_selection() {
selection_fill && JX.DOM.remove(selection_fill);
selection_border && JX.DOM.remove(selection_border);
}
function load_inline_comments() { function load_inline_comments() {
var comment_holder = JX.$('mock-inline-comments'); var comment_holder = JX.$('mock-inline-comments');
@ -324,7 +325,6 @@ JX.behavior('pholio-mock-view', function(config) {
'inline-save-cancel', 'inline-save-cancel',
function(e) { function(e) {
e.kill(); e.kill();
interrupt_typing(); interrupt_typing();
} }
); );
@ -347,36 +347,28 @@ JX.behavior('pholio-mock-view', function(config) {
var saveURI = "/pholio/inline/save/"; var saveURI = "/pholio/inline/save/";
var inlineComment = new JX.Request(saveURI, function(r) { var inlineComment = new JX.Request(saveURI, function(r) {
if (!r.success) return; if (!inline_comments[active_image.id]) {
inline_comments[active_image.id] = [];
}
inline_comments[active_image.id].push(r);
JX.DOM.appendContent( interrupt_typing();
JX.$('mock-inline-comments'), redraw_inlines(active_image.id);
JX.$H(r.contentHTML)); });
JX.Stratcom.addSigil(selection_fill, 'image_selection');
selection_fill.id = r.phid + '_fill';
JX.Stratcom.addData(selection_fill, {phid: r.phid});
selection_border.id = r.phid + '_selection';
JX.DOM.remove(JX.$('pholio-new-inline-comment-dialog'));
is_typing = false;
});
var commentToAdd = { var commentToAdd = {
mockID: config.mockID, mockID: config.mockID,
op: 'save', op: 'save',
imageID: active_image.id, imageID: active_image.id,
startX: Math.min(startPos.x, endPos.x), startX: Math.min(drag_begin.x, drag_end.x),
startY: Math.min(startPos.y, endPos.y), startY: Math.min(drag_begin.y, drag_end.y),
endX: Math.max(startPos.x,endPos.x), endX: Math.max(drag_begin.x, drag_end.x),
endY: Math.max(startPos.y,endPos.y), endY: Math.max(drag_begin.y, drag_end.y),
comment: new_content comment: new_content
}; };
inlineComment.addData(commentToAdd); inlineComment.addData(commentToAdd);
inlineComment.send(); inlineComment.send();
} }
); );
@ -389,12 +381,15 @@ JX.behavior('pholio-mock-view', function(config) {
} }
function interrupt_typing() { function interrupt_typing() {
if (is_typing == true) { clear_selection();
JX.DOM.remove(selection_fill);
JX.DOM.remove(selection_border); try {
JX.DOM.remove(JX.$('pholio-new-inline-comment-dialog')); JX.DOM.remove(JX.$('pholio-new-inline-comment-dialog'));
is_typing = false; } catch (x) {
// TODO: For now, ignore this.
} }
drag_begin = null;
} }
load_inline_comments(); load_inline_comments();