Improve file preview in Maniphest
Summary: Show large thumbnails of attached files in Maniphest. Test Plan: Looked at large thumbnails in Maniphest. Reviewed By: jungejason Reviewers: tomo, aran, jungejason, tuomaspelkonen CC: anjali, aran, epriestley, jungejason Differential Revision: 335
This commit is contained in:
		| @@ -9,7 +9,7 @@ | ||||
| celerity_register_resource_map(array( | ||||
|   'aphront-attached-file-view-css' => | ||||
|   array( | ||||
|     'uri' => '/res/79bc2c2e/rsrc/css/aphront/attached-file-view.css', | ||||
|     'uri' => '/res/bac9f95c/rsrc/css/aphront/attached-file-view.css', | ||||
|     'type' => 'css', | ||||
|     'requires' => | ||||
|     array( | ||||
|   | ||||
| @@ -23,6 +23,7 @@ phutil_register_library_map(array( | ||||
|     'AphrontDialogView' => 'view/dialog', | ||||
|     'AphrontErrorView' => 'view/form/error', | ||||
|     'AphrontException' => 'aphront/exception/base', | ||||
|     'AphrontFilePreviewView' => 'view/layout/filepreview', | ||||
|     'AphrontFileResponse' => 'aphront/response/file', | ||||
|     'AphrontFormCheckboxControl' => 'view/form/control/checkbox', | ||||
|     'AphrontFormControl' => 'view/form/control/base', | ||||
| @@ -537,6 +538,7 @@ phutil_register_library_map(array( | ||||
|     'AphrontDialogResponse' => 'AphrontResponse', | ||||
|     'AphrontDialogView' => 'AphrontView', | ||||
|     'AphrontErrorView' => 'AphrontView', | ||||
|     'AphrontFilePreviewView' => 'AphrontView', | ||||
|     'AphrontFileResponse' => 'AphrontResponse', | ||||
|     'AphrontFormCheckboxControl' => 'AphrontFormControl', | ||||
|     'AphrontFormControl' => 'AphrontView', | ||||
|   | ||||
| @@ -206,6 +206,11 @@ class PhabricatorFile extends PhabricatorFileDAO { | ||||
|     return '/file/xform/thumb-60x45/'.$this->getPHID().'/'; | ||||
|   } | ||||
|  | ||||
|   public function getThumb160x120URI() { | ||||
|     return '/file/xform/thumb-160x120/'.$this->getPHID().'/'; | ||||
|   } | ||||
|  | ||||
|  | ||||
|   public function isViewableInBrowser() { | ||||
|     return ($this->getViewableMimeType() !== null); | ||||
|   } | ||||
|   | ||||
| @@ -121,13 +121,22 @@ class ManiphestTaskDetailController extends ManiphestController { | ||||
|     } | ||||
|  | ||||
|     if (idx($attached, PhabricatorPHIDConstants::PHID_TYPE_FILE)) { | ||||
|       $revs = idx($attached, PhabricatorPHIDConstants::PHID_TYPE_FILE); | ||||
|       $rev_links = array(); | ||||
|       foreach ($revs as $rev => $info) { | ||||
|         $rev_links[] = $handles[$rev]->renderLink(); | ||||
|       $file_infos = idx($attached, PhabricatorPHIDConstants::PHID_TYPE_FILE); | ||||
|       $file_phids = array_keys($file_infos); | ||||
|  | ||||
|       if ($file_phids) { | ||||
|         $files = id(new PhabricatorFile())->loadAllWhere( | ||||
|           'phid IN (%Ls)', | ||||
|           $file_phids); | ||||
|  | ||||
|         $views = array(); | ||||
|         foreach ($files as $file) { | ||||
|           $view = new AphrontFilePreviewView(); | ||||
|           $view->setFile($file); | ||||
|           $views[] = $view->render(); | ||||
|         } | ||||
|         $dict['Files'] = implode('', $views); | ||||
|       } | ||||
|       $rev_links = implode(', ', $rev_links); | ||||
|       $dict['Files'] = $rev_links; | ||||
|     } | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -9,6 +9,7 @@ | ||||
| phutil_require_module('phabricator', 'aphront/response/404'); | ||||
| phutil_require_module('phabricator', 'applications/differential/parser/markup'); | ||||
| phutil_require_module('phabricator', 'applications/draft/storage/draft'); | ||||
| phutil_require_module('phabricator', 'applications/files/storage/file'); | ||||
| phutil_require_module('phabricator', 'applications/maniphest/constants/priority'); | ||||
| phutil_require_module('phabricator', 'applications/maniphest/constants/status'); | ||||
| phutil_require_module('phabricator', 'applications/maniphest/constants/transactiontype'); | ||||
| @@ -27,6 +28,7 @@ phutil_require_module('phabricator', 'view/form/control/select'); | ||||
| phutil_require_module('phabricator', 'view/form/control/submit'); | ||||
| phutil_require_module('phabricator', 'view/form/control/textarea'); | ||||
| phutil_require_module('phabricator', 'view/form/control/tokenizer'); | ||||
| phutil_require_module('phabricator', 'view/layout/filepreview'); | ||||
| phutil_require_module('phabricator', 'view/layout/headsup/action'); | ||||
| phutil_require_module('phabricator', 'view/layout/headsup/actionlist'); | ||||
| phutil_require_module('phabricator', 'view/layout/panel'); | ||||
|   | ||||
| @@ -47,6 +47,7 @@ class AphrontFormDragAndDropUploadControl extends AphrontFormControl { | ||||
|  | ||||
|     $files = $this->getValue(); | ||||
|     $value = array(); | ||||
|     if ($files) { | ||||
|       foreach ($files as $file) { | ||||
|         $view = new AphrontAttachedFileView(); | ||||
|         $view->setFile($file); | ||||
| @@ -55,6 +56,7 @@ class AphrontFormDragAndDropUploadControl extends AphrontFormControl { | ||||
|           'html' => $view->render(), | ||||
|         ); | ||||
|       } | ||||
|     } | ||||
|  | ||||
|     Javelin::initBehavior( | ||||
|       'aphront-drag-and-drop', | ||||
|   | ||||
							
								
								
									
										57
									
								
								src/view/layout/filepreview/AphrontFilePreviewView.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										57
									
								
								src/view/layout/filepreview/AphrontFilePreviewView.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,57 @@ | ||||
| <?php | ||||
|  | ||||
| /* | ||||
|  * Copyright 2011 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 AphrontFilePreviewView extends AphrontView { | ||||
|  | ||||
|   private $file; | ||||
|  | ||||
|   public function setFile(PhabricatorFile $file) { | ||||
|     $this->file = $file; | ||||
|     return $this; | ||||
|   } | ||||
|  | ||||
|   public function render() { | ||||
|     require_celerity_resource('aphront-attached-file-view-css'); | ||||
|  | ||||
|     $file = $this->file; | ||||
|  | ||||
|     $img = phutil_render_tag( | ||||
|       'img', | ||||
|       array( | ||||
|         'src'     => $file->getThumb160x120URI(), | ||||
|         'width'   => 160, | ||||
|         'height'  => 120, | ||||
|       )); | ||||
|     $link = phutil_render_tag( | ||||
|       'a', | ||||
|       array( | ||||
|         'href'    => $file->getViewURI(), | ||||
|         'target'  => '_blank', | ||||
|       ), | ||||
|       $img); | ||||
|  | ||||
|     return | ||||
|       '<div class="aphront-file-preview-view"> | ||||
|         <div class="aphront-file-preview-thumb">'. | ||||
|           $link. | ||||
|         '</div>'. | ||||
|         phutil_escape_html($file->getName()). | ||||
|       '</div>'; | ||||
|   } | ||||
|  | ||||
| } | ||||
							
								
								
									
										15
									
								
								src/view/layout/filepreview/__init__.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								src/view/layout/filepreview/__init__.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| <?php | ||||
| /** | ||||
|  * This file is automatically generated. Lint this module to rebuild it. | ||||
|  * @generated | ||||
|  */ | ||||
|  | ||||
|  | ||||
|  | ||||
| phutil_require_module('phabricator', 'infrastructure/celerity/api'); | ||||
| phutil_require_module('phabricator', 'view/base'); | ||||
|  | ||||
| phutil_require_module('phutil', 'markup'); | ||||
|  | ||||
|  | ||||
| phutil_require_source('AphrontFilePreviewView.php'); | ||||
| @@ -22,3 +22,18 @@ | ||||
| .aphront-attached-file-view-remove { | ||||
|   vertical-align: middle; | ||||
| } | ||||
|  | ||||
| .aphront-file-preview-view { | ||||
|   float: left; | ||||
|   margin: 4px 4px 12px; | ||||
|   text-align: center; | ||||
|   font-size: 11px; | ||||
|   color: #333333; | ||||
| } | ||||
|  | ||||
| .aphront-file-preview-thumb { | ||||
|   padding: 2px; | ||||
|   border: 1px solid #000000; | ||||
|   background: #ffffff; | ||||
|   margin-bottom: 2px; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 epriestley
					epriestley