Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/controller/PhabricatorFileViewController.php
Show First 20 Lines • Show All 314 Lines • ▼ Show 20 Lines | if (strlen($custom_alt)) { | ||||
$finfo->addProperty(pht('Custom Alt Text'), $custom_alt); | $finfo->addProperty(pht('Custom Alt Text'), $custom_alt); | ||||
} | } | ||||
$default_alt = $file->getDefaultAltText(); | $default_alt = $file->getDefaultAltText(); | ||||
if (strlen($default_alt)) { | if (strlen($default_alt)) { | ||||
$finfo->addProperty(pht('Default Alt Text'), $default_alt); | $finfo->addProperty(pht('Default Alt Text'), $default_alt); | ||||
} | } | ||||
$phids = $file->getObjectPHIDs(); | $attachments_table = $this->newAttachmentsView($file); | ||||
if ($phids) { | |||||
$attached = new PHUIPropertyListView(); | |||||
$tab_group->addTab( | $tab_group->addTab( | ||||
id(new PHUITabView()) | id(new PHUITabView()) | ||||
->setName(pht('Attached')) | ->setName(pht('Attached')) | ||||
->setKey('attached') | ->setKey('attached') | ||||
->appendChild($attached)); | ->appendChild($attachments_table)); | ||||
$attached->addProperty( | |||||
pht('Attached To'), | |||||
$viewer->renderHandleList($phids)); | |||||
} | |||||
$engine = $this->loadStorageEngine($file); | $engine = $this->loadStorageEngine($file); | ||||
if ($engine) { | if ($engine) { | ||||
if ($engine->isChunkEngine()) { | if ($engine->isChunkEngine()) { | ||||
$chunkinfo = new PHUIPropertyListView(); | $chunkinfo = new PHUIPropertyListView(); | ||||
$tab_group->addTab( | $tab_group->addTab( | ||||
id(new PHUITabView()) | id(new PHUITabView()) | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | $ref = id(new PhabricatorDocumentRef()) | ||||
->setFile($file); | ->setFile($file); | ||||
$engine = id(new PhabricatorFileDocumentRenderingEngine()) | $engine = id(new PhabricatorFileDocumentRenderingEngine()) | ||||
->setRequest($request); | ->setRequest($request); | ||||
return $engine->newDocumentView($ref); | return $engine->newDocumentView($ref); | ||||
} | } | ||||
private function newAttachmentsView(PhabricatorFile $file) { | |||||
$viewer = $this->getViewer(); | |||||
$attachments = id(new PhabricatorFileAttachmentQuery()) | |||||
->setViewer($viewer) | |||||
->withFilePHIDs(array($file->getPHID())) | |||||
->execute(); | |||||
$handles = $viewer->loadHandles(mpull($attachments, 'getObjectPHID')); | |||||
$rows = array(); | |||||
$mode_map = PhabricatorFileAttachment::getModeNameMap(); | |||||
$mode_attach = PhabricatorFileAttachment::MODE_ATTACH; | |||||
foreach ($attachments as $attachment) { | |||||
$object_phid = $attachment->getObjectPHID(); | |||||
$handle = $handles[$object_phid]; | |||||
$attachment_mode = $attachment->getAttachmentMode(); | |||||
$mode_name = idx($mode_map, $attachment_mode); | |||||
if ($mode_name === null) { | |||||
$mode_name = pht('Unknown ("%s")', $attachment_mode); | |||||
} | |||||
$detach_uri = urisprintf( | |||||
'/file/ui/detach/%s/%s/', | |||||
$object_phid, | |||||
$file->getPHID()); | |||||
$is_disabled = !$attachment->canDetach(); | |||||
$detach_button = id(new PHUIButtonView()) | |||||
->setHref($detach_uri) | |||||
->setTag('a') | |||||
->setWorkflow(true) | |||||
->setDisabled($is_disabled) | |||||
->setColor(PHUIButtonView::GREY) | |||||
->setSize(PHUIButtonView::SMALL) | |||||
->setText(pht('Detach File')); | |||||
javelin_tag( | |||||
'a', | |||||
array( | |||||
'href' => $detach_uri, | |||||
'sigil' => 'workflow', | |||||
'disabled' => true, | |||||
'class' => 'small button button-grey disabled', | |||||
), | |||||
pht('Detach File')); | |||||
$rows[] = array( | |||||
$handle->renderLink(), | |||||
$mode_name, | |||||
$detach_button, | |||||
); | |||||
} | |||||
$table = id(new AphrontTableView($rows)) | |||||
->setHeaders( | |||||
array( | |||||
pht('Attached To'), | |||||
pht('Mode'), | |||||
null, | |||||
)) | |||||
->setColumnClasses( | |||||
array( | |||||
'pri wide', | |||||
null, | |||||
null, | |||||
)); | |||||
return $table; | |||||
} | |||||
} | } |