Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15525490
D9007.id21396.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D9007.id21396.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1462,6 +1462,7 @@
'PhabricatorDashboardPanelTransactionEditor' => 'applications/dashboard/editor/PhabricatorDashboardPanelTransactionEditor.php',
'PhabricatorDashboardPanelTransactionQuery' => 'applications/dashboard/query/PhabricatorDashboardPanelTransactionQuery.php',
'PhabricatorDashboardPanelType' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelType.php',
+ 'PhabricatorDashboardPanelTypeQuery' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php',
'PhabricatorDashboardPanelTypeText' => 'applications/dashboard/paneltype/PhabricatorDashboardPanelTypeText.php',
'PhabricatorDashboardPanelViewController' => 'applications/dashboard/controller/PhabricatorDashboardPanelViewController.php',
'PhabricatorDashboardQuery' => 'applications/dashboard/query/PhabricatorDashboardQuery.php',
@@ -4304,6 +4305,7 @@
'PhabricatorDashboardPanelTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
'PhabricatorDashboardPanelTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'PhabricatorDashboardPanelType' => 'Phobject',
+ 'PhabricatorDashboardPanelTypeQuery' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardPanelTypeText' => 'PhabricatorDashboardPanelType',
'PhabricatorDashboardPanelViewController' => 'PhabricatorDashboardController',
'PhabricatorDashboardQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
diff --git a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
--- a/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
+++ b/src/applications/dashboard/engine/PhabricatorDashboardPanelRenderingEngine.php
@@ -50,8 +50,16 @@
}
}
-
- return $panel_type->renderPanel($viewer, $panel);
+ try {
+ return $panel_type->renderPanel($viewer, $panel);
+ } catch (Exception $ex) {
+ return $this->renderErrorPanel(
+ $panel->getName(),
+ pht(
+ '%s: %s',
+ phutil_tag('strong', array(), get_class($ex)),
+ $ex->getMessage()));
+ }
}
private function renderErrorPanel($title, $body) {
diff --git a/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php
new file mode 100644
--- /dev/null
+++ b/src/applications/dashboard/paneltype/PhabricatorDashboardPanelTypeQuery.php
@@ -0,0 +1,82 @@
+<?php
+
+final class PhabricatorDashboardPanelTypeQuery
+ extends PhabricatorDashboardPanelType {
+
+ public function getPanelTypeKey() {
+ return 'query';
+ }
+
+ public function getPanelTypeName() {
+ return pht('Query Panel');
+ }
+
+ public function getPanelTypeDescription() {
+ return pht(
+ 'Show results of a search query, like the most recently filed tasks or '.
+ 'revisions you need to review.');
+ }
+
+ public function getFieldSpecifications() {
+ return array(
+ 'class' => array(
+ 'name' => pht('ApplicationSearch Class'),
+ 'type' => 'text',
+ ),
+ 'key' => array(
+ 'name' => pht('ApplicationSearch Key'),
+ 'type' => 'text',
+ ),
+ );
+ }
+
+ protected function renderPanelContent(
+ PhabricatorUser $viewer,
+ PhabricatorDashboardPanel $panel) {
+
+ $class = $panel->getProperty('class');
+
+ $engine = PhabricatorApplicationSearchEngine::getEngineByClassName($class);
+ if (!$engine) {
+ throw new Exception(
+ pht(
+ 'The application search engine "%s" is not known to Phabricator!',
+ $class));
+ }
+
+ $engine->setViewer($viewer);
+
+ $key = $panel->getProperty('key');
+ if ($engine->isBuiltinQuery($key)) {
+ $saved = $engine->buildSavedQueryFromBuiltin($key);
+ } else {
+ $saved = id(new PhabricatorSavedQueryQuery())
+ ->setViewer($viewer)
+ ->withEngineClassNames(array($class))
+ ->withQueryKeys(array($key))
+ ->executeOne();
+ }
+
+ if (!$saved) {
+ throw new Exception(
+ pht(
+ 'Query "%s" is unknown to application search engine "%s"!',
+ $key,
+ $class));
+ }
+
+ $query = $engine->buildQueryFromSavedQuery($saved);
+
+ $results = $query
+ ->setViewer($viewer)
+ ->execute();
+
+ $out = array();
+ foreach ($results as $result) {
+ $out[] = phutil_tag('div', array(), $result->getPHID());
+ }
+
+ return $out;
+ }
+
+}
diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
--- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
+++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
@@ -4,10 +4,11 @@
* Represents an abstract search engine for an application. It supports
* creating and storing saved queries.
*
- * @task builtin Builtin Queries
- * @task uri Query URIs
- * @task dates Date Filters
- * @task read Reading Utilities
+ * @task construct Constructing Engines
+ * @task builtin Builtin Queries
+ * @task uri Query URIs
+ * @task dates Date Filters
+ * @task read Reading Utilities
*
* @group search
*/
@@ -174,6 +175,36 @@
}
+/* -( Constructing Engines )----------------------------------------------- */
+
+
+ /**
+ * Load all available application search engines.
+ *
+ * @return list<PhabricatorApplicationSearchEngine> All available engines.
+ * @task construct
+ */
+ public static function getAllEngines() {
+ $engines = id(new PhutilSymbolLoader())
+ ->setAncestorClass(__CLASS__)
+ ->loadObjects();
+
+ return $engines;
+ }
+
+
+ /**
+ * Get an engine by class name, if it exists.
+ *
+ * @return PhabricatorApplicationSearchEngine|null Engine, or null if it does
+ * not exist.
+ * @task construct
+ */
+ public static function getEngineByClassName($class_name) {
+ return idx(self::getAllEngines(), $class_name);
+ }
+
+
/* -( Builtin Queries )---------------------------------------------------- */
diff --git a/src/applications/search/query/PhabricatorSavedQueryQuery.php b/src/applications/search/query/PhabricatorSavedQueryQuery.php
--- a/src/applications/search/query/PhabricatorSavedQueryQuery.php
+++ b/src/applications/search/query/PhabricatorSavedQueryQuery.php
@@ -40,21 +40,21 @@
private function buildWhereClause($conn_r) {
$where = array();
- if ($this->ids) {
+ if ($this->ids !== null) {
$where[] = qsprintf(
$conn_r,
'id IN (%Ld)',
$this->ids);
}
- if ($this->engineClassNames) {
+ if ($this->engineClassNames !== null) {
$where[] = qsprintf(
$conn_r,
'engineClassName IN (%Ls)',
$this->engineClassNames);
}
- if ($this->queryKeys) {
+ if ($this->queryKeys !== null) {
$where[] = qsprintf(
$conn_r,
'queryKey IN (%Ls)',
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Apr 22, 2:47 PM (1 d, 5 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7595149
Default Alt Text
D9007.id21396.diff (7 KB)
Attached To
Mode
D9007: Rough skeleton of a "Query" dashboard panel
Attached
Detach File
Event Timeline
Log In to Comment