Skip to content

Commit 8641ef3

Browse files
author
epriestley
committedFeb 23, 2013
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
1 parent 1e1ad07 commit 8641ef3

File tree

6 files changed

+108
-116
lines changed

6 files changed

+108
-116
lines changed
 

‎src/__celerity_resource_map__.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@
18731873
),
18741874
'javelin-behavior-pholio-mock-view' =>
18751875
array(
1876-
'uri' => '/res/a6fae7ae/rsrc/js/application/pholio/behavior-pholio-mock-view.js',
1876+
'uri' => '/res/e2778b8e/rsrc/js/application/pholio/behavior-pholio-mock-view.js',
18771877
'type' => 'js',
18781878
'requires' =>
18791879
array(

‎src/applications/pholio/controller/PholioInlineController.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,9 @@ public function processRequest() {
3737
$inline_view->setEditable(true);
3838
}
3939

40-
$inlines[] = array(
41-
'id' => $inline_comment->getID(),
42-
'phid' => $inline_comment->getPHID(),
43-
'transactionphid' => $inline_comment->getTransactionPHID(),
44-
'x' => $inline_comment->getX(),
45-
'y' => $inline_comment->getY(),
46-
'width' => $inline_comment->getWidth(),
47-
'height' => $inline_comment->getHeight(),
48-
'contentHTML' => $inline_view->render());
40+
$inlines[] = $inline_comment->toDictionary() + array(
41+
'contentHTML' => $inline_view->render(),
42+
);
4943
}
5044

5145
return id(new AphrontAjaxResponse())->setContent($inlines);

‎src/applications/pholio/controller/PholioInlineSaveController.php

+12-19
Original file line numberDiff line numberDiff line change
@@ -59,25 +59,18 @@ public function processRequest() {
5959

6060
$draft->save();
6161

62-
if ($request->isAjax()) {
63-
$inline_view = id(new PholioInlineCommentView())
64-
->setInlineComment($draft)
65-
->setEditable(true)
66-
->setHandle(
67-
PhabricatorObjectHandleData::loadOneHandle($user->getPHID()));
68-
69-
return id(new AphrontAjaxResponse())
70-
->setContent(array(
71-
'success' => true,
72-
'phid' => $draft->getPHID(),
73-
'contentHTML' => $inline_view->render()
74-
));
75-
76-
} else {
77-
return id(new AphrontRedirectResponse())->setUri('/M'.$mock->getID());
78-
}
79-
}
80-
else {
62+
$inline_view = id(new PholioInlineCommentView())
63+
->setInlineComment($draft)
64+
->setEditable(true)
65+
->setHandle(
66+
PhabricatorObjectHandleData::loadOneHandle($user->getPHID()));
67+
68+
return id(new AphrontAjaxResponse())
69+
->setContent(
70+
$draft->toDictionary() + array(
71+
'contentHTML' => $inline_view->render(),
72+
));
73+
} else {
8174
$dialog = new PholioInlineCommentSaveView();
8275

8376
$dialog->setUser($user);

‎src/applications/pholio/controller/PholioInlineViewController.php

+2-4
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@ public function processRequest() {
2929
}
3030

3131
return id(new AphrontAjaxResponse())->setContent(
32-
array(
33-
'id' => $inline_comment->getID(),
34-
'phid' => $inline_comment->getPHID(),
35-
'contentHTML' => $inline_view->render()
32+
$inline_comment->toDictionary() + array(
33+
'contentHTML' => $inline_view->render(),
3634
));
3735
}
3836

‎src/applications/pholio/storage/PholioTransactionComment.php

+12
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,16 @@ public function getApplicationTransactionObject() {
1616
return new PholioTransaction();
1717
}
1818

19+
public function toDictionary() {
20+
return array(
21+
'id' => $this->getID(),
22+
'phid' => $this->getPHID(),
23+
'transactionphid' => $this->getTransactionPHID(),
24+
'x' => $this->getX(),
25+
'y' => $this->getY(),
26+
'width' => $this->getWidth(),
27+
'height' => $this->getHeight(),
28+
);
29+
}
30+
1931
}

‎webroot/rsrc/js/application/pholio/behavior-pholio-mock-view.js

+78-83
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
*/
1010
JX.behavior('pholio-mock-view', function(config) {
1111
var is_dragging = false;
12-
var is_typing = false;
1312

1413
var wrapper = JX.$('mock-wrapper');
15-
var startPos;
16-
var endPos;
14+
var drag_begin;
15+
var drag_end;
1716

1817
var selection_border;
1918
var selection_fill;
@@ -55,72 +54,31 @@ JX.behavior('pholio-mock-view', function(config) {
5554
// Select and show the first image.
5655
select_image(config.images[0].id);
5756

58-
function draw_rectangle(nodes, current, init) {
59-
for (var ii = 0; ii < nodes.length; ii++) {
60-
var node = nodes[ii];
61-
62-
JX.$V(
63-
Math.abs(current.x-init.x),
64-
Math.abs(current.y-init.y))
65-
.setDim(node);
66-
67-
JX.$V(
68-
(current.x-init.x < 0) ? current.x:init.x,
69-
(current.y-init.y < 0) ? current.y:init.y)
70-
.setPos(node);
71-
}
72-
}
73-
74-
function getRealXY(parent, point) {
75-
var pos = {x: (point.x - parent.x), y: (point.y - parent.y)};
76-
var dim = JX.Vector.getDim(JX.$(config.mainID));
77-
78-
pos.x = Math.max(0, Math.min(pos.x, dim.x));
79-
pos.y = Math.max(0, Math.min(pos.y, dim.y));
80-
81-
return pos;
82-
}
83-
8457
JX.Stratcom.listen('mousedown', 'mock-wrapper', function(e) {
8558
if (!e.isNormalMouseEvent()) {
8659
return;
8760
}
8861

89-
if (is_typing) {
90-
JX.DOM.remove(JX.$('pholio-new-inline-comment-dialog'));
91-
JX.DOM.remove(selection_fill);
92-
JX.DOM.remove(selection_border);
62+
if (drag_begin) {
63+
return;
9364
}
9465

95-
e.getRawEvent().target.draggable = false;
96-
is_dragging = true;
97-
98-
startPos = getRealXY(JX.$V(wrapper),JX.$V(e));
66+
e.kill();
9967

100-
selection_border = JX.$N(
101-
'div',
102-
{className: 'pholio-mock-select-border'});
103-
104-
selection_fill = JX.$N(
105-
'div',
106-
{className: 'pholio-mock-select-fill'});
107-
108-
JX.$V(startPos.x, startPos.y).setPos(selection_border);
109-
JX.$V(startPos.x, startPos.y).setPos(selection_fill);
68+
is_dragging = true;
69+
drag_begin = get_image_xy(JX.$V(e));
70+
drag_end = drag_begin;
11071

111-
JX.DOM.appendContent(wrapper, [selection_border, selection_fill]);
72+
redraw_selection();
11273
});
11374

11475
JX.enableDispatch(document.body, 'mousemove');
115-
JX.Stratcom.listen('mousemove',null, function(e) {
76+
JX.Stratcom.listen('mousemove', null, function(e) {
11677
if (!is_dragging) {
11778
return;
11879
}
119-
120-
draw_rectangle(
121-
[selection_border, selection_fill],
122-
getRealXY(JX.$V(wrapper),
123-
JX.$V(e)), startPos);
80+
drag_end = get_image_xy(JX.$V(e));
81+
redraw_selection();
12482
});
12583

12684
JX.Stratcom.listen(
@@ -145,9 +103,8 @@ JX.behavior('pholio-mock-view', function(config) {
145103
return;
146104
}
147105
is_dragging = false;
148-
is_typing = true;
149106

150-
endPos = getRealXY(JX.$V(wrapper), JX.$V(e));
107+
drag_end = get_image_xy(JX.$V(e));
151108

152109
var create_inline = new JX.Request("/pholio/inline/save/", function(r) {
153110
JX.DOM.appendContent(JX.$('pholio-mock-image-container'), JX.$H(r));
@@ -158,8 +115,9 @@ JX.behavior('pholio-mock-view', function(config) {
158115
var wrapperDimensions = JX.Vector.getDim(wrapper);
159116

160117
JX.$V(
161-
wrapperVector.x + Math.max(startPos.x,endPos.x),
162-
wrapperVector.y + Math.max(startPos.y,endPos.y)
118+
// TODO: This is a little funky for now.
119+
Math.max(drag_begin.x, drag_end.x),
120+
Math.max(drag_begin.y, drag_end.y)
163121
).setPos(dialog);
164122

165123
});
@@ -206,7 +164,7 @@ JX.behavior('pholio-mock-view', function(config) {
206164

207165
position_inline_rectangle(inline, inlineSelection);
208166

209-
if (inline.transactionphid == null) {
167+
if (!inline.transactionphid) {
210168

211169
var inlineDraft = JX.$N(
212170
'div',
@@ -232,6 +190,49 @@ JX.behavior('pholio-mock-view', function(config) {
232190
JX.$V(inline.width, inline.height).setDim(rect);
233191
}
234192

193+
function get_image_xy(p) {
194+
var main = JX.$(config.mainID);
195+
var mainp = JX.$V(main);
196+
197+
var x = Math.max(0, Math.min(p.x - mainp.x, main.naturalWidth));
198+
var y = Math.max(0, Math.min(p.y - mainp.y, main.naturalHeight));
199+
200+
return {
201+
x: x,
202+
y: y
203+
};
204+
}
205+
206+
function redraw_selection() {
207+
selection_border = selection_border || JX.$N(
208+
'div',
209+
{className: 'pholio-mock-select-border'});
210+
211+
selection_fill = selection_fill || JX.$N(
212+
'div',
213+
{className: 'pholio-mock-select-fill'});
214+
215+
var p = JX.$V(
216+
Math.min(drag_begin.x, drag_end.x),
217+
Math.min(drag_begin.y, drag_end.y));
218+
219+
var d = JX.$V(
220+
Math.max(drag_begin.x, drag_end.x) - p.x,
221+
Math.max(drag_begin.y, drag_end.y) - p.y);
222+
223+
var nodes = [selection_border, selection_fill];
224+
for (var ii = 0; ii < nodes.length; ii++) {
225+
var node = nodes[ii];
226+
wrapper.appendChild(node);
227+
p.setPos(node);
228+
d.setDim(node);
229+
}
230+
}
231+
232+
function clear_selection() {
233+
selection_fill && JX.DOM.remove(selection_fill);
234+
selection_border && JX.DOM.remove(selection_border);
235+
}
235236

236237
function load_inline_comments() {
237238
var comment_holder = JX.$('mock-inline-comments');
@@ -324,7 +325,6 @@ JX.behavior('pholio-mock-view', function(config) {
324325
'inline-save-cancel',
325326
function(e) {
326327
e.kill();
327-
328328
interrupt_typing();
329329
}
330330
);
@@ -347,36 +347,28 @@ JX.behavior('pholio-mock-view', function(config) {
347347
var saveURI = "/pholio/inline/save/";
348348

349349
var inlineComment = new JX.Request(saveURI, function(r) {
350-
if (!r.success) return;
351-
352-
JX.DOM.appendContent(
353-
JX.$('mock-inline-comments'),
354-
JX.$H(r.contentHTML));
355-
356-
JX.Stratcom.addSigil(selection_fill, 'image_selection');
357-
selection_fill.id = r.phid + '_fill';
358-
JX.Stratcom.addData(selection_fill, {phid: r.phid});
359-
selection_border.id = r.phid + '_selection';
350+
if (!inline_comments[active_image.id]) {
351+
inline_comments[active_image.id] = [];
352+
}
353+
inline_comments[active_image.id].push(r);
360354

361-
JX.DOM.remove(JX.$('pholio-new-inline-comment-dialog'));
362-
is_typing = false;
363-
});
355+
interrupt_typing();
356+
redraw_inlines(active_image.id);
357+
});
364358

365359
var commentToAdd = {
366360
mockID: config.mockID,
367361
op: 'save',
368362
imageID: active_image.id,
369-
startX: Math.min(startPos.x, endPos.x),
370-
startY: Math.min(startPos.y, endPos.y),
371-
endX: Math.max(startPos.x,endPos.x),
372-
endY: Math.max(startPos.y,endPos.y),
363+
startX: Math.min(drag_begin.x, drag_end.x),
364+
startY: Math.min(drag_begin.y, drag_end.y),
365+
endX: Math.max(drag_begin.x, drag_end.x),
366+
endY: Math.max(drag_begin.y, drag_end.y),
373367
comment: new_content
374368
};
375369

376370
inlineComment.addData(commentToAdd);
377371
inlineComment.send();
378-
379-
380372
}
381373
);
382374

@@ -389,12 +381,15 @@ JX.behavior('pholio-mock-view', function(config) {
389381
}
390382

391383
function interrupt_typing() {
392-
if (is_typing == true) {
393-
JX.DOM.remove(selection_fill);
394-
JX.DOM.remove(selection_border);
384+
clear_selection();
385+
386+
try {
395387
JX.DOM.remove(JX.$('pholio-new-inline-comment-dialog'));
396-
is_typing = false;
388+
} catch (x) {
389+
// TODO: For now, ignore this.
397390
}
391+
392+
drag_begin = null;
398393
}
399394

400395
load_inline_comments();

0 commit comments

Comments
 (0)
Failed to load comments.