mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-28 17:52:43 +01:00
3d457a53be
Summary: Fixes T4299, Add status dropdown to mock edit view Test Plan: Edit mock, close mock, thumbnail title should read (Disabled). Default mocks list should show only open mocks. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: chad, epriestley, Korvin Maniphest Tasks: T4299 Differential Revision: https://secure.phabricator.com/D9145
147 lines
3.8 KiB
PHP
147 lines
3.8 KiB
PHP
<?php
|
|
|
|
final class PholioMockSearchEngine
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
public function getApplicationClassName() {
|
|
return 'PhabricatorApplicationPholio';
|
|
}
|
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
$saved = new PhabricatorSavedQuery();
|
|
$saved->setParameter(
|
|
'authorPHIDs',
|
|
$this->readUsersFromRequest($request, 'authors'));
|
|
$saved->setParameter(
|
|
'statuses',
|
|
$request->getStrList('status'));
|
|
|
|
return $saved;
|
|
}
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
$query = id(new PholioMockQuery())
|
|
->needCoverFiles(true)
|
|
->needImages(true)
|
|
->needTokenCounts(true)
|
|
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()))
|
|
->withStatuses($saved->getParameter('statuses', array()));
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function buildSearchForm(
|
|
AphrontFormView $form,
|
|
PhabricatorSavedQuery $saved_query) {
|
|
|
|
$phids = $saved_query->getParameter('authorPHIDs', array());
|
|
$author_handles = id(new PhabricatorHandleQuery())
|
|
->setViewer($this->requireViewer())
|
|
->withPHIDs($phids)
|
|
->execute();
|
|
|
|
$statuses = array(
|
|
''=>pht('Any Status'),
|
|
'closed'=>pht('Closed'),
|
|
'open'=>pht('Open'));
|
|
|
|
$status = $saved_query->getParameter('statuses', array());
|
|
$status = head($status);
|
|
|
|
$form
|
|
->appendChild(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setDatasource('/typeahead/common/users/')
|
|
->setName('authors')
|
|
->setLabel(pht('Authors'))
|
|
->setValue($author_handles))
|
|
->appendChild(
|
|
id(new AphrontFormSelectControl())
|
|
->setLabel(pht('Status'))
|
|
->setName('status')
|
|
->setOptions($statuses)
|
|
->setValue($status));
|
|
}
|
|
|
|
protected function getURI($path) {
|
|
return '/pholio/'.$path;
|
|
}
|
|
|
|
public function getBuiltinQueryNames() {
|
|
$names = array(
|
|
'open' => pht('Open Mocks'),
|
|
'all' => pht('All Mocks'),
|
|
);
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
$names['authored'] = pht('Authored');
|
|
}
|
|
|
|
return $names;
|
|
}
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
$query->setQueryKey($query_key);
|
|
|
|
switch ($query_key) {
|
|
case 'open':
|
|
return $query->setParameter(
|
|
'statuses',
|
|
array('open'));
|
|
case 'all':
|
|
return $query;
|
|
case 'authored':
|
|
return $query->setParameter(
|
|
'authorPHIDs',
|
|
array($this->requireViewer()->getPHID()));
|
|
}
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
}
|
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
|
array $mocks,
|
|
PhabricatorSavedQuery $query) {
|
|
return mpull($mocks, 'getAuthorPHID');
|
|
}
|
|
|
|
protected function renderResultList(
|
|
array $mocks,
|
|
PhabricatorSavedQuery $query,
|
|
array $handles) {
|
|
assert_instances_of($mocks, 'PholioMock');
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
$board = new PHUIPinboardView();
|
|
foreach ($mocks as $mock) {
|
|
|
|
$header = 'M'.$mock->getID().' '.$mock->getName();
|
|
if ($mock->isClosed()) {
|
|
$header = pht('%s (Closed)', $header);
|
|
}
|
|
|
|
$item = id(new PHUIPinboardItemView())
|
|
->setHeader($header)
|
|
->setURI('/M'.$mock->getID())
|
|
->setImageURI($mock->getCoverFile()->getThumb280x210URI())
|
|
->setImageSize(280, 210)
|
|
->addIconCount('fa-picture-o', count($mock->getImages()))
|
|
->addIconCount('fa-trophy', $mock->getTokenCount());
|
|
|
|
if ($mock->getAuthorPHID()) {
|
|
$author_handle = $handles[$mock->getAuthorPHID()];
|
|
$datetime = phabricator_date($mock->getDateCreated(), $viewer);
|
|
$item->appendChild(
|
|
pht('By %s on %s', $author_handle->renderLink(), $datetime));
|
|
}
|
|
|
|
$board->addItem($item);
|
|
}
|
|
|
|
return $board;
|
|
}
|
|
|
|
}
|