1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Moved rendering to PholioInlineCommentView

Summary:
Rendering of inline comments has now been moved to PholioInlineCommentView controller.
Delete almost deletes and edit... well not so much, but replaced google.fi with amazing popup.

Test Plan: Verified that inline comments still show up. Verified that delete almost deletes.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Maniphest Tasks: T2446

Differential Revision: https://secure.phabricator.com/D4994

Conflicts:

	src/applications/pholio/controller/PholioInlineController.php
This commit is contained in:
Lauri-Henrik Jalonen 2013-02-19 14:12:33 -08:00 committed by epriestley
parent 8eb404aea7
commit f1bd1da062
11 changed files with 270 additions and 75 deletions

View file

@ -1446,8 +1446,11 @@ phutil_register_library_map(array(
'PholioController' => 'applications/pholio/controller/PholioController.php',
'PholioDAO' => 'applications/pholio/storage/PholioDAO.php',
'PholioImage' => 'applications/pholio/storage/PholioImage.php',
'PholioInlineCommentView' => 'applications/pholio/view/PholioInlineCommentView.php',
'PholioInlineController' => 'applications/pholio/controller/PholioInlineController.php',
'PholioInlineDeleteController' => 'applications/pholio/controller/PholioInlineDeleteController.php',
'PholioInlineSaveController' => 'applications/pholio/controller/PholioInlineSaveController.php',
'PholioInlineViewController' => 'applications/pholio/controller/PholioInlineViewController.php',
'PholioMock' => 'applications/pholio/storage/PholioMock.php',
'PholioMockCommentController' => 'applications/pholio/controller/PholioMockCommentController.php',
'PholioMockEditController' => 'applications/pholio/controller/PholioMockEditController.php',
@ -2917,8 +2920,11 @@ phutil_register_library_map(array(
0 => 'PholioDAO',
1 => 'PhabricatorMarkupInterface',
),
'PholioInlineCommentView' => 'AphrontView',
'PholioInlineController' => 'PholioController',
'PholioInlineDeleteController' => 'PholioController',
'PholioInlineSaveController' => 'PholioController',
'PholioInlineViewController' => 'PholioController',
'PholioMock' =>
array(
0 => 'PholioDAO',

View file

@ -43,8 +43,12 @@ final class PhabricatorApplicationPholio extends PhabricatorApplication {
'new/' => 'PholioMockEditController',
'edit/(?P<id>\d+)/' => 'PholioMockEditController',
'comment/(?P<id>\d+)/' => 'PholioMockCommentController',
'inline/(?P<id>\d+)/' => 'PholioInlineController',
'inline/save/' => 'PholioInlineSaveController',
'inline/' => array(
'(?P<id>\d+)/' => 'PholioInlineController',
'save/' => 'PholioInlineSaveController',
'delete/(?P<id>\d+)/' => 'PholioInlineDeleteController',
'view/(?P<id>\d+)/' => 'PholioInlineViewController'
),
),
);
}

View file

@ -16,35 +16,35 @@ final class PholioInlineController extends PholioController {
$user = $request->getUser();
$inline_comments = id(new PholioTransactionComment())->loadAllWhere(
'imageid = %d AND transactionphid IS NOT NULL',
$this->id);
'imageid = %d AND (transactionphid IS NOT NULL
OR (authorphid = %s AND transactionphid IS NULL))',
$this->id,
$user->getPHID());
$inline_comments = array_merge(
$inline_comments,
id(new PholioTransactionComment())->loadAllWhere(
'imageid = %d AND authorphid = %s AND transactionphid IS NULL',
$this->id,
$user->getPHID()));
$author_phids = mpull($inline_comments, 'getAuthorPHID');
$authors = id(new PhabricatorObjectHandleData($author_phids))
->loadHandles();
$inlines = array();
foreach ($inline_comments as $inline_comment) {
$author = id(new PhabricatorUser())->loadOneWhere(
'phid = %s',
$inline_comment->getAuthorPHID());
$inline_view = id(new PholioInlineCommentView())
->setHandle($authors[$inline_comment->getAuthorPHID()])
->setInlineComment($inline_comment);
if ($inline_comment->getEditPolicy(PhabricatorPolicyCapability::CAN_EDIT)
== $user->getPHID() && $inline_comment->getTransactionPHID() === null) {
$inline_view->setEditable(true);
}
$inlines[] = array(
'phid' => $inline_comment->getPHID(),
'userphid' => $author->getPHID(),
'username' => $author->getUserName(),
'canEdit' => ($inline_comment->
getEditPolicy(PhabricatorPolicyCapability::CAN_EDIT) ==
$user->getPHID()) ? true : false,
'transactionphid' => $inline_comment->getTransactionPHID(),
'imageID' => $inline_comment->getImageID(),
'x' => $inline_comment->getX(),
'y' => $inline_comment->getY(),
'width' => $inline_comment->getWidth(),
'height' => $inline_comment->getHeight(),
'content' => $inline_comment->getContent());
'contentHTML' => $inline_view->render());
}
return id(new AphrontAjaxResponse())->setContent($inlines);

View file

@ -0,0 +1,32 @@
<?php
/**
* @group pholio
*/
final class PholioInlineDeleteController extends PholioController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$inline_comment = id(new PholioTransactionComment())->loadOneWhere(
'id = %d AND authorphid = %s AND transactionphid IS NULL',
$this->id,
$user->getPHID());
if ($inline_comment == null) {
return new Aphront404Response();
} else {
return id(new AphrontAjaxResponse())
->setContent(array('success' => true));
}
}
}

View file

@ -11,10 +11,6 @@ final class PholioInlineSaveController extends PholioController {
$mock = id(new PholioMockQuery())
->setViewer($user)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW
))
->withIDs(array($request->getInt('mockID')))
->executeOne();
@ -46,8 +42,22 @@ final class PholioInlineSaveController extends PholioController {
$draft->setContent($request->getStr('comment'));
$draft->save();
$inlineID = $draft->getID();
if ($request->isAjax()) {
$inline_view = id(new PholioInlineCommentView())
->setInlineComment($draft)
->setEditable(true)
->setHandle(
PhabricatorObjectHandleData::loadOneHandle($user->getPHID()));
return id(new AphrontAjaxResponse())
->setContent(array('contentHTML' => $inline_view->render()));
} else {
return id(new AphrontRedirectResponse())->setUri('/M'.$mock->getID());
}
return id(new AphrontAjaxResponse())->setContent(array());
}
}

View file

@ -0,0 +1,35 @@
<?php
/**
* @group pholio
*/
final class PholioInlineViewController extends PholioController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$inline_comment = id(new PholioTransactionComment())->load($this->id);
$handle = PhabricatorObjectHandleData::loadOneHandle(
$inline_comment->getAuthorPHID());
$inline_view = id(new PholioInlineCommentView())
->setHandle($handle)
->setInlineComment($inline_comment);
if ($inline_comment->getEditPolicy(PhabricatorPolicyCapability::CAN_EDIT)
== $user->getPHID() && $inline_comment->getTransactionPHID() === null) {
$inline_view->setEditable(true);
}
return id(new AphrontAjaxResponse())->setContent(
array('contentHTML' => $inline_view->render()));
}
}

View file

@ -12,6 +12,7 @@ final class PholioMockQuery
private $needCoverFiles;
private $needImages;
private $needInlineComments;
public function withIDs(array $ids) {
$this->ids = $ids;
@ -92,6 +93,11 @@ final class PholioMockQuery
return $this;
}
public function needInlineComments($need_inline_comments) {
$this->needInlineComments = $need_inline_comments;
return $this;
}
public function loadImages(array $mocks) {
assert_instances_of($mocks, 'PholioMock');
@ -105,8 +111,19 @@ final class PholioMockQuery
'phid IN (%Ls)',
$file_phids), null, 'getPHID');
if ($this->needInlineComments) {
$all_inline_comments = id(new PholioTransactionComment())
->loadAllWhere('imageid IN (%Ld)',
mpull($all_images, 'getID'));
$all_inline_comments = mgroup($all_inline_comments, 'getImageID');
}
foreach ($all_images as $image) {
$image->attachFile($all_files[$image->getFilePHID()]);
if ($this->needInlineComments) {
$inlines = idx($all_images, $image->getID(), array());
$image->attachInlineComments($inlines);
}
}
$image_groups = mgroup($all_images, 'getMockID');

View file

@ -13,9 +13,24 @@ final class PholioImage extends PholioDAO
protected $name = '';
protected $description = '';
protected $sequence;
protected $inlineComments;
private $file;
public function attachInlineComments(array $inline_comments) {
assert_instances_of($inline_comments, 'PholioTransactionComment');
$this->inlineComments = $inline_comments;
return $this;
}
public function getInlineComments() {
if ($this->inlineComments === null) {
throw new Exception("Call attachImages() before getImages()!");
}
return $this->inlineComments;
}
/* -( PhabricatorMarkupInterface )----------------------------------------- */

View file

@ -0,0 +1,93 @@
<?php
final class PholioInlineCommentView extends AphrontView {
private $inlineComment;
private $handle;
private $editable;
public function setInlineComment(PholioTransactionComment $inline_comment) {
if ($inline_comment->getImageID() === null) {
throw new Exception("Comment provided is not inline comment");
}
$this->inlineComment = $inline_comment;
return $this;
}
public function setHandle(PhabricatorObjectHandle $handle) {
$this->handle = $handle;
return $this;
}
public function setEditable($editable) {
$this->editable = $editable;
return $this;
}
public function render() {
if (!$this->inlineComment) {
throw new Exception("Call setInlineComment() before render()!");
}
$actions = null;
if ($this->editable) {
$edit_action = javelin_tag(
'a',
array(
'href' => '/pholio/inline/edit/'.$this->inlineComment->getID(),
'sigil' => 'inline-edit',
'meta' => array(
'phid' => $this->inlineComment->getPHID()
)
),
pht('Edit'));
$delete_action = javelin_tag(
'a',
array(
'href' => '/pholio/inline/delete/'.$this->inlineComment->getID(),
'sigil' => 'inline-delete',
'meta' => array(
'phid' => $this->inlineComment->getPHID()
)
),
pht('Delete'));
$actions = phutil_tag(
'span',
array(
'class' => 'pholio-inline-head-links'
),
array($edit_action, $delete_action));
}
$comment_header = phutil_tag(
'div',
array(
'class' => 'pholio-inline-comment-header'
),
array($this->handle->getName(), $actions));
$comment_body = phutil_tag(
'div',
array(
),
$this->inlineComment->getContent());
$comment_block = javelin_tag(
'div',
array(
'id' => $this->inlineComment->getPHID()."_comment",
'class' => 'pholio-inline-comment'
),
array($comment_header, $comment_body));
return $this->renderSingleView($comment_block);
}
}

View file

@ -6,6 +6,7 @@ final class PholioMockImagesView extends AphrontView {
public function setMock(PholioMock $mock) {
$this->mock = $mock;
return $this;
}
public function render() {

View file

@ -127,7 +127,9 @@ JX.behavior('pholio-mock-view', function(config) {
var saveURL = "/pholio/inline/save/";
var inlineComment = new JX.Request(saveURL, function(r) {
JX.DOM.appendContent(
JX.$('mock-inline-comments'),
JX.$H(r.contentHTML));
});
var commentToAdd = {
@ -141,50 +143,8 @@ JX.behavior('pholio-mock-view', function(config) {
inlineComment.addData(commentToAdd);
inlineComment.send();
load_inline_comments();
});
function forge_inline_comment(data) {
var comment_head = data.username;
if (data.transactionphid == null) comment_head += " (draft)";
var links = null;
if (data.canEdit && data.transactionphid == null) {
links = JX.$N(
'span',
{
className: 'pholio-inline-head-links'
},
[
JX.$N('a',{href: 'http://www.google.fi'},'Edit'),
JX.$N('a',{href: 'http://www.google.fi'},'Delete')
]);
}
var comment_header = JX.$N(
'div',
{
className: 'pholio-inline-comment-header'
},
[comment_head, links]);
var comment_body = JX.$N(
'div',
{},
data.content);
var inline_comment = JX.$N(
'div',
{
id: data.phid + "_comment",
className: 'pholio-inline-comment'
},
[comment_header, comment_body]);
return inline_comment;
}
function load_inline_comments() {
var data = JX.Stratcom.getData(JX.$(config.mainID));
var comment_holder = JX.$('mock-inline-comments');
@ -199,8 +159,7 @@ JX.behavior('pholio-mock-view', function(config) {
'div',
{
id: r[i].phid + "_selection",
className: 'pholio-mock-select-border',
title: r[i].content
className: 'pholio-mock-select-border'
});
JX.Stratcom.addData(
@ -208,7 +167,7 @@ JX.behavior('pholio-mock-view', function(config) {
{phid: r[i].phid});
JX.Stratcom.addSigil(inlineSelection, "image_selection");
JX.DOM.appendContent(comment_holder, forge_inline_comment(r[i]));
JX.DOM.appendContent(comment_holder, JX.$H(r[i].contentHTML));
JX.DOM.appendContent(wrapper, inlineSelection);
@ -218,7 +177,11 @@ JX.behavior('pholio-mock-view', function(config) {
if (r[i].transactionphid == null) {
var inlineDraft = JX.$N(
'div',{className: 'pholio-mock-select-fill'});
'div',
{
className: 'pholio-mock-select-fill',
id: r[i].phid + "_fill"
});
JX.$V(r[i].x, r[i].y).setPos(inlineDraft);
JX.$V(r[i].width, r[i].height).setDim(inlineDraft);
@ -233,6 +196,28 @@ JX.behavior('pholio-mock-view', function(config) {
}
}
JX.Stratcom.listen(
'click',
'inline-delete',
function(e) {
var data = e.getNodeData('inline-delete');
e.kill();
JX.DOM.hide(
JX.$(data.phid + "_comment"),
JX.$(data.phid + "_fill"),
JX.$(data.phid + "_selection")
);
});
JX.Stratcom.listen(
'click',
'inline-edit',
function(e) {
e.kill();
alert("WIP");
}
);
JX.Stratcom.listen(
'mouseover',
'image_selection',
@ -261,6 +246,3 @@ JX.behavior('pholio-mock-view', function(config) {
load_inline_comments();
});