@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.

Pholio - back end for image re-ordering

Summary:
companion diff to D6729. This is the back-end stuff, plus calls the JS in D6729 for when images are removed, un-removed, uploaded, or replaced.

Fixes T3640.

Test Plan: messed around with images. hit save - new order! temporarily showed these stories and got text about re-ordering stuff.

Reviewers: epriestley, chad

Reviewed By: epriestley

CC: Korvin, aran

Maniphest Tasks: T3640

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

+68 -8
+1
src/applications/pholio/constants/PholioTransactionType.php
··· 14 14 const TYPE_IMAGE_NAME= 'image-name'; 15 15 const TYPE_IMAGE_DESCRIPTION = 'image-description'; 16 16 const TYPE_IMAGE_REPLACE = 'image-replace'; 17 + const TYPE_IMAGE_SEQUENCE = 'image-sequence'; 17 18 18 19 /* your witty commentary at the mock : image : x,y level */ 19 20 const TYPE_INLINE = 'inline';
+8 -3
src/applications/pholio/controller/PholioMockEditController.php
··· 110 110 ->setNewValue($value); 111 111 } 112 112 113 - $sequence = 0; 113 + $order = $request->getStrList('imageOrder'); 114 + $sequence_map = array_flip($order); 114 115 $replaces = $request->getArr('replaces'); 115 116 $replaces_map = array_flip($replaces); 116 117 ··· 133 134 134 135 $title = (string)$request->getStr('title_'.$file_phid); 135 136 $description = (string)$request->getStr('description_'.$file_phid); 137 + $sequence = $sequence_map[$file_phid]; 136 138 137 139 if ($replaces_image_phid) { 138 140 $replace_image = id(new PholioImage()) ··· 165 167 PholioTransactionType::TYPE_IMAGE_DESCRIPTION) 166 168 ->setNewValue( 167 169 array($existing_image->getPHID() => $description)); 168 - $existing_image->setSequence($sequence); 170 + $xactions[] = id(new PholioTransaction()) 171 + ->setTransactionType( 172 + PholioTransactionType::TYPE_IMAGE_SEQUENCE) 173 + ->setNewValue( 174 + array($existing_image->getPHID() => $sequence)); 169 175 } 170 - $sequence++; 171 176 } 172 177 foreach ($mock_images as $file_phid => $mock_image) { 173 178 if (!isset($files[$file_phid]) && !isset($replaces[$file_phid])) {
+22 -4
src/applications/pholio/editor/PholioMockEditor.php
··· 31 31 $types[] = PholioTransactionType::TYPE_IMAGE_NAME; 32 32 $types[] = PholioTransactionType::TYPE_IMAGE_DESCRIPTION; 33 33 $types[] = PholioTransactionType::TYPE_IMAGE_REPLACE; 34 + $types[] = PholioTransactionType::TYPE_IMAGE_SEQUENCE; 34 35 35 36 return $types; 36 37 } ··· 55 56 $name = $image->getName(); 56 57 $phid = $image->getPHID(); 57 58 } 58 - return array ($phid => $name); 59 + return array($phid => $name); 59 60 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 60 61 $description = null; 61 62 $phid = null; ··· 68 69 case PholioTransactionType::TYPE_IMAGE_REPLACE: 69 70 $raw = $xaction->getNewValue(); 70 71 return $raw->getReplacesImagePHID(); 72 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 73 + $sequence = null; 74 + $phid = null; 75 + $image = $this->getImageForXaction($object, $xaction); 76 + if ($image) { 77 + $sequence = $image->getSequence(); 78 + $phid = $image->getPHID(); 79 + } 80 + return array($phid => $sequence); 71 81 } 72 82 } 73 83 ··· 80 90 case PholioTransactionType::TYPE_DESCRIPTION: 81 91 case PholioTransactionType::TYPE_IMAGE_NAME: 82 92 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 93 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 83 94 return $xaction->getNewValue(); 84 95 case PholioTransactionType::TYPE_IMAGE_REPLACE: 85 96 $raw = $xaction->getNewValue(); ··· 214 225 } 215 226 $object->attachImages($images); 216 227 break; 217 - case PholioTransactionType::TYPE_IMAGE_NAME: 218 - $image = $this->getImageForXaction($object, $xaction); 219 - $value = (string) head($xaction->getNewValue()); 228 + case PholioTransactionType::TYPE_IMAGE_NAME: 229 + $image = $this->getImageForXaction($object, $xaction); 230 + $value = (string) head($xaction->getNewValue()); 220 231 $image->setName($value); 221 232 $image->save(); 222 233 break; ··· 224 235 $image = $this->getImageForXaction($object, $xaction); 225 236 $value = (string) head($xaction->getNewValue()); 226 237 $image->setDescription($value); 238 + $image->save(); 239 + break; 240 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 241 + $image = $this->getImageForXaction($object, $xaction); 242 + $value = (int) head($xaction->getNewValue()); 243 + $image->setSequence($value); 227 244 $image->save(); 228 245 break; 229 246 } ··· 257 274 return $this->mergePHIDOrEdgeTransactions($u, $v); 258 275 case PholioTransactionType::TYPE_IMAGE_NAME: 259 276 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 277 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 260 278 $raw_new_value_u = $u->getNewValue(); 261 279 $raw_new_value_v = $v->getNewValue(); 262 280 $phid_u = key($raw_new_value_u);
+2 -1
src/applications/pholio/query/PholioMockQuery.php
··· 124 124 foreach ($mocks as $mock) { 125 125 $mock_images = idx($image_groups, $mock->getID(), array()); 126 126 $mock->attachAllImages($mock_images); 127 - $mock->attachImages(mfilter($mock_images, 'getIsObsolete', true)); 127 + $active_images = mfilter($mock_images, 'getIsObsolete', true); 128 + $mock->attachImages(msort($active_images, 'getSequence')); 128 129 } 129 130 } 130 131
+31
src/applications/pholio/storage/PholioTransaction.php
··· 42 42 break; 43 43 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 44 44 case PholioTransactionType::TYPE_IMAGE_NAME: 45 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 45 46 $phids[] = key($new); 46 47 break; 47 48 } ··· 58 59 case PholioTransactionType::TYPE_IMAGE_NAME: 59 60 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 60 61 return ($old === array(null => null)); 62 + // this is boring / silly to surface; changing sequence is NBD 63 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 64 + return true; 61 65 } 62 66 63 67 return parent::shouldHide(); ··· 71 75 case PholioTransactionType::TYPE_DESCRIPTION: 72 76 case PholioTransactionType::TYPE_IMAGE_NAME: 73 77 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 78 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 74 79 return 'edit'; 75 80 case PholioTransactionType::TYPE_IMAGE_FILE: 76 81 case PholioTransactionType::TYPE_IMAGE_REPLACE: ··· 168 173 $this->renderHandleLink($author_phid), 169 174 $this->renderHandleLink(key($new))); 170 175 break; 176 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 177 + return pht( 178 + '%s updated an image\'s (%s) sequence.', 179 + $this->renderHandleLink($author_phid), 180 + $this->renderHandleLink(key($new))); 181 + break; 171 182 } 172 183 173 184 return parent::getTitle(); ··· 228 239 $this->renderHandleLink($author_phid), 229 240 $this->renderHandleLink($object_phid)); 230 241 break; 242 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 243 + return pht( 244 + '%s updated image sequence of %s.', 245 + $this->renderHandleLink($author_phid), 246 + $this->renderHandleLink($object_phid)); 247 + break; 231 248 } 232 249 233 250 return parent::getTitleForFeed(); ··· 282 299 case PholioTransactionType::TYPE_DESCRIPTION: 283 300 case PholioTransactionType::TYPE_IMAGE_NAME: 284 301 case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 302 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 285 303 return PhabricatorTransactions::COLOR_BLUE; 286 304 case PholioTransactionType::TYPE_IMAGE_REPLACE: 287 305 return PhabricatorTransactions::COLOR_YELLOW; ··· 298 316 } 299 317 300 318 return parent::getColor(); 319 + } 320 + 321 + public function getNoEffectDescription() { 322 + switch ($this->getTransactionType()) { 323 + case PholioTransactionType::TYPE_IMAGE_NAME: 324 + return pht('The image title was not updated.'); 325 + case PholioTransactionType::TYPE_IMAGE_DESCRIPTION: 326 + return pht('The image description was not updated.'); 327 + case PholioTransactionType::TYPE_IMAGE_SEQUENCE: 328 + return pht('The image sequence was not updated.'); 329 + } 330 + 331 + return parent::getNoEffectDescription(); 301 332 } 302 333 }
+4
webroot/rsrc/js/application/pholio/behavior-pholio-mock-edit.js
··· 35 35 JX.DOM.listen(undo, 'click', 'pholio-drop-undo', function(e) { 36 36 e.kill(); 37 37 JX.DOM.replace(undo, node); 38 + synchronize_order(); 38 39 }); 39 40 40 41 JX.DOM.replace(node, undo); 42 + synchronize_order(); 41 43 }); 42 44 43 45 ··· 116 118 build_update_control(new_node); 117 119 118 120 JX.DOM.replace(node, new_node); 121 + synchronize_order(); 119 122 }) 120 123 .start(); 121 124 }); ··· 154 157 155 158 JX.DOM.replace(node, new_node); 156 159 JX.DOM.alterClass(node, 'pholio-replacing', false); 160 + synchronize_order(); 157 161 }) 158 162 .start(); 159 163 });