mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-27 15:08:20 +01:00
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:
parent
b3900a399c
commit
ee6c6943b3
7 changed files with 101 additions and 16 deletions
|
@ -38,6 +38,7 @@ phutil_register_library_map(array(
|
|||
'AphrontFormDividerControl' => 'view/form/control/AphrontFormDividerControl.php',
|
||||
'AphrontFormDragAndDropUploadControl' => 'view/form/control/AphrontFormDragAndDropUploadControl.php',
|
||||
'AphrontFormFileControl' => 'view/form/control/AphrontFormFileControl.php',
|
||||
'AphrontFormImageControl' => 'view/form/control/AphrontFormImageControl.php',
|
||||
'AphrontFormInsetView' => 'view/form/AphrontFormInsetView.php',
|
||||
'AphrontFormLayoutView' => 'view/form/AphrontFormLayoutView.php',
|
||||
'AphrontFormMarkupControl' => 'view/form/control/AphrontFormMarkupControl.php',
|
||||
|
@ -1125,6 +1126,7 @@ phutil_register_library_map(array(
|
|||
'AphrontFormDividerControl' => 'AphrontFormControl',
|
||||
'AphrontFormDragAndDropUploadControl' => 'AphrontFormControl',
|
||||
'AphrontFormFileControl' => 'AphrontFormControl',
|
||||
'AphrontFormImageControl' => 'AphrontFormControl',
|
||||
'AphrontFormInsetView' => 'AphrontView',
|
||||
'AphrontFormLayoutView' => 'AphrontView',
|
||||
'AphrontFormMarkupControl' => 'AphrontFormControl',
|
||||
|
|
|
@ -51,7 +51,11 @@ final class PhabricatorUserProfileSettingsPanelController
|
|||
// Checked in runtime.
|
||||
$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');
|
||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
||||
$file = PhabricatorFile::newFromPHPUpload(
|
||||
|
@ -188,7 +192,7 @@ final class PhabricatorUserProfileSettingsPanelController
|
|||
'src' => $img_src,
|
||||
))))
|
||||
->appendChild(
|
||||
id(new AphrontFormFileControl())
|
||||
id(new AphrontFormImageControl())
|
||||
->setLabel('Change Image')
|
||||
->setName('image')
|
||||
->setError($e_image)
|
||||
|
|
|
@ -40,17 +40,7 @@ final class PhabricatorProjectProfileController
|
|||
$profile = new PhabricatorProjectProfile();
|
||||
}
|
||||
|
||||
$src_phid = $profile->getProfileImagePHID();
|
||||
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();
|
||||
}
|
||||
$picture = $profile->loadProfileImageURI();
|
||||
|
||||
$members = mpull($project->loadAffiliations(), null, 'getUserPHID');
|
||||
|
||||
|
|
|
@ -33,11 +33,12 @@ final class PhabricatorProjectProfileEditController
|
|||
return new Aphront404Response();
|
||||
}
|
||||
$profile = $project->loadProfile();
|
||||
|
||||
if (empty($profile)) {
|
||||
$profile = new PhabricatorProjectProfile();
|
||||
}
|
||||
|
||||
$img_src = $profile->loadProfileImageURI();
|
||||
|
||||
if ($project->getSubprojectPHIDs()) {
|
||||
$phids = $project->getSubprojectPHIDs();
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||
|
@ -93,7 +94,10 @@ final class PhabricatorProjectProfileEditController
|
|||
$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');
|
||||
if ($err != UPLOAD_ERR_NO_FILE) {
|
||||
$file = PhabricatorFile::newFromPHPUpload(
|
||||
|
@ -252,7 +256,16 @@ final class PhabricatorProjectProfileEditController
|
|||
->setName('set_subprojects')
|
||||
->setValue($subprojects))
|
||||
->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')
|
||||
->setName('image')
|
||||
->setError($e_image)
|
||||
|
|
|
@ -22,4 +22,15 @@ final class PhabricatorProjectProfile extends PhabricatorProjectDAO {
|
|||
protected $blurb;
|
||||
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;
|
||||
}
|
||||
|
||||
.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 {
|
||||
border: none;
|
||||
background: #bbbbbb;
|
||||
|
|
Loading…
Add table
Reference in a new issue