1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-19 16:58:48 +02:00

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:
epriestley 2011-05-22 17:06:42 -07:00
parent 109a202b6c
commit ce8a406424
9 changed files with 121 additions and 14 deletions

View file

@ -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(

View file

@ -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',

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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');

View file

@ -47,13 +47,15 @@ class AphrontFormDragAndDropUploadControl extends AphrontFormControl {
$files = $this->getValue();
$value = array();
foreach ($files as $file) {
$view = new AphrontAttachedFileView();
$view->setFile($file);
$value[$file->getPHID()] = array(
'phid' => $file->getPHID(),
'html' => $view->render(),
);
if ($files) {
foreach ($files as $file) {
$view = new AphrontAttachedFileView();
$view->setFile($file);
$value[$file->getPHID()] = array(
'phid' => $file->getPHID(),
'html' => $view->render(),
);
}
}
Javelin::initBehavior(

View 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>';
}
}

View 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');

View file

@ -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;
}