mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
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
This commit is contained in:
parent
fe0873408d
commit
65b875d29d
6 changed files with 68 additions and 8 deletions
|
@ -14,6 +14,7 @@ final class PholioTransactionType extends PholioConstants {
|
||||||
const TYPE_IMAGE_NAME= 'image-name';
|
const TYPE_IMAGE_NAME= 'image-name';
|
||||||
const TYPE_IMAGE_DESCRIPTION = 'image-description';
|
const TYPE_IMAGE_DESCRIPTION = 'image-description';
|
||||||
const TYPE_IMAGE_REPLACE = 'image-replace';
|
const TYPE_IMAGE_REPLACE = 'image-replace';
|
||||||
|
const TYPE_IMAGE_SEQUENCE = 'image-sequence';
|
||||||
|
|
||||||
/* your witty commentary at the mock : image : x,y level */
|
/* your witty commentary at the mock : image : x,y level */
|
||||||
const TYPE_INLINE = 'inline';
|
const TYPE_INLINE = 'inline';
|
||||||
|
|
|
@ -110,7 +110,8 @@ final class PholioMockEditController extends PholioController {
|
||||||
->setNewValue($value);
|
->setNewValue($value);
|
||||||
}
|
}
|
||||||
|
|
||||||
$sequence = 0;
|
$order = $request->getStrList('imageOrder');
|
||||||
|
$sequence_map = array_flip($order);
|
||||||
$replaces = $request->getArr('replaces');
|
$replaces = $request->getArr('replaces');
|
||||||
$replaces_map = array_flip($replaces);
|
$replaces_map = array_flip($replaces);
|
||||||
|
|
||||||
|
@ -133,6 +134,7 @@ final class PholioMockEditController extends PholioController {
|
||||||
|
|
||||||
$title = (string)$request->getStr('title_'.$file_phid);
|
$title = (string)$request->getStr('title_'.$file_phid);
|
||||||
$description = (string)$request->getStr('description_'.$file_phid);
|
$description = (string)$request->getStr('description_'.$file_phid);
|
||||||
|
$sequence = $sequence_map[$file_phid];
|
||||||
|
|
||||||
if ($replaces_image_phid) {
|
if ($replaces_image_phid) {
|
||||||
$replace_image = id(new PholioImage())
|
$replace_image = id(new PholioImage())
|
||||||
|
@ -165,9 +167,12 @@ final class PholioMockEditController extends PholioController {
|
||||||
PholioTransactionType::TYPE_IMAGE_DESCRIPTION)
|
PholioTransactionType::TYPE_IMAGE_DESCRIPTION)
|
||||||
->setNewValue(
|
->setNewValue(
|
||||||
array($existing_image->getPHID() => $description));
|
array($existing_image->getPHID() => $description));
|
||||||
$existing_image->setSequence($sequence);
|
$xactions[] = id(new PholioTransaction())
|
||||||
|
->setTransactionType(
|
||||||
|
PholioTransactionType::TYPE_IMAGE_SEQUENCE)
|
||||||
|
->setNewValue(
|
||||||
|
array($existing_image->getPHID() => $sequence));
|
||||||
}
|
}
|
||||||
$sequence++;
|
|
||||||
}
|
}
|
||||||
foreach ($mock_images as $file_phid => $mock_image) {
|
foreach ($mock_images as $file_phid => $mock_image) {
|
||||||
if (!isset($files[$file_phid]) && !isset($replaces[$file_phid])) {
|
if (!isset($files[$file_phid]) && !isset($replaces[$file_phid])) {
|
||||||
|
|
|
@ -31,6 +31,7 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
$types[] = PholioTransactionType::TYPE_IMAGE_NAME;
|
$types[] = PholioTransactionType::TYPE_IMAGE_NAME;
|
||||||
$types[] = PholioTransactionType::TYPE_IMAGE_DESCRIPTION;
|
$types[] = PholioTransactionType::TYPE_IMAGE_DESCRIPTION;
|
||||||
$types[] = PholioTransactionType::TYPE_IMAGE_REPLACE;
|
$types[] = PholioTransactionType::TYPE_IMAGE_REPLACE;
|
||||||
|
$types[] = PholioTransactionType::TYPE_IMAGE_SEQUENCE;
|
||||||
|
|
||||||
return $types;
|
return $types;
|
||||||
}
|
}
|
||||||
|
@ -55,7 +56,7 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
$name = $image->getName();
|
$name = $image->getName();
|
||||||
$phid = $image->getPHID();
|
$phid = $image->getPHID();
|
||||||
}
|
}
|
||||||
return array ($phid => $name);
|
return array($phid => $name);
|
||||||
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
||||||
$description = null;
|
$description = null;
|
||||||
$phid = null;
|
$phid = null;
|
||||||
|
@ -68,6 +69,15 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
case PholioTransactionType::TYPE_IMAGE_REPLACE:
|
case PholioTransactionType::TYPE_IMAGE_REPLACE:
|
||||||
$raw = $xaction->getNewValue();
|
$raw = $xaction->getNewValue();
|
||||||
return $raw->getReplacesImagePHID();
|
return $raw->getReplacesImagePHID();
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
|
$sequence = null;
|
||||||
|
$phid = null;
|
||||||
|
$image = $this->getImageForXaction($object, $xaction);
|
||||||
|
if ($image) {
|
||||||
|
$sequence = $image->getSequence();
|
||||||
|
$phid = $image->getPHID();
|
||||||
|
}
|
||||||
|
return array($phid => $sequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,6 +90,7 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
case PholioTransactionType::TYPE_DESCRIPTION:
|
case PholioTransactionType::TYPE_DESCRIPTION:
|
||||||
case PholioTransactionType::TYPE_IMAGE_NAME:
|
case PholioTransactionType::TYPE_IMAGE_NAME:
|
||||||
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
return $xaction->getNewValue();
|
return $xaction->getNewValue();
|
||||||
case PholioTransactionType::TYPE_IMAGE_REPLACE:
|
case PholioTransactionType::TYPE_IMAGE_REPLACE:
|
||||||
$raw = $xaction->getNewValue();
|
$raw = $xaction->getNewValue();
|
||||||
|
@ -214,9 +225,9 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
}
|
}
|
||||||
$object->attachImages($images);
|
$object->attachImages($images);
|
||||||
break;
|
break;
|
||||||
case PholioTransactionType::TYPE_IMAGE_NAME:
|
case PholioTransactionType::TYPE_IMAGE_NAME:
|
||||||
$image = $this->getImageForXaction($object, $xaction);
|
$image = $this->getImageForXaction($object, $xaction);
|
||||||
$value = (string) head($xaction->getNewValue());
|
$value = (string) head($xaction->getNewValue());
|
||||||
$image->setName($value);
|
$image->setName($value);
|
||||||
$image->save();
|
$image->save();
|
||||||
break;
|
break;
|
||||||
|
@ -226,6 +237,12 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
$image->setDescription($value);
|
$image->setDescription($value);
|
||||||
$image->save();
|
$image->save();
|
||||||
break;
|
break;
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
|
$image = $this->getImageForXaction($object, $xaction);
|
||||||
|
$value = (int) head($xaction->getNewValue());
|
||||||
|
$image->setSequence($value);
|
||||||
|
$image->save();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,6 +274,7 @@ final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
|
||||||
return $this->mergePHIDOrEdgeTransactions($u, $v);
|
return $this->mergePHIDOrEdgeTransactions($u, $v);
|
||||||
case PholioTransactionType::TYPE_IMAGE_NAME:
|
case PholioTransactionType::TYPE_IMAGE_NAME:
|
||||||
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
$raw_new_value_u = $u->getNewValue();
|
$raw_new_value_u = $u->getNewValue();
|
||||||
$raw_new_value_v = $v->getNewValue();
|
$raw_new_value_v = $v->getNewValue();
|
||||||
$phid_u = key($raw_new_value_u);
|
$phid_u = key($raw_new_value_u);
|
||||||
|
|
|
@ -124,7 +124,8 @@ final class PholioMockQuery
|
||||||
foreach ($mocks as $mock) {
|
foreach ($mocks as $mock) {
|
||||||
$mock_images = idx($image_groups, $mock->getID(), array());
|
$mock_images = idx($image_groups, $mock->getID(), array());
|
||||||
$mock->attachAllImages($mock_images);
|
$mock->attachAllImages($mock_images);
|
||||||
$mock->attachImages(mfilter($mock_images, 'getIsObsolete', true));
|
$active_images = mfilter($mock_images, 'getIsObsolete', true);
|
||||||
|
$mock->attachImages(msort($active_images, 'getSequence'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,6 +42,7 @@ final class PholioTransaction extends PhabricatorApplicationTransaction {
|
||||||
break;
|
break;
|
||||||
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
||||||
case PholioTransactionType::TYPE_IMAGE_NAME:
|
case PholioTransactionType::TYPE_IMAGE_NAME:
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
$phids[] = key($new);
|
$phids[] = key($new);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +59,9 @@ final class PholioTransaction extends PhabricatorApplicationTransaction {
|
||||||
case PholioTransactionType::TYPE_IMAGE_NAME:
|
case PholioTransactionType::TYPE_IMAGE_NAME:
|
||||||
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
||||||
return ($old === array(null => null));
|
return ($old === array(null => null));
|
||||||
|
// this is boring / silly to surface; changing sequence is NBD
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::shouldHide();
|
return parent::shouldHide();
|
||||||
|
@ -71,6 +75,7 @@ final class PholioTransaction extends PhabricatorApplicationTransaction {
|
||||||
case PholioTransactionType::TYPE_DESCRIPTION:
|
case PholioTransactionType::TYPE_DESCRIPTION:
|
||||||
case PholioTransactionType::TYPE_IMAGE_NAME:
|
case PholioTransactionType::TYPE_IMAGE_NAME:
|
||||||
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
return 'edit';
|
return 'edit';
|
||||||
case PholioTransactionType::TYPE_IMAGE_FILE:
|
case PholioTransactionType::TYPE_IMAGE_FILE:
|
||||||
case PholioTransactionType::TYPE_IMAGE_REPLACE:
|
case PholioTransactionType::TYPE_IMAGE_REPLACE:
|
||||||
|
@ -168,6 +173,12 @@ final class PholioTransaction extends PhabricatorApplicationTransaction {
|
||||||
$this->renderHandleLink($author_phid),
|
$this->renderHandleLink($author_phid),
|
||||||
$this->renderHandleLink(key($new)));
|
$this->renderHandleLink(key($new)));
|
||||||
break;
|
break;
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
|
return pht(
|
||||||
|
'%s updated an image\'s (%s) sequence.',
|
||||||
|
$this->renderHandleLink($author_phid),
|
||||||
|
$this->renderHandleLink(key($new)));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getTitle();
|
return parent::getTitle();
|
||||||
|
@ -228,6 +239,12 @@ final class PholioTransaction extends PhabricatorApplicationTransaction {
|
||||||
$this->renderHandleLink($author_phid),
|
$this->renderHandleLink($author_phid),
|
||||||
$this->renderHandleLink($object_phid));
|
$this->renderHandleLink($object_phid));
|
||||||
break;
|
break;
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
|
return pht(
|
||||||
|
'%s updated image sequence of %s.',
|
||||||
|
$this->renderHandleLink($author_phid),
|
||||||
|
$this->renderHandleLink($object_phid));
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return parent::getTitleForFeed();
|
return parent::getTitleForFeed();
|
||||||
|
@ -282,6 +299,7 @@ final class PholioTransaction extends PhabricatorApplicationTransaction {
|
||||||
case PholioTransactionType::TYPE_DESCRIPTION:
|
case PholioTransactionType::TYPE_DESCRIPTION:
|
||||||
case PholioTransactionType::TYPE_IMAGE_NAME:
|
case PholioTransactionType::TYPE_IMAGE_NAME:
|
||||||
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
return PhabricatorTransactions::COLOR_BLUE;
|
return PhabricatorTransactions::COLOR_BLUE;
|
||||||
case PholioTransactionType::TYPE_IMAGE_REPLACE:
|
case PholioTransactionType::TYPE_IMAGE_REPLACE:
|
||||||
return PhabricatorTransactions::COLOR_YELLOW;
|
return PhabricatorTransactions::COLOR_YELLOW;
|
||||||
|
@ -299,4 +317,17 @@ final class PholioTransaction extends PhabricatorApplicationTransaction {
|
||||||
|
|
||||||
return parent::getColor();
|
return parent::getColor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getNoEffectDescription() {
|
||||||
|
switch ($this->getTransactionType()) {
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_NAME:
|
||||||
|
return pht('The image title was not updated.');
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
|
||||||
|
return pht('The image description was not updated.');
|
||||||
|
case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
|
||||||
|
return pht('The image sequence was not updated.');
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::getNoEffectDescription();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,9 +35,11 @@ JX.behavior('pholio-mock-edit', function(config) {
|
||||||
JX.DOM.listen(undo, 'click', 'pholio-drop-undo', function(e) {
|
JX.DOM.listen(undo, 'click', 'pholio-drop-undo', function(e) {
|
||||||
e.kill();
|
e.kill();
|
||||||
JX.DOM.replace(undo, node);
|
JX.DOM.replace(undo, node);
|
||||||
|
synchronize_order();
|
||||||
});
|
});
|
||||||
|
|
||||||
JX.DOM.replace(node, undo);
|
JX.DOM.replace(node, undo);
|
||||||
|
synchronize_order();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -116,6 +118,7 @@ JX.behavior('pholio-mock-edit', function(config) {
|
||||||
build_update_control(new_node);
|
build_update_control(new_node);
|
||||||
|
|
||||||
JX.DOM.replace(node, new_node);
|
JX.DOM.replace(node, new_node);
|
||||||
|
synchronize_order();
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
});
|
});
|
||||||
|
@ -154,6 +157,7 @@ JX.behavior('pholio-mock-edit', function(config) {
|
||||||
|
|
||||||
JX.DOM.replace(node, new_node);
|
JX.DOM.replace(node, new_node);
|
||||||
JX.DOM.alterClass(node, 'pholio-replacing', false);
|
JX.DOM.alterClass(node, 'pholio-replacing', false);
|
||||||
|
synchronize_order();
|
||||||
})
|
})
|
||||||
.start();
|
.start();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue