mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-11 15:21:03 +01:00
Add "parent" and "ancestor" information to the project.search API
Summary: Ref T12074. - Adds a new "parent" property on main results. This shows an abbreviated version of the project's parent, or `null` if the project is a root project. - Adds a new "ancestor" attachment to pull the entire ancestor list. - Adds a new "depth" property on main results. - You can use "parent" or "depth" to tell if a project is a subproject or not. These attempt to balance convenience, power, and performance: the full ancestor list can be big so I made it an attachment, but the other stuff isn't too big and is cheap and seems reasonable to always include. Test Plan: In API results: - Saw null parent (root projects) and non-null parent (subprojects/milestones). - Used "ancestors" attchment, got full list of ancestors. - Saw appropriate "depth" values. Reviewers: chad Reviewed By: chad Maniphest Tasks: T12074 Differential Revision: https://secure.phabricator.com/D17154
This commit is contained in:
parent
e03103f349
commit
c0bec6c0ed
3 changed files with 69 additions and 0 deletions
|
@ -3514,6 +3514,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorProjectWatcherListView' => 'applications/project/view/PhabricatorProjectWatcherListView.php',
|
'PhabricatorProjectWatcherListView' => 'applications/project/view/PhabricatorProjectWatcherListView.php',
|
||||||
'PhabricatorProjectWorkboardBackgroundColor' => 'applications/project/constants/PhabricatorProjectWorkboardBackgroundColor.php',
|
'PhabricatorProjectWorkboardBackgroundColor' => 'applications/project/constants/PhabricatorProjectWorkboardBackgroundColor.php',
|
||||||
'PhabricatorProjectWorkboardProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php',
|
'PhabricatorProjectWorkboardProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php',
|
||||||
|
'PhabricatorProjectsAncestorsSearchEngineAttachment' => 'applications/project/engineextension/PhabricatorProjectsAncestorsSearchEngineAttachment.php',
|
||||||
'PhabricatorProjectsCurtainExtension' => 'applications/project/engineextension/PhabricatorProjectsCurtainExtension.php',
|
'PhabricatorProjectsCurtainExtension' => 'applications/project/engineextension/PhabricatorProjectsCurtainExtension.php',
|
||||||
'PhabricatorProjectsEditEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsEditEngineExtension.php',
|
'PhabricatorProjectsEditEngineExtension' => 'applications/project/engineextension/PhabricatorProjectsEditEngineExtension.php',
|
||||||
'PhabricatorProjectsEditField' => 'applications/transactions/editfield/PhabricatorProjectsEditField.php',
|
'PhabricatorProjectsEditField' => 'applications/transactions/editfield/PhabricatorProjectsEditField.php',
|
||||||
|
@ -8666,6 +8667,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorProjectWatcherListView' => 'PhabricatorProjectUserListView',
|
'PhabricatorProjectWatcherListView' => 'PhabricatorProjectUserListView',
|
||||||
'PhabricatorProjectWorkboardBackgroundColor' => 'Phobject',
|
'PhabricatorProjectWorkboardBackgroundColor' => 'Phobject',
|
||||||
'PhabricatorProjectWorkboardProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
'PhabricatorProjectWorkboardProfileMenuItem' => 'PhabricatorProfileMenuItem',
|
||||||
|
'PhabricatorProjectsAncestorsSearchEngineAttachment' => 'PhabricatorSearchEngineAttachment',
|
||||||
'PhabricatorProjectsCurtainExtension' => 'PHUICurtainExtension',
|
'PhabricatorProjectsCurtainExtension' => 'PHUICurtainExtension',
|
||||||
'PhabricatorProjectsEditEngineExtension' => 'PhabricatorEditEngineExtension',
|
'PhabricatorProjectsEditEngineExtension' => 'PhabricatorEditEngineExtension',
|
||||||
'PhabricatorProjectsEditField' => 'PhabricatorTokenizerEditField',
|
'PhabricatorProjectsEditField' => 'PhabricatorTokenizerEditField',
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorProjectsAncestorsSearchEngineAttachment
|
||||||
|
extends PhabricatorSearchEngineAttachment {
|
||||||
|
|
||||||
|
public function getAttachmentName() {
|
||||||
|
return pht('Project Ancestors');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttachmentDescription() {
|
||||||
|
return pht('Get the full ancestor list for each project.');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAttachmentForObject($object, $data, $spec) {
|
||||||
|
$ancestors = $object->getAncestorProjects();
|
||||||
|
|
||||||
|
// Order ancestors by depth, ascending.
|
||||||
|
$ancestors = array_reverse($ancestors);
|
||||||
|
|
||||||
|
$results = array();
|
||||||
|
foreach ($ancestors as $ancestor) {
|
||||||
|
$results[] = $ancestor->getRefForConduit();
|
||||||
|
}
|
||||||
|
|
||||||
|
return array(
|
||||||
|
'ancestors' => $results,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -745,6 +745,20 @@ final class PhabricatorProject extends PhabricatorProjectDAO
|
||||||
->setKey('milestone')
|
->setKey('milestone')
|
||||||
->setType('int?')
|
->setType('int?')
|
||||||
->setDescription(pht('For milestones, milestone sequence number.')),
|
->setDescription(pht('For milestones, milestone sequence number.')),
|
||||||
|
id(new PhabricatorConduitSearchFieldSpecification())
|
||||||
|
->setKey('parent')
|
||||||
|
->setType('map<string, wild>?')
|
||||||
|
->setDescription(
|
||||||
|
pht(
|
||||||
|
'For subprojects and milestones, a brief description of the '.
|
||||||
|
'parent project.')),
|
||||||
|
id(new PhabricatorConduitSearchFieldSpecification())
|
||||||
|
->setKey('depth')
|
||||||
|
->setType('int')
|
||||||
|
->setDescription(
|
||||||
|
pht(
|
||||||
|
'For subprojects and milestones, depth of this project in the '.
|
||||||
|
'tree. Root projects have depth 0.')),
|
||||||
id(new PhabricatorConduitSearchFieldSpecification())
|
id(new PhabricatorConduitSearchFieldSpecification())
|
||||||
->setKey('icon')
|
->setKey('icon')
|
||||||
->setType('map<string, wild>')
|
->setType('map<string, wild>')
|
||||||
|
@ -766,10 +780,19 @@ final class PhabricatorProject extends PhabricatorProjectDAO
|
||||||
$milestone = null;
|
$milestone = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$parent = $this->getParentProject();
|
||||||
|
if ($parent) {
|
||||||
|
$parent_ref = $parent->getRefForConduit();
|
||||||
|
} else {
|
||||||
|
$parent_ref = null;
|
||||||
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'name' => $this->getName(),
|
'name' => $this->getName(),
|
||||||
'slug' => $this->getPrimarySlug(),
|
'slug' => $this->getPrimarySlug(),
|
||||||
'milestone' => $milestone,
|
'milestone' => $milestone,
|
||||||
|
'depth' => (int)$this->getProjectDepth(),
|
||||||
|
'parent' => $parent_ref,
|
||||||
'icon' => array(
|
'icon' => array(
|
||||||
'key' => $this->getDisplayIconKey(),
|
'key' => $this->getDisplayIconKey(),
|
||||||
'name' => $this->getDisplayIconName(),
|
'name' => $this->getDisplayIconName(),
|
||||||
|
@ -788,6 +811,20 @@ final class PhabricatorProject extends PhabricatorProjectDAO
|
||||||
->setAttachmentKey('members'),
|
->setAttachmentKey('members'),
|
||||||
id(new PhabricatorProjectsWatchersSearchEngineAttachment())
|
id(new PhabricatorProjectsWatchersSearchEngineAttachment())
|
||||||
->setAttachmentKey('watchers'),
|
->setAttachmentKey('watchers'),
|
||||||
|
id(new PhabricatorProjectsAncestorsSearchEngineAttachment())
|
||||||
|
->setAttachmentKey('ancestors'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get an abbreviated representation of this project for use in providing
|
||||||
|
* "parent" and "ancestor" information.
|
||||||
|
*/
|
||||||
|
public function getRefForConduit() {
|
||||||
|
return array(
|
||||||
|
'id' => (int)$this->getID(),
|
||||||
|
'phid' => $this->getPHID(),
|
||||||
|
'name' => $this->getName(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue