@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

authored by

Lauri-Henrik Jalonen and committed by
epriestley
f1bd1da0 8eb404ae

+270 -75
+6
src/__phutil_library_map__.php
··· 1446 1446 'PholioController' => 'applications/pholio/controller/PholioController.php', 1447 1447 'PholioDAO' => 'applications/pholio/storage/PholioDAO.php', 1448 1448 'PholioImage' => 'applications/pholio/storage/PholioImage.php', 1449 + 'PholioInlineCommentView' => 'applications/pholio/view/PholioInlineCommentView.php', 1449 1450 'PholioInlineController' => 'applications/pholio/controller/PholioInlineController.php', 1451 + 'PholioInlineDeleteController' => 'applications/pholio/controller/PholioInlineDeleteController.php', 1450 1452 'PholioInlineSaveController' => 'applications/pholio/controller/PholioInlineSaveController.php', 1453 + 'PholioInlineViewController' => 'applications/pholio/controller/PholioInlineViewController.php', 1451 1454 'PholioMock' => 'applications/pholio/storage/PholioMock.php', 1452 1455 'PholioMockCommentController' => 'applications/pholio/controller/PholioMockCommentController.php', 1453 1456 'PholioMockEditController' => 'applications/pholio/controller/PholioMockEditController.php', ··· 2917 2920 0 => 'PholioDAO', 2918 2921 1 => 'PhabricatorMarkupInterface', 2919 2922 ), 2923 + 'PholioInlineCommentView' => 'AphrontView', 2920 2924 'PholioInlineController' => 'PholioController', 2925 + 'PholioInlineDeleteController' => 'PholioController', 2921 2926 'PholioInlineSaveController' => 'PholioController', 2927 + 'PholioInlineViewController' => 'PholioController', 2922 2928 'PholioMock' => 2923 2929 array( 2924 2930 0 => 'PholioDAO',
+6 -2
src/applications/pholio/application/PhabricatorApplicationPholio.php
··· 43 43 'new/' => 'PholioMockEditController', 44 44 'edit/(?P<id>\d+)/' => 'PholioMockEditController', 45 45 'comment/(?P<id>\d+)/' => 'PholioMockCommentController', 46 - 'inline/(?P<id>\d+)/' => 'PholioInlineController', 47 - 'inline/save/' => 'PholioInlineSaveController', 46 + 'inline/' => array( 47 + '(?P<id>\d+)/' => 'PholioInlineController', 48 + 'save/' => 'PholioInlineSaveController', 49 + 'delete/(?P<id>\d+)/' => 'PholioInlineDeleteController', 50 + 'view/(?P<id>\d+)/' => 'PholioInlineViewController' 51 + ), 48 52 ), 49 53 ); 50 54 }
+18 -18
src/applications/pholio/controller/PholioInlineController.php
··· 16 16 $user = $request->getUser(); 17 17 18 18 $inline_comments = id(new PholioTransactionComment())->loadAllWhere( 19 - 'imageid = %d AND transactionphid IS NOT NULL', 20 - $this->id); 19 + 'imageid = %d AND (transactionphid IS NOT NULL 20 + OR (authorphid = %s AND transactionphid IS NULL))', 21 + $this->id, 22 + $user->getPHID()); 21 23 22 - $inline_comments = array_merge( 23 - $inline_comments, 24 - id(new PholioTransactionComment())->loadAllWhere( 25 - 'imageid = %d AND authorphid = %s AND transactionphid IS NULL', 26 - $this->id, 27 - $user->getPHID())); 24 + $author_phids = mpull($inline_comments, 'getAuthorPHID'); 25 + $authors = id(new PhabricatorObjectHandleData($author_phids)) 26 + ->loadHandles(); 28 27 29 28 $inlines = array(); 29 + 30 30 foreach ($inline_comments as $inline_comment) { 31 - $author = id(new PhabricatorUser())->loadOneWhere( 32 - 'phid = %s', 33 - $inline_comment->getAuthorPHID()); 31 + $inline_view = id(new PholioInlineCommentView()) 32 + ->setHandle($authors[$inline_comment->getAuthorPHID()]) 33 + ->setInlineComment($inline_comment); 34 + 35 + if ($inline_comment->getEditPolicy(PhabricatorPolicyCapability::CAN_EDIT) 36 + == $user->getPHID() && $inline_comment->getTransactionPHID() === null) { 37 + $inline_view->setEditable(true); 38 + } 39 + 34 40 $inlines[] = array( 35 41 'phid' => $inline_comment->getPHID(), 36 - 'userphid' => $author->getPHID(), 37 - 'username' => $author->getUserName(), 38 - 'canEdit' => ($inline_comment-> 39 - getEditPolicy(PhabricatorPolicyCapability::CAN_EDIT) == 40 - $user->getPHID()) ? true : false, 41 42 'transactionphid' => $inline_comment->getTransactionPHID(), 42 - 'imageID' => $inline_comment->getImageID(), 43 43 'x' => $inline_comment->getX(), 44 44 'y' => $inline_comment->getY(), 45 45 'width' => $inline_comment->getWidth(), 46 46 'height' => $inline_comment->getHeight(), 47 - 'content' => $inline_comment->getContent()); 47 + 'contentHTML' => $inline_view->render()); 48 48 } 49 49 50 50 return id(new AphrontAjaxResponse())->setContent($inlines);
+32
src/applications/pholio/controller/PholioInlineDeleteController.php
··· 1 + <?php 2 + 3 + /** 4 + * @group pholio 5 + */ 6 + final class PholioInlineDeleteController extends PholioController { 7 + 8 + private $id; 9 + 10 + public function willProcessRequest(array $data) { 11 + $this->id = $data['id']; 12 + } 13 + 14 + public function processRequest() { 15 + $request = $this->getRequest(); 16 + $user = $request->getUser(); 17 + 18 + $inline_comment = id(new PholioTransactionComment())->loadOneWhere( 19 + 'id = %d AND authorphid = %s AND transactionphid IS NULL', 20 + $this->id, 21 + $user->getPHID()); 22 + 23 + if ($inline_comment == null) { 24 + return new Aphront404Response(); 25 + } else { 26 + return id(new AphrontAjaxResponse()) 27 + ->setContent(array('success' => true)); 28 + } 29 + 30 + } 31 + 32 + }
+15 -5
src/applications/pholio/controller/PholioInlineSaveController.php
··· 11 11 12 12 $mock = id(new PholioMockQuery()) 13 13 ->setViewer($user) 14 - ->requireCapabilities( 15 - array( 16 - PhabricatorPolicyCapability::CAN_VIEW 17 - )) 18 14 ->withIDs(array($request->getInt('mockID'))) 19 15 ->executeOne(); 20 16 ··· 46 42 $draft->setContent($request->getStr('comment')); 47 43 48 44 $draft->save(); 45 + $inlineID = $draft->getID(); 49 46 50 - return id(new AphrontAjaxResponse())->setContent(array()); 47 + if ($request->isAjax()) { 48 + $inline_view = id(new PholioInlineCommentView()) 49 + ->setInlineComment($draft) 50 + ->setEditable(true) 51 + ->setHandle( 52 + PhabricatorObjectHandleData::loadOneHandle($user->getPHID())); 53 + 54 + return id(new AphrontAjaxResponse()) 55 + ->setContent(array('contentHTML' => $inline_view->render())); 56 + 57 + } else { 58 + return id(new AphrontRedirectResponse())->setUri('/M'.$mock->getID()); 59 + } 60 + 51 61 } 52 62 53 63 }
+35
src/applications/pholio/controller/PholioInlineViewController.php
··· 1 + <?php 2 + 3 + /** 4 + * @group pholio 5 + */ 6 + final class PholioInlineViewController extends PholioController { 7 + 8 + private $id; 9 + 10 + public function willProcessRequest(array $data) { 11 + $this->id = $data['id']; 12 + } 13 + 14 + public function processRequest() { 15 + $request = $this->getRequest(); 16 + $user = $request->getUser(); 17 + 18 + $inline_comment = id(new PholioTransactionComment())->load($this->id); 19 + $handle = PhabricatorObjectHandleData::loadOneHandle( 20 + $inline_comment->getAuthorPHID()); 21 + 22 + $inline_view = id(new PholioInlineCommentView()) 23 + ->setHandle($handle) 24 + ->setInlineComment($inline_comment); 25 + 26 + if ($inline_comment->getEditPolicy(PhabricatorPolicyCapability::CAN_EDIT) 27 + == $user->getPHID() && $inline_comment->getTransactionPHID() === null) { 28 + $inline_view->setEditable(true); 29 + } 30 + 31 + return id(new AphrontAjaxResponse())->setContent( 32 + array('contentHTML' => $inline_view->render())); 33 + } 34 + 35 + }
+17
src/applications/pholio/query/PholioMockQuery.php
··· 12 12 13 13 private $needCoverFiles; 14 14 private $needImages; 15 + private $needInlineComments; 15 16 16 17 public function withIDs(array $ids) { 17 18 $this->ids = $ids; ··· 92 93 return $this; 93 94 } 94 95 96 + public function needInlineComments($need_inline_comments) { 97 + $this->needInlineComments = $need_inline_comments; 98 + return $this; 99 + } 100 + 95 101 public function loadImages(array $mocks) { 96 102 assert_instances_of($mocks, 'PholioMock'); 97 103 ··· 105 111 'phid IN (%Ls)', 106 112 $file_phids), null, 'getPHID'); 107 113 114 + if ($this->needInlineComments) { 115 + $all_inline_comments = id(new PholioTransactionComment()) 116 + ->loadAllWhere('imageid IN (%Ld)', 117 + mpull($all_images, 'getID')); 118 + $all_inline_comments = mgroup($all_inline_comments, 'getImageID'); 119 + } 120 + 108 121 foreach ($all_images as $image) { 109 122 $image->attachFile($all_files[$image->getFilePHID()]); 123 + if ($this->needInlineComments) { 124 + $inlines = idx($all_images, $image->getID(), array()); 125 + $image->attachInlineComments($inlines); 126 + } 110 127 } 111 128 112 129 $image_groups = mgroup($all_images, 'getMockID');
+15
src/applications/pholio/storage/PholioImage.php
··· 13 13 protected $name = ''; 14 14 protected $description = ''; 15 15 protected $sequence; 16 + protected $inlineComments; 16 17 17 18 private $file; 19 + 20 + public function attachInlineComments(array $inline_comments) { 21 + assert_instances_of($inline_comments, 'PholioTransactionComment'); 22 + $this->inlineComments = $inline_comments; 23 + return $this; 24 + } 25 + 26 + public function getInlineComments() { 27 + if ($this->inlineComments === null) { 28 + throw new Exception("Call attachImages() before getImages()!"); 29 + } 30 + return $this->inlineComments; 31 + } 32 + 18 33 19 34 /* -( PhabricatorMarkupInterface )----------------------------------------- */ 20 35
+93
src/applications/pholio/view/PholioInlineCommentView.php
··· 1 + <?php 2 + 3 + final class PholioInlineCommentView extends AphrontView { 4 + 5 + private $inlineComment; 6 + 7 + private $handle; 8 + private $editable; 9 + 10 + public function setInlineComment(PholioTransactionComment $inline_comment) { 11 + if ($inline_comment->getImageID() === null) { 12 + throw new Exception("Comment provided is not inline comment"); 13 + } 14 + 15 + $this->inlineComment = $inline_comment; 16 + return $this; 17 + } 18 + 19 + public function setHandle(PhabricatorObjectHandle $handle) { 20 + $this->handle = $handle; 21 + return $this; 22 + } 23 + 24 + public function setEditable($editable) { 25 + $this->editable = $editable; 26 + return $this; 27 + } 28 + 29 + public function render() { 30 + if (!$this->inlineComment) { 31 + throw new Exception("Call setInlineComment() before render()!"); 32 + } 33 + 34 + $actions = null; 35 + 36 + if ($this->editable) { 37 + $edit_action = javelin_tag( 38 + 'a', 39 + array( 40 + 'href' => '/pholio/inline/edit/'.$this->inlineComment->getID(), 41 + 'sigil' => 'inline-edit', 42 + 'meta' => array( 43 + 'phid' => $this->inlineComment->getPHID() 44 + ) 45 + ), 46 + pht('Edit')); 47 + 48 + $delete_action = javelin_tag( 49 + 'a', 50 + array( 51 + 'href' => '/pholio/inline/delete/'.$this->inlineComment->getID(), 52 + 'sigil' => 'inline-delete', 53 + 'meta' => array( 54 + 'phid' => $this->inlineComment->getPHID() 55 + ) 56 + ), 57 + pht('Delete')); 58 + 59 + 60 + $actions = phutil_tag( 61 + 'span', 62 + array( 63 + 'class' => 'pholio-inline-head-links' 64 + ), 65 + array($edit_action, $delete_action)); 66 + } 67 + 68 + $comment_header = phutil_tag( 69 + 'div', 70 + array( 71 + 'class' => 'pholio-inline-comment-header' 72 + ), 73 + array($this->handle->getName(), $actions)); 74 + 75 + $comment_body = phutil_tag( 76 + 'div', 77 + array( 78 + 79 + ), 80 + $this->inlineComment->getContent()); 81 + 82 + $comment_block = javelin_tag( 83 + 'div', 84 + array( 85 + 'id' => $this->inlineComment->getPHID()."_comment", 86 + 'class' => 'pholio-inline-comment' 87 + ), 88 + array($comment_header, $comment_body)); 89 + 90 + 91 + return $this->renderSingleView($comment_block); 92 + } 93 + }
+1
src/applications/pholio/view/PholioMockImagesView.php
··· 6 6 7 7 public function setMock(PholioMock $mock) { 8 8 $this->mock = $mock; 9 + return $this; 9 10 } 10 11 11 12 public function render() {
+32 -50
webroot/rsrc/js/application/pholio/behavior-pholio-mock-view.js
··· 127 127 var saveURL = "/pholio/inline/save/"; 128 128 129 129 var inlineComment = new JX.Request(saveURL, function(r) { 130 - 130 + JX.DOM.appendContent( 131 + JX.$('mock-inline-comments'), 132 + JX.$H(r.contentHTML)); 131 133 }); 132 134 133 135 var commentToAdd = { ··· 141 143 142 144 inlineComment.addData(commentToAdd); 143 145 inlineComment.send(); 144 - load_inline_comments(); 145 146 }); 146 147 147 - function forge_inline_comment(data) { 148 - var comment_head = data.username; 149 - if (data.transactionphid == null) comment_head += " (draft)"; 150 - 151 - var links = null; 152 - if (data.canEdit && data.transactionphid == null) { 153 - links = JX.$N( 154 - 'span', 155 - { 156 - className: 'pholio-inline-head-links' 157 - }, 158 - [ 159 - JX.$N('a',{href: 'http://www.google.fi'},'Edit'), 160 - JX.$N('a',{href: 'http://www.google.fi'},'Delete') 161 - ]); 162 - 163 - } 164 - 165 - var comment_header = JX.$N( 166 - 'div', 167 - { 168 - className: 'pholio-inline-comment-header' 169 - }, 170 - [comment_head, links]); 171 - 172 - var comment_body = JX.$N( 173 - 'div', 174 - {}, 175 - data.content); 176 - 177 - var inline_comment = JX.$N( 178 - 'div', 179 - { 180 - id: data.phid + "_comment", 181 - className: 'pholio-inline-comment' 182 - }, 183 - [comment_header, comment_body]); 184 - 185 - return inline_comment; 186 - } 187 - 188 148 function load_inline_comments() { 189 149 var data = JX.Stratcom.getData(JX.$(config.mainID)); 190 150 var comment_holder = JX.$('mock-inline-comments'); ··· 199 159 'div', 200 160 { 201 161 id: r[i].phid + "_selection", 202 - className: 'pholio-mock-select-border', 203 - title: r[i].content 162 + className: 'pholio-mock-select-border' 204 163 }); 205 164 206 165 JX.Stratcom.addData( ··· 208 167 {phid: r[i].phid}); 209 168 210 169 JX.Stratcom.addSigil(inlineSelection, "image_selection"); 211 - JX.DOM.appendContent(comment_holder, forge_inline_comment(r[i])); 170 + JX.DOM.appendContent(comment_holder, JX.$H(r[i].contentHTML)); 212 171 213 172 JX.DOM.appendContent(wrapper, inlineSelection); 214 173 ··· 218 177 if (r[i].transactionphid == null) { 219 178 220 179 var inlineDraft = JX.$N( 221 - 'div',{className: 'pholio-mock-select-fill'}); 180 + 'div', 181 + { 182 + className: 'pholio-mock-select-fill', 183 + id: r[i].phid + "_fill" 184 + }); 222 185 223 186 JX.$V(r[i].x, r[i].y).setPos(inlineDraft); 224 187 JX.$V(r[i].width, r[i].height).setDim(inlineDraft); ··· 234 197 } 235 198 236 199 JX.Stratcom.listen( 200 + 'click', 201 + 'inline-delete', 202 + function(e) { 203 + var data = e.getNodeData('inline-delete'); 204 + e.kill(); 205 + JX.DOM.hide( 206 + JX.$(data.phid + "_comment"), 207 + JX.$(data.phid + "_fill"), 208 + JX.$(data.phid + "_selection") 209 + ); 210 + }); 211 + 212 + JX.Stratcom.listen( 213 + 'click', 214 + 'inline-edit', 215 + function(e) { 216 + e.kill(); 217 + alert("WIP"); 218 + } 219 + ); 220 + 221 + JX.Stratcom.listen( 237 222 'mouseover', 238 223 'image_selection', 239 224 function(e) { ··· 261 246 262 247 load_inline_comments(); 263 248 }); 264 - 265 - 266 -