Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phragment/controller/PhragmentController.php
Show First 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | protected function createCurrentFragmentView($fragment, $is_history_view) { | ||||
$viewer = $this->getRequest()->getUser(); | $viewer = $this->getRequest()->getUser(); | ||||
$phids = array(); | $phids = array(); | ||||
$phids[] = $fragment->getLatestVersionPHID(); | $phids[] = $fragment->getLatestVersionPHID(); | ||||
$this->loadHandles($phids); | $this->loadHandles($phids); | ||||
$file = null; | |||||
$file_uri = null; | |||||
if (!$fragment->isDirectory()) { | |||||
$file = id(new PhabricatorFileQuery()) | $file = id(new PhabricatorFileQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withPHIDs(array($fragment->getLatestVersion()->getFilePHID())) | ->withPHIDs(array($fragment->getLatestVersion()->getFilePHID())) | ||||
->executeOne(); | ->executeOne(); | ||||
$file_uri = null; | |||||
if ($file !== null) { | if ($file !== null) { | ||||
$file_uri = $file->getBestURI(); | $file_uri = $file->getBestURI(); | ||||
} | } | ||||
} | |||||
$header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
->setHeader($fragment->getName()) | ->setHeader($fragment->getName()) | ||||
->setPolicyObject($fragment) | ->setPolicyObject($fragment) | ||||
->setUser($viewer); | ->setUser($viewer); | ||||
$actions = id(new PhabricatorActionListView()) | $actions = id(new PhabricatorActionListView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setObject($fragment) | ->setObject($fragment) | ||||
->setObjectURI($fragment->getURI()); | ->setObjectURI($fragment->getURI()); | ||||
$actions->addAction( | $actions->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('Download Fragment')) | ->setName(pht('Download Fragment')) | ||||
->setHref($file_uri) | ->setHref($file_uri) | ||||
->setDisabled($file === null) | ->setDisabled($file === null) | ||||
->setIcon('download')); | ->setIcon('download')); | ||||
$actions->addAction( | $actions->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('Download Contents as ZIP')) | ->setName(pht('Download Contents as ZIP')) | ||||
->setHref($this->getApplicationURI("zip/".$fragment->getPath())) | ->setHref($this->getApplicationURI("zip/".$fragment->getPath())) | ||||
->setDisabled(false) // TODO: Policy | ->setDisabled(false) // TODO: Policy | ||||
->setIcon('zip')); | ->setIcon('zip')); | ||||
if (!$fragment->isDirectory()) { | |||||
$actions->addAction( | $actions->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('Update Fragment')) | ->setName(pht('Update Fragment')) | ||||
->setHref($this->getApplicationURI("update/".$fragment->getPath())) | ->setHref($this->getApplicationURI("update/".$fragment->getPath())) | ||||
->setDisabled(false) // TODO: Policy | ->setDisabled(false) // TODO: Policy | ||||
->setIcon('edit')); | ->setIcon('edit')); | ||||
} else { | |||||
$actions->addAction( | |||||
id(new PhabricatorActionView()) | |||||
->setName(pht('Convert to File')) | |||||
->setHref($this->getApplicationURI("update/".$fragment->getPath())) | |||||
->setDisabled(false) // TODO: Policy | |||||
->setIcon('edit')); | |||||
} | |||||
if ($is_history_view) { | if ($is_history_view) { | ||||
$actions->addAction( | $actions->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('View Child Fragments')) | ->setName(pht('View Child Fragments')) | ||||
->setHref($this->getApplicationURI("browse/".$fragment->getPath())) | ->setHref($this->getApplicationURI("browse/".$fragment->getPath())) | ||||
->setIcon('browse')); | ->setIcon('browse')); | ||||
} else { | } else { | ||||
$actions->addAction( | $actions->addAction( | ||||
id(new PhabricatorActionView()) | id(new PhabricatorActionView()) | ||||
->setName(pht('View History')) | ->setName(pht('View History')) | ||||
->setHref($this->getApplicationURI("history/".$fragment->getPath())) | ->setHref($this->getApplicationURI("history/".$fragment->getPath())) | ||||
->setIcon('history')); | ->setIcon('history')); | ||||
} | } | ||||
$properties = id(new PHUIPropertyListView()) | $properties = id(new PHUIPropertyListView()) | ||||
->setUser($viewer) | ->setUser($viewer) | ||||
->setObject($fragment) | ->setObject($fragment) | ||||
->setActionList($actions); | ->setActionList($actions); | ||||
if (!$fragment->isDirectory()) { | |||||
$properties->addProperty( | |||||
pht('Type'), | |||||
pht('File')); | |||||
$properties->addProperty( | $properties->addProperty( | ||||
pht('Latest Version'), | pht('Latest Version'), | ||||
$this->renderHandlesForPHIDs(array($fragment->getLatestVersionPHID()))); | $this->renderHandlesForPHIDs(array($fragment->getLatestVersionPHID()))); | ||||
} else { | |||||
$properties->addProperty( | |||||
pht('Type'), | |||||
pht('Directory')); | |||||
} | |||||
return id(new PHUIObjectBoxView()) | return id(new PHUIObjectBoxView()) | ||||
->setHeader($header) | ->setHeader($header) | ||||
->addPropertyList($properties); | ->addPropertyList($properties); | ||||
} | } | ||||
} | } |