Page MenuHomePhabricator

D19099.id45779.diff
No OneTemporary

D19099.id45779.diff

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
@@ -4870,6 +4870,8 @@
'PhrictionDocumentPHIDType' => 'applications/phriction/phid/PhrictionDocumentPHIDType.php',
'PhrictionDocumentPathHeraldField' => 'applications/phriction/herald/PhrictionDocumentPathHeraldField.php',
'PhrictionDocumentQuery' => 'applications/phriction/query/PhrictionDocumentQuery.php',
+ 'PhrictionDocumentSearchConduitAPIMethod' => 'applications/phriction/conduit/PhrictionDocumentSearchConduitAPIMethod.php',
+ 'PhrictionDocumentSearchEngine' => 'applications/phriction/query/PhrictionDocumentSearchEngine.php',
'PhrictionDocumentStatus' => 'applications/phriction/constants/PhrictionDocumentStatus.php',
'PhrictionDocumentTitleHeraldField' => 'applications/phriction/herald/PhrictionDocumentTitleHeraldField.php',
'PhrictionDocumentTitleTransaction' => 'applications/phriction/xaction/PhrictionDocumentTitleTransaction.php',
@@ -4886,7 +4888,6 @@
'PhrictionRemarkupRule' => 'applications/phriction/markup/PhrictionRemarkupRule.php',
'PhrictionReplyHandler' => 'applications/phriction/mail/PhrictionReplyHandler.php',
'PhrictionSchemaSpec' => 'applications/phriction/storage/PhrictionSchemaSpec.php',
- 'PhrictionSearchEngine' => 'applications/phriction/query/PhrictionSearchEngine.php',
'PhrictionTransaction' => 'applications/phriction/storage/PhrictionTransaction.php',
'PhrictionTransactionComment' => 'applications/phriction/storage/PhrictionTransactionComment.php',
'PhrictionTransactionEditor' => 'applications/phriction/editor/PhrictionTransactionEditor.php',
@@ -10799,7 +10800,9 @@
'PhrictionDocumentPHIDType' => 'PhabricatorPHIDType',
'PhrictionDocumentPathHeraldField' => 'PhrictionDocumentHeraldField',
'PhrictionDocumentQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
- 'PhrictionDocumentStatus' => 'PhrictionConstants',
+ 'PhrictionDocumentSearchConduitAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
+ 'PhrictionDocumentSearchEngine' => 'PhabricatorApplicationSearchEngine',
+ 'PhrictionDocumentStatus' => 'PhabricatorObjectStatus',
'PhrictionDocumentTitleHeraldField' => 'PhrictionDocumentHeraldField',
'PhrictionDocumentTitleTransaction' => 'PhrictionDocumentTransactionType',
'PhrictionDocumentTransactionType' => 'PhabricatorModularTransactionType',
@@ -10815,7 +10818,6 @@
'PhrictionRemarkupRule' => 'PhutilRemarkupRule',
'PhrictionReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
'PhrictionSchemaSpec' => 'PhabricatorConfigSchemaSpec',
- 'PhrictionSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhrictionTransaction' => 'PhabricatorModularTransaction',
'PhrictionTransactionComment' => 'PhabricatorApplicationTransactionComment',
'PhrictionTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
diff --git a/src/applications/phriction/conduit/PhrictionDocumentSearchConduitAPIMethod.php b/src/applications/phriction/conduit/PhrictionDocumentSearchConduitAPIMethod.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phriction/conduit/PhrictionDocumentSearchConduitAPIMethod.php
@@ -0,0 +1,18 @@
+<?php
+
+final class PhrictionDocumentSearchConduitAPIMethod
+ extends PhabricatorSearchEngineAPIMethod {
+
+ public function getAPIMethodName() {
+ return 'phriction.document.search';
+ }
+
+ public function newSearchEngine() {
+ return new PhrictionDocumentSearchEngine();
+ }
+
+ public function getMethodSummary() {
+ return pht('Read information about Phriction documents.');
+ }
+
+}
diff --git a/src/applications/phriction/constants/PhrictionDocumentStatus.php b/src/applications/phriction/constants/PhrictionDocumentStatus.php
--- a/src/applications/phriction/constants/PhrictionDocumentStatus.php
+++ b/src/applications/phriction/constants/PhrictionDocumentStatus.php
@@ -1,6 +1,7 @@
<?php
-final class PhrictionDocumentStatus extends PhrictionConstants {
+final class PhrictionDocumentStatus
+ extends PhabricatorObjectStatus {
const STATUS_EXISTS = 0;
const STATUS_DELETED = 1;
@@ -18,4 +19,45 @@
return idx($map, $const, 'unknown');
}
+ public static function newStatusObject($key) {
+ return new self($key, id(new self())->getStatusSpecification($key));
+ }
+
+ public static function getStatusMap() {
+ $map = id(new self())->getStatusSpecifications();
+ return ipull($map, 'name', 'key');
+ }
+
+ public function isActive() {
+ return ($this->getKey() == self::STATUS_EXISTS);
+ }
+
+ protected function newStatusSpecifications() {
+ return array(
+ array(
+ 'key' => self::STATUS_EXISTS,
+ 'name' => pht('Active'),
+ 'icon' => 'fa-file-text-o',
+ 'color' => 'bluegrey',
+ ),
+ array(
+ 'key' => self::STATUS_DELETED,
+ 'name' => pht('Deleted'),
+ 'icon' => 'fa-file-text-o',
+ 'color' => 'grey',
+ ),
+ array(
+ 'key' => self::STATUS_MOVED,
+ 'name' => pht('Moved'),
+ 'icon' => 'fa-arrow-right',
+ 'color' => 'grey',
+ ),
+ array(
+ 'key' => self::STATUS_STUB,
+ 'name' => pht('Stub'),
+ 'icon' => 'fa-file-text-o',
+ 'color' => 'grey',
+ ),
+ );
+ }
}
diff --git a/src/applications/phriction/controller/PhrictionController.php b/src/applications/phriction/controller/PhrictionController.php
--- a/src/applications/phriction/controller/PhrictionController.php
+++ b/src/applications/phriction/controller/PhrictionController.php
@@ -13,7 +13,7 @@
$nav->addFilter('/phriction/', pht('Index'));
}
- id(new PhrictionSearchEngine())
+ id(new PhrictionDocumentSearchEngine())
->setViewer($user)
->addNavigationItems($nav->getMenu());
diff --git a/src/applications/phriction/controller/PhrictionListController.php b/src/applications/phriction/controller/PhrictionListController.php
--- a/src/applications/phriction/controller/PhrictionListController.php
+++ b/src/applications/phriction/controller/PhrictionListController.php
@@ -12,7 +12,7 @@
$controller = id(new PhabricatorApplicationSearchController())
->setQueryKey($querykey)
- ->setSearchEngine(new PhrictionSearchEngine())
+ ->setSearchEngine(new PhrictionDocumentSearchEngine())
->setNavigation($this->buildSideNavView());
return $this->delegateToController($controller);
diff --git a/src/applications/phriction/query/PhrictionDocumentQuery.php b/src/applications/phriction/query/PhrictionDocumentQuery.php
--- a/src/applications/phriction/query/PhrictionDocumentQuery.php
+++ b/src/applications/phriction/query/PhrictionDocumentQuery.php
@@ -12,12 +12,7 @@
private $needContent;
- private $status = 'status-any';
- const STATUS_ANY = 'status-any';
- const STATUS_OPEN = 'status-open';
- const STATUS_NONSTUB = 'status-nonstub';
-
- const ORDER_HIERARCHY = 'order-hierarchy';
+ const ORDER_HIERARCHY = 'hierarchy';
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -49,11 +44,6 @@
return $this;
}
- public function withStatus($status) {
- $this->status = $status;
- return $this;
- }
-
public function needContent($need_content) {
$this->needContent = $need_content;
return $this;
@@ -224,42 +214,16 @@
$this->depths);
}
- switch ($this->status) {
- case self::STATUS_OPEN:
- $where[] = qsprintf(
- $conn,
- 'd.status NOT IN (%Ld)',
- array(
- PhrictionDocumentStatus::STATUS_DELETED,
- PhrictionDocumentStatus::STATUS_MOVED,
- PhrictionDocumentStatus::STATUS_STUB,
- ));
- break;
- case self::STATUS_NONSTUB:
- $where[] = qsprintf(
- $conn,
- 'd.status NOT IN (%Ld)',
- array(
- PhrictionDocumentStatus::STATUS_MOVED,
- PhrictionDocumentStatus::STATUS_STUB,
- ));
- break;
- case self::STATUS_ANY:
- break;
- default:
- throw new Exception(pht("Unknown status '%s'!", $this->status));
- }
-
return $where;
}
public function getBuiltinOrders() {
- return array(
+ return parent::getBuiltinOrders() + array(
self::ORDER_HIERARCHY => array(
'vector' => array('depth', 'title', 'updated'),
'name' => pht('Hierarchy'),
),
- ) + parent::getBuiltinOrders();
+ );
}
public function getOrderableColumns() {
diff --git a/src/applications/phriction/query/PhrictionSearchEngine.php b/src/applications/phriction/query/PhrictionDocumentSearchEngine.php
rename from src/applications/phriction/query/PhrictionSearchEngine.php
rename to src/applications/phriction/query/PhrictionDocumentSearchEngine.php
--- a/src/applications/phriction/query/PhrictionSearchEngine.php
+++ b/src/applications/phriction/query/PhrictionDocumentSearchEngine.php
@@ -1,6 +1,6 @@
<?php
-final class PhrictionSearchEngine
+final class PhrictionDocumentSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
@@ -13,15 +13,14 @@
public function newQuery() {
return id(new PhrictionDocumentQuery())
- ->needContent(true)
- ->withStatus(PhrictionDocumentQuery::STATUS_NONSTUB);
+ ->needContent(true);
}
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
- if ($map['status']) {
- $query->withStatus($map['status']);
+ if ($map['statuses']) {
+ $query->withStatuses($map['statuses']);
}
return $query;
@@ -29,10 +28,10 @@
protected function buildCustomSearchFields() {
return array(
- id(new PhabricatorSearchSelectField())
- ->setKey('status')
+ id(new PhabricatorSearchCheckboxesField())
+ ->setKey('statuses')
->setLabel(pht('Status'))
- ->setOptions($this->getStatusOptions()),
+ ->setOptions(PhrictionDocumentStatus::getStatusMap()),
);
}
@@ -59,19 +58,15 @@
return $query;
case 'active':
return $query->setParameter(
- 'status', PhrictionDocumentQuery::STATUS_OPEN);
+ 'statuses',
+ array(
+ PhrictionDocumentStatus::STATUS_EXISTS,
+ ));
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
- private function getStatusOptions() {
- return array(
- PhrictionDocumentQuery::STATUS_OPEN => pht('Show Active Documents'),
- PhrictionDocumentQuery::STATUS_NONSTUB => pht('Show All Documents'),
- );
- }
-
protected function getRequiredHandlePHIDsForResultList(
array $documents,
PhabricatorSavedQuery $query) {
@@ -118,15 +113,14 @@
$item->addAttribute($slug_uri);
- switch ($document->getStatus()) {
- case PhrictionDocumentStatus::STATUS_DELETED:
- $item->setDisabled(true);
- $item->addIcon('delete', pht('Deleted'));
- break;
- case PhrictionDocumentStatus::STATUS_MOVED:
- $item->setDisabled(true);
- $item->addIcon('arrow-right', pht('Moved Away'));
- break;
+ $icon = $document->getStatusIcon();
+ $color = $document->getStatusColor();
+ $label = $document->getStatusDisplayName();
+
+ $item->setStatusIcon("{$icon} {$color}", $label);
+
+ if (!$document->isActive()) {
+ $item->setDisabled(true);
}
$list->addItem($item);
diff --git a/src/applications/phriction/search/PhrictionDocumentFerretEngine.php b/src/applications/phriction/search/PhrictionDocumentFerretEngine.php
--- a/src/applications/phriction/search/PhrictionDocumentFerretEngine.php
+++ b/src/applications/phriction/search/PhrictionDocumentFerretEngine.php
@@ -12,7 +12,7 @@
}
public function newSearchEngine() {
- return new PhrictionSearchEngine();
+ return new PhrictionDocumentSearchEngine();
}
}
diff --git a/src/applications/phriction/storage/PhrictionDocument.php b/src/applications/phriction/storage/PhrictionDocument.php
--- a/src/applications/phriction/storage/PhrictionDocument.php
+++ b/src/applications/phriction/storage/PhrictionDocument.php
@@ -148,6 +148,29 @@
return $this;
}
+/* -( Status )------------------------------------------------------------- */
+
+
+ public function getStatusObject() {
+ return PhrictionDocumentStatus::newStatusObject($this->getStatus());
+ }
+
+ public function getStatusIcon() {
+ return $this->getStatusObject()->getIcon();
+ }
+
+ public function getStatusColor() {
+ return $this->getStatusObject()->getColor();
+ }
+
+ public function getStatusDisplayName() {
+ return $this->getStatusObject()->getDisplayName();
+ }
+
+ public function isActive() {
+ return $this->getStatusObject()->isActive();
+ }
+
/* -( PhabricatorPolicyInterface )----------------------------------------- */

File Metadata

Mime Type
text/plain
Expires
Sun, Mar 16, 11:00 PM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7485452
Default Alt Text
D19099.id45779.diff (12 KB)

Event Timeline