diff --git a/src/applications/home/menuitem/PhabricatorHomeLauncherProfileMenuItem.php b/src/applications/home/menuitem/PhabricatorHomeLauncherProfileMenuItem.php index dbf1586366..ef66fe332e 100644 --- a/src/applications/home/menuitem/PhabricatorHomeLauncherProfileMenuItem.php +++ b/src/applications/home/menuitem/PhabricatorHomeLauncherProfileMenuItem.php @@ -1,70 +1,65 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); + } + public function getMenuItemTypeIcon() { return 'fa-ellipsis-h'; } public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { return false; } public function canMakeDefault( PhabricatorProfileMenuItemConfiguration $config) { return false; } - public function getDisplayName( - PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); - } - public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); $name = $this->getDisplayName($config); $icon = 'fa-ellipsis-h'; $uri = '/applications/'; $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon($icon); return array( $item, ); } } diff --git a/src/applications/home/menuitem/PhabricatorHomeProfileMenuItem.php b/src/applications/home/menuitem/PhabricatorHomeProfileMenuItem.php index a002b59da5..c150b81035 100644 --- a/src/applications/home/menuitem/PhabricatorHomeProfileMenuItem.php +++ b/src/applications/home/menuitem/PhabricatorHomeProfileMenuItem.php @@ -1,73 +1,68 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); + } + public function getMenuItemTypeIcon() { return 'fa-home'; } public function canMakeDefault( PhabricatorProfileMenuItemConfiguration $config) { return true; } - public function getDisplayName( - PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); - } - public function newPageContent( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); return id(new PHUIHomeView()) ->setViewer($viewer); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); $name = $this->getDisplayName($config); $icon = 'fa-home'; $uri = $this->getItemViewURI($config); $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon($icon); return array( $item, ); } } diff --git a/src/applications/people/menuitem/PhabricatorPeopleBadgesProfileMenuItem.php b/src/applications/people/menuitem/PhabricatorPeopleBadgesProfileMenuItem.php index 71f3aa1392..6f5e1eb953 100644 --- a/src/applications/people/menuitem/PhabricatorPeopleBadgesProfileMenuItem.php +++ b/src/applications/people/menuitem/PhabricatorPeopleBadgesProfileMenuItem.php @@ -1,59 +1,54 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); } - public function getDisplayName( + public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); + return true; } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $user = $config->getProfileObject(); $id = $user->getID(); $item = $this->newItemView() ->setURI("/people/badges/{$id}/") ->setName($this->getDisplayName($config)) ->setIcon('fa-trophy'); return array( $item, ); } } diff --git a/src/applications/people/menuitem/PhabricatorPeopleCommitsProfileMenuItem.php b/src/applications/people/menuitem/PhabricatorPeopleCommitsProfileMenuItem.php index b6c1c446cc..95b31d4539 100644 --- a/src/applications/people/menuitem/PhabricatorPeopleCommitsProfileMenuItem.php +++ b/src/applications/people/menuitem/PhabricatorPeopleCommitsProfileMenuItem.php @@ -1,59 +1,54 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); } - public function getDisplayName( + public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); + return true; } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $user = $config->getProfileObject(); $id = $user->getID(); $item = $this->newItemView() ->setURI("/people/commits/{$id}/") ->setName($this->getDisplayName($config)) ->setIcon('fa-code'); return array( $item, ); } } diff --git a/src/applications/people/menuitem/PhabricatorPeopleDetailsProfileMenuItem.php b/src/applications/people/menuitem/PhabricatorPeopleDetailsProfileMenuItem.php index 61508ff515..73624321aa 100644 --- a/src/applications/people/menuitem/PhabricatorPeopleDetailsProfileMenuItem.php +++ b/src/applications/people/menuitem/PhabricatorPeopleDetailsProfileMenuItem.php @@ -1,56 +1,51 @@ getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); + $default = $this->getDefaultName(); + return $this->getNameFromConfig($config, $default); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $user = $config->getProfileObject(); $uri = urisprintf( '/p/%s/', $user->getUsername()); $item = $this->newItemView() ->setURI($uri) ->setName(pht('Profile')) ->setIcon('fa-user'); return array( $item, ); } } diff --git a/src/applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php b/src/applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php index 43d2271a79..0399698728 100644 --- a/src/applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php +++ b/src/applications/people/menuitem/PhabricatorPeopleManageProfileMenuItem.php @@ -1,59 +1,54 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); } - public function getDisplayName( + public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); + return false; } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $user = $config->getProfileObject(); $id = $user->getID(); $item = $this->newItemView() ->setURI("/people/manage/{$id}/") ->setName($this->getDisplayName($config)) ->setIcon('fa-gears'); return array( $item, ); } } diff --git a/src/applications/people/menuitem/PhabricatorPeoplePictureProfileMenuItem.php b/src/applications/people/menuitem/PhabricatorPeoplePictureProfileMenuItem.php index 3e3fc62bf0..8c66de3f17 100644 --- a/src/applications/people/menuitem/PhabricatorPeoplePictureProfileMenuItem.php +++ b/src/applications/people/menuitem/PhabricatorPeoplePictureProfileMenuItem.php @@ -1,49 +1,49 @@ getDefaultName(); } - public function getDisplayName( + public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { - return $this->getDefaultName(); + return false; } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array(); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $user = $config->getProfileObject(); $picture = $user->getProfileImageURI(); $name = $user->getUsername(); $item = $this->newItemView() ->setDisabled($user->getIsDisabled()); $item->newProfileImage($picture); return array( $item, ); } } diff --git a/src/applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php b/src/applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php index cfa760fcd6..23cfab05c5 100644 --- a/src/applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php +++ b/src/applications/people/menuitem/PhabricatorPeopleRevisionsProfileMenuItem.php @@ -1,59 +1,54 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); } - public function getDisplayName( + public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); + return true; } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $user = $config->getProfileObject(); $id = $user->getID(); $item = $this->newItemView() ->setURI("/people/revisions/{$id}/") ->setName($this->getDisplayName($config)) ->setIcon('fa-gear'); return array( $item, ); } } diff --git a/src/applications/people/menuitem/PhabricatorPeopleTasksProfileMenuItem.php b/src/applications/people/menuitem/PhabricatorPeopleTasksProfileMenuItem.php index 5dea58cb29..4b72bcc879 100644 --- a/src/applications/people/menuitem/PhabricatorPeopleTasksProfileMenuItem.php +++ b/src/applications/people/menuitem/PhabricatorPeopleTasksProfileMenuItem.php @@ -1,59 +1,54 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); } - public function getDisplayName( + public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); + return true; } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $user = $config->getProfileObject(); $id = $user->getID(); $item = $this->newItemView() ->setURI("/people/tasks/{$id}/") ->setName($this->getDisplayName($config)) ->setIcon('fa-anchor'); return array( $item, ); } } diff --git a/src/applications/project/menuitem/PhabricatorProjectDetailsProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectDetailsProfileMenuItem.php index a3021e0239..6e206de567 100644 --- a/src/applications/project/menuitem/PhabricatorProjectDetailsProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectDetailsProfileMenuItem.php @@ -1,73 +1,68 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); + } + public function getMenuItemTypeIcon() { return 'fa-file-text-o'; } public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { return false; } public function canMakeDefault( PhabricatorProfileMenuItemConfiguration $config) { return true; } - public function getDisplayName( - PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); - } - public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $project = $config->getProfileObject(); $id = $project->getID(); $name = $project->getName(); $icon = $project->getDisplayIconIcon(); $uri = "/project/profile/{$id}/"; $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon($icon); return array( $item, ); } } diff --git a/src/applications/project/menuitem/PhabricatorProjectManageProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectManageProfileMenuItem.php index 9b8a769318..ba723ea5be 100644 --- a/src/applications/project/menuitem/PhabricatorProjectManageProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectManageProfileMenuItem.php @@ -1,73 +1,68 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); + } + public function getMenuItemTypeIcon() { return 'fa-cog'; } public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { return false; } public function canMakeDefault( PhabricatorProfileMenuItemConfiguration $config) { return true; } - public function getDisplayName( - PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); - } - public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $project = $config->getProfileObject(); $id = $project->getID(); $name = $this->getDisplayName($config); $icon = 'fa-gears'; $uri = "/project/manage/{$id}/"; $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon($icon); return array( $item, ); } } diff --git a/src/applications/project/menuitem/PhabricatorProjectMembersProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectMembersProfileMenuItem.php index 11a57d3a5b..777054547d 100644 --- a/src/applications/project/menuitem/PhabricatorProjectMembersProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectMembersProfileMenuItem.php @@ -1,63 +1,58 @@ getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } + $default = $this->getDefaultName(); + return $this->getNameFromConfig($config, $default); + } - return $this->getDefaultName(); + public function getMenuItemTypeIcon() { + return 'fa-users'; } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $project = $config->getProfileObject(); $id = $project->getID(); $name = $this->getDisplayName($config); $icon = 'fa-group'; $uri = "/project/members/{$id}/"; $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon($icon); return array( $item, ); } } diff --git a/src/applications/project/menuitem/PhabricatorProjectPictureProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectPictureProfileMenuItem.php index 5a58b3af41..3330a94944 100644 --- a/src/applications/project/menuitem/PhabricatorProjectPictureProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectPictureProfileMenuItem.php @@ -1,51 +1,51 @@ getDefaultName(); + } + public function getMenuItemTypeIcon() { return 'fa-image'; } public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { return false; } - public function getDisplayName( - PhabricatorProfileMenuItemConfiguration $config) { - return $this->getDefaultName(); - } - public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array(); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $project = $config->getProfileObject(); $picture = $project->getProfileImageURI(); $item = $this->newItemView() ->setDisabled($project->isArchived()); $item->newProfileImage($picture); return array( $item, ); } } diff --git a/src/applications/project/menuitem/PhabricatorProjectPointsProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectPointsProfileMenuItem.php index 20c8d2985b..f04f7e6361 100644 --- a/src/applications/project/menuitem/PhabricatorProjectPointsProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectPointsProfileMenuItem.php @@ -1,177 +1,177 @@ getDefaultName(); + } + public function shouldEnableForObject($object) { $viewer = $this->getViewer(); // Only render this element for milestones. if (!$object->isMilestone()) { return false; } // Don't show if points aren't configured. if (!ManiphestTaskPoints::getIsEnabled()) { return false; } // Points are only available if Maniphest is installed. $class = 'PhabricatorManiphestApplication'; if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { return false; } return true; } - public function getDisplayName( - PhabricatorProfileMenuItemConfiguration $config) { - return $this->getDefaultName(); - } - public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorInstructionsEditField()) ->setValue( pht( 'This is a progress bar which shows how many points of work '. 'are complete within the milestone. It has no configurable '. 'settings.')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); $project = $config->getProfileObject(); $limit = 250; $tasks = id(new ManiphestTaskQuery()) ->setViewer($viewer) ->withEdgeLogicPHIDs( PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, PhabricatorQueryConstraint::OPERATOR_AND, array($project->getPHID())) ->setLimit($limit + 1) ->execute(); $error = array(); if (count($tasks) > $limit) { $error[] = pht( 'Too many tasks (%s).', new PhutilNumber($limit)); } if (!$tasks) { $error[] = pht('This milestone has no tasks.'); } $statuses = array(); $points_done = 0; $points_total = 0; $no_points = 0; foreach ($tasks as $task) { $points = $task->getPoints(); if ($points === null) { $no_points++; continue; } if (!$points) { continue; } $status = $task->getStatus(); if (empty($statuses[$status])) { $statuses[$status] = 0; } $statuses[$status] += $points; if (ManiphestTaskStatus::isClosedStatus($status)) { $points_done += $points; } $points_total += $points; } if ($no_points == count($tasks)) { $error[] = pht('No tasks have points assigned.'); } if (!$points_total) { $error[] = pht('No tasks have positive points.'); } $label = pht( '%s of %s %s', new PhutilNumber($points_done), new PhutilNumber($points_total), ManiphestTaskPoints::getPointsLabel()); $bar = id(new PHUISegmentBarView()) ->setLabel($label); $map = ManiphestTaskStatus::getTaskStatusMap(); $statuses = array_select_keys($statuses, array_keys($map)); foreach ($statuses as $status => $points) { if (!$points) { continue; } if (!ManiphestTaskStatus::isClosedStatus($status)) { continue; } $color = ManiphestTaskStatus::getStatusColor($status); if (!$color) { $color = 'sky'; } $tooltip = pht( '%s %s', new PhutilNumber($points), ManiphestTaskStatus::getTaskStatusName($status)); $bar->newSegment() ->setWidth($points / $points_total) ->setColor($color) ->setTooltip($tooltip); } if ($error) { $bar->setLabel(head($error)); } $bar = phutil_tag( 'div', array( 'class' => 'phui-profile-segment-bar', ), $bar); $item = $this->newItemView(); $item->newProgressBar($bar); return array( $item, ); } } diff --git a/src/applications/project/menuitem/PhabricatorProjectReportsProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectReportsProfileMenuItem.php index 8639b6d72c..9617dd2f3d 100644 --- a/src/applications/project/menuitem/PhabricatorProjectReportsProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectReportsProfileMenuItem.php @@ -1,85 +1,80 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); + } + public function getMenuItemTypeIcon() { return 'fa-area-chart'; } public function canMakeDefault( PhabricatorProfileMenuItemConfiguration $config) { return true; } public function shouldEnableForObject($object) { $viewer = $this->getViewer(); if (!PhabricatorEnv::getEnvConfig('phabricator.show-prototypes')) { return false; } $class = 'PhabricatorManiphestApplication'; if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { return false; } $class = 'PhabricatorFactApplication'; if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { return false; } return true; } - public function getDisplayName( - PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); - } - public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $project = $config->getProfileObject(); $id = $project->getID(); $uri = $project->getReportsURI(); $name = $this->getDisplayName($config); $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon('fa-area-chart'); return array( $item, ); } } diff --git a/src/applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php index b1782e8f1c..6c8a94395e 100644 --- a/src/applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php @@ -1,70 +1,65 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); + } + public function getMenuItemTypeIcon() { return 'fa-sitemap'; } public function shouldEnableForObject($object) { if ($object->isMilestone()) { return false; } return true; } - public function getDisplayName( - PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); - } - public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $project = $config->getProfileObject(); $id = $project->getID(); $name = $this->getDisplayName($config); $icon = 'fa-sitemap'; $uri = "/project/subprojects/{$id}/"; $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon($icon); return array( $item, ); } } diff --git a/src/applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php b/src/applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php index 34152f85e7..20cda3b4f5 100644 --- a/src/applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php +++ b/src/applications/project/menuitem/PhabricatorProjectWorkboardProfileMenuItem.php @@ -1,77 +1,72 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); + } + public function getMenuItemTypeIcon() { return 'fa-columns'; } public function canMakeDefault( PhabricatorProfileMenuItemConfiguration $config) { return true; } public function shouldEnableForObject($object) { $viewer = $this->getViewer(); // Workboards are only available if Maniphest is installed. $class = 'PhabricatorManiphestApplication'; if (!PhabricatorApplication::isClassInstalledForViewer($class, $viewer)) { return false; } return true; } - public function getDisplayName( - PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); - } - public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) ->setValue($config->getMenuItemProperty('name')), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $project = $config->getProfileObject(); $id = $project->getID(); $uri = $project->getWorkboardURI(); $name = $this->getDisplayName($config); $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon('fa-columns'); return array( $item, ); } } diff --git a/src/applications/search/menuitem/PhabricatorApplicationProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorApplicationProfileMenuItem.php index 040b877368..2007f55034 100644 --- a/src/applications/search/menuitem/PhabricatorApplicationProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorApplicationProfileMenuItem.php @@ -1,147 +1,138 @@ getApplication($config); if (!$application) { return pht('(Restricted/Invalid Application)'); } - $name = $this->getName($config); - if (strlen($name)) { - return $name; - } - - return $application->getName(); + $default = $application->getName(); + return $this->getNameFromConfig($config, $default); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorDatasourceEditField()) ->setKey(self::FIELD_APPLICATION) ->setLabel(pht('Application')) ->setDatasource(new PhabricatorApplicationDatasource()) ->setIsRequired(true) ->setSingleValue($config->getMenuItemProperty('application')), id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) - ->setValue($this->getName($config)), + ->setValue($this->getNameFromConfig($config)), ); } - private function getName( - PhabricatorProfileMenuItemConfiguration $config) { - return $config->getMenuItemProperty('name'); - } - private function getApplication( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); $phid = $config->getMenuItemProperty('application'); $apps = id(new PhabricatorApplicationQuery()) ->setViewer($viewer) ->withPHIDs(array($phid)) ->execute(); return head($apps); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); $app = $this->getApplication($config); if (!$app) { return array(); } $is_installed = PhabricatorApplication::isClassInstalledForViewer( get_class($app), $viewer); if (!$is_installed) { return array(); } $item = $this->newItemView() ->setURI($app->getApplicationURI()) ->setName($this->getDisplayName($config)) ->setIcon($app->getIcon()); // Don't show tooltip if they've set a custom name $name = $config->getMenuItemProperty('name'); if (!strlen($name)) { $item->setTooltip($app->getShortDescription()); } return array( $item, ); } public function validateTransactions( PhabricatorProfileMenuItemConfiguration $config, $field_key, $value, array $xactions) { $viewer = $this->getViewer(); $errors = array(); if ($field_key == self::FIELD_APPLICATION) { if ($this->isEmptyTransaction($value, $xactions)) { $errors[] = $this->newRequiredError( pht('You must choose an application.'), $field_key); } foreach ($xactions as $xaction) { $new = $xaction['new']; if (!$new) { continue; } if ($new === $value) { continue; } $applications = id(new PhabricatorApplicationQuery()) ->setViewer($viewer) ->withPHIDs(array($new)) ->execute(); if (!$applications) { $errors[] = $this->newInvalidError( pht( 'Application "%s" is not a valid application which you have '. 'permission to see.', $new), $xaction['xaction']); } } } return $errors; } } diff --git a/src/applications/search/menuitem/PhabricatorConpherenceProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorConpherenceProfileMenuItem.php index 591dee8604..1210c7eb18 100644 --- a/src/applications/search/menuitem/PhabricatorConpherenceProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorConpherenceProfileMenuItem.php @@ -1,176 +1,167 @@ isInstalled()) { return false; } return true; } public function attachConpherence($conpherence) { $this->conpherence = $conpherence; return $this; } public function getConpherence() { $conpherence = $this->conpherence; if (!$conpherence) { return null; } return $conpherence; } public function willGetMenuItemViewList(array $items) { $viewer = $this->getViewer(); $room_phids = array(); foreach ($items as $item) { $room_phids[] = $item->getMenuItemProperty('conpherence'); } $rooms = id(new ConpherenceThreadQuery()) ->setViewer($viewer) ->withPHIDs($room_phids) ->needProfileImage(true) ->execute(); $rooms = mpull($rooms, null, 'getPHID'); foreach ($items as $item) { $room_phid = $item->getMenuItemProperty('conpherence'); $room = idx($rooms, $room_phid, null); $item->getMenuItem()->attachConpherence($room); } } public function getDisplayName( PhabricatorProfileMenuItemConfiguration $config) { $room = $this->getConpherence($config); if (!$room) { return pht('(Restricted/Invalid Conpherence)'); } - $name = $this->getName($config); - if (strlen($name)) { - return $name; - } - - return $room->getTitle(); + $default = $room->getTitle(); + return $this->getNameFromConfig($config, $default); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorDatasourceEditField()) ->setKey(self::FIELD_CONPHERENCE) ->setLabel(pht('Conpherence Room')) ->setDatasource(new ConpherenceThreadDatasource()) ->setIsRequired(true) ->setSingleValue($config->getMenuItemProperty('conpherence')), id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) - ->setValue($this->getName($config)), + ->setValue($this->getNameFromConfig($config)), ); } - private function getName( - PhabricatorProfileMenuItemConfiguration $config) { - return $config->getMenuItemProperty('name'); - } - protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); $room = $this->getConpherence($config); if (!$room) { return array(); } $participants = $room->getParticipants(); $viewer_phid = $viewer->getPHID(); $unread_count = null; if (isset($participants[$viewer_phid])) { $data = $room->getDisplayData($viewer); $unread_count = $data['unread_count']; } $item = $this->newItemView() ->setURI('/'.$room->getMonogram()) ->setName($this->getDisplayName($config)) ->setIcon('fa-comments'); if ($unread_count) { $item->newCount($unread_count); } return array( $item, ); } public function validateTransactions( PhabricatorProfileMenuItemConfiguration $config, $field_key, $value, array $xactions) { $viewer = $this->getViewer(); $errors = array(); if ($field_key == self::FIELD_CONPHERENCE) { if ($this->isEmptyTransaction($value, $xactions)) { $errors[] = $this->newRequiredError( pht('You must choose a room.'), $field_key); } foreach ($xactions as $xaction) { $new = $xaction['new']; if (!$new) { continue; } if ($new === $value) { continue; } $rooms = id(new ConpherenceThreadQuery()) ->setViewer($viewer) ->withPHIDs(array($new)) ->execute(); if (!$rooms) { $errors[] = $this->newInvalidError( pht( 'Room "%s" is not a valid room which you have '. 'permission to see.', $new), $xaction['xaction']); } } } return $errors; } } diff --git a/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php index 9d89c52ff8..7fbfc741b1 100644 --- a/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorDashboardProfileMenuItem.php @@ -1,250 +1,239 @@ dashboard = $dashboard; return $this; } private function getDashboard() { return $this->dashboard; } public function getAffectedObjectPHIDs( PhabricatorProfileMenuItemConfiguration $config) { return array( $this->getDashboardPHID($config), ); } - public function newPageContent( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); $dashboard_phid = $this->getDashboardPHID($config); // Reload the dashboard to attach panels, which we need for rendering. $dashboard = id(new PhabricatorDashboardQuery()) ->setViewer($viewer) ->withPHIDs(array($dashboard_phid)) ->executeOne(); if (!$dashboard) { return $this->newEmptyView( pht('Invalid Dashboard'), pht('This dashboard is invalid and could not be loaded.')); } if ($dashboard->isArchived()) { return $this->newEmptyView( pht('Archived Dashboard'), pht('This dashboard has been archived.')); } $engine = id(new PhabricatorDashboardRenderingEngine()) ->setViewer($viewer) ->setDashboard($dashboard); return $engine->renderDashboard(); } public function willGetMenuItemViewList(array $items) { $viewer = $this->getViewer(); $dashboard_phids = array(); foreach ($items as $item) { $dashboard_phids[] = $this->getDashboardPHID($item); } $dashboards = id(new PhabricatorDashboardQuery()) ->setViewer($viewer) ->withPHIDs($dashboard_phids) ->execute(); $handles = $viewer->loadHandles($dashboard_phids); $dashboards = mpull($dashboards, null, 'getPHID'); foreach ($items as $item) { $dashboard_phid = $this->getDashboardPHID($item); $dashboard = idx($dashboards, $dashboard_phid, null); $menu_item = $item->getMenuItem(); $menu_item ->attachDashboard($dashboard) ->setDashboardHandle($handles[$dashboard_phid]); } } public function getDisplayName( PhabricatorProfileMenuItemConfiguration $config) { $dashboard = $this->getDashboard(); - if (!$dashboard) { if ($this->getDashboardHandle()->getPolicyFiltered()) { return pht('Restricted Dashboard'); - } else { - return pht('Invalid Dashboard'); } + return pht('Invalid Dashboard'); } if ($dashboard->isArchived()) { return pht('Archived Dashboard'); } - if (strlen($this->getName($config))) { - return $this->getName($config); - } else { - return $dashboard->getName(); - } + $default = $dashboard->getName(); + return $this->getNameFromConfig($config, $default); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorDatasourceEditField()) ->setKey(self::FIELD_DASHBOARD) ->setLabel(pht('Dashboard')) ->setIsRequired(true) ->setDatasource(new PhabricatorDashboardDatasource()) ->setSingleValue($this->getDashboardPHID($config)), id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) - ->setValue($this->getName($config)), + ->setValue($this->getNameFromConfig($config)), ); } - private function getName( - PhabricatorProfileMenuItemConfiguration $config) { - return $config->getMenuItemProperty('name'); - } - protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $is_disabled = true; $action_uri = null; $dashboard = $this->getDashboard(); if ($dashboard) { if ($dashboard->isArchived()) { $icon = 'fa-ban'; $name = $this->getDisplayName($config); } else { $icon = $dashboard->getIcon(); $name = $this->getDisplayName($config); $is_disabled = false; $action_uri = $dashboard->getURI(); } } else { $icon = 'fa-ban'; if ($this->getDashboardHandle()->getPolicyFiltered()) { $name = pht('Restricted Dashboard'); } else { $name = pht('Invalid Dashboard'); } } $uri = $this->getItemViewURI($config); $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon($icon) ->setDisabled($is_disabled); if ($action_uri) { $item->newAction($action_uri); } return array( $item, ); } public function validateTransactions( PhabricatorProfileMenuItemConfiguration $config, $field_key, $value, array $xactions) { $viewer = $this->getViewer(); $errors = array(); if ($field_key == self::FIELD_DASHBOARD) { if ($this->isEmptyTransaction($value, $xactions)) { $errors[] = $this->newRequiredError( pht('You must choose a dashboard.'), $field_key); } foreach ($xactions as $xaction) { $new = $xaction['new']; if (!$new) { continue; } if ($new === $value) { continue; } $dashboards = id(new PhabricatorDashboardQuery()) ->setViewer($viewer) ->withPHIDs(array($new)) ->execute(); if (!$dashboards) { $errors[] = $this->newInvalidError( pht( 'Dashboard "%s" is not a valid dashboard which you have '. 'permission to see.', $new), $xaction['xaction']); } } } return $errors; } private function getDashboardPHID( PhabricatorProfileMenuItemConfiguration $config) { return $config->getMenuItemProperty('dashboardPHID'); } private function getDashboardHandle() { return $this->dashboardHandle; } private function setDashboardHandle(PhabricatorObjectHandle $handle) { $this->dashboardHandle = $handle; return $this; } } diff --git a/src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php index 71e3d7e8a5..15f7bb56af 100644 --- a/src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorEditEngineProfileMenuItem.php @@ -1,177 +1,170 @@ form = $form; return $this; } public function getForm() { $form = $this->form; if (!$form) { return null; } return $form; } public function willGetMenuItemViewList(array $items) { $viewer = $this->getViewer(); $engines = PhabricatorEditEngine::getAllEditEngines(); $engine_keys = array_keys($engines); $forms = id(new PhabricatorEditEngineConfigurationQuery()) ->setViewer($viewer) ->withEngineKeys($engine_keys) ->withIsDisabled(false) ->execute(); $form_engines = mgroup($forms, 'getEngineKey'); $form_ids = $forms; $builtin_map = array(); foreach ($form_engines as $engine_key => $form_engine) { $builtin_map[$engine_key] = mpull($form_engine, null, 'getBuiltinKey'); } foreach ($items as $item) { $key = $item->getMenuItemProperty('formKey'); list($engine_key, $form_key) = PhabricatorEditEngine::splitFullKey($key); if (is_numeric($form_key)) { $form = idx($form_ids, $form_key, null); $item->getMenuItem()->attachForm($form); } else if (isset($builtin_map[$engine_key][$form_key])) { $form = $builtin_map[$engine_key][$form_key]; $item->getMenuItem()->attachForm($form); } } } public function getDisplayName( PhabricatorProfileMenuItemConfiguration $config) { $form = $this->getForm(); if (!$form) { return pht('(Restricted/Invalid Form)'); } - if (strlen($this->getName($config))) { - return $this->getName($config); - } else { - return $form->getName(); - } + + $default = $form->getName(); + return $this->getNameFromConfig($config, $default); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorDatasourceEditField()) ->setKey(self::FIELD_FORM) ->setLabel(pht('Form')) ->setIsRequired(true) ->setDatasource(new PhabricatorEditEngineDatasource()) ->setSingleValue($config->getMenuItemProperty('formKey')), id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) - ->setValue($this->getName($config)), + ->setValue($this->getNameFromConfig($config)), ); } - private function getName( - PhabricatorProfileMenuItemConfiguration $config) { - return $config->getMenuItemProperty('name'); - } - protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $form = $this->getForm(); if (!$form) { return array(); } $icon = $form->getIcon(); $name = $this->getDisplayName($config); $uri = $form->getCreateURI(); if ($uri === null) { return array(); } $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon($icon); return array( $item, ); } public function validateTransactions( PhabricatorProfileMenuItemConfiguration $config, $field_key, $value, array $xactions) { $viewer = $this->getViewer(); $errors = array(); if ($field_key == self::FIELD_FORM) { if ($this->isEmptyTransaction($value, $xactions)) { $errors[] = $this->newRequiredError( pht('You must choose a form.'), $field_key); } foreach ($xactions as $xaction) { $new = $xaction['new']; if (!$new) { continue; } if ($new === $value) { continue; } list($engine_key, $form_key) = PhabricatorEditEngine::splitFullKey( $new); $forms = id(new PhabricatorEditEngineConfigurationQuery()) ->setViewer($viewer) ->withEngineKeys(array($engine_key)) ->withIdentifiers(array($form_key)) ->execute(); if (!$forms) { $errors[] = $this->newInvalidError( pht( 'Form "%s" is not a valid form which you have permission to '. 'see.', $new), $xaction['xaction']); } } } return $errors; } } diff --git a/src/applications/search/menuitem/PhabricatorLabelProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorLabelProfileMenuItem.php index a152da5898..a48e9a56ca 100644 --- a/src/applications/search/menuitem/PhabricatorLabelProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorLabelProfileMenuItem.php @@ -1,75 +1,68 @@ getLabelName($config); + return $this->getNameFromConfig($config); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey(self::FIELD_NAME) ->setLabel(pht('Name')) ->setIsRequired(true) - ->setValue($this->getLabelName($config)), + ->setValue($this->getNameFromConfig($config)), ); } - private function getLabelName( - PhabricatorProfileMenuItemConfiguration $config) { - return $config->getMenuItemProperty('name'); - } - protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { - $name = $this->getLabelName($config); - $item = $this->newItemView() - ->setName($name) + ->setName($this->getNameFromConfig($config)) ->setIsLabel(true); return array( $item, ); } public function validateTransactions( PhabricatorProfileMenuItemConfiguration $config, $field_key, $value, array $xactions) { $viewer = $this->getViewer(); $errors = array(); if ($field_key == self::FIELD_NAME) { if ($this->isEmptyTransaction($value, $xactions)) { $errors[] = $this->newRequiredError( pht('You must choose a label name.'), $field_key); } } return $errors; } } diff --git a/src/applications/search/menuitem/PhabricatorLinkProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorLinkProfileMenuItem.php index bba3b01060..9a64edb090 100644 --- a/src/applications/search/menuitem/PhabricatorLinkProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorLinkProfileMenuItem.php @@ -1,151 +1,146 @@ getLinkName($config); + return $this->getNameFromConfig($config); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey(self::FIELD_NAME) ->setLabel(pht('Name')) ->setIsRequired(true) - ->setValue($this->getLinkName($config)), + ->setValue($this->getNameFromConfig($config)), id(new PhabricatorTextEditField()) ->setKey(self::FIELD_URI) ->setLabel(pht('URI')) ->setIsRequired(true) ->setValue($this->getLinkURI($config)), id(new PhabricatorTextEditField()) ->setKey(self::FIELD_TOOLTIP) ->setLabel(pht('Tooltip')) ->setValue($this->getLinkTooltip($config)), id(new PhabricatorIconSetEditField()) ->setKey('icon') ->setLabel(pht('Icon')) ->setIconSet(new PhabricatorProfileMenuItemIconSet()) ->setValue($this->getLinkIcon($config)), ); } - private function getLinkName( - PhabricatorProfileMenuItemConfiguration $config) { - return $config->getMenuItemProperty('name'); - } - private function getLinkIcon( PhabricatorProfileMenuItemConfiguration $config) { return $config->getMenuItemProperty('icon', 'link'); } private function getLinkURI( PhabricatorProfileMenuItemConfiguration $config) { return $config->getMenuItemProperty('uri'); } private function getLinkTooltip( PhabricatorProfileMenuItemConfiguration $config) { return $config->getMenuItemProperty('tooltip'); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $icon = $this->getLinkIcon($config); - $name = $this->getLinkName($config); + $name = $this->getNameFromConfig($config); $uri = $this->getLinkURI($config); $tooltip = $this->getLinkTooltip($config); $icon_object = id(new PhabricatorProfileMenuItemIconSet()) ->getIcon($icon); if ($icon_object) { $icon_class = $icon_object->getIcon(); } else { $icon_class = 'fa-link'; } $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon($icon_class) ->setTooltip($tooltip) ->setIsExternalLink(true); return array( $item, ); } public function validateTransactions( PhabricatorProfileMenuItemConfiguration $config, $field_key, $value, array $xactions) { $viewer = $this->getViewer(); $errors = array(); if ($field_key == self::FIELD_NAME) { if ($this->isEmptyTransaction($value, $xactions)) { $errors[] = $this->newRequiredError( pht('You must choose a link name.'), $field_key); } } if ($field_key == self::FIELD_URI) { if ($this->isEmptyTransaction($value, $xactions)) { $errors[] = $this->newRequiredError( pht('You must choose a URI to link to.'), $field_key); } foreach ($xactions as $xaction) { $new = $xaction['new']; if (!$new) { continue; } if ($new === $value) { continue; } if (!PhabricatorEnv::isValidURIForLink($new)) { $errors[] = $this->newInvalidError( pht( 'URI "%s" is not a valid link URI. It should be a full, valid '. 'URI beginning with a protocol like "%s".', $new, 'https://'), $xaction['xaction']); } } } return $errors; } } diff --git a/src/applications/search/menuitem/PhabricatorManageProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorManageProfileMenuItem.php index 89ac4a5633..06a053c9b4 100644 --- a/src/applications/search/menuitem/PhabricatorManageProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorManageProfileMenuItem.php @@ -1,76 +1,71 @@ getDefaultName(); + return $this->getNameFromConfig($config, $default); + } + public function getMenuItemTypeIcon() { return 'fa-pencil'; } public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { return false; } public function canMakeDefault( PhabricatorProfileMenuItemConfiguration $config) { return false; } - public function getDisplayName( - PhabricatorProfileMenuItemConfiguration $config) { - $name = $config->getMenuItemProperty('name'); - - if (strlen($name)) { - return $name; - } - - return $this->getDefaultName(); - } - public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) ->setPlaceholder($this->getDefaultName()) - ->setValue($config->getMenuItemProperty('name')), + ->setValue($this->getNameFromConfig($config)), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $viewer = $this->getViewer(); if (!$viewer->isLoggedIn()) { return array(); } $engine = $this->getEngine(); $uri = $engine->getItemURI('configure/'); $name = $this->getDisplayName($config); $icon = 'fa-pencil'; $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIcon($icon); return array( $item, ); } } diff --git a/src/applications/search/menuitem/PhabricatorMotivatorProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorMotivatorProfileMenuItem.php index d85b02b3a2..ad6a11b1fb 100644 --- a/src/applications/search/menuitem/PhabricatorMotivatorProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorMotivatorProfileMenuItem.php @@ -1,160 +1,159 @@ getOptions(); $name = idx($options, $config->getMenuItemProperty('source')); - if ($name !== null) { + if ($name !== null && strlen($name)) { return pht('Motivator: %s', $name); - } else { - return pht('Motivator'); } + return pht('Motivator'); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorInstructionsEditField()) ->setValue( pht( 'Motivate your team with inspirational quotes from great minds. '. 'This menu item shows a new quote every day.')), id(new PhabricatorSelectEditField()) ->setKey('source') ->setLabel(pht('Source')) ->setOptions($this->getOptions()), ); } private function getOptions() { return array( 'catfacts' => pht('Cat Facts'), ); } protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $source = $config->getMenuItemProperty('source'); switch ($source) { case 'catfacts': default: $facts = $this->getCatFacts(); $fact_name = pht('Cat Facts'); $fact_icon = 'fa-paw'; break; } $fact_text = $this->selectFact($facts); $item = $this->newItemView() ->setName($fact_name) ->setIcon($fact_icon) ->setTooltip($fact_text) ->setURI('#'); return array( $item, ); } private function getCatFacts() { return array( pht('Cats purr when they are happy, upset, or asleep.'), pht('The first cats evolved on the savannah about 8,000 years ago.'), pht( 'Cats have a tail, two feet, between one and three ears, and two '. 'other feet.'), pht('Cats use their keen sense of smell to avoid feeling empathy.'), pht('The first cats evolved in swamps about 65 years ago.'), pht( 'You can tell how warm a cat is by examining the coloration: cooler '. 'areas are darker.'), pht( 'Cat tails are flexible because they contain thousands of tiny '. 'bones.'), pht( 'A cattail is a wetland plant with an appearance that resembles '. 'the tail of a cat.'), pht( 'Cats must eat a diet rich in fish to replace the tiny bones in '. 'their tails.'), pht('Cats are stealthy predators and nearly invisible to radar.'), pht( 'Cats use a special type of magnetism to help them land on their '. 'feet.'), pht( 'A cat can run seven times faster than a human, but only for a '. 'short distance.'), pht( 'The largest recorded cat was nearly 11 inches long from nose to '. 'tail.'), pht( 'Not all cats can retract their claws, but most of them can.'), pht( 'In the wild, cats and raccoons sometimes hunt together in packs.'), pht( 'The Spanish word for cat is "cato". The biggest cat is called '. '"el cato".'), pht( 'The Japanese word for cat is "kome", which is also the word for '. 'rice. Japanese cats love to eat rice, so the two are synonymous.'), pht('Cats have five pointy ends.'), pht('cat -A can find mice hiding in files.'), pht('A cat\'s visual, olfactory, and auditory senses, '. 'Contribute to their hunting skills and natural defenses.'), pht( 'Cats with high self-esteem seek out high perches '. 'to launch their attacks. Watch out!'), pht('Cats prefer vanilla ice cream.'), pht('Taco cat spelled backwards is taco cat.'), pht( 'Cats will often bring you their prey because they feel sorry '. 'for your inability to hunt.'), pht('Cats spend most of their time plotting to kill their owner.'), pht('Outside of the CAT scan, cats have made almost no contributions '. 'to modern medicine.'), pht('In ancient Egypt, the cat-god Horus watched over all cats.'), pht('The word "catastrophe" has no etymological relationship to the '. 'word "cat".'), pht('Many cats appear black in low light, suffering a -2 modifier to '. 'luck rolls.'), pht('The popular trivia game "World of Warcraft" features a race of '. 'cat people called the Khajiit.'), ); } private function selectFact(array $facts) { // This is a simple pseudorandom number generator that avoids touching // srand(), because it would seed it to a highly predictable value. It // selects a new fact every day. $seed = ((int)date('Y') * 366) + (int)date('z'); for ($ii = 0; $ii < 32; $ii++) { $seed = ((1664525 * $seed) + 1013904223) % (1 << 31); } return $facts[$seed % count($facts)]; } } diff --git a/src/applications/search/menuitem/PhabricatorProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorProfileMenuItem.php index 773a0f09ac..f3590cc615 100644 --- a/src/applications/search/menuitem/PhabricatorProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorProfileMenuItem.php @@ -1,167 +1,178 @@ getMenuItemProperty('name'); + + if ($name !== null && strlen($name)) { + return $name; + } + return $default; + } + public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array(); } public function canAddToObject($object) { return false; } public function shouldEnableForObject($object) { return true; } public function canHideMenuItem( PhabricatorProfileMenuItemConfiguration $config) { return true; } public function canMakeDefault( PhabricatorProfileMenuItemConfiguration $config) { return false; } public function setViewer(PhabricatorUser $viewer) { $this->viewer = $viewer; return $this; } public function getViewer() { return $this->viewer; } public function setEngine(PhabricatorProfileMenuEngine $engine) { $this->engine = $engine; return $this; } public function getEngine() { return $this->engine; } final public function getMenuItemKey() { return $this->getPhobjectClassConstant('MENUITEMKEY'); } final public static function getAllMenuItems() { return id(new PhutilClassMapQuery()) ->setAncestorClass(__CLASS__) ->setUniqueMethod('getMenuItemKey') ->execute(); } final protected function newItemView() { return new PhabricatorProfileMenuItemView(); } public function willGetMenuItemViewList(array $items) {} final public function getMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $list = $this->newMenuItemViewList($config); if (!is_array($list)) { throw new Exception( pht( 'Expected "newMenuItemViewList()" to return a list (in class "%s"), '. 'but it returned something else ("%s").', get_class($this), phutil_describe_type($list))); } assert_instances_of($list, 'PhabricatorProfileMenuItemView'); foreach ($list as $view) { $view->setMenuItemConfiguration($config); } return $list; } abstract protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config); public function newPageContent( PhabricatorProfileMenuItemConfiguration $config) { return null; } public function getItemViewURI( PhabricatorProfileMenuItemConfiguration $config) { $engine = $this->getEngine(); $key = $config->getItemIdentifier(); return $engine->getItemURI("view/{$key}/"); } public function validateTransactions( PhabricatorProfileMenuItemConfiguration $config, $field_key, $value, array $xactions) { return array(); } final protected function isEmptyTransaction($value, array $xactions) { $result = $value; foreach ($xactions as $xaction) { $result = $xaction['new']; } return !strlen($result); } final protected function newError($title, $message, $xaction = null) { return new PhabricatorApplicationTransactionValidationError( PhabricatorProfileMenuItemConfigurationTransaction::TYPE_PROPERTY, $title, $message, $xaction); } final protected function newRequiredError($message, $type) { $xaction = id(new PhabricatorProfileMenuItemConfigurationTransaction()) ->setMetadataValue('property.key', $type); return $this->newError(pht('Required'), $message, $xaction) ->setIsMissingFieldError(true); } final protected function newInvalidError($message, $xaction = null) { return $this->newError(pht('Invalid'), $message, $xaction); } final protected function newEmptyView($title, $message) { return id(new PHUIInfoView()) ->setTitle($title) ->setSeverity(PHUIInfoView::SEVERITY_NODATA) ->setErrors( array( $message, )); } public function getAffectedObjectPHIDs( PhabricatorProfileMenuItemConfiguration $config) { return array(); } } diff --git a/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php b/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php index efb61f06a1..7dbf2e59e5 100644 --- a/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php +++ b/src/applications/search/menuitem/PhabricatorProjectProfileMenuItem.php @@ -1,160 +1,153 @@ project = $project; return $this; } public function getProject() { $project = $this->project; if (!$project) { return null; } else if ($project->isArchived()) { return null; } return $project; } public function willGetMenuItemViewList(array $items) { $viewer = $this->getViewer(); $project_phids = array(); foreach ($items as $item) { $project_phids[] = $item->getMenuItemProperty('project'); } $projects = id(new PhabricatorProjectQuery()) ->setViewer($viewer) ->withPHIDs($project_phids) ->needImages(true) ->execute(); $projects = mpull($projects, null, 'getPHID'); foreach ($items as $item) { $project_phid = $item->getMenuItemProperty('project'); $project = idx($projects, $project_phid, null); $item->getMenuItem()->attachProject($project); } } public function getDisplayName( PhabricatorProfileMenuItemConfiguration $config) { $project = $this->getProject(); if (!$project) { return pht('(Restricted/Invalid Project)'); } - if (strlen($this->getName($config))) { - return $this->getName($config); - } else { - return $project->getName(); - } + + $default = $project->getName(); + return $this->getNameFromConfig($config, $default); } public function buildEditEngineFields( PhabricatorProfileMenuItemConfiguration $config) { return array( id(new PhabricatorDatasourceEditField()) ->setKey(self::FIELD_PROJECT) ->setLabel(pht('Project')) ->setIsRequired(true) ->setDatasource(new PhabricatorProjectDatasource()) ->setSingleValue($config->getMenuItemProperty('project')), id(new PhabricatorTextEditField()) ->setKey('name') ->setLabel(pht('Name')) - ->setValue($this->getName($config)), + ->setValue($this->getNameFromConfig($config)), ); } - private function getName( - PhabricatorProfileMenuItemConfiguration $config) { - return $config->getMenuItemProperty('name'); - } - protected function newMenuItemViewList( PhabricatorProfileMenuItemConfiguration $config) { $project = $this->getProject(); if (!$project) { return array(); } $picture = $project->getProfileImageURI(); $name = $this->getDisplayName($config); $uri = $project->getURI(); $item = $this->newItemView() ->setURI($uri) ->setName($name) ->setIconImage($picture); return array( $item, ); } public function validateTransactions( PhabricatorProfileMenuItemConfiguration $config, $field_key, $value, array $xactions) { $viewer = $this->getViewer(); $errors = array(); if ($field_key == self::FIELD_PROJECT) { if ($this->isEmptyTransaction($value, $xactions)) { $errors[] = $this->newRequiredError( pht('You must choose a project.'), $field_key); } foreach ($xactions as $xaction) { $new = $xaction['new']; if (!$new) { continue; } if ($new === $value) { continue; } $projects = id(new PhabricatorProjectQuery()) ->setViewer($viewer) ->withPHIDs(array($new)) ->execute(); if (!$projects) { $errors[] = $this->newInvalidError( pht( 'Project "%s" is not a valid project which you have '. 'permission to see.', $new), $xaction['xaction']); } } } return $errors; } }