diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 6fb37525ab..8729bf61c9 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -638,6 +638,8 @@ phutil_register_library_map(array( 'PhabricatorFactManagementStatusWorkflow' => 'applications/fact/management/PhabricatorFactManagementStatusWorkflow.php', 'PhabricatorFactManagementWorkflow' => 'applications/fact/management/PhabricatorFactManagementWorkflow.php', 'PhabricatorFactRaw' => 'applications/fact/storage/PhabricatorFactRaw.php', + 'PhabricatorFactSimpleSpec' => 'applications/fact/spec/PhabricatorFactSimpleSpec.php', + 'PhabricatorFactSpec' => 'applications/fact/spec/PhabricatorFactSpec.php', 'PhabricatorFactUpdateIterator' => 'applications/fact/extract/PhabricatorFactUpdateIterator.php', 'PhabricatorFeedBuilder' => 'applications/feed/builder/PhabricatorFeedBuilder.php', 'PhabricatorFeedConstants' => 'applications/feed/constants/PhabricatorFeedConstants.php', diff --git a/src/applications/fact/controller/PhabricatorFactHomeController.php b/src/applications/fact/controller/PhabricatorFactHomeController.php index 3783b20671..e632396b25 100644 --- a/src/applications/fact/controller/PhabricatorFactHomeController.php +++ b/src/applications/fact/controller/PhabricatorFactHomeController.php @@ -19,17 +19,32 @@ final class PhabricatorFactHomeController extends PhabricatorFactController { public function processRequest() { + $request = $this->getRequest(); + $user = $request->getUser(); + + $types = array( + '+N:*', + '+N:DREV', + 'updated', + ); + + $engines = PhabricatorFactEngine::loadAllEngines(); + $specs = PhabricatorFactSpec::newSpecsForFactTypes($engines, $types); $facts = id(new PhabricatorFactAggregate())->loadAllWhere( - 'factType LIKE %> OR factType = %s', - '+N:', - 'updated'); + 'factType IN (%Ls)', + $types); $rows = array(); foreach ($facts as $fact) { + $spec = $specs[$fact->getFactType()]; + + $name = $spec->getName(); + $value = $spec->formatValueForDisplay($user, $fact->getValueX()); + $rows[] = array( - phutil_escape_html($fact->getFactType()), - (int)$fact->getValueX(), + phutil_escape_html($name), + phutil_escape_html($value), ); } diff --git a/src/applications/fact/engine/PhabricatorFactCountEngine.php b/src/applications/fact/engine/PhabricatorFactCountEngine.php index 9792a79c32..5e2c35a894 100644 --- a/src/applications/fact/engine/PhabricatorFactCountEngine.php +++ b/src/applications/fact/engine/PhabricatorFactCountEngine.php @@ -21,6 +21,24 @@ */ final class PhabricatorFactCountEngine extends PhabricatorFactEngine { + public function getFactSpecs(array $fact_types) { + $results = array(); + foreach ($fact_types as $type) { + if (!strncmp($type, '+N:', 3)) { + if ($type == '+N:*') { + $name = 'Total Objects'; + } else { + $name = 'Total Objects of type '.substr($type, 3); + } + + $results[] = id(new PhabricatorFactSimpleSpec($type)) + ->setName($name) + ->setUnit(PhabricatorFactSimpleSpec::UNIT_COUNT); + } + } + return $results; + } + public function shouldComputeRawFactsForObject(PhabricatorLiskDAO $object) { return true; } diff --git a/src/applications/fact/engine/PhabricatorFactEngine.php b/src/applications/fact/engine/PhabricatorFactEngine.php index a868a36671..7d5dec2eca 100644 --- a/src/applications/fact/engine/PhabricatorFactEngine.php +++ b/src/applications/fact/engine/PhabricatorFactEngine.php @@ -32,6 +32,10 @@ abstract class PhabricatorFactEngine { return $objects; } + public function getFactSpecs(array $fact_types) { + return array(); + } + public function shouldComputeRawFactsForObject(PhabricatorLiskDAO $object) { return false; } diff --git a/src/applications/fact/engine/PhabricatorFactLastUpdatedEngine.php b/src/applications/fact/engine/PhabricatorFactLastUpdatedEngine.php index cd9f1024ce..40404dd735 100644 --- a/src/applications/fact/engine/PhabricatorFactLastUpdatedEngine.php +++ b/src/applications/fact/engine/PhabricatorFactLastUpdatedEngine.php @@ -21,6 +21,18 @@ */ final class PhabricatorFactLastUpdatedEngine extends PhabricatorFactEngine { + public function getFactSpecs(array $fact_types) { + $results = array(); + foreach ($fact_types as $type) { + if ($type == 'updated') { + $results[] = id(new PhabricatorFactSimpleSpec($type)) + ->setName('Facts Last Updated') + ->setUnit(PhabricatorFactSimpleSpec::UNIT_EPOCH); + } + } + return $results; + } + public function shouldComputeAggregateFacts() { return true; } diff --git a/src/applications/fact/spec/PhabricatorFactSimpleSpec.php b/src/applications/fact/spec/PhabricatorFactSimpleSpec.php new file mode 100644 index 0000000000..450e2b2740 --- /dev/null +++ b/src/applications/fact/spec/PhabricatorFactSimpleSpec.php @@ -0,0 +1,54 @@ +type = $type; + } + + public function getType() { + return $this->type; + } + + public function setUnit($unit) { + $this->unit = $unit; + return $this; + } + + public function getUnit() { + return $this->unit; + } + + public function setName($name) { + $this->name = $name; + return $this; + } + + public function getName() { + if ($this->name !== null) { + return $this->name; + } + return parent::getName(); + } + +} diff --git a/src/applications/fact/spec/PhabricatorFactSpec.php b/src/applications/fact/spec/PhabricatorFactSpec.php new file mode 100644 index 0000000000..52eb37bcea --- /dev/null +++ b/src/applications/fact/spec/PhabricatorFactSpec.php @@ -0,0 +1,68 @@ +getFactSpecs($fact_types); + $specs = mpull($specs, null, 'getType'); + $map += $specs; + } + + foreach ($fact_types as $type) { + if (empty($map[$type])) { + $map[$type] = new PhabricatorFactSimpleSpec($type); + } + } + + return $map; + } + + abstract public function getType(); + + public function getUnit() { + return null; + } + + public function getName() { + $type = $this->getType(); + return "Fact ({$type})"; + } + + public function formatValueForDisplay(PhabricatorUser $user, $value) { + $unit = $this->getUnit(); + switch ($unit) { + case self::UNIT_COUNT: + return number_format($value); + case self::UNIT_EPOCH: + return phabricator_datetime($value, $user); + default: + return $value; + } + } + +}