Changeset View
Changeset View
Standalone View
Standalone View
src/applications/files/controller/PhabricatorFileViewController.php
- This file was moved from src/applications/files/controller/PhabricatorFileInfoController.php.
<?php | <?php | ||||
final class PhabricatorFileInfoController extends PhabricatorFileController { | final class PhabricatorFileViewController extends PhabricatorFileController { | ||||
public function shouldAllowPublic() { | public function shouldAllowPublic() { | ||||
return true; | return true; | ||||
} | } | ||||
public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
$viewer = $request->getViewer(); | $viewer = $request->getViewer(); | ||||
$id = $request->getURIData('id'); | $id = $request->getURIData('id'); | ||||
▲ Show 20 Lines • Show All 387 Lines • ▼ Show 20 Lines | try { | ||||
// Don't bother raising this anywhere for now. | // Don't bother raising this anywhere for now. | ||||
} | } | ||||
return $engine; | return $engine; | ||||
} | } | ||||
private function newFileContent(PhabricatorFile $file) { | private function newFileContent(PhabricatorFile $file) { | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
$request = $this->getRequest(); | |||||
$ref = id(new PhabricatorDocumentRef()) | $ref = id(new PhabricatorDocumentRef()) | ||||
->setFile($file); | ->setFile($file); | ||||
$engines = PhabricatorDocumentEngine::getEnginesForRef($viewer, $ref); | $engines = PhabricatorDocumentEngine::getEnginesForRef($viewer, $ref); | ||||
$engine = head($engines); | |||||
$content = $engine->newDocument($ref); | |||||
$icon = $engine->newDocumentIcon($ref); | $engine_key = $request->getURIData('engineKey'); | ||||
if (!isset($engines[$engine_key])) { | |||||
$engine_key = head_key($engines); | |||||
} | |||||
$engine = $engines[$engine_key]; | |||||
$lines = $request->getURILineRange('lines', 1000); | |||||
if ($lines) { | |||||
$engine->setHighlightedLines(range($lines[0], $lines[1])); | |||||
} | |||||
$views = array(); | $views = array(); | ||||
foreach ($engines as $candidate_engine) { | foreach ($engines as $candidate_key => $candidate_engine) { | ||||
$label = $candidate_engine->getViewAsLabel($ref); | $label = $candidate_engine->getViewAsLabel($ref); | ||||
if ($label === null) { | if ($label === null) { | ||||
continue; | continue; | ||||
} | } | ||||
$view_uri = '/file/view/'.$file->getID().'/'.$candidate_key.'/'; | |||||
$view_icon = $candidate_engine->getViewAsIconIcon($ref); | $view_icon = $candidate_engine->getViewAsIconIcon($ref); | ||||
$view_color = $candidate_engine->getViewAsIconColor($ref); | $view_color = $candidate_engine->getViewAsIconColor($ref); | ||||
$loading = $candidate_engine->newLoadingContent($ref); | |||||
$views[] = array( | $views[] = array( | ||||
'viewKey' => $candidate_engine->getDocumentEngineKey(), | 'viewKey' => $candidate_engine->getDocumentEngineKey(), | ||||
'icon' => $view_icon, | 'icon' => $view_icon, | ||||
'color' => $view_color, | 'color' => $view_color, | ||||
'name' => $label, | 'name' => $label, | ||||
'engineURI' => $candidate_engine->getRenderURI($ref), | 'engineURI' => $candidate_engine->getRenderURI($ref), | ||||
'viewURI' => $view_uri, | |||||
'loadingMarkup' => hsprintf('%s', $loading), | |||||
); | ); | ||||
} | } | ||||
Javelin::initBehavior('document-engine'); | |||||
$viewport_id = celerity_generate_unique_node_id(); | $viewport_id = celerity_generate_unique_node_id(); | ||||
$control_id = celerity_generate_unique_node_id(); | |||||
$icon = $engine->newDocumentIcon($ref); | |||||
if ($engine->shouldRenderAsync($ref)) { | |||||
$content = $engine->newLoadingContent($ref); | |||||
$config = array( | |||||
'renderControlID' => $control_id, | |||||
); | |||||
} else { | |||||
$content = $engine->newDocument($ref); | |||||
$config = array(); | |||||
} | |||||
Javelin::initBehavior('document-engine', $config); | |||||
$viewport = phutil_tag( | $viewport = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'id' => $viewport_id, | 'id' => $viewport_id, | ||||
), | ), | ||||
$content); | $content); | ||||
$meta = array( | $meta = array( | ||||
'viewportID' => $viewport_id, | 'viewportID' => $viewport_id, | ||||
'viewKey' => $engine->getDocumentEngineKey(), | 'viewKey' => $engine->getDocumentEngineKey(), | ||||
'views' => $views, | 'views' => $views, | ||||
'standaloneURI' => $engine->getRenderURI($ref), | 'standaloneURI' => $engine->getRenderURI($ref), | ||||
); | ); | ||||
$view_button = id(new PHUIButtonView()) | $view_button = id(new PHUIButtonView()) | ||||
->setTag('a') | ->setTag('a') | ||||
->setText(pht('View Options')) | ->setText(pht('View Options')) | ||||
->setIcon('fa-file-image-o') | ->setIcon('fa-file-image-o') | ||||
->setColor(PHUIButtonView::GREY) | ->setColor(PHUIButtonView::GREY) | ||||
->setID($control_id) | |||||
->setMetadata($meta) | ->setMetadata($meta) | ||||
->setDropdown(true) | ->setDropdown(true) | ||||
->addSigil('document-engine-view-dropdown'); | ->addSigil('document-engine-view-dropdown'); | ||||
$header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
->setHeaderIcon($icon) | ->setHeaderIcon($icon) | ||||
->setHeader($ref->getName()) | ->setHeader($ref->getName()) | ||||
->addActionLink($view_button); | ->addActionLink($view_button); | ||||
return id(new PHUIObjectBoxView()) | return id(new PHUIObjectBoxView()) | ||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
->setHeader($header) | ->setHeader($header) | ||||
->appendChild($viewport); | ->appendChild($viewport); | ||||
} | } | ||||
} | } |