diff --git a/src/applications/almanac/query/AlmanacServiceQuery.php b/src/applications/almanac/query/AlmanacServiceQuery.php index 34879d5ca5..c31969d53f 100644 --- a/src/applications/almanac/query/AlmanacServiceQuery.php +++ b/src/applications/almanac/query/AlmanacServiceQuery.php @@ -1,214 +1,214 @@ ids = $ids; return $this; } public function withPHIDs(array $phids) { $this->phids = $phids; return $this; } public function withNames(array $names) { $this->names = $names; return $this; } public function withServiceClasses(array $classes) { $this->serviceClasses = $classes; return $this; } public function withDevicePHIDs(array $phids) { $this->devicePHIDs = $phids; return $this; } public function withLocked($locked) { $this->locked = $locked; return $this; } public function withNamePrefix($prefix) { $this->namePrefix = $prefix; return $this; } public function withNameSuffix($suffix) { $this->nameSuffix = $suffix; return $this; } public function needBindings($need_bindings) { $this->needBindings = $need_bindings; return $this; } protected function loadPage() { return $this->loadStandardPage(new AlmanacService()); } protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { $joins = parent::buildJoinClauseParts($conn); if ($this->devicePHIDs !== null) { $joins[] = qsprintf( $conn, 'JOIN %T binding ON service.phid = binding.servicePHID', id(new AlmanacBinding())->getTableName()); } return $joins; } protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { $where = parent::buildWhereClauseParts($conn); if ($this->ids !== null) { $where[] = qsprintf( $conn, 'service.id IN (%Ld)', $this->ids); } if ($this->phids !== null) { $where[] = qsprintf( $conn, 'service.phid IN (%Ls)', $this->phids); } if ($this->names !== null) { $hashes = array(); foreach ($this->names as $name) { $hashes[] = PhabricatorHash::digestForIndex($name); } $where[] = qsprintf( $conn, 'service.nameIndex IN (%Ls)', $hashes); } if ($this->serviceClasses !== null) { $where[] = qsprintf( $conn, 'service.serviceClass IN (%Ls)', $this->serviceClasses); } if ($this->devicePHIDs !== null) { $where[] = qsprintf( $conn, 'binding.devicePHID IN (%Ls)', $this->devicePHIDs); } if ($this->locked !== null) { $where[] = qsprintf( $conn, 'service.isLocked = %d', (int)$this->locked); } if ($this->namePrefix !== null) { $where[] = qsprintf( $conn, 'service.name LIKE %>', $this->namePrefix); } if ($this->nameSuffix !== null) { $where[] = qsprintf( $conn, 'service.name LIKE %<', $this->nameSuffix); } return $where; } protected function willFilterPage(array $services) { $service_types = AlmanacServiceType::getAllServiceTypes(); foreach ($services as $key => $service) { $service_class = $service->getServiceClass(); $service_type = idx($service_types, $service_class); if (!$service_type) { $this->didRejectResult($service); unset($services[$key]); continue; } $service->attachServiceType($service_type); } return $services; } protected function didFilterPage(array $services) { if ($this->needBindings) { $service_phids = mpull($services, 'getPHID'); $bindings = id(new AlmanacBindingQuery()) ->setViewer($this->getViewer()) ->withServicePHIDs($service_phids) ->execute(); $bindings = mgroup($bindings, 'getServicePHID'); foreach ($services as $service) { $service_bindings = idx($bindings, $service->getPHID(), array()); $service->attachBindings($service_bindings); } } return parent::didFilterPage($services); } - public function getPrimaryTableAlias() { + protected function getPrimaryTableAlias() { return 'service'; } public function getOrderableColumns() { return parent::getOrderableColumns() + array( 'name' => array( 'table' => $this->getPrimaryTableAlias(), 'column' => 'name', 'type' => 'string', 'unique' => true, 'reverse' => true, ), ); } protected function getValueMap($cursor, array $keys) { $service = $this->loadCursorObject($cursor); return array( 'id' => $service->getID(), 'name' => $service->getServiceName(), ); } public function getBuiltinOrders() { return array( 'name' => array( 'vector' => array('name'), 'name' => pht('Service Name'), ), ) + parent::getBuiltinOrders(); } } diff --git a/src/applications/files/query/PhabricatorFileSearchEngine.php b/src/applications/files/query/PhabricatorFileSearchEngine.php index 69eeb0e98a..57db0223bd 100644 --- a/src/applications/files/query/PhabricatorFileSearchEngine.php +++ b/src/applications/files/query/PhabricatorFileSearchEngine.php @@ -1,177 +1,177 @@ setKey('authorPHIDs') ->setAliases(array('author', 'authors')) ->setLabel(pht('Authors')), id(new PhabricatorSearchThreeStateField()) ->setKey('explicit') ->setLabel(pht('Upload Source')) ->setOptions( pht('(Show All)'), pht('Show Only Manually Uploaded Files'), pht('Hide Manually Uploaded Files')), id(new PhabricatorSearchDateField()) ->setKey('createdStart') ->setLabel(pht('Created After')), id(new PhabricatorSearchDateField()) ->setKey('createdEnd') ->setLabel(pht('Created Before')), ); } protected function getDefaultFieldOrder() { return array( '...', 'createdStart', 'createdEnd', ); } - public function buildQueryFromParameters(array $map) { + protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); if ($map['authorPHIDs']) { $query->withAuthorPHIDs($map['authorPHIDs']); } if ($map['explicit'] !== null) { $query->showOnlyExplicitUploads($map['explicit']); } if ($map['createdStart']) { $query->withDateCreatedAfter($map['createdStart']); } if ($map['createdEnd']) { $query->withDateCreatedBefore($map['createdEnd']); } return $query; } protected function getURI($path) { return '/file/'.$path; } protected function getBuiltinQueryNames() { $names = array(); if ($this->requireViewer()->isLoggedIn()) { $names['authored'] = pht('Authored'); } $names += array( 'all' => pht('All'), ); return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'all': return $query; case 'authored': $author_phid = array($this->requireViewer()->getPHID()); return $query ->setParameter('authorPHIDs', $author_phid) ->setParameter('explicit', true); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function getRequiredHandlePHIDsForResultList( array $files, PhabricatorSavedQuery $query) { return mpull($files, 'getAuthorPHID'); } protected function renderResultList( array $files, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($files, 'PhabricatorFile'); $request = $this->getRequest(); if ($request) { $highlighted_ids = $request->getStrList('h'); } else { $highlighted_ids = array(); } $viewer = $this->requireViewer(); $highlighted_ids = array_fill_keys($highlighted_ids, true); $list_view = id(new PHUIObjectItemListView()) ->setUser($viewer); foreach ($files as $file) { $id = $file->getID(); $phid = $file->getPHID(); $name = $file->getName(); $file_uri = $this->getApplicationURI("/info/{$phid}/"); $date_created = phabricator_date($file->getDateCreated(), $viewer); $author_phid = $file->getAuthorPHID(); if ($author_phid) { $author_link = $handles[$author_phid]->renderLink(); $uploaded = pht('Uploaded by %s on %s', $author_link, $date_created); } else { $uploaded = pht('Uploaded on %s', $date_created); } $item = id(new PHUIObjectItemView()) ->setObject($file) ->setObjectName("F{$id}") ->setHeader($name) ->setHref($file_uri) ->addAttribute($uploaded) ->addIcon('none', phutil_format_bytes($file->getByteSize())); $ttl = $file->getTTL(); if ($ttl !== null) { $item->addIcon('blame', pht('Temporary')); } if ($file->getIsPartial()) { $item->addIcon('fa-exclamation-triangle orange', pht('Partial')); } if (isset($highlighted_ids[$id])) { $item->setEffect('highlighted'); } $list_view->addItem($item); } $list_view->appendChild(id(new PhabricatorGlobalUploadTargetView()) ->setUser($viewer)); return $list_view; } } diff --git a/src/applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php b/src/applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php index 6d2fe319ae..7555fdc258 100644 --- a/src/applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php +++ b/src/applications/harbormaster/query/HarbormasterBuildPlanSearchEngine.php @@ -1,99 +1,99 @@ setLabel(pht('Status')) ->setKey('status') ->setAliases(array('statuses')) ->setOptions( array( HarbormasterBuildPlan::STATUS_ACTIVE => pht('Active'), HarbormasterBuildPlan::STATUS_DISABLED => pht('Disabled'), )), ); } - public function buildQueryFromParameters(array $map) { + protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); if ($map['status']) { $query->withStatuses($map['status']); } return $query; } protected function getURI($path) { return '/harbormaster/plan/'.$path; } protected function getBuiltinQueryNames() { return array( 'active' => pht('Active Plans'), 'all' => pht('All Plans'), ); } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'active': return $query->setParameter( 'status', array( HarbormasterBuildPlan::STATUS_ACTIVE, )); case 'all': return $query; } return parent::buildSavedQueryFromBuiltin($query_key); } protected function renderResultList( array $plans, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($plans, 'HarbormasterBuildPlan'); $viewer = $this->requireViewer(); $list = new PHUIObjectItemListView(); foreach ($plans as $plan) { $id = $plan->getID(); $item = id(new PHUIObjectItemView()) ->setObjectName(pht('Plan %d', $plan->getID())) ->setHeader($plan->getName()); if ($plan->isDisabled()) { $item->setDisabled(true); } $item->setHref($this->getApplicationURI("plan/{$id}/")); $list->addItem($item); } return $list; } } diff --git a/src/applications/macro/query/PhabricatorMacroSearchEngine.php b/src/applications/macro/query/PhabricatorMacroSearchEngine.php index 6bf41e35bb..5c69716bbf 100644 --- a/src/applications/macro/query/PhabricatorMacroSearchEngine.php +++ b/src/applications/macro/query/PhabricatorMacroSearchEngine.php @@ -1,184 +1,184 @@ needFiles(true); } protected function buildCustomSearchFields() { return array( id(new PhabricatorSearchSelectField()) ->setLabel(pht('Status')) ->setKey('status') ->setOptions(PhabricatorMacroQuery::getStatusOptions()), id(new PhabricatorSearchUsersField()) ->setLabel(pht('Authors')) ->setKey('authorPHIDs') ->setAliases(array('author', 'authors')), id(new PhabricatorSearchTextField()) ->setLabel(pht('Name Contains')) ->setKey('nameLike'), id(new PhabricatorSearchStringListField()) ->setLabel(pht('Exact Names')) ->setKey('names'), id(new PhabricatorSearchSelectField()) ->setLabel(pht('Marked with Flag')) ->setKey('flagColor') ->setDefault('-1') ->setOptions(PhabricatorMacroQuery::getFlagColorsOptions()), id(new PhabricatorSearchDateField()) ->setLabel(pht('Created After')) ->setKey('createdStart'), id(new PhabricatorSearchDateField()) ->setLabel(pht('Created Before')) ->setKey('createdEnd'), ); } protected function getDefaultFieldOrder() { return array( '...', 'createdStart', 'createdEnd', ); } - public function buildQueryFromParameters(array $map) { + protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); if ($map['authorPHIDs']) { $query->withAuthorPHIDs($map['authorPHIDs']); } if ($map['status']) { $query->withStatus($map['status']); } if ($map['names']) { $query->withNames($map['names']); } if (strlen($map['nameLike'])) { $query->withNameLike($map['nameLike']); } if ($map['createdStart']) { $query->withDateCreatedAfter($map['createdStart']); } if ($map['createdEnd']) { $query->withDateCreatedBefore($map['createdEnd']); } if ($map['flagColor'] !== null) { $query->withFlagColor($map['flagColor']); } return $query; } protected function getURI($path) { return '/macro/'.$path; } protected function getBuiltinQueryNames() { $names = array( 'active' => pht('Active'), 'all' => pht('All'), ); if ($this->requireViewer()->isLoggedIn()) { $names['authored'] = pht('Authored'); } return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'active': return $query; case 'all': return $query->setParameter( 'status', PhabricatorMacroQuery::STATUS_ANY); case 'authored': return $query->setParameter( 'authorPHIDs', array($this->requireViewer()->getPHID())); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function renderResultList( array $macros, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($macros, 'PhabricatorFileImageMacro'); $viewer = $this->requireViewer(); $handles = $viewer->loadHandles(mpull($macros, 'getAuthorPHID')); $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD); $pinboard = new PHUIPinboardView(); foreach ($macros as $macro) { $file = $macro->getFile(); $item = new PHUIPinboardItemView(); if ($file) { $item->setImageURI($file->getURIForTransform($xform)); list($x, $y) = $xform->getTransformedDimensions($file); $item->setImageSize($x, $y); } if ($macro->getDateCreated()) { $datetime = phabricator_date($macro->getDateCreated(), $viewer); $item->appendChild( phutil_tag( 'div', array(), pht('Created on %s', $datetime))); } else { // Very old macros don't have a creation date. Rendering something // keeps all the pins at the same height and avoids flow issues. $item->appendChild( phutil_tag( 'div', array(), pht('Created in ages long past'))); } if ($macro->getAuthorPHID()) { $author_handle = $handles[$macro->getAuthorPHID()]; $item->appendChild( pht('Created by %s', $author_handle->renderLink())); } $item->setURI($this->getApplicationURI('/view/'.$macro->getID().'/')); $item->setDisabled($macro->getisDisabled()); $item->setHeader($macro->getName()); $pinboard->addItem($item); } return $pinboard; } } diff --git a/src/applications/people/query/PhabricatorPeopleSearchEngine.php b/src/applications/people/query/PhabricatorPeopleSearchEngine.php index 64b9f9db62..5038e4db5e 100644 --- a/src/applications/people/query/PhabricatorPeopleSearchEngine.php +++ b/src/applications/people/query/PhabricatorPeopleSearchEngine.php @@ -1,253 +1,253 @@ needPrimaryEmail(true) ->needProfileImage(true); } protected function buildCustomSearchFields() { return array( id(new PhabricatorSearchStringListField()) ->setLabel(pht('Usernames')) ->setKey('usernames') ->setAliases(array('username')), id(new PhabricatorSearchTextField()) ->setLabel(pht('Name Contains')) ->setKey('nameLike'), id(new PhabricatorSearchThreeStateField()) ->setLabel(pht('Administrators')) ->setKey('isAdmin') ->setOptions( pht('(Show All)'), pht('Show Only Administrators'), pht('Hide Administrators')), id(new PhabricatorSearchThreeStateField()) ->setLabel(pht('Disabled')) ->setKey('isDisabled') ->setOptions( pht('(Show All)'), pht('Show Only Disabled Users'), pht('Hide Disabled Users')), id(new PhabricatorSearchThreeStateField()) ->setLabel(pht('Bots')) ->setKey('isSystemAgent') ->setOptions( pht('(Show All)'), pht('Show Only Bots'), pht('Hide Bots')), id(new PhabricatorSearchThreeStateField()) ->setLabel(pht('Mailing Lists')) ->setKey('isMailingList') ->setOptions( pht('(Show All)'), pht('Show Only Mailing Lists'), pht('Hide Mailing Lists')), id(new PhabricatorSearchThreeStateField()) ->setLabel(pht('Needs Approval')) ->setKey('needsApproval') ->setOptions( pht('(Show All)'), pht('Show Only Unapproved Users'), pht('Hide Unappproved Users')), id(new PhabricatorSearchDateField()) ->setKey('createdStart') ->setLabel(pht('Joined After')), id(new PhabricatorSearchDateField()) ->setKey('createdEnd') ->setLabel(pht('Joined Before')), ); } protected function getDefaultFieldOrder() { return array( '...', 'createdStart', 'createdEnd', ); } - public function buildQueryFromParameters(array $map) { + protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); $viewer = $this->requireViewer(); // If the viewer can't browse the user directory, restrict the query to // just the user's own profile. This is a little bit silly, but serves to // restrict users from creating a dashboard panel which essentially just // contains a user directory anyway. $can_browse = PhabricatorPolicyFilter::hasCapability( $viewer, $this->getApplication(), PeopleBrowseUserDirectoryCapability::CAPABILITY); if (!$can_browse) { $query->withPHIDs(array($viewer->getPHID())); } if ($map['usernames']) { $query->withUsernames($map['usernames']); } if ($map['nameLike']) { $query->withNameLike($map['nameLike']); } if ($map['isAdmin'] !== null) { $query->withIsAdmin($map['isAdmin']); } if ($map['isDisabled'] !== null) { $query->withIsDisabled($map['isDisabled']); } if ($map['isMailingList'] !== null) { $query->withIsMailingList($map['isMailingList']); } if ($map['isSystemAgent'] !== null) { $query->withIsSystemAgent($map['isSystemAgent']); } if ($map['needsApproval'] !== null) { $query->withIsApproved(!$map['needsApproval']); } if ($map['createdStart']) { $query->withDateCreatedAfter($map['createdStart']); } if ($map['createdEnd']) { $query->withDateCreatedBefore($map['createdEnd']); } return $query; } protected function getURI($path) { return '/people/'.$path; } protected function getBuiltinQueryNames() { $names = array( 'active' => pht('Active'), 'all' => pht('All'), ); $viewer = $this->requireViewer(); if ($viewer->getIsAdmin()) { $names['approval'] = pht('Approval Queue'); } return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'all': return $query; case 'active': return $query ->setParameter('isDisabled', false); case 'approval': return $query ->setParameter('needsApproval', true) ->setParameter('isDisabled', false); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function renderResultList( array $users, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($users, 'PhabricatorUser'); $request = $this->getRequest(); $viewer = $this->requireViewer(); $list = new PHUIObjectItemListView(); $is_approval = ($query->getQueryKey() == 'approval'); foreach ($users as $user) { $primary_email = $user->loadPrimaryEmail(); if ($primary_email && $primary_email->getIsVerified()) { $email = pht('Verified'); } else { $email = pht('Unverified'); } $item = new PHUIObjectItemView(); $item->setHeader($user->getFullName()) ->setHref('/p/'.$user->getUsername().'/') ->addAttribute(phabricator_datetime($user->getDateCreated(), $viewer)) ->addAttribute($email) ->setImageURI($user->getProfileImageURI()); if ($is_approval && $primary_email) { $item->addAttribute($primary_email->getAddress()); } if ($user->getIsDisabled()) { $item->addIcon('fa-ban', pht('Disabled')); } if (!$is_approval) { if (!$user->getIsApproved()) { $item->addIcon('fa-clock-o', pht('Needs Approval')); } } if ($user->getIsAdmin()) { $item->addIcon('fa-star', pht('Admin')); } if ($user->getIsSystemAgent()) { $item->addIcon('fa-desktop', pht('Bot')); } if ($user->getIsMailingList()) { $item->addIcon('fa-envelope-o', pht('Mailing List')); } if ($viewer->getIsAdmin()) { $user_id = $user->getID(); if ($is_approval) { $item->addAction( id(new PHUIListItemView()) ->setIcon('fa-ban') ->setName(pht('Disable')) ->setWorkflow(true) ->setHref($this->getApplicationURI('disapprove/'.$user_id.'/'))); $item->addAction( id(new PHUIListItemView()) ->setIcon('fa-thumbs-o-up') ->setName(pht('Approve')) ->setWorkflow(true) ->setHref($this->getApplicationURI('approve/'.$user_id.'/'))); } } $list->addItem($item); } return $list; } } diff --git a/src/applications/pholio/query/PholioMockSearchEngine.php b/src/applications/pholio/query/PholioMockSearchEngine.php index 8b0f290c25..26b22034a7 100644 --- a/src/applications/pholio/query/PholioMockSearchEngine.php +++ b/src/applications/pholio/query/PholioMockSearchEngine.php @@ -1,133 +1,133 @@ needCoverFiles(true) ->needImages(true) ->needTokenCounts(true); } protected function buildCustomSearchFields() { return array( id(new PhabricatorSearchUsersField()) ->setKey('authorPHIDs') ->setAliases(array('authors')) ->setLabel(pht('Authors')), id(new PhabricatorSearchCheckboxesField()) ->setKey('statuses') ->setLabel(pht('Status')) ->setOptions( id(new PholioMock()) ->getStatuses()), ); } - public function buildQueryFromParameters(array $map) { + protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); if ($map['authorPHIDs']) { $query->withAuthorPHIDs($map['authorPHIDs']); } if ($map['statuses']) { $query->withStatuses($map['statuses']); } return $query; } protected function getURI($path) { return '/pholio/'.$path; } protected function getBuiltinQueryNames() { $names = array( 'open' => pht('Open Mocks'), 'all' => pht('All Mocks'), ); if ($this->requireViewer()->isLoggedIn()) { $names['authored'] = pht('Authored'); } return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'open': return $query->setParameter( 'statuses', array('open')); case 'all': return $query; case 'authored': return $query->setParameter( 'authorPHIDs', array($this->requireViewer()->getPHID())); } return parent::buildSavedQueryFromBuiltin($query_key); } protected function getRequiredHandlePHIDsForResultList( array $mocks, PhabricatorSavedQuery $query) { return mpull($mocks, 'getAuthorPHID'); } protected function renderResultList( array $mocks, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($mocks, 'PholioMock'); $viewer = $this->requireViewer(); $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD); $board = new PHUIPinboardView(); foreach ($mocks as $mock) { $image = $mock->getCoverFile(); $image_uri = $image->getURIForTransform($xform); list($x, $y) = $xform->getTransformedDimensions($image); $header = 'M'.$mock->getID().' '.$mock->getName(); $item = id(new PHUIPinboardItemView()) ->setHeader($header) ->setURI('/M'.$mock->getID()) ->setImageURI($image_uri) ->setImageSize($x, $y) ->setDisabled($mock->isClosed()) ->addIconCount('fa-picture-o', count($mock->getImages())) ->addIconCount('fa-trophy', $mock->getTokenCount()); if ($mock->getAuthorPHID()) { $author_handle = $handles[$mock->getAuthorPHID()]; $datetime = phabricator_date($mock->getDateCreated(), $viewer); $item->appendChild( pht('By %s on %s', $author_handle->renderLink(), $datetime)); } $board->addItem($item); } return $board; } } diff --git a/src/applications/project/query/PhabricatorProjectSearchEngine.php b/src/applications/project/query/PhabricatorProjectSearchEngine.php index 4a384b492a..07ddb512d7 100644 --- a/src/applications/project/query/PhabricatorProjectSearchEngine.php +++ b/src/applications/project/query/PhabricatorProjectSearchEngine.php @@ -1,199 +1,199 @@ needImages(true); } protected function buildCustomSearchFields() { return array( id(new PhabricatorSearchTextField()) ->setLabel(pht('Name')) ->setKey('name'), id(new PhabricatorSearchUsersField()) ->setLabel(pht('Members')) ->setKey('memberPHIDs') ->setAliases(array('member', 'members')), id(new PhabricatorSearchSelectField()) ->setLabel(pht('Status')) ->setKey('status') ->setOptions($this->getStatusOptions()), id(new PhabricatorSearchCheckboxesField()) ->setLabel(pht('Icons')) ->setKey('icons') ->setOptions($this->getIconOptions()), id(new PhabricatorSearchCheckboxesField()) ->setLabel(pht('Colors')) ->setKey('colors') ->setOptions($this->getColorOptions()), ); } - public function buildQueryFromParameters(array $map) { +protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); if (strlen($map['name'])) { $tokens = PhabricatorTypeaheadDatasource::tokenizeString($map['name']); $query->withNameTokens($tokens); } if ($map['memberPHIDs']) { $query->withMemberPHIDs($map['memberPHIDs']); } if ($map['status']) { $status = idx($this->getStatusValues(), $map['status']); if ($status) { $query->withStatus($status); } } if ($map['icons']) { $query->withIcons($map['icons']); } if ($map['colors']) { $query->withColors($map['colors']); } return $query; } protected function getURI($path) { return '/project/'.$path; } protected function getBuiltinQueryNames() { $names = array(); if ($this->requireViewer()->isLoggedIn()) { $names['joined'] = pht('Joined'); } $names['active'] = pht('Active'); $names['all'] = pht('All'); return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); $viewer_phid = $this->requireViewer()->getPHID(); switch ($query_key) { case 'all': return $query; case 'active': return $query ->setParameter('status', 'active'); case 'joined': return $query ->setParameter('memberPHIDs', array($viewer_phid)) ->setParameter('status', 'active'); } return parent::buildSavedQueryFromBuiltin($query_key); } private function getStatusOptions() { return array( 'active' => pht('Show Only Active Projects'), 'archived' => pht('Show Only Archived Projects'), 'all' => pht('Show All Projects'), ); } private function getStatusValues() { return array( 'active' => PhabricatorProjectQuery::STATUS_ACTIVE, 'archived' => PhabricatorProjectQuery::STATUS_ARCHIVED, 'all' => PhabricatorProjectQuery::STATUS_ANY, ); } private function getIconOptions() { $options = array(); foreach (PhabricatorProjectIcon::getIconMap() as $icon => $name) { $options[$icon] = array( id(new PHUIIconView()) ->setIconFont($icon), ' ', $name, ); } return $options; } private function getColorOptions() { $options = array(); foreach (PhabricatorProjectIcon::getColorMap() as $color => $name) { $options[$color] = array( id(new PHUITagView()) ->setType(PHUITagView::TYPE_SHADE) ->setShade($color) ->setName($name), ' ', $name, ); } return $options; } protected function renderResultList( array $projects, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($projects, 'PhabricatorProject'); $viewer = $this->requireViewer(); $handles = $viewer->loadHandles(mpull($projects, 'getPHID')); $list = new PHUIObjectItemListView(); $list->setUser($viewer); $can_edit_projects = id(new PhabricatorPolicyFilter()) ->setViewer($viewer) ->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT)) ->apply($projects); foreach ($projects as $key => $project) { $id = $project->getID(); $tag_list = id(new PHUIHandleTagListView()) ->setSlim(true) ->setHandles(array($handles[$project->getPHID()])); $item = id(new PHUIObjectItemView()) ->setHeader($project->getName()) ->setHref($this->getApplicationURI("view/{$id}/")) ->setImageURI($project->getProfileImageURI()) ->addAttribute($tag_list); if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ARCHIVED) { $item->addIcon('delete-grey', pht('Archived')); $item->setDisabled(true); } $list->addItem($item); } return $list; } } diff --git a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php index e4c1eb14c6..2070586498 100644 --- a/src/applications/repository/query/PhabricatorRepositorySearchEngine.php +++ b/src/applications/repository/query/PhabricatorRepositorySearchEngine.php @@ -1,231 +1,231 @@ needProjectPHIDs(true) ->needCommitCounts(true) ->needMostRecentCommits(true); } protected function buildCustomSearchFields() { return array( id(new PhabricatorSearchStringListField()) ->setLabel(pht('Callsigns')) ->setKey('callsigns'), id(new PhabricatorSearchTextField()) ->setLabel(pht('Name Contains')) ->setKey('name'), id(new PhabricatorSearchSelectField()) ->setLabel(pht('Status')) ->setKey('status') ->setOptions($this->getStatusOptions()), id(new PhabricatorSearchSelectField()) ->setLabel(pht('Hosted')) ->setKey('hosted') ->setOptions($this->getHostedOptions()), id(new PhabricatorSearchCheckboxesField()) ->setLabel(pht('Types')) ->setKey('types') ->setOptions(PhabricatorRepositoryType::getAllRepositoryTypes()), ); } - public function buildQueryFromParameters(array $map) { + protected function buildQueryFromParameters(array $map) { $query = $this->newQuery(); if ($map['callsigns']) { $query->withCallsigns($map['callsigns']); } if ($map['status']) { $status = idx($this->getStatusValues(), $map['status']); if ($status) { $query->withStatus($status); } } if ($map['hosted']) { $hosted = idx($this->getHostedValues(), $map['hosted']); if ($hosted) { $query->withHosted($hosted); } } if ($map['types']) { $query->withTypes($map['types']); } if (strlen($map['name'])) { $query->withNameContains($map['name']); } return $query; } protected function getURI($path) { return '/diffusion/'.$path; } protected function getBuiltinQueryNames() { $names = array( 'active' => pht('Active Repositories'), 'all' => pht('All Repositories'), ); return $names; } public function buildSavedQueryFromBuiltin($query_key) { $query = $this->newSavedQuery(); $query->setQueryKey($query_key); switch ($query_key) { case 'active': return $query->setParameter('status', 'open'); case 'all': return $query; } return parent::buildSavedQueryFromBuiltin($query_key); } private function getStatusOptions() { return array( '' => pht('Active and Inactive Repositories'), 'open' => pht('Active Repositories'), 'closed' => pht('Inactive Repositories'), ); } private function getStatusValues() { return array( '' => PhabricatorRepositoryQuery::STATUS_ALL, 'open' => PhabricatorRepositoryQuery::STATUS_OPEN, 'closed' => PhabricatorRepositoryQuery::STATUS_CLOSED, ); } private function getHostedOptions() { return array( '' => pht('Hosted and Remote Repositories'), 'phabricator' => pht('Hosted Repositories'), 'remote' => pht('Remote Repositories'), ); } private function getHostedValues() { return array( '' => PhabricatorRepositoryQuery::HOSTED_ALL, 'phabricator' => PhabricatorRepositoryQuery::HOSTED_PHABRICATOR, 'remote' => PhabricatorRepositoryQuery::HOSTED_REMOTE, ); } protected function getRequiredHandlePHIDsForResultList( array $repositories, PhabricatorSavedQuery $query) { return array_mergev(mpull($repositories, 'getProjectPHIDs')); } protected function renderResultList( array $repositories, PhabricatorSavedQuery $query, array $handles) { assert_instances_of($repositories, 'PhabricatorRepository'); $viewer = $this->requireViewer(); $list = new PHUIObjectItemListView(); foreach ($repositories as $repository) { $id = $repository->getID(); $item = id(new PHUIObjectItemView()) ->setUser($viewer) ->setHeader($repository->getName()) ->setObjectName('r'.$repository->getCallsign()) ->setHref($this->getApplicationURI($repository->getCallsign().'/')); $commit = $repository->getMostRecentCommit(); if ($commit) { $commit_link = DiffusionView::linkCommit( $repository, $commit->getCommitIdentifier(), $commit->getSummary()); $item->setSubhead($commit_link); $item->setEpoch($commit->getEpoch()); } $item->addIcon( 'none', PhabricatorRepositoryType::getNameForRepositoryType( $repository->getVersionControlSystem())); $size = $repository->getCommitCount(); if ($size) { $history_uri = DiffusionRequest::generateDiffusionURI( array( 'callsign' => $repository->getCallsign(), 'action' => 'history', )); $item->addAttribute( phutil_tag( 'a', array( 'href' => $history_uri, ), pht('%s Commit(s)', new PhutilNumber($size)))); } else { $item->addAttribute(pht('No Commits')); } $project_handles = array_select_keys( $handles, $repository->getProjectPHIDs()); if ($project_handles) { $item->addAttribute( id(new PHUIHandleTagListView()) ->setSlim(true) ->setHandles($project_handles)); } if (!$repository->isTracked()) { $item->setDisabled(true); $item->addIcon('disable-grey', pht('Inactive')); } $list->addItem($item); } return $list; } protected function willUseSavedQuery(PhabricatorSavedQuery $saved) { $project_phids = $saved->getParameter('projectPHIDs', array()); $old = $saved->getParameter('projects', array()); foreach ($old as $phid) { $project_phids[] = $phid; } $any = $saved->getParameter('anyProjectPHIDs', array()); foreach ($any as $project) { $project_phids[] = 'any('.$project.')'; } $saved->setParameter('projectPHIDs', $project_phids); } }