Differential D16155 Diff 38866 src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/typeahead/controller/PhabricatorTypeaheadModularDatasourceController.php
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (isset($sources[$class])) { | ||||
if (($offset + $limit) >= $hard_limit) { | if (($offset + $limit) >= $hard_limit) { | ||||
// Offset-based paging is intrinsically slow; hard-cap how far we're | // Offset-based paging is intrinsically slow; hard-cap how far we're | ||||
// willing to go with it. | // willing to go with it. | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$composite | $composite | ||||
->setOffset($offset); | ->setOffset($offset) | ||||
->setIsBrowse(true); | |||||
} | } | ||||
$results = $composite->loadResults(); | $results = $composite->loadResults(); | ||||
if ($is_browse) { | if ($is_browse) { | ||||
// If this is a request for a specific token after the user clicks | // If this is a request for a specific token after the user clicks | ||||
// "Select", return the token in wire format so it can be added to | // "Select", return the token in wire format so it can be added to | ||||
// the tokenizer. | // the tokenizer. | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | if (isset($sources[$class])) { | ||||
$select = array( | $select = array( | ||||
'offset' => $offset, | 'offset' => $offset, | ||||
'q' => $query, | 'q' => $query, | ||||
); | ); | ||||
$items = array(); | $items = array(); | ||||
foreach ($results as $result) { | foreach ($results as $result) { | ||||
$token = PhabricatorTypeaheadTokenView::newFromTypeaheadResult( | $information = $this->renderBrowseResult($result); | ||||
$result); | |||||
// Disable already-selected tokens. | // Disable already-selected tokens. | ||||
$disabled = isset($exclude[$result->getPHID()]); | $disabled = isset($exclude[$result->getPHID()]); | ||||
$value = $select + array('phid' => $result->getPHID()); | $value = $select + array('phid' => $result->getPHID()); | ||||
$value = json_encode($value); | $value = json_encode($value); | ||||
$button = phutil_tag( | $button = phutil_tag( | ||||
'button', | 'button', | ||||
array( | array( | ||||
'class' => 'small grey', | 'class' => 'small grey', | ||||
'name' => 'select', | 'name' => 'select', | ||||
'value' => $value, | 'value' => $value, | ||||
'disabled' => $disabled ? 'disabled' : null, | 'disabled' => $disabled ? 'disabled' : null, | ||||
), | ), | ||||
pht('Select')); | pht('Select')); | ||||
$items[] = phutil_tag( | $items[] = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'typeahead-browse-item grouped', | 'class' => 'typeahead-browse-item grouped', | ||||
), | ), | ||||
array( | array( | ||||
$token, | |||||
$button, | $button, | ||||
$information, | |||||
)); | )); | ||||
} | } | ||||
$markup = array( | $markup = array( | ||||
$items, | $items, | ||||
$next_link, | $next_link, | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | $view = id(new PHUITwoColumnView()) | ||||
$result_box, | $result_box, | ||||
)); | )); | ||||
return $this->newPage() | return $this->newPage() | ||||
->setTitle($title) | ->setTitle($title) | ||||
->appendChild($view); | ->appendChild($view); | ||||
} | } | ||||
private function renderBrowseResult(PhabricatorTypeaheadResult $result) { | |||||
$class = array(); | |||||
$style = array(); | |||||
$separator = " \xC2\xB7 "; | |||||
$class[] = 'phabricator-main-search-typeahead-result'; | |||||
$name = phutil_tag( | |||||
'div', | |||||
array( | |||||
'class' => 'result-name', | |||||
), | |||||
$result->getDisplayName()); | |||||
$icon = $result->getIcon(); | |||||
$icon = id(new PHUIIconView())->setIcon($icon); | |||||
$attributes = $result->getAttributes(); | |||||
$attributes = phutil_implode_html($separator, $attributes); | |||||
$attributes = array($icon, ' ', $attributes); | |||||
$closed = $result->getClosed(); | |||||
if ($closed) { | |||||
$class[] = 'result-closed'; | |||||
$attributes = array($closed, $separator, $attributes); | |||||
} | |||||
$attributes = phutil_tag( | |||||
'div', | |||||
array( | |||||
'class' => 'result-type', | |||||
), | |||||
$attributes); | |||||
$image = $result->getImageURI(); | |||||
if ($image) { | |||||
$style[] = 'background-image: url('.$image.');'; | |||||
$class[] = 'has-image'; | |||||
} | |||||
return phutil_tag( | |||||
'div', | |||||
array( | |||||
'class' => implode(' ', $class), | |||||
'style' => implode(' ', $style), | |||||
), | |||||
array( | |||||
$name, | |||||
$attributes, | |||||
)); | |||||
} | |||||
} | } |