1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-26 15:30:58 +01:00

Make Maniphest Transaction preview tokenizer aware

Summary:
...pretty sure the JS is too hack-tastic but it works...! :D

also fixed a small error from assert_instances_of change where a null value is all errors and what have you

Test Plan: played around with tasks in firefox and safari. made cc, owner, and project changes, as well as priority, etc.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran

Maniphest Tasks: T1074

Differential Revision: https://secure.phabricator.com/D2234
This commit is contained in:
Bob Trahan 2012-04-14 07:05:58 -07:00
parent 304948f039
commit 6be9f6f3a8
6 changed files with 120 additions and 57 deletions

View file

@ -1173,14 +1173,16 @@ celerity_register_resource_map(array(
),
'javelin-behavior-maniphest-transaction-preview' =>
array(
'uri' => '/res/44e86555/rsrc/js/application/maniphest/behavior-transaction-preview.js',
'uri' => '/res/855c9f0c/rsrc/js/application/maniphest/behavior-transaction-preview.js',
'type' => 'js',
'requires' =>
array(
0 => 'javelin-behavior',
1 => 'javelin-dom',
2 => 'javelin-util',
3 => 'phabricator-shaped-request',
3 => 'javelin-json',
4 => 'javelin-stratcom',
5 => 'phabricator-shaped-request',
),
'disk' => '/rsrc/js/application/maniphest/behavior-transaction-preview.js',
),
@ -2550,7 +2552,7 @@ celerity_register_resource_map(array(
'uri' => '/res/pkg/8db30c56/maniphest.pkg.css',
'type' => 'css',
),
'86fc0b0c' =>
'2055a702' =>
array(
'name' => 'maniphest.pkg.js',
'symbols' =>
@ -2560,7 +2562,7 @@ celerity_register_resource_map(array(
2 => 'javelin-behavior-maniphest-transaction-preview',
3 => 'javelin-behavior-maniphest-transaction-expand',
),
'uri' => '/res/pkg/86fc0b0c/maniphest.pkg.js',
'uri' => '/res/pkg/2055a702/maniphest.pkg.js',
'type' => 'js',
),
'2af849fb' =>
@ -2621,10 +2623,10 @@ celerity_register_resource_map(array(
'javelin-behavior-differential-keyboard-navigation' => '270dd507',
'javelin-behavior-differential-populate' => '270dd507',
'javelin-behavior-differential-show-more' => '270dd507',
'javelin-behavior-maniphest-batch-selector' => '86fc0b0c',
'javelin-behavior-maniphest-transaction-controls' => '86fc0b0c',
'javelin-behavior-maniphest-transaction-expand' => '86fc0b0c',
'javelin-behavior-maniphest-transaction-preview' => '86fc0b0c',
'javelin-behavior-maniphest-batch-selector' => '2055a702',
'javelin-behavior-maniphest-transaction-controls' => '2055a702',
'javelin-behavior-maniphest-transaction-expand' => '2055a702',
'javelin-behavior-maniphest-transaction-preview' => '2055a702',
'javelin-behavior-phabricator-autofocus' => '21d01ed8',
'javelin-behavior-phabricator-keyboard-shortcuts' => '21d01ed8',
'javelin-behavior-phabricator-object-selector' => '270dd507',

View file

@ -450,39 +450,42 @@ final class ManiphestTaskDetailController extends ManiphestController {
ManiphestTransactionType::TYPE_ATTACH => 'file',
);
Javelin::initBehavior('maniphest-transaction-controls', array(
'select' => 'transaction-action',
'controlMap' => $control_map,
'tokenizers' => array(
ManiphestTransactionType::TYPE_PROJECTS => array(
'id' => 'projects-tokenizer',
'src' => '/typeahead/common/projects/',
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
'placeholder' => 'Type a project name...',
),
ManiphestTransactionType::TYPE_OWNER => array(
'id' => 'assign-tokenizer',
'src' => '/typeahead/common/users/',
'value' => $default_claim,
'limit' => 1,
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
'placeholder' => 'Type a user name...',
),
ManiphestTransactionType::TYPE_CCS => array(
'id' => 'cc-tokenizer',
'src' => '/typeahead/common/mailable/',
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
'placeholder' => 'Type a user or mailing list...',
),
$tokenizer_map = array(
ManiphestTransactionType::TYPE_PROJECTS => array(
'id' => 'projects-tokenizer',
'src' => '/typeahead/common/projects/',
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
'placeholder' => 'Type a project name...',
),
ManiphestTransactionType::TYPE_OWNER => array(
'id' => 'assign-tokenizer',
'src' => '/typeahead/common/users/',
'value' => $default_claim,
'limit' => 1,
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
'placeholder' => 'Type a user name...',
),
ManiphestTransactionType::TYPE_CCS => array(
'id' => 'cc-tokenizer',
'src' => '/typeahead/common/mailable/',
'ondemand' => PhabricatorEnv::getEnvConfig('tokenizer.ondemand'),
'placeholder' => 'Type a user or mailing list...',
),
);
Javelin::initBehavior('maniphest-transaction-controls', array(
'select' => 'transaction-action',
'controlMap' => $control_map,
'tokenizers' => $tokenizer_map,
));
Javelin::initBehavior('maniphest-transaction-preview', array(
'uri' => '/maniphest/transaction/preview/'.$task->getID().'/',
'preview' => 'transaction-preview',
'comments' => 'transaction-comments',
'action' => 'transaction-action',
'map' => $control_map,
'uri' => '/maniphest/transaction/preview/'.$task->getID().'/',
'preview' => 'transaction-preview',
'comments' => 'transaction-comments',
'action' => 'transaction-action',
'map' => $control_map,
'tokenizers' => $tokenizer_map,
));
$comment_panel = new AphrontPanelView();

View file

@ -51,7 +51,6 @@ final class ManiphestTransactionPreviewController extends ManiphestController {
$draft->setDraft($comments);
$draft->save();
$phids = array($user->getPHID());
$action = $request->getStr('action');
@ -61,23 +60,63 @@ final class ManiphestTransactionPreviewController extends ManiphestController {
$transaction->setTransactionType($action);
$value = $request->getStr('value');
// grab phids for handles and set transaction values based on action and
// value (empty or control-specific format) coming in from the wire
switch ($action) {
case ManiphestTransactionType::TYPE_OWNER:
if (!$value) {
$value = $user->getPHID();
}
$phids[] = $value;
break;
case ManiphestTransactionType::TYPE_PRIORITY:
$transaction->setOldValue($task->getPriority());
$transaction->setNewValue($value);
break;
case ManiphestTransactionType::TYPE_OWNER:
if ($value) {
$value = current(json_decode($value));
$phids = array($value);
} else {
$phids = array();
}
$transaction->setNewValue($value);
break;
case ManiphestTransactionType::TYPE_CCS:
if ($value) {
$value = json_decode($value);
$phids = $value;
foreach ($task->getCCPHIDs() as $cc_phid) {
$phids[] = $cc_phid;
$value[] = $cc_phid;
}
$transaction->setNewValue($value);
} else {
$phids = array();
$transaction->setNewValue(array());
}
$transaction->setOldValue($task->getCCPHIDs());
break;
case ManiphestTransactionType::TYPE_PROJECTS:
if ($value) {
$value = json_decode($value);
$phids = $value;
foreach ($task->getProjectPHIDs() as $project_phid) {
$phids[] = $project_phid;
$value[] = $project_phid;
}
$transaction->setNewValue($value);
} else {
$phids = array();
$transaction->setNewValue(array());
}
$transaction->setOldValue($task->getProjectPHIDs());
break;
default:
$phids = array();
$transaction->setNewValue($value);
break;
}
$transaction->setNewValue($value);
$phids[] = $user->getPHID();
$handles = id(new PhabricatorObjectHandleData($phids))
->loadHandles();
$transactions = array();
$transactions = array();
$transactions[] = $transaction;
$engine = PhabricatorMarkupEngine::newManiphestMarkupEngine();

View file

@ -358,13 +358,14 @@ final class ManiphestTransactionDetailView extends ManiphestView {
}
break;
case ManiphestTransactionType::TYPE_CCS:
if ($this->preview) {
$added = array_diff($new, $old);
$removed = array_diff($old, $new);
// can only add in preview so just show placeholder if nothing to add
if ($this->preview && empty($added)) {
$verb = 'Changed CC';
$desc = 'changed CCs..';
break;
}
$added = array_diff($new, $old);
$removed = array_diff($old, $new);
if ($added && !$removed) {
$verb = 'Added CC';
if (count($added) == 1) {
@ -386,13 +387,14 @@ final class ManiphestTransactionDetailView extends ManiphestView {
}
break;
case ManiphestTransactionType::TYPE_PROJECTS:
if ($this->preview) {
$added = array_diff($new, $old);
$removed = array_diff($old, $new);
// can only add in preview so just show placeholder if nothing to add
if ($this->preview && empty($added)) {
$verb = 'Changed Projects';
$desc = 'changed projects..';
break;
}
$added = array_diff($new, $old);
$removed = array_diff($old, $new);
if ($added && !$removed) {
$verb = 'Added Project';
if (count($added) == 1) {

View file

@ -61,6 +61,13 @@ final class ManiphestTransactionListView extends ManiphestView {
return $this;
}
private function getAuxiliaryFields() {
if (empty($this->auxiliaryFields)) {
return array();
}
return $this->auxiliaryFields;
}
public function render() {
$views = array();
@ -108,7 +115,7 @@ final class ManiphestTransactionListView extends ManiphestView {
foreach ($groups as $group) {
$view = new ManiphestTransactionDetailView();
$view->setUser($this->user);
$view->setAuxiliaryFields($this->auxiliaryFields);
$view->setAuxiliaryFields($this->getAuxiliaryFields());
$view->setTransactionGroup($group);
$view->setHandles($this->handles);
$view->setMarkupEngine($this->markupEngine);

View file

@ -3,6 +3,8 @@
* @requires javelin-behavior
* javelin-dom
* javelin-util
* javelin-json
* javelin-stratcom
* phabricator-shaped-request
*/
@ -24,10 +26,18 @@ JX.behavior('maniphest-transaction-preview', function(config) {
var input = ([]
.concat(JX.DOM.scry(control, 'select'))
.concat(JX.DOM.scry(control, 'input')))[0];
value = input.value;
if (JX.DOM.isType(input, 'input') && input.type != 'hidden') {
// Avoid reading 'value' out of the tokenizer free text input.
value = null;
if (JX.DOM.isType(input, 'input')) {
// Avoid reading 'value'(s) out of the tokenizer free text input.
if (input.type != 'hidden') {
value = null;
// Get the tokenizer and all that delicious data
} else {
var tokenizer_dom = JX.$(config.tokenizers[selected].id);
var tokenizer = JX.Stratcom.getData(tokenizer_dom).tokenizer;
value = JX.JSON.stringify(JX.keys(tokenizer.getTokens()));
}
} else {
value = input.value;
}
} catch (_ignored_) {
// Ignored.