1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-03-02 07:29:25 +01:00
phorge-phorge/src/applications/dashboard/query/PhabricatorDashboardPanelSearchEngine.php
Joshua Spence 86c399b657 Rename PhabricatorApplication subclasses
Summary: Ref T5655. Some discussion in D9839. Generally speaking, `Phabricator{$name}Application` is clearer than `PhabricatorApplication{$name}`.

Test Plan:
# Pinned and uninstalled some applications.
# Applied patch and performed migrations.
# Verified that the pinned applications were still pinned and that the uninstalled applications were still uninstalled.
# Performed a sanity check on the database contents.

Reviewers: btrahan, epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: hach-que, epriestley, Korvin

Maniphest Tasks: T5655

Differential Revision: https://secure.phabricator.com/D9982
2014-07-23 10:03:09 +10:00

120 lines
2.9 KiB
PHP

<?php
final class PhabricatorDashboardPanelSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Dashboard Panels');
}
public function getApplicationClassName() {
return 'PhabricatorDashboardApplication';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter('status', $request->getStr('status'));
return $saved;
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new PhabricatorDashboardPanelQuery());
$status = $saved->getParameter('status');
switch ($status) {
case 'active':
$query->withArchived(false);
break;
case 'archived':
$query->withArchived(true);
break;
default:
break;
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$status = $saved_query->getParameter('status', '');
$form
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Status'))
->setName('status')
->setValue($status)
->setOptions(
array(
'' => pht('(All Panels)'),
'active' => pht('Active Panels'),
'archived' => pht('Archived Panels'),
)));
}
protected function getURI($path) {
return '/dashboard/panel/'.$path;
}
public function getBuiltinQueryNames() {
return array(
'active' => pht('Active Panels'),
'all' => pht('All Panels'),
);
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'active':
return $query->setParameter('status', 'active');
case 'all':
return $query;
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function renderResultList(
array $panels,
PhabricatorSavedQuery $query,
array $handles) {
$viewer = $this->requireViewer();
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($panels as $panel) {
$item = id(new PHUIObjectItemView())
->setObjectName($panel->getMonogram())
->setHeader($panel->getName())
->setHref('/'.$panel->getMonogram())
->setObject($panel);
$impl = $panel->getImplementation();
if ($impl) {
$type_text = $impl->getPanelTypeName();
$type_icon = 'none';
} else {
$type_text = nonempty($panel->getPanelType(), pht('Unknown Type'));
$type_icon = 'fa-question';
}
$item->addIcon($type_icon, $type_text);
if ($panel->getIsArchived()) {
$item->setDisabled(true);
}
$list->addItem($item);
}
return $list;
}
}