Skip to content

Commit 65b875d

Browse files
committedAug 12, 2013
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
1 parent fe08734 commit 65b875d

File tree

6 files changed

+68
-8
lines changed

6 files changed

+68
-8
lines changed
 

‎src/applications/pholio/constants/PholioTransactionType.php

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ final class PholioTransactionType extends PholioConstants {
1414
const TYPE_IMAGE_NAME= 'image-name';
1515
const TYPE_IMAGE_DESCRIPTION = 'image-description';
1616
const TYPE_IMAGE_REPLACE = 'image-replace';
17+
const TYPE_IMAGE_SEQUENCE = 'image-sequence';
1718

1819
/* your witty commentary at the mock : image : x,y level */
1920
const TYPE_INLINE = 'inline';

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ public function processRequest() {
110110
->setNewValue($value);
111111
}
112112

113-
$sequence = 0;
113+
$order = $request->getStrList('imageOrder');
114+
$sequence_map = array_flip($order);
114115
$replaces = $request->getArr('replaces');
115116
$replaces_map = array_flip($replaces);
116117

@@ -133,6 +134,7 @@ public function processRequest() {
133134

134135
$title = (string)$request->getStr('title_'.$file_phid);
135136
$description = (string)$request->getStr('description_'.$file_phid);
137+
$sequence = $sequence_map[$file_phid];
136138

137139
if ($replaces_image_phid) {
138140
$replace_image = id(new PholioImage())
@@ -165,9 +167,12 @@ public function processRequest() {
165167
PholioTransactionType::TYPE_IMAGE_DESCRIPTION)
166168
->setNewValue(
167169
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));
169175
}
170-
$sequence++;
171176
}
172177
foreach ($mock_images as $file_phid => $mock_image) {
173178
if (!isset($files[$file_phid]) && !isset($replaces[$file_phid])) {

‎src/applications/pholio/editor/PholioMockEditor.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function getTransactionTypes() {
3131
$types[] = PholioTransactionType::TYPE_IMAGE_NAME;
3232
$types[] = PholioTransactionType::TYPE_IMAGE_DESCRIPTION;
3333
$types[] = PholioTransactionType::TYPE_IMAGE_REPLACE;
34+
$types[] = PholioTransactionType::TYPE_IMAGE_SEQUENCE;
3435

3536
return $types;
3637
}
@@ -55,7 +56,7 @@ protected function getCustomTransactionOldValue(
5556
$name = $image->getName();
5657
$phid = $image->getPHID();
5758
}
58-
return array ($phid => $name);
59+
return array($phid => $name);
5960
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
6061
$description = null;
6162
$phid = null;
@@ -68,6 +69,15 @@ protected function getCustomTransactionOldValue(
6869
case PholioTransactionType::TYPE_IMAGE_REPLACE:
6970
$raw = $xaction->getNewValue();
7071
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);
7181
}
7282
}
7383

@@ -80,6 +90,7 @@ protected function getCustomTransactionNewValue(
8090
case PholioTransactionType::TYPE_DESCRIPTION:
8191
case PholioTransactionType::TYPE_IMAGE_NAME:
8292
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
93+
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
8394
return $xaction->getNewValue();
8495
case PholioTransactionType::TYPE_IMAGE_REPLACE:
8596
$raw = $xaction->getNewValue();
@@ -214,9 +225,9 @@ protected function applyCustomExternalTransaction(
214225
}
215226
$object->attachImages($images);
216227
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());
220231
$image->setName($value);
221232
$image->save();
222233
break;
@@ -226,6 +237,12 @@ protected function applyCustomExternalTransaction(
226237
$image->setDescription($value);
227238
$image->save();
228239
break;
240+
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
241+
$image = $this->getImageForXaction($object, $xaction);
242+
$value = (int) head($xaction->getNewValue());
243+
$image->setSequence($value);
244+
$image->save();
245+
break;
229246
}
230247
}
231248

@@ -257,6 +274,7 @@ protected function mergeTransactions(
257274
return $this->mergePHIDOrEdgeTransactions($u, $v);
258275
case PholioTransactionType::TYPE_IMAGE_NAME:
259276
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
277+
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
260278
$raw_new_value_u = $u->getNewValue();
261279
$raw_new_value_v = $v->getNewValue();
262280
$phid_u = key($raw_new_value_u);

‎src/applications/pholio/query/PholioMockQuery.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,8 @@ private function loadImages(array $mocks) {
124124
foreach ($mocks as $mock) {
125125
$mock_images = idx($image_groups, $mock->getID(), array());
126126
$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'));
128129
}
129130
}
130131

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

+31
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function getRequiredHandlePHIDs() {
4242
break;
4343
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
4444
case PholioTransactionType::TYPE_IMAGE_NAME:
45+
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
4546
$phids[] = key($new);
4647
break;
4748
}
@@ -58,6 +59,9 @@ public function shouldHide() {
5859
case PholioTransactionType::TYPE_IMAGE_NAME:
5960
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
6061
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;
6165
}
6266

6367
return parent::shouldHide();
@@ -71,6 +75,7 @@ public function getIcon() {
7175
case PholioTransactionType::TYPE_DESCRIPTION:
7276
case PholioTransactionType::TYPE_IMAGE_NAME:
7377
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
78+
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
7479
return 'edit';
7580
case PholioTransactionType::TYPE_IMAGE_FILE:
7681
case PholioTransactionType::TYPE_IMAGE_REPLACE:
@@ -168,6 +173,12 @@ public function getTitle() {
168173
$this->renderHandleLink($author_phid),
169174
$this->renderHandleLink(key($new)));
170175
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;
171182
}
172183

173184
return parent::getTitle();
@@ -228,6 +239,12 @@ public function getTitleForFeed() {
228239
$this->renderHandleLink($author_phid),
229240
$this->renderHandleLink($object_phid));
230241
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;
231248
}
232249

233250
return parent::getTitleForFeed();
@@ -282,6 +299,7 @@ public function getColor() {
282299
case PholioTransactionType::TYPE_DESCRIPTION:
283300
case PholioTransactionType::TYPE_IMAGE_NAME:
284301
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
302+
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
285303
return PhabricatorTransactions::COLOR_BLUE;
286304
case PholioTransactionType::TYPE_IMAGE_REPLACE:
287305
return PhabricatorTransactions::COLOR_YELLOW;
@@ -299,4 +317,17 @@ public function getColor() {
299317

300318
return parent::getColor();
301319
}
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();
332+
}
302333
}

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

+4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ JX.behavior('pholio-mock-edit', function(config) {
3535
JX.DOM.listen(undo, 'click', 'pholio-drop-undo', function(e) {
3636
e.kill();
3737
JX.DOM.replace(undo, node);
38+
synchronize_order();
3839
});
3940

4041
JX.DOM.replace(node, undo);
42+
synchronize_order();
4143
});
4244

4345

@@ -116,6 +118,7 @@ JX.behavior('pholio-mock-edit', function(config) {
116118
build_update_control(new_node);
117119

118120
JX.DOM.replace(node, new_node);
121+
synchronize_order();
119122
})
120123
.start();
121124
});
@@ -154,6 +157,7 @@ JX.behavior('pholio-mock-edit', function(config) {
154157

155158
JX.DOM.replace(node, new_node);
156159
JX.DOM.alterClass(node, 'pholio-replacing', false);
160+
synchronize_order();
157161
})
158162
.start();
159163
});

0 commit comments

Comments
 (0)
Failed to load comments.