Robustify profile image controls ever so slightly
Summary: show project profile image on pertinent edit page. also add a "Use Default Image" checkbox for both project and user profiles. Also added a function for projects to get the profile picture to prevent some copy + paste action. Test Plan: set my user profile and project profile image. clicked "Use Default Image" and got the default image back. Reviewers: epriestley, floatinglomas Reviewed By: floatinglomas CC: aran, Korvin Maniphest Tasks: T1307 Differential Revision: https://secure.phabricator.com/D2852
This commit is contained in:
@@ -38,6 +38,7 @@ phutil_register_library_map(array(
|
|||||||
'AphrontFormDividerControl' => 'view/form/control/AphrontFormDividerControl.php',
|
'AphrontFormDividerControl' => 'view/form/control/AphrontFormDividerControl.php',
|
||||||
'AphrontFormDragAndDropUploadControl' => 'view/form/control/AphrontFormDragAndDropUploadControl.php',
|
'AphrontFormDragAndDropUploadControl' => 'view/form/control/AphrontFormDragAndDropUploadControl.php',
|
||||||
'AphrontFormFileControl' => 'view/form/control/AphrontFormFileControl.php',
|
'AphrontFormFileControl' => 'view/form/control/AphrontFormFileControl.php',
|
||||||
|
'AphrontFormImageControl' => 'view/form/control/AphrontFormImageControl.php',
|
||||||
'AphrontFormInsetView' => 'view/form/AphrontFormInsetView.php',
|
'AphrontFormInsetView' => 'view/form/AphrontFormInsetView.php',
|
||||||
'AphrontFormLayoutView' => 'view/form/AphrontFormLayoutView.php',
|
'AphrontFormLayoutView' => 'view/form/AphrontFormLayoutView.php',
|
||||||
'AphrontFormMarkupControl' => 'view/form/control/AphrontFormMarkupControl.php',
|
'AphrontFormMarkupControl' => 'view/form/control/AphrontFormMarkupControl.php',
|
||||||
@@ -1125,6 +1126,7 @@ phutil_register_library_map(array(
|
|||||||
'AphrontFormDividerControl' => 'AphrontFormControl',
|
'AphrontFormDividerControl' => 'AphrontFormControl',
|
||||||
'AphrontFormDragAndDropUploadControl' => 'AphrontFormControl',
|
'AphrontFormDragAndDropUploadControl' => 'AphrontFormControl',
|
||||||
'AphrontFormFileControl' => 'AphrontFormControl',
|
'AphrontFormFileControl' => 'AphrontFormControl',
|
||||||
|
'AphrontFormImageControl' => 'AphrontFormControl',
|
||||||
'AphrontFormInsetView' => 'AphrontView',
|
'AphrontFormInsetView' => 'AphrontView',
|
||||||
'AphrontFormLayoutView' => 'AphrontView',
|
'AphrontFormLayoutView' => 'AphrontView',
|
||||||
'AphrontFormMarkupControl' => 'AphrontFormControl',
|
'AphrontFormMarkupControl' => 'AphrontFormControl',
|
||||||
|
|||||||
@@ -51,7 +51,11 @@ final class PhabricatorUserProfileSettingsPanelController
|
|||||||
// Checked in runtime.
|
// Checked in runtime.
|
||||||
$user->setTranslation($request->getStr('translation'));
|
$user->setTranslation($request->getStr('translation'));
|
||||||
|
|
||||||
if (!empty($_FILES['image'])) {
|
$default_image = $request->getExists('default_image');
|
||||||
|
if ($default_image) {
|
||||||
|
$profile->setProfileImagePHID(null);
|
||||||
|
$user->setProfileImagePHID(null);
|
||||||
|
} else if (!empty($_FILES['image'])) {
|
||||||
$err = idx($_FILES['image'], 'error');
|
$err = idx($_FILES['image'], 'error');
|
||||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
if ($err != UPLOAD_ERR_NO_FILE) {
|
||||||
$file = PhabricatorFile::newFromPHPUpload(
|
$file = PhabricatorFile::newFromPHPUpload(
|
||||||
@@ -188,7 +192,7 @@ final class PhabricatorUserProfileSettingsPanelController
|
|||||||
'src' => $img_src,
|
'src' => $img_src,
|
||||||
))))
|
))))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormFileControl())
|
id(new AphrontFormImageControl())
|
||||||
->setLabel('Change Image')
|
->setLabel('Change Image')
|
||||||
->setName('image')
|
->setName('image')
|
||||||
->setError($e_image)
|
->setError($e_image)
|
||||||
|
|||||||
@@ -40,17 +40,7 @@ final class PhabricatorProjectProfileController
|
|||||||
$profile = new PhabricatorProjectProfile();
|
$profile = new PhabricatorProjectProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
$src_phid = $profile->getProfileImagePHID();
|
$picture = $profile->loadProfileImageURI();
|
||||||
if (!$src_phid) {
|
|
||||||
$src_phid = $user->getProfileImagePHID();
|
|
||||||
}
|
|
||||||
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s',
|
|
||||||
$src_phid);
|
|
||||||
if ($file) {
|
|
||||||
$picture = $file->getBestURI();
|
|
||||||
} else {
|
|
||||||
$picture = PhabricatorUser::getDefaultProfileImageURI();
|
|
||||||
}
|
|
||||||
|
|
||||||
$members = mpull($project->loadAffiliations(), null, 'getUserPHID');
|
$members = mpull($project->loadAffiliations(), null, 'getUserPHID');
|
||||||
|
|
||||||
|
|||||||
@@ -33,11 +33,12 @@ final class PhabricatorProjectProfileEditController
|
|||||||
return new Aphront404Response();
|
return new Aphront404Response();
|
||||||
}
|
}
|
||||||
$profile = $project->loadProfile();
|
$profile = $project->loadProfile();
|
||||||
|
|
||||||
if (empty($profile)) {
|
if (empty($profile)) {
|
||||||
$profile = new PhabricatorProjectProfile();
|
$profile = new PhabricatorProjectProfile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$img_src = $profile->loadProfileImageURI();
|
||||||
|
|
||||||
if ($project->getSubprojectPHIDs()) {
|
if ($project->getSubprojectPHIDs()) {
|
||||||
$phids = $project->getSubprojectPHIDs();
|
$phids = $project->getSubprojectPHIDs();
|
||||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||||
@@ -93,7 +94,10 @@ final class PhabricatorProjectProfileEditController
|
|||||||
$e_name = null;
|
$e_name = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($_FILES['image'])) {
|
$default_image = $request->getExists('default_image');
|
||||||
|
if ($default_image) {
|
||||||
|
$profile->setProfileImagePHID(null);
|
||||||
|
} else if (!empty($_FILES['image'])) {
|
||||||
$err = idx($_FILES['image'], 'error');
|
$err = idx($_FILES['image'], 'error');
|
||||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
if ($err != UPLOAD_ERR_NO_FILE) {
|
||||||
$file = PhabricatorFile::newFromPHPUpload(
|
$file = PhabricatorFile::newFromPHPUpload(
|
||||||
@@ -252,7 +256,16 @@ final class PhabricatorProjectProfileEditController
|
|||||||
->setName('set_subprojects')
|
->setName('set_subprojects')
|
||||||
->setValue($subprojects))
|
->setValue($subprojects))
|
||||||
->appendChild(
|
->appendChild(
|
||||||
id(new AphrontFormFileControl())
|
id(new AphrontFormMarkupControl())
|
||||||
|
->setLabel('Profile Image')
|
||||||
|
->setValue(
|
||||||
|
phutil_render_tag(
|
||||||
|
'img',
|
||||||
|
array(
|
||||||
|
'src' => $img_src,
|
||||||
|
))))
|
||||||
|
->appendChild(
|
||||||
|
id(new AphrontFormImageControl())
|
||||||
->setLabel('Change Image')
|
->setLabel('Change Image')
|
||||||
->setName('image')
|
->setName('image')
|
||||||
->setError($e_image)
|
->setError($e_image)
|
||||||
|
|||||||
@@ -22,4 +22,15 @@ final class PhabricatorProjectProfile extends PhabricatorProjectDAO {
|
|||||||
protected $blurb;
|
protected $blurb;
|
||||||
protected $profileImagePHID;
|
protected $profileImagePHID;
|
||||||
|
|
||||||
|
public function loadProfileImageURI() {
|
||||||
|
$src_phid = $this->getProfileImagePHID();
|
||||||
|
|
||||||
|
$file = id(new PhabricatorFile())->loadOneWhere('phid = %s', $src_phid);
|
||||||
|
if ($file) {
|
||||||
|
return $file->getBestURI();
|
||||||
|
}
|
||||||
|
|
||||||
|
return PhabricatorUser::getDefaultProfileImageURI();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
53
src/view/form/control/AphrontFormImageControl.php
Normal file
53
src/view/form/control/AphrontFormImageControl.php
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Copyright 2012 Facebook, Inc.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
final class AphrontFormImageControl extends AphrontFormControl {
|
||||||
|
|
||||||
|
protected function getCustomControlClass() {
|
||||||
|
return 'aphront-form-control-image';
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function renderInput() {
|
||||||
|
$id = celerity_generate_unique_node_id();
|
||||||
|
|
||||||
|
return
|
||||||
|
phutil_render_tag(
|
||||||
|
'input',
|
||||||
|
array(
|
||||||
|
'type' => 'file',
|
||||||
|
'name' => $this->getName(),
|
||||||
|
'class' => 'image',
|
||||||
|
)).
|
||||||
|
'<span>-or-</span>'.
|
||||||
|
phutil_render_tag(
|
||||||
|
'input',
|
||||||
|
array(
|
||||||
|
'type' => 'checkbox',
|
||||||
|
'name' => 'default_image',
|
||||||
|
'class' => 'default-image',
|
||||||
|
'id' => $id,
|
||||||
|
)).
|
||||||
|
phutil_render_tag(
|
||||||
|
'label',
|
||||||
|
array(
|
||||||
|
'for' => $id,
|
||||||
|
),
|
||||||
|
'Use Default Image');
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -139,6 +139,18 @@ table.aphront-form-control-checkbox-layout th {
|
|||||||
max-width: 400px;
|
max-width: 400px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.aphront-form-control-image .image {
|
||||||
|
width: 164px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.aphront-form-control-image span {
|
||||||
|
margin: 0px 4px 0px 2px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.aphront-form-control-image .default-image {
|
||||||
|
width: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
.aphront-form-input hr {
|
.aphront-form-input hr {
|
||||||
border: none;
|
border: none;
|
||||||
background: #bbbbbb;
|
background: #bbbbbb;
|
||||||
|
|||||||
Reference in New Issue
Block a user