2014-02-21 21:51:25 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class HeraldTranscriptSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
2014-06-12 22:22:20 +02:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Herald Transcripts');
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:47:48 +01:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorHeraldApplication';
|
2014-05-09 21:25:52 +02:00
|
|
|
}
|
|
|
|
|
2017-02-22 18:25:36 +01:00
|
|
|
public function canUseInPanelContext() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-21 21:51:25 +01:00
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
$object_monograms = $request->getStrList('objectMonograms');
|
|
|
|
$saved->setParameter('objectMonograms', $object_monograms);
|
|
|
|
|
|
|
|
$ids = $request->getStrList('ids');
|
|
|
|
foreach ($ids as $key => $id) {
|
|
|
|
if (!$id || !is_numeric($id)) {
|
|
|
|
unset($ids[$key]);
|
|
|
|
} else {
|
|
|
|
$ids[$key] = $id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$saved->setParameter('ids', $ids);
|
|
|
|
|
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
$query = id(new HeraldTranscriptQuery());
|
|
|
|
|
|
|
|
$object_monograms = $saved->getParameter('objectMonograms');
|
|
|
|
if ($object_monograms) {
|
|
|
|
$objects = id(new PhabricatorObjectQuery())
|
|
|
|
->setViewer($this->requireViewer())
|
|
|
|
->withNames($object_monograms)
|
|
|
|
->execute();
|
|
|
|
$query->withObjectPHIDs(mpull($objects, 'getPHID'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$ids = $saved->getParameter('ids');
|
|
|
|
if ($ids) {
|
|
|
|
$query->withIDs($ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
|
|
|
PhabricatorSavedQuery $saved) {
|
|
|
|
|
|
|
|
$object_monograms = $saved->getParameter('objectMonograms', array());
|
|
|
|
$ids = $saved->getParameter('ids', array());
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('objectMonograms')
|
|
|
|
->setLabel(pht('Object Monograms'))
|
|
|
|
->setValue(implode(', ', $object_monograms)))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('ids')
|
|
|
|
->setLabel(pht('Transcript IDs'))
|
|
|
|
->setValue(implode(', ', $ids)));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/herald/transcript/'.$path;
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:34:51 +01:00
|
|
|
protected function getBuiltinQueryNames() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return array(
|
2015-11-29 02:05:28 +01:00
|
|
|
'all' => pht('All Transcripts'),
|
2014-07-23 02:03:09 +02:00
|
|
|
);
|
2014-02-21 21:51:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
$viewer_phid = $this->requireViewer()->getPHID();
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
|
|
|
array $transcripts,
|
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
return mpull($transcripts, 'getObjectPHID');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderResultList(
|
|
|
|
array $transcripts,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
assert_instances_of($transcripts, 'HeraldTranscript');
|
|
|
|
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
|
|
$list = new PHUIObjectItemListView();
|
|
|
|
foreach ($transcripts as $xscript) {
|
|
|
|
$view_href = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => '/herald/transcript/'.$xscript->getID().'/',
|
|
|
|
),
|
|
|
|
pht('View Full Transcript'));
|
|
|
|
|
|
|
|
$item = new PHUIObjectItemView();
|
|
|
|
$item->setObjectName($xscript->getID());
|
|
|
|
$item->setHeader($view_href);
|
|
|
|
if ($xscript->getDryRun()) {
|
|
|
|
$item->addAttribute(pht('Dry Run'));
|
|
|
|
}
|
|
|
|
$item->addAttribute($handles[$xscript->getObjectPHID()]->renderLink());
|
|
|
|
$item->addAttribute(
|
2015-05-23 14:36:02 +02:00
|
|
|
pht('%s ms', new PhutilNumber((int)(1000 * $xscript->getDuration()))));
|
2014-05-09 21:25:52 +02:00
|
|
|
$item->addIcon(
|
|
|
|
'none',
|
|
|
|
phabricator_datetime($xscript->getTime(), $viewer));
|
|
|
|
|
|
|
|
$list->addItem($item);
|
|
|
|
}
|
|
|
|
|
2015-06-19 12:46:20 +02:00
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
|
|
|
$result->setObjectList($list);
|
|
|
|
$result->setNoDataString(pht('No transcripts found.'));
|
|
|
|
|
|
|
|
return $result;
|
2014-05-09 21:25:52 +02:00
|
|
|
}
|
|
|
|
|
2014-02-21 21:51:25 +01:00
|
|
|
}
|