1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-20 09:18:48 +02:00

Make browse view show tokens instead of raw data

Summary: Ref T5750. Move the server-side token rendering code to a shared location and use it in the browse view.

Test Plan: {F372252}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T5750

Differential Revision: https://secure.phabricator.com/D12424
This commit is contained in:
epriestley 2015-04-15 09:16:26 -07:00
parent 64182dc94d
commit 6a4de406b8
6 changed files with 134 additions and 40 deletions

View file

@ -2633,6 +2633,7 @@ phutil_register_library_map(array(
'PhabricatorTypeaheadOwnerDatasource' => 'applications/typeahead/datasource/PhabricatorTypeaheadOwnerDatasource.php', 'PhabricatorTypeaheadOwnerDatasource' => 'applications/typeahead/datasource/PhabricatorTypeaheadOwnerDatasource.php',
'PhabricatorTypeaheadResult' => 'applications/typeahead/storage/PhabricatorTypeaheadResult.php', 'PhabricatorTypeaheadResult' => 'applications/typeahead/storage/PhabricatorTypeaheadResult.php',
'PhabricatorTypeaheadRuntimeCompositeDatasource' => 'applications/typeahead/datasource/PhabricatorTypeaheadRuntimeCompositeDatasource.php', 'PhabricatorTypeaheadRuntimeCompositeDatasource' => 'applications/typeahead/datasource/PhabricatorTypeaheadRuntimeCompositeDatasource.php',
'PhabricatorTypeaheadTokenView' => 'applications/typeahead/view/PhabricatorTypeaheadTokenView.php',
'PhabricatorUIConfigOptions' => 'applications/config/option/PhabricatorUIConfigOptions.php', 'PhabricatorUIConfigOptions' => 'applications/config/option/PhabricatorUIConfigOptions.php',
'PhabricatorUIExample' => 'applications/uiexample/examples/PhabricatorUIExample.php', 'PhabricatorUIExample' => 'applications/uiexample/examples/PhabricatorUIExample.php',
'PhabricatorUIExampleRenderController' => 'applications/uiexample/controller/PhabricatorUIExampleRenderController.php', 'PhabricatorUIExampleRenderController' => 'applications/uiexample/controller/PhabricatorUIExampleRenderController.php',
@ -6030,6 +6031,7 @@ phutil_register_library_map(array(
'PhabricatorTypeaheadNoOwnerDatasource' => 'PhabricatorTypeaheadDatasource', 'PhabricatorTypeaheadNoOwnerDatasource' => 'PhabricatorTypeaheadDatasource',
'PhabricatorTypeaheadOwnerDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorTypeaheadOwnerDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorTypeaheadRuntimeCompositeDatasource' => 'PhabricatorTypeaheadCompositeDatasource', 'PhabricatorTypeaheadRuntimeCompositeDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'PhabricatorTypeaheadTokenView' => 'AphrontTagView',
'PhabricatorUIConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorUIConfigOptions' => 'PhabricatorApplicationConfigOptions',
'PhabricatorUIExampleRenderController' => 'PhabricatorController', 'PhabricatorUIExampleRenderController' => 'PhabricatorController',
'PhabricatorUIExamplesApplication' => 'PhabricatorApplication', 'PhabricatorUIExamplesApplication' => 'PhabricatorApplication',

View file

@ -9,6 +9,10 @@ final class PhabricatorApplicationApplicationPHIDType
return pht('Application'); return pht('Application');
} }
public function getTypeIcon() {
return 'fa-globe';
}
public function newObject() { public function newObject() {
return null; return null;
} }

View file

@ -38,7 +38,7 @@ final class PhabricatorTypeaheadModularDatasourceController
->setRawQuery($raw_query); ->setRawQuery($raw_query);
if ($is_browse) { if ($is_browse) {
$limit = 3; $limit = 10;
$offset = $request->getInt('offset'); $offset = $request->getInt('offset');
$composite $composite
->setLimit($limit + 1) ->setLimit($limit + 1)
@ -60,18 +60,22 @@ final class PhabricatorTypeaheadModularDatasourceController
pht('Next Page')); pht('Next Page'));
} }
$rows = array(); $items = array();
foreach ($results as $result) { foreach ($results as $result) {
// TODO: Render nicely. $token = PhabricatorTypeaheadTokenView::newForTypeaheadResult(
$rows[] = array_slice($result->getWireFormat(), 0, 3, true); $result);
$items[] = phutil_tag(
'div',
array(
'class' => 'grouped',
),
$token);
} }
$table = id(new AphrontTableView($rows));
return $this->newDialog() return $this->newDialog()
->setWidth(AphrontDialogView::WIDTH_FORM) ->setWidth(AphrontDialogView::WIDTH_FORM)
->setTitle(get_class($source)) // TODO: Provide nice names. ->setTitle(get_class($source)) // TODO: Provide nice names.
->appendChild($table) ->appendChild($items)
->appendChild($next_link) ->appendChild($next_link)
->addCancelButton('/', pht('Close')); ->addCancelButton('/', pht('Close'));
} }

View file

@ -73,6 +73,18 @@ final class PhabricatorTypeaheadResult {
return $this->name; return $this->name;
} }
public function getDisplayName() {
return coalesce($this->displayName, $this->getName());
}
public function getIcon() {
return nonempty($this->icon, $this->getDefaultIcon());
}
public function getPHID() {
return $this->phid;
}
public function getWireFormat() { public function getWireFormat() {
$data = array( $data = array(
$this->name, $this->name,
@ -83,7 +95,7 @@ final class PhabricatorTypeaheadResult {
$this->displayType, $this->displayType,
$this->imageURI ? (string)$this->imageURI : null, $this->imageURI ? (string)$this->imageURI : null,
$this->priorityType, $this->priorityType,
($this->icon === null) ? $this->getDefaultIcon() : $this->icon, $this->getIcon(),
$this->closed, $this->closed,
$this->imageSprite ? (string)$this->imageSprite : null, $this->imageSprite ? (string)$this->imageSprite : null,
); );

View file

@ -0,0 +1,99 @@
<?php
final class PhabricatorTypeaheadTokenView
extends AphrontTagView {
private $key;
private $icon;
private $inputName;
private $value;
public static function newForTypeaheadResult(
PhabricatorTypeaheadResult $result) {
return id(new PhabricatorTypeaheadTokenView())
->setKey($result->getPHID())
->setIcon($result->getIcon())
->setValue($result->getDisplayName());
}
public function setKey($key) {
$this->key = $key;
return $this;
}
public function getKey() {
return $this->key;
}
public function setInputName($input_name) {
$this->inputName = $input_name;
return $this;
}
public function getInputName() {
return $this->inputName;
}
public function setIcon($icon) {
$this->icon = $icon;
return $this;
}
public function getIcon() {
return $this->icon;
}
public function setValue($value) {
$this->value = $value;
return $this;
}
public function getValue() {
return $this->value;
}
protected function getTagName() {
return 'a';
}
protected function getTagAttributes() {
return array(
'class' => 'jx-tokenizer-token',
);
}
protected function getTagContent() {
$input_name = $this->getInputName();
if ($input_name) {
$input_name .= '[]';
}
$value = $this->getValue();
$icon = $this->getIcon();
if ($icon) {
$value = array(
phutil_tag(
'span',
array(
'class' => 'phui-icon-view phui-font-fa bluetext '.$icon,
)),
$value,
);
}
return array(
$value,
phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => $input_name,
'value' => $this->getKey(),
)),
phutil_tag('span', array('class' => 'jx-tokenizer-x-placeholder'), ''),
);
}
}

View file

@ -71,38 +71,11 @@ final class AphrontTokenizerTemplateView extends AphrontView {
} }
private function renderToken($key, $value, $icon) { private function renderToken($key, $value, $icon) {
$input_name = $this->getName(); return id(new PhabricatorTypeaheadTokenView())
if ($input_name) { ->setKey($key)
$input_name .= '[]'; ->setValue($value)
} ->setIcon($icon)
->setInputName($this->getName());
if ($icon) {
$value = array(
phutil_tag(
'span',
array(
'class' => 'phui-icon-view phui-font-fa bluetext '.$icon,
)),
$value,
);
}
return phutil_tag(
'a',
array(
'class' => 'jx-tokenizer-token',
),
array(
$value,
phutil_tag(
'input',
array(
'type' => 'hidden',
'name' => $input_name,
'value' => $key,
)),
phutil_tag('span', array('class' => 'jx-tokenizer-x-placeholder'), ''),
));
} }
} }