Update project profile image composer for new IconSet code
Summary: Fixes T6856. Fixes T10164. - Make the profile image composer code use the underlying icon name instead of the top-level icon key, so it works instead of 404'ing. - Change the button to show a preview of the profile icon instead of the text "Use Icon and Color". - When creating a new non-milestone project, automatically set the profile image to the icon + color image. Test Plan: - Created several new projects, saw appropriate default icons. - Edited projects, saw icon previews. - Clicked icon buttons to set icons. - Poked around other applications which use builtins (Pholio, user profiles) to look for anything I broke, but everything seemed fine. Reviewers: chad Reviewed By: chad Maniphest Tasks: T6856, T10164 Differential Revision: https://secure.phabricator.com/D15050
This commit is contained in:
@@ -123,7 +123,7 @@ final class PhabricatorProjectEditPictureController
|
||||
|
||||
$images[PhabricatorPHIDConstants::PHID_VOID] = array(
|
||||
'uri' => $default_image->getBestURI(),
|
||||
'tip' => pht('Default Picture'),
|
||||
'tip' => pht('No Picture'),
|
||||
);
|
||||
|
||||
require_celerity_resource('people-profile-css');
|
||||
@@ -181,7 +181,11 @@ final class PhabricatorProjectEditPictureController
|
||||
$form->appendChild(
|
||||
id(new AphrontFormMarkupControl())
|
||||
->setLabel(pht('Use Picture'))
|
||||
->setValue($buttons));
|
||||
->setValue(
|
||||
array(
|
||||
$this->renderDefaultForm($project),
|
||||
$buttons,
|
||||
)));
|
||||
|
||||
$launch_id = celerity_generate_unique_node_id();
|
||||
$input_id = celerity_generate_unique_node_id();
|
||||
@@ -226,38 +230,6 @@ final class PhabricatorProjectEditPictureController
|
||||
->setLabel(pht('Quick Create'))
|
||||
->setValue($compose_form));
|
||||
|
||||
$default_button = javelin_tag(
|
||||
'button',
|
||||
array(
|
||||
'class' => 'grey',
|
||||
),
|
||||
pht('Use Project Icon'));
|
||||
|
||||
$default_input = javelin_tag(
|
||||
'input',
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => 'projectPHID',
|
||||
'value' => $project->getPHID(),
|
||||
));
|
||||
|
||||
$default_form = phabricator_form(
|
||||
$viewer,
|
||||
array(
|
||||
'class' => 'profile-image-form',
|
||||
'method' => 'POST',
|
||||
'action' => '/file/compose/',
|
||||
),
|
||||
array(
|
||||
$default_input,
|
||||
$default_button,
|
||||
));
|
||||
|
||||
$form->appendChild(
|
||||
id(new AphrontFormMarkupControl())
|
||||
->setLabel(pht('Use Default'))
|
||||
->setValue($default_form));
|
||||
|
||||
$upload_form = id(new AphrontFormView())
|
||||
->setUser($viewer)
|
||||
->setEncType('multipart/form-data')
|
||||
@@ -294,4 +266,69 @@ final class PhabricatorProjectEditPictureController
|
||||
$upload_box,
|
||||
));
|
||||
}
|
||||
|
||||
private function renderDefaultForm(PhabricatorProject $project) {
|
||||
$viewer = $this->getViewer();
|
||||
$compose_color = $project->getDisplayIconComposeColor();
|
||||
$compose_icon = $project->getDisplayIconComposeIcon();
|
||||
|
||||
$default_builtin = id(new PhabricatorFilesComposeIconBuiltinFile())
|
||||
->setColor($compose_color)
|
||||
->setIcon($compose_icon);
|
||||
|
||||
$file_builtins = PhabricatorFile::loadBuiltins(
|
||||
$viewer,
|
||||
array($default_builtin));
|
||||
|
||||
$file_builtin = head($file_builtins);
|
||||
|
||||
$default_button = javelin_tag(
|
||||
'button',
|
||||
array(
|
||||
'class' => 'grey profile-image-button',
|
||||
'sigil' => 'has-tooltip',
|
||||
'meta' => array(
|
||||
'tip' => pht('Use Icon and Color'),
|
||||
'size' => 300,
|
||||
),
|
||||
),
|
||||
phutil_tag(
|
||||
'img',
|
||||
array(
|
||||
'height' => 50,
|
||||
'width' => 50,
|
||||
'src' => $file_builtin->getBestURI(),
|
||||
)));
|
||||
|
||||
$inputs = array(
|
||||
'projectPHID' => $project->getPHID(),
|
||||
'icon' => $compose_icon,
|
||||
'color' => $compose_color,
|
||||
);
|
||||
|
||||
foreach ($inputs as $key => $value) {
|
||||
$inputs[$key] = javelin_tag(
|
||||
'input',
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => $key,
|
||||
'value' => $value,
|
||||
));
|
||||
}
|
||||
|
||||
$default_form = phabricator_form(
|
||||
$viewer,
|
||||
array(
|
||||
'class' => 'profile-image-form',
|
||||
'method' => 'POST',
|
||||
'action' => '/file/compose/',
|
||||
),
|
||||
array(
|
||||
$inputs,
|
||||
$default_button,
|
||||
));
|
||||
|
||||
return $default_form;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -713,6 +713,10 @@ final class PhabricatorProjectTransactionEditor
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->getIsNewObject()) {
|
||||
$this->setDefaultProfilePicture($object);
|
||||
}
|
||||
|
||||
// TODO: We should dump an informational transaction onto the parent
|
||||
// project to show that we created the sub-thing.
|
||||
|
||||
@@ -886,5 +890,31 @@ final class PhabricatorProjectTransactionEditor
|
||||
return $results;
|
||||
}
|
||||
|
||||
private function setDefaultProfilePicture(PhabricatorProject $project) {
|
||||
if ($project->isMilestone()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$compose_color = $project->getDisplayIconComposeColor();
|
||||
$compose_icon = $project->getDisplayIconComposeIcon();
|
||||
|
||||
$builtin = id(new PhabricatorFilesComposeIconBuiltinFile())
|
||||
->setColor($compose_color)
|
||||
->setIcon($compose_icon);
|
||||
|
||||
$data = $builtin->loadBuiltinFileData();
|
||||
|
||||
$file = PhabricatorFile::newFromFileData(
|
||||
$data,
|
||||
array(
|
||||
'name' => $builtin->getBuiltinDisplayName(),
|
||||
'profile' => true,
|
||||
'canCDN' => true,
|
||||
));
|
||||
|
||||
$project
|
||||
->setProfileImagePHID($file->getPHID())
|
||||
->save();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -519,6 +519,23 @@ final class PhabricatorProject extends PhabricatorProjectDAO
|
||||
return $this->getColor();
|
||||
}
|
||||
|
||||
public function getDisplayIconComposeIcon() {
|
||||
$icon = $this->getDisplayIconIcon();
|
||||
return $icon;
|
||||
}
|
||||
|
||||
public function getDisplayIconComposeColor() {
|
||||
$color = $this->getDisplayColor();
|
||||
|
||||
$map = array(
|
||||
'grey' => 'charcoal',
|
||||
'checkered' => 'backdrop',
|
||||
);
|
||||
|
||||
return idx($map, $color, $color);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* -( PhabricatorSubscribableInterface )----------------------------------- */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user