Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/pholio/constants/PholioTransactionType.php b/src/applications/pholio/constants/PholioTransactionType.php
index 42713a0b12..e106628636 100644
--- a/src/applications/pholio/constants/PholioTransactionType.php
+++ b/src/applications/pholio/constants/PholioTransactionType.php
@@ -1,20 +1,21 @@
<?php
/**
* @group pholio
*/
final class PholioTransactionType extends PholioConstants {
/* edits to the high level mock */
const TYPE_NAME = 'name';
const TYPE_DESCRIPTION = 'description';
/* edits to images within the mock */
const TYPE_IMAGE_FILE = 'image-file';
const TYPE_IMAGE_NAME= 'image-name';
const TYPE_IMAGE_DESCRIPTION = 'image-description';
const TYPE_IMAGE_REPLACE = 'image-replace';
+ const TYPE_IMAGE_SEQUENCE = 'image-sequence';
/* your witty commentary at the mock : image : x,y level */
const TYPE_INLINE = 'inline';
}
diff --git a/src/applications/pholio/controller/PholioMockEditController.php b/src/applications/pholio/controller/PholioMockEditController.php
index 6d5c570d1a..e5b6ce464a 100644
--- a/src/applications/pholio/controller/PholioMockEditController.php
+++ b/src/applications/pholio/controller/PholioMockEditController.php
@@ -1,340 +1,345 @@
<?php
/**
* @group pholio
*/
final class PholioMockEditController extends PholioController {
private $id;
public function willProcessRequest(array $data) {
$this->id = idx($data, 'id');
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
if ($this->id) {
$mock = id(new PholioMockQuery())
->setViewer($user)
->needImages(true)
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->withIDs(array($this->id))
->executeOne();
if (!$mock) {
return new Aphront404Response();
}
$title = pht('Edit Mock');
$is_new = false;
$mock_images = $mock->getImages();
$files = mpull($mock_images, 'getFile');
$mock_images = mpull($mock_images, null, 'getFilePHID');
} else {
$mock = id(new PholioMock())
->setAuthorPHID($user->getPHID())
->attachImages(array())
->setViewPolicy(PhabricatorPolicies::POLICY_USER);
$title = pht('Create Mock');
$is_new = true;
$files = array();
$mock_images = array();
}
$e_name = true;
$e_images = true;
$errors = array();
$v_name = $mock->getName();
$v_desc = $mock->getDescription();
$v_view = $mock->getViewPolicy();
$v_cc = PhabricatorSubscribersQuery::loadSubscribersForPHID(
$mock->getPHID());
if ($request->isFormPost()) {
$xactions = array();
$type_name = PholioTransactionType::TYPE_NAME;
$type_desc = PholioTransactionType::TYPE_DESCRIPTION;
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
$type_cc = PhabricatorTransactions::TYPE_SUBSCRIBERS;
$v_name = $request->getStr('name');
$v_desc = $request->getStr('description');
$v_view = $request->getStr('can_view');
$v_cc = $request->getArr('cc');
$mock_xactions = array();
$mock_xactions[$type_name] = $v_name;
$mock_xactions[$type_desc] = $v_desc;
$mock_xactions[$type_view] = $v_view;
$mock_xactions[$type_cc] = array('=' => $v_cc);
if (!strlen($request->getStr('name'))) {
$e_name = 'Required';
$errors[] = pht('You must give the mock a name.');
}
$file_phids = $request->getArr('file_phids');
if ($file_phids) {
$files = id(new PhabricatorFileQuery())
->setViewer($user)
->withPHIDs($file_phids)
->execute();
$files = mpull($files, null, 'getPHID');
$files = array_select_keys($files, $file_phids);
} else {
$files = array();
}
if (!$files) {
$e_images = pht('Required');
$errors[] = pht('You must add at least one image to the mock.');
} else {
$mock->setCoverPHID(head($files)->getPHID());
}
if (!$errors) {
foreach ($mock_xactions as $type => $value) {
$xactions[$type] = id(new PholioTransaction())
->setTransactionType($type)
->setNewValue($value);
}
- $sequence = 0;
+ $order = $request->getStrList('imageOrder');
+ $sequence_map = array_flip($order);
$replaces = $request->getArr('replaces');
$replaces_map = array_flip($replaces);
/**
* Foreach file posted, check to see whether we are replacing an image,
* adding an image, or simply updating image metadata. Create
* transactions for these cases as appropos.
*/
foreach ($files as $file_phid => $file) {
$replaces_image_phid = null;
if (isset($replaces_map[$file_phid])) {
$old_file_phid = $replaces_map[$file_phid];
$old_image = idx($mock_images, $old_file_phid);
if ($old_image) {
$replaces_image_phid = $old_image->getPHID();
}
}
$existing_image = idx($mock_images, $file_phid);
$title = (string)$request->getStr('title_'.$file_phid);
$description = (string)$request->getStr('description_'.$file_phid);
+ $sequence = $sequence_map[$file_phid];
if ($replaces_image_phid) {
$replace_image = id(new PholioImage())
->setReplacesImagePHID($replaces_image_phid)
->setFilePhid($file_phid)
->setName(strlen($title) ? $title : $file->getName())
->setDescription($description)
->setSequence($sequence);
$xactions[] = id(new PholioTransaction())
->setTransactionType(
PholioTransactionType::TYPE_IMAGE_REPLACE)
->setNewValue($replace_image);
} else if (!$existing_image) { // this is an add
$add_image = id(new PholioImage())
->setFilePhid($file_phid)
->setName(strlen($title) ? $title : $file->getName())
->setDescription($description)
->setSequence($sequence);
$xactions[] = id(new PholioTransaction())
->setTransactionType(PholioTransactionType::TYPE_IMAGE_FILE)
->setNewValue(
array('+' => array($add_image)));
} else {
$xactions[] = id(new PholioTransaction())
->setTransactionType(PholioTransactionType::TYPE_IMAGE_NAME)
->setNewValue(
array($existing_image->getPHID() => $title));
$xactions[] = id(new PholioTransaction())
->setTransactionType(
PholioTransactionType::TYPE_IMAGE_DESCRIPTION)
->setNewValue(
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) {
if (!isset($files[$file_phid]) && !isset($replaces[$file_phid])) {
// this is an outright delete
$xactions[] = id(new PholioTransaction())
->setTransactionType(PholioTransactionType::TYPE_IMAGE_FILE)
->setNewValue(
array('-' => array($mock_image)));
}
}
$mock->openTransaction();
$editor = id(new PholioMockEditor())
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setActor($user);
$xactions = $editor->applyTransactions($mock, $xactions);
$mock->saveTransaction();
return id(new AphrontRedirectResponse())
->setURI('/M'.$mock->getID());
}
}
if ($errors) {
$error_view = id(new AphrontErrorView())
->setTitle(pht('Form Errors'))
->setErrors($errors);
} else {
$error_view = null;
}
if ($this->id) {
$submit = id(new AphrontFormSubmitControl())
->addCancelButton('/M'.$this->id)
->setValue(pht('Save'));
} else {
$submit = id(new AphrontFormSubmitControl())
->addCancelButton($this->getApplicationURI())
->setValue(pht('Create'));
}
$policies = id(new PhabricatorPolicyQuery())
->setViewer($user)
->setObject($mock)
->execute();
// NOTE: Make this show up correctly on the rendered form.
$mock->setViewPolicy($v_view);
$handles = id(new PhabricatorObjectHandleData($v_cc))
->setViewer($user)
->loadHandles();
$cc_tokens = mpull($handles, 'getFullName', 'getPHID');
$image_elements = array();
foreach ($mock_images as $mock_image) {
$image_elements[] = id(new PholioUploadedImageView())
->setUser($user)
->setImage($mock_image);
}
$list_id = celerity_generate_unique_node_id();
$drop_id = celerity_generate_unique_node_id();
$order_id = celerity_generate_unique_node_id();
$list_control = phutil_tag(
'div',
array(
'id' => $list_id,
'class' => 'pholio-edit-list',
),
$image_elements);
$drop_control = phutil_tag(
'div',
array(
'id' => $drop_id,
'class' => 'pholio-edit-drop',
),
'Drag and drop images here to add them to the mock.');
$order_control = phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => 'imageOrder',
'id' => $order_id,
));
Javelin::initBehavior(
'pholio-mock-edit',
array(
'listID' => $list_id,
'dropID' => $drop_id,
'orderID' => $order_id,
'uploadURI' => '/file/dropupload/',
'renderURI' => $this->getApplicationURI('image/upload/'),
'pht' => array(
'uploading' => pht('Uploading Image...'),
'uploaded' => pht('Upload Complete...'),
'undo' => pht('Undo'),
'removed' => pht('This image will be removed from the mock.'),
),
));
require_celerity_resource('pholio-edit-css');
$form = id(new AphrontFormView())
->setUser($user)
->setFlexible(true)
->appendChild($order_control)
->appendChild(
id(new AphrontFormTextControl())
->setName('name')
->setValue($v_name)
->setLabel(pht('Name'))
->setError($e_name))
->appendChild(
id(new PhabricatorRemarkupControl())
->setName('description')
->setValue($v_desc)
->setLabel(pht('Description'))
->setUser($user))
->appendChild(
id(new AphrontFormTokenizerControl())
->setLabel(pht('CC'))
->setName('cc')
->setValue($cc_tokens)
->setUser($user)
->setDatasource('/typeahead/common/mailable/'))
->appendChild(
id(new AphrontFormPolicyControl())
->setUser($user)
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
->setPolicyObject($mock)
->setPolicies($policies)
->setName('can_view'))
->appendChild(
id(new AphrontFormMarkupControl())
->setValue($list_control))
->appendChild(
id(new AphrontFormMarkupControl())
->setValue($drop_control)
->setError($e_images))
->appendChild($submit);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addCrumb(
id(new PhabricatorCrumbView())
->setName($title)
->setHref($this->getApplicationURI()));
$content = array(
$crumbs,
$error_view,
$form,
);
return $this->buildApplicationPage(
$content,
array(
'title' => $title,
'device' => true,
));
}
}
diff --git a/src/applications/pholio/editor/PholioMockEditor.php b/src/applications/pholio/editor/PholioMockEditor.php
index 6da81252db..a7e66ed8e3 100644
--- a/src/applications/pholio/editor/PholioMockEditor.php
+++ b/src/applications/pholio/editor/PholioMockEditor.php
@@ -1,397 +1,415 @@
<?php
/**
* @group pholio
*/
final class PholioMockEditor extends PhabricatorApplicationTransactionEditor {
private $newImages = array();
private function setNewImages(array $new_images) {
assert_instances_of($new_images, 'PholioImage');
$this->newImages = $new_images;
return $this;
}
private function getNewImages() {
return $this->newImages;
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorTransactions::TYPE_EDGE;
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhabricatorTransactions::TYPE_VIEW_POLICY;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
$types[] = PholioTransactionType::TYPE_NAME;
$types[] = PholioTransactionType::TYPE_DESCRIPTION;
$types[] = PholioTransactionType::TYPE_INLINE;
$types[] = PholioTransactionType::TYPE_IMAGE_FILE;
$types[] = PholioTransactionType::TYPE_IMAGE_NAME;
$types[] = PholioTransactionType::TYPE_IMAGE_DESCRIPTION;
$types[] = PholioTransactionType::TYPE_IMAGE_REPLACE;
+ $types[] = PholioTransactionType::TYPE_IMAGE_SEQUENCE;
return $types;
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PholioTransactionType::TYPE_NAME:
return $object->getName();
case PholioTransactionType::TYPE_DESCRIPTION:
return $object->getDescription();
case PholioTransactionType::TYPE_IMAGE_FILE:
$images = $object->getImages();
return mpull($images, 'getPHID');
case PholioTransactionType::TYPE_IMAGE_NAME:
$name = null;
$phid = null;
$image = $this->getImageForXaction($object, $xaction);
if ($image) {
$name = $image->getName();
$phid = $image->getPHID();
}
- return array ($phid => $name);
+ return array($phid => $name);
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
$description = null;
$phid = null;
$image = $this->getImageForXaction($object, $xaction);
if ($image) {
$description = $image->getDescription();
$phid = $image->getPHID();
}
return array($phid => $description);
case PholioTransactionType::TYPE_IMAGE_REPLACE:
$raw = $xaction->getNewValue();
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);
}
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PholioTransactionType::TYPE_NAME:
case PholioTransactionType::TYPE_DESCRIPTION:
case PholioTransactionType::TYPE_IMAGE_NAME:
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
+ case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
return $xaction->getNewValue();
case PholioTransactionType::TYPE_IMAGE_REPLACE:
$raw = $xaction->getNewValue();
return $raw->getPHID();
case PholioTransactionType::TYPE_IMAGE_FILE:
$raw_new_value = $xaction->getNewValue();
$new_value = array();
foreach ($raw_new_value as $key => $images) {
$new_value[$key] = mpull($images, 'getPHID');
}
$xaction->setNewValue($new_value);
return $this->getPHIDTransactionNewValue($xaction);
}
}
protected function transactionHasEffect(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PholioTransactionType::TYPE_INLINE:
return true;
}
return parent::transactionHasEffect($object, $xaction);
}
protected function shouldApplyInitialEffects(
PhabricatorLiskDAO $object,
array $xactions) {
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PholioTransactionType::TYPE_IMAGE_FILE:
case PholioTransactionType::TYPE_IMAGE_REPLACE:
return true;
break;
}
}
return false;
}
protected function applyInitialEffects(
PhabricatorLiskDAO $object,
array $xactions) {
$new_images = array();
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PholioTransactionType::TYPE_IMAGE_FILE:
$new_value = $xaction->getNewValue();
foreach ($new_value as $key => $txn_images) {
if ($key != '+') {
continue;
}
foreach ($txn_images as $image) {
$image->save();
$new_images[] = $image;
}
}
break;
case PholioTransactionType::TYPE_IMAGE_REPLACE:
$image = $xaction->getNewValue();
$image->save();
$new_images[] = $image;
break;
}
}
$this->setNewImages($new_images);
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PholioTransactionType::TYPE_NAME:
$object->setName($xaction->getNewValue());
if ($object->getOriginalName() === null) {
$object->setOriginalName($xaction->getNewValue());
}
break;
case PholioTransactionType::TYPE_DESCRIPTION:
$object->setDescription($xaction->getNewValue());
break;
}
}
private function getImageForXaction(
PholioMock $mock,
PhabricatorApplicationTransaction $xaction) {
$raw_new_value = $xaction->getNewValue();
$image_phid = key($raw_new_value);
$images = $mock->getImages();
foreach ($images as $image) {
if ($image->getPHID() == $image_phid) {
return $image;
}
}
return null;
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PholioTransactionType::TYPE_IMAGE_FILE:
$old_map = array_fuse($xaction->getOldValue());
$new_map = array_fuse($xaction->getNewValue());
$obsolete_map = array_diff_key($old_map, $new_map);
$images = $object->getImages();
foreach ($images as $seq => $image) {
if (isset($obsolete_map[$image->getPHID()])) {
$image->setIsObsolete(1);
$image->save();
unset($images[$seq]);
}
}
$object->attachImages($images);
break;
case PholioTransactionType::TYPE_IMAGE_REPLACE:
$old = $xaction->getOldValue();
$images = $object->getImages();
foreach ($images as $seq => $image) {
if ($image->getPHID() == $old) {
$image->setIsObsolete(1);
$image->save();
unset($images[$seq]);
}
}
$object->attachImages($images);
break;
- case PholioTransactionType::TYPE_IMAGE_NAME:
- $image = $this->getImageForXaction($object, $xaction);
- $value = (string) head($xaction->getNewValue());
+ case PholioTransactionType::TYPE_IMAGE_NAME:
+ $image = $this->getImageForXaction($object, $xaction);
+ $value = (string) head($xaction->getNewValue());
$image->setName($value);
$image->save();
break;
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
$image = $this->getImageForXaction($object, $xaction);
$value = (string) head($xaction->getNewValue());
$image->setDescription($value);
$image->save();
break;
+ case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
+ $image = $this->getImageForXaction($object, $xaction);
+ $value = (int) head($xaction->getNewValue());
+ $image->setSequence($value);
+ $image->save();
+ break;
}
}
protected function applyFinalEffects(
PhabricatorLiskDAO $object,
array $xactions) {
$images = $this->getNewImages();
foreach ($images as $image) {
$image->setMockID($object->getID());
$image->save();
}
}
protected function mergeTransactions(
PhabricatorApplicationTransaction $u,
PhabricatorApplicationTransaction $v) {
$type = $u->getTransactionType();
switch ($type) {
case PholioTransactionType::TYPE_NAME:
case PholioTransactionType::TYPE_DESCRIPTION:
return $v;
case PholioTransactionType::TYPE_IMAGE_REPLACE:
if ($u->getNewValue() == $v->getOldValue()) {
return $v;
}
case PholioTransactionType::TYPE_IMAGE_FILE:
return $this->mergePHIDOrEdgeTransactions($u, $v);
case PholioTransactionType::TYPE_IMAGE_NAME:
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
+ case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
$raw_new_value_u = $u->getNewValue();
$raw_new_value_v = $v->getNewValue();
$phid_u = key($raw_new_value_u);
$phid_v = key($raw_new_value_v);
if ($phid_u == $phid_v) {
return $v;
}
break;
}
return parent::mergeTransactions($u, $v);
}
protected function supportsMail() {
return true;
}
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
return id(new PholioReplyHandler())
->setMailReceiver($object);
}
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
$id = $object->getID();
$name = $object->getName();
$original_name = $object->getOriginalName();
return id(new PhabricatorMetaMTAMail())
->setSubject("M{$id}: {$name}")
->addHeader('Thread-Topic', "M{$id}: {$original_name}");
}
protected function getMailTo(PhabricatorLiskDAO $object) {
return array(
$object->getAuthorPHID(),
$this->requireActor()->getPHID(),
);
}
protected function buildMailBody(
PhabricatorLiskDAO $object,
array $xactions) {
$body = new PhabricatorMetaMTAMailBody();
$headers = array();
$comments = array();
$inline_comments = array();
foreach ($xactions as $xaction) {
if ($xaction->shouldHide()) {
continue;
}
$comment = $xaction->getComment();
switch ($xaction->getTransactionType()) {
case PholioTransactionType::TYPE_INLINE:
if ($comment && strlen($comment->getContent())) {
$inline_comments[] = $comment;
}
break;
case PhabricatorTransactions::TYPE_COMMENT:
if ($comment && strlen($comment->getContent())) {
$comments[] = $comment->getContent();
}
// fallthrough
default:
$headers[] = id(clone $xaction)
->setRenderingTarget('text')
->getTitle();
break;
}
}
$body->addRawSection(implode("\n", $headers));
foreach ($comments as $comment) {
$body->addRawSection($comment);
}
if ($inline_comments) {
$body->addRawSection(pht('INLINE COMMENTS'));
foreach ($inline_comments as $comment) {
$text = pht(
'Image %d: %s',
$comment->getImageID(),
$comment->getContent());
$body->addRawSection($text);
}
}
$body->addTextSection(
pht('MOCK DETAIL'),
PhabricatorEnv::getProductionURI('/M'.$object->getID()));
return $body;
}
protected function getMailSubjectPrefix() {
return PhabricatorEnv::getEnvConfig('metamta.pholio.subject-prefix');
}
protected function supportsFeed() {
return true;
}
protected function supportsSearch() {
return true;
}
protected function sortTransactions(array $xactions) {
$head = array();
$tail = array();
// Move inline comments to the end, so the comments precede them.
foreach ($xactions as $xaction) {
$type = $xaction->getTransactionType();
if ($type == PholioTransactionType::TYPE_INLINE) {
$tail[] = $xaction;
} else {
$head[] = $xaction;
}
}
return array_values(array_merge($head, $tail));
}
protected function shouldImplyCC(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PholioTransactionType::TYPE_INLINE:
return true;
}
return parent::shouldImplyCC($object, $xaction);
}
}
diff --git a/src/applications/pholio/query/PholioMockQuery.php b/src/applications/pholio/query/PholioMockQuery.php
index 825a38442b..1f37935d28 100644
--- a/src/applications/pholio/query/PholioMockQuery.php
+++ b/src/applications/pholio/query/PholioMockQuery.php
@@ -1,160 +1,161 @@
<?php
/**
* @group pholio
*/
final class PholioMockQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $authorPHIDs;
private $needCoverFiles;
private $needImages;
private $needInlineComments;
private $needTokenCounts;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
public function withAuthorPHIDs(array $author_phids) {
$this->authorPHIDs = $author_phids;
return $this;
}
public function needCoverFiles($need_cover_files) {
$this->needCoverFiles = $need_cover_files;
return $this;
}
public function needImages($need_images) {
$this->needImages = $need_images;
return $this;
}
public function needInlineComments($need_inline_comments) {
$this->needInlineComments = $need_inline_comments;
return $this;
}
public function needTokenCounts($need) {
$this->needTokenCounts = $need;
return $this;
}
protected function loadPage() {
$table = new PholioMock();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
$mocks = $table->loadAllFromArray($data);
if ($mocks && $this->needImages) {
$this->loadImages($mocks);
}
if ($mocks && $this->needCoverFiles) {
$this->loadCoverFiles($mocks);
}
if ($mocks && $this->needTokenCounts) {
$this->loadTokenCounts($mocks);
}
return $mocks;
}
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
$where[] = $this->buildPagingClause($conn_r);
if ($this->ids) {
$where[] = qsprintf(
$conn_r,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
'phid IN (%Ls)',
$this->phids);
}
if ($this->authorPHIDs) {
$where[] = qsprintf(
$conn_r,
'authorPHID in (%Ls)',
$this->authorPHIDs);
}
return $this->formatWhereClause($where);
}
private function loadImages(array $mocks) {
assert_instances_of($mocks, 'PholioMock');
$mock_map = mpull($mocks, null, 'getID');
$all_images = id(new PholioImageQuery())
->setViewer($this->getViewer())
->setMockCache($mock_map)
->withMockIDs(array_keys($mock_map))
->needInlineComments($this->needInlineComments)
->execute();
$image_groups = mgroup($all_images, 'getMockID');
foreach ($mocks as $mock) {
$mock_images = idx($image_groups, $mock->getID(), array());
$mock->attachAllImages($mock_images);
- $mock->attachImages(mfilter($mock_images, 'getIsObsolete', true));
+ $active_images = mfilter($mock_images, 'getIsObsolete', true);
+ $mock->attachImages(msort($active_images, 'getSequence'));
}
}
private function loadCoverFiles(array $mocks) {
assert_instances_of($mocks, 'PholioMock');
$cover_file_phids = mpull($mocks, 'getCoverPHID');
$cover_files = mpull(id(new PhabricatorFile())->loadAllWhere(
'phid IN (%Ls)',
$cover_file_phids), null, 'getPHID');
foreach ($mocks as $mock) {
$file = idx($cover_files, $mock->getCoverPHID());
if (!$file) {
$file = PhabricatorFile::loadBuiltin($this->getViewer(), 'missing.png');
}
$mock->attachCoverFile($file);
}
}
private function loadTokenCounts(array $mocks) {
assert_instances_of($mocks, 'PholioMock');
$phids = mpull($mocks, 'getPHID');
$counts = id(new PhabricatorTokenCountQuery())
->withObjectPHIDs($phids)
->execute();
foreach ($mocks as $mock) {
$mock->attachTokenCount(idx($counts, $mock->getPHID(), 0));
}
}
}
diff --git a/src/applications/pholio/storage/PholioTransaction.php b/src/applications/pholio/storage/PholioTransaction.php
index a928852cd6..6f9f7f8cce 100644
--- a/src/applications/pholio/storage/PholioTransaction.php
+++ b/src/applications/pholio/storage/PholioTransaction.php
@@ -1,302 +1,333 @@
<?php
/**
* @group pholio
*/
final class PholioTransaction extends PhabricatorApplicationTransaction {
public function getApplicationName() {
return 'pholio';
}
public function getApplicationTransactionType() {
return PholioPHIDTypeMock::TYPECONST;
}
public function getApplicationTransactionCommentObject() {
return new PholioTransactionComment();
}
public function getApplicationTransactionViewObject() {
return new PholioTransactionView();
}
public function getApplicationObjectTypeName() {
return pht('mock');
}
public function getRequiredHandlePHIDs() {
$phids = parent::getRequiredHandlePHIDs();
$phids[] = $this->getObjectPHID();
$new = $this->getNewValue();
$old = $this->getOldValue();
switch ($this->getTransactionType()) {
case PholioTransactionType::TYPE_IMAGE_FILE:
$phids = array_merge($phids, $new, $old);
break;
case PholioTransactionType::TYPE_IMAGE_REPLACE:
$phids[] = $new;
$phids[] = $old;
break;
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
case PholioTransactionType::TYPE_IMAGE_NAME:
+ case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
$phids[] = key($new);
break;
}
return $phids;
}
public function shouldHide() {
$old = $this->getOldValue();
switch ($this->getTransactionType()) {
case PholioTransactionType::TYPE_DESCRIPTION:
return ($old === null);
case PholioTransactionType::TYPE_IMAGE_NAME:
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
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();
}
public function getIcon() {
switch ($this->getTransactionType()) {
case PholioTransactionType::TYPE_INLINE:
return 'comment';
case PholioTransactionType::TYPE_NAME:
case PholioTransactionType::TYPE_DESCRIPTION:
case PholioTransactionType::TYPE_IMAGE_NAME:
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
+ case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
return 'edit';
case PholioTransactionType::TYPE_IMAGE_FILE:
case PholioTransactionType::TYPE_IMAGE_REPLACE:
return 'attach';
}
return parent::getIcon();
}
public function getTitle() {
$author_phid = $this->getAuthorPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
$type = $this->getTransactionType();
switch ($type) {
case PholioTransactionType::TYPE_NAME:
if ($old === null) {
return pht(
'%s created "%s".',
$this->renderHandleLink($author_phid),
$new);
} else {
return pht(
'%s renamed this mock from "%s" to "%s".',
$this->renderHandleLink($author_phid),
$old,
$new);
}
break;
case PholioTransactionType::TYPE_DESCRIPTION:
return pht(
"%s updated the mock's description.",
$this->renderHandleLink($author_phid));
break;
case PholioTransactionType::TYPE_INLINE:
$count = 1;
foreach ($this->getTransactionGroup() as $xaction) {
if ($xaction->getTransactionType() == $type) {
$count++;
}
}
return pht(
'%s added %d inline comment(s).',
$this->renderHandleLink($author_phid),
$count);
break;
case PholioTransactionType::TYPE_IMAGE_REPLACE:
return pht(
'%s replaced %s with %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($old),
$this->renderHandleLink($new));
break;
case PholioTransactionType::TYPE_IMAGE_FILE:
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
if ($add && $rem) {
return pht(
'%s edited image(s), added %d: %s; removed %d: %s.',
$this->renderHandleLink($author_phid),
count($add),
$this->renderHandleList($add),
count($rem),
$this->renderHandleList($rem));
} else if ($add) {
return pht(
'%s added %d image(s): %s.',
$this->renderHandleLink($author_phid),
count($add),
$this->renderHandleList($add));
} else {
return pht(
'%s removed %d image(s): %s.',
$this->renderHandleLink($author_phid),
count($rem),
$this->renderHandleList($rem));
}
break;
case PholioTransactionType::TYPE_IMAGE_NAME:
return pht(
'%s renamed an image (%s) from "%s" to "%s".',
$this->renderHandleLink($author_phid),
$this->renderHandleLink(key($new)),
reset($old),
reset($new));
break;
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
return pht(
'%s updated an image\'s (%s) description.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink(key($new)));
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();
}
public function getTitleForFeed() {
$author_phid = $this->getAuthorPHID();
$object_phid = $this->getObjectPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
$type = $this->getTransactionType();
switch ($type) {
case PholioTransactionType::TYPE_NAME:
if ($old === null) {
return pht(
'%s created %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
} else {
return pht(
'%s renamed %s from "%s" to "%s".',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid),
$old,
$new);
}
break;
case PholioTransactionType::TYPE_DESCRIPTION:
return pht(
'%s updated the description for %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
case PholioTransactionType::TYPE_INLINE:
return pht(
'%s added an inline comment to %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
case PholioTransactionType::TYPE_IMAGE_REPLACE:
case PholioTransactionType::TYPE_IMAGE_FILE:
return pht(
'%s updated images of %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
case PholioTransactionType::TYPE_IMAGE_NAME:
return pht(
'%s updated the image names of %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
break;
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
return pht(
'%s updated image descriptions of %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
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();
}
public function getBodyForFeed() {
switch ($this->getTransactionType()) {
case PholioTransactionType::TYPE_INLINE:
$text = $this->getComment()->getContent();
return phutil_escape_html_newlines(
phutil_utf8_shorten($text, 128));
break;
}
return parent::getBodyForFeed();
}
public function hasChangeDetails() {
switch ($this->getTransactionType()) {
case PholioTransactionType::TYPE_DESCRIPTION:
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
return true;
}
return parent::hasChangeDetails();
}
public function renderChangeDetails(PhabricatorUser $viewer) {
$old = $this->getOldValue();
$new = $this->getNewValue();
if ($this->getTransactionType() ==
PholioTransactionType::TYPE_IMAGE_DESCRIPTION) {
$old = reset($old);
$new = reset($new);
}
$view = id(new PhabricatorApplicationTransactionTextDiffDetailView())
->setUser($viewer)
->setOldText($old)
->setNewText($new);
return $view->render();
}
public function getColor() {
$old = $this->getOldValue();
$new = $this->getNewValue();
switch ($this->getTransactionType()) {
case PholioTransactionType::TYPE_NAME:
if ($old === null) {
return PhabricatorTransactions::COLOR_GREEN;
}
case PholioTransactionType::TYPE_DESCRIPTION:
case PholioTransactionType::TYPE_IMAGE_NAME:
case PholioTransactionType::TYPE_IMAGE_DESCRIPTION:
+ case PholioTransactionType::TYPE_IMAGE_SEQUENCE:
return PhabricatorTransactions::COLOR_BLUE;
case PholioTransactionType::TYPE_IMAGE_REPLACE:
return PhabricatorTransactions::COLOR_YELLOW;
case PholioTransactionType::TYPE_IMAGE_FILE:
$add = array_diff($new, $old);
$rem = array_diff($old, $new);
if ($add && $rem) {
return PhabricatorTransactions::COLOR_YELLOW;
} else if ($add) {
return PhabricatorTransactions::COLOR_GREEN;
} else {
return PhabricatorTransactions::COLOR_RED;
}
}
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();
+ }
}
diff --git a/webroot/rsrc/js/application/pholio/behavior-pholio-mock-edit.js b/webroot/rsrc/js/application/pholio/behavior-pholio-mock-edit.js
index 8e18c8f28e..8b10f2dedf 100644
--- a/webroot/rsrc/js/application/pholio/behavior-pholio-mock-edit.js
+++ b/webroot/rsrc/js/application/pholio/behavior-pholio-mock-edit.js
@@ -1,193 +1,197 @@
/**
* @provides javelin-behavior-pholio-mock-edit
* @requires javelin-behavior
* javelin-stratcom
* javelin-dom
* javelin-workflow
* phabricator-phtize
* phabricator-drag-and-drop-file-upload
* phabricator-draggable-list
*/
JX.behavior('pholio-mock-edit', function(config) {
var pht = JX.phtize(config.pht);
var nodes = {
list: JX.$(config.listID),
drop: JX.$(config.dropID),
order: JX.$(config.orderID)
};
var uploading = [];
/* -( Deleting Images )---------------------------------------------------- */
// When the user clicks the "X" on an image, we replace it with a "click to
// undo" element. If they click to undo, we put the original node back in the
// DOM.
JX.Stratcom.listen('click', 'pholio-drop-remove', function(e) {
e.kill();
var node = e.getNode('pholio-drop-image');
var undo = render_undo();
JX.DOM.listen(undo, 'click', 'pholio-drop-undo', function(e) {
e.kill();
JX.DOM.replace(undo, node);
+ synchronize_order();
});
JX.DOM.replace(node, undo);
+ synchronize_order();
});
/* -( Reordering Images )-------------------------------------------------- */
var draglist = new JX.DraggableList('pholio-drop-image', nodes.list)
.setGhostNode(JX.$N('div', {className: 'drag-ghost'}))
.setFindItemsHandler(function() {
return JX.DOM.scry(nodes.list, 'div', 'pholio-drop-image');
});
// Only let the user drag images by the handle, not the whole entry.
draglist.listen('shouldBeginDrag', function(e) {
if (!e.getNode('pholio-drag-handle')) {
JX.Stratcom.context().prevent();
}
});
// Reflect the display order in a hidden input.
var synchronize_order = function() {
var items = draglist.findItems();
var order = [];
for (var ii = 0; ii < items.length; ii++) {
order.push(JX.Stratcom.getData(items[ii]).filePHID);
}
nodes.order.value = order.join(',');
};
draglist.listen('didDrop', synchronize_order);
synchronize_order();
/* -( Build )-------------------------------------------------------------- */
var build_drop_upload = function(node) {
var drop = new JX.PhabricatorDragAndDropFileUpload(node)
.setURI(config.uploadURI);
drop.listen('didBeginDrag', function(e) {
JX.DOM.alterClass(node, 'pholio-drop-active', true);
});
drop.listen('didEndDrag', function(e) {
JX.DOM.alterClass(node, 'pholio-drop-active', false);
});
return drop;
};
var build_add_control = function(add_node) {
var drop = build_drop_upload(add_node);
drop.listen('willUpload', function(file) {
var node = render_uploading();
uploading.push({node: node, file: file});
nodes.list.appendChild(node);
});
drop.listen('didUpload', function(file) {
var node;
for (var ii = 0; ii < uploading.length; ii++) {
if (uploading[ii].file === file) {
node = uploading[ii].node;
uploading.splice(ii, 1);
break;
}
}
JX.DOM.setContent(node, pht('uploaded'));
new JX.Workflow(config.renderURI, {filePHID: file.getPHID()})
.setHandler(function(response) {
var new_node = JX.$H(response.markup).getFragment().firstChild;
build_update_control(new_node);
JX.DOM.replace(node, new_node);
+ synchronize_order();
})
.start();
});
drop.start();
};
var build_list_controls = function(list_node) {
var nodes = JX.DOM.scry(list_node, 'div', 'pholio-drop-image');
for (var ii = 0; ii < nodes.length; ii++) {
build_update_control(nodes[ii]);
}
};
var build_update_control = function(node) {
var drop = build_drop_upload(node);
drop.listen('willUpload', function(file) {
JX.DOM.alterClass(node, 'pholio-replacing', true);
});
drop.listen('didUpload', function(file) {
var node_data = JX.Stratcom.getData(node);
var data = {
filePHID: file.getPHID(),
replacesPHID: node_data.replacesPHID || node_data.filePHID || null,
title: JX.DOM.find(node, 'input', 'image-title').value,
description: JX.DOM.find(node, 'textarea', 'image-description').value
};
new JX.Workflow(config.renderURI, data)
.setHandler(function(response) {
var new_node = JX.$H(response.markup).getFragment().firstChild;
build_update_control(new_node);
JX.DOM.replace(node, new_node);
JX.DOM.alterClass(node, 'pholio-replacing', false);
+ synchronize_order();
})
.start();
});
drop.start();
};
/* -( Rendering )---------------------------------------------------------- */
var render_uploading = function() {
return JX.$N(
'div',
{className: 'pholio-drop-uploading'},
pht('uploading'));
};
var render_undo = function() {
var link = JX.$N(
'a',
{href: '#', sigil: 'pholio-drop-undo'},
pht('undo'));
return JX.$N(
'div',
{className: 'pholio-drop-undo'},
[pht('removed'), ' ', link]);
};
/* -( Init )--------------------------------------------------------------- */
build_add_control(nodes.drop);
build_list_controls(nodes.list);
});

File Metadata

Mime Type
text/x-diff
Expires
Fri, Aug 15, 12:25 PM (6 d, 12 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
202430
Default Alt Text
(46 KB)

Event Timeline