Changeset View
Changeset View
Standalone View
Standalone View
src/applications/diffusion/controller/DiffusionBrowseController.php
| <?php | <?php | ||||
| final class DiffusionBrowseController extends DiffusionController { | final class DiffusionBrowseController extends DiffusionController { | ||||
| private $lintCommit; | private $lintCommit; | ||||
| private $lintMessages; | private $lintMessages; | ||||
| private $coverage; | private $coverage; | ||||
| private $corpusButtons = array(); | |||||
| public function shouldAllowPublic() { | public function shouldAllowPublic() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function handleRequest(AphrontRequest $request) { | public function handleRequest(AphrontRequest $request) { | ||||
| $response = $this->loadDiffusionContext(); | $response = $this->loadDiffusionContext(); | ||||
| if ($response) { | if ($response) { | ||||
| ▲ Show 20 Lines • Show All 219 Lines • ▼ Show 20 Lines | private function browseFile() { | ||||
| if ($request->isAjax()) { | if ($request->isAjax()) { | ||||
| return id(new AphrontAjaxResponse())->setContent($corpus); | return id(new AphrontAjaxResponse())->setContent($corpus); | ||||
| } | } | ||||
| require_celerity_resource('diffusion-source-css'); | require_celerity_resource('diffusion-source-css'); | ||||
| // Render the page. | // Render the page. | ||||
| $curtain = $this->buildCurtain($drequest, $show_blame, $show_editor); | $bar = $this->buildButtonBar($drequest, $show_blame, $show_editor); | ||||
| $properties = $this->buildPropertyView($drequest); | |||||
| $header = $this->buildHeaderView($drequest); | $header = $this->buildHeaderView($drequest); | ||||
| $header->setHeaderIcon('fa-file-code-o'); | $header->setHeaderIcon('fa-file-code-o'); | ||||
| $content = array(); | |||||
| $follow = $request->getStr('follow'); | $follow = $request->getStr('follow'); | ||||
| $follow_notice = null; | |||||
| if ($follow) { | if ($follow) { | ||||
| $notice = new PHUIInfoView(); | $follow_notice = id(new PHUIInfoView()) | ||||
| $notice->setSeverity(PHUIInfoView::SEVERITY_WARNING); | ->setSeverity(PHUIInfoView::SEVERITY_WARNING) | ||||
| $notice->setTitle(pht('Unable to Continue')); | ->setTitle(pht('Unable to Continue')); | ||||
| switch ($follow) { | switch ($follow) { | ||||
| case 'first': | case 'first': | ||||
| $notice->appendChild( | $follow_notice->appendChild( | ||||
| pht( | pht( | ||||
| 'Unable to continue tracing the history of this file because '. | 'Unable to continue tracing the history of this file because '. | ||||
| 'this commit is the first commit in the repository.')); | 'this commit is the first commit in the repository.')); | ||||
| break; | break; | ||||
| case 'created': | case 'created': | ||||
| $notice->appendChild( | $follow_notice->appendChild( | ||||
| pht( | pht( | ||||
| 'Unable to continue tracing the history of this file because '. | 'Unable to continue tracing the history of this file because '. | ||||
| 'this commit created the file.')); | 'this commit created the file.')); | ||||
| break; | break; | ||||
| } | } | ||||
| $content[] = $notice; | |||||
| } | } | ||||
| $renamed = $request->getStr('renamed'); | $renamed = $request->getStr('renamed'); | ||||
| $renamed_notice = null; | |||||
| if ($renamed) { | if ($renamed) { | ||||
| $notice = new PHUIInfoView(); | $renamed_notice = id(new PHUIInfoView()) | ||||
| $notice->setSeverity(PHUIInfoView::SEVERITY_NOTICE); | ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) | ||||
| $notice->setTitle(pht('File Renamed')); | ->setTitle(pht('File Renamed')) | ||||
| $notice->appendChild( | ->appendChild( | ||||
| pht( | pht( | ||||
| 'File history passes through a rename from "%s" to "%s".', | 'File history passes through a rename from "%s" to "%s".', | ||||
| $drequest->getPath(), | $drequest->getPath(), | ||||
| $renamed)); | $renamed)); | ||||
| $content[] = $notice; | |||||
| } | } | ||||
| $content[] = $corpus; | $open_revisions = $this->buildOpenRevisions(); | ||||
| $content[] = $this->buildOpenRevisions(); | $owners_list = $this->buildOwnersList($drequest); | ||||
| $crumbs = $this->buildCrumbs( | $crumbs = $this->buildCrumbs( | ||||
| array( | array( | ||||
| 'branch' => true, | 'branch' => true, | ||||
| 'path' => true, | 'path' => true, | ||||
| 'view' => 'browse', | 'view' => 'browse', | ||||
| )); | )); | ||||
| $crumbs->setBorder(true); | $crumbs->setBorder(true); | ||||
| $basename = basename($this->getDiffusionRequest()->getPath()); | $basename = basename($this->getDiffusionRequest()->getPath()); | ||||
| $tabs = $this->buildTabsView('code'); | $tabs = $this->buildTabsView('code'); | ||||
| $bar->setRight($this->corpusButtons); | |||||
| $view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setTabs($tabs) | ->setTabs($tabs) | ||||
| ->setCurtain($curtain) | ->setFooter(array( | ||||
| ->setMainColumn(array( | $bar, | ||||
| $content, | $follow_notice, | ||||
| $renamed_notice, | |||||
| $corpus, | |||||
| $open_revisions, | |||||
| $owners_list, | |||||
| )); | )); | ||||
| if ($properties) { | |||||
| $view->addPropertySection(pht('Details'), $properties); | |||||
| } | |||||
| $title = array($basename, $repository->getDisplayName()); | $title = array($basename, $repository->getDisplayName()); | ||||
| return $this->newPage() | return $this->newPage() | ||||
| ->setTitle($title) | ->setTitle($title) | ||||
| ->setCrumbs($crumbs) | ->setCrumbs($crumbs) | ||||
| ->appendChild( | ->appendChild( | ||||
| array( | array( | ||||
| $view, | $view, | ||||
| )); | )); | ||||
| } | } | ||||
| public function browseDirectory( | public function browseDirectory( | ||||
| DiffusionBrowseResultSet $results, | DiffusionBrowseResultSet $results, | ||||
| PHUIPagerView $pager) { | PHUIPagerView $pager) { | ||||
| $request = $this->getRequest(); | $request = $this->getRequest(); | ||||
| $drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
| $repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
| $reason = $results->getReasonForEmptyResultSet(); | $reason = $results->getReasonForEmptyResultSet(); | ||||
| $actions = $this->getActions($drequest); | $this->buildActionButtons($drequest, true); | ||||
| $details = $this->buildPropertyView($drequest); | $details = $this->buildPropertyView($drequest); | ||||
| $header = $this->buildHeaderView($drequest); | $header = $this->buildHeaderView($drequest); | ||||
| $header->setHeaderIcon('fa-folder-open'); | $header->setHeaderIcon('fa-folder-open'); | ||||
| $empty_result = null; | $empty_result = null; | ||||
| $browse_panel = null; | $browse_panel = null; | ||||
| $branch_panel = null; | $branch_panel = null; | ||||
| Show All 19 Lines | if (!$results->isValidResults()) { | ||||
| $browse_table = id(new DiffusionBrowseTableView()) | $browse_table = id(new DiffusionBrowseTableView()) | ||||
| ->setDiffusionRequest($drequest) | ->setDiffusionRequest($drequest) | ||||
| ->setHandles($handles) | ->setHandles($handles) | ||||
| ->setPaths($results->getPaths()) | ->setPaths($results->getPaths()) | ||||
| ->setUser($request->getUser()); | ->setUser($request->getUser()); | ||||
| $title = nonempty(basename($drequest->getPath()), '/'); | $title = nonempty(basename($drequest->getPath()), '/'); | ||||
| $icon = 'fa-folder-open'; | $icon = 'fa-folder-open'; | ||||
| $browse_header = $this->buildPanelHeaderView($title, $icon, $actions); | $browse_header = $this->buildPanelHeaderView($title, $icon); | ||||
| $browse_panel = id(new PHUIObjectBoxView()) | $browse_panel = id(new PHUIObjectBoxView()) | ||||
| ->setHeader($browse_header) | ->setHeader($browse_header) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->setTable($browse_table) | ->setTable($browse_table) | ||||
| ->setPager($pager); | ->setPager($pager); | ||||
| $path = $drequest->getPath(); | $path = $drequest->getPath(); | ||||
| Show All 10 Lines | $crumbs = $this->buildCrumbs( | ||||
| array( | array( | ||||
| 'branch' => true, | 'branch' => true, | ||||
| 'path' => true, | 'path' => true, | ||||
| 'view' => 'browse', | 'view' => 'browse', | ||||
| )); | )); | ||||
| $crumbs->setBorder(true); | $crumbs->setBorder(true); | ||||
| $tabs = $this->buildTabsView('code'); | $tabs = $this->buildTabsView('code'); | ||||
| $owners_list = $this->buildOwnersList($drequest); | |||||
| $bar = id(new PHUILeftRightView()) | |||||
| ->setRight($this->corpusButtons) | |||||
| ->addClass('diffusion-action-bar'); | |||||
| $view = id(new PHUITwoColumnView()) | $view = id(new PHUITwoColumnView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setTabs($tabs) | ->setTabs($tabs) | ||||
| ->setFooter( | ->setFooter( | ||||
| array( | array( | ||||
| $bar, | |||||
| $branch_panel, | $branch_panel, | ||||
| $empty_result, | $empty_result, | ||||
| $browse_panel, | $browse_panel, | ||||
| $open_revisions, | $open_revisions, | ||||
| $owners_list, | |||||
| $readme, | $readme, | ||||
| )); | )); | ||||
| if ($details) { | if ($details) { | ||||
| $view->addPropertySection(pht('Details'), $details); | $view->addPropertySection(pht('Details'), $details); | ||||
| } | } | ||||
| return $this->newPage() | return $this->newPage() | ||||
| ▲ Show 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | $corpus = phutil_tag( | ||||
| 'div', | 'div', | ||||
| array( | array( | ||||
| 'id' => $id, | 'id' => $id, | ||||
| ), | ), | ||||
| $corpus_table); | $corpus_table); | ||||
| Javelin::initBehavior('load-blame', array('id' => $id)); | Javelin::initBehavior('load-blame', array('id' => $id)); | ||||
| $file = $this->renderFileButton(); | $this->corpusButtons[] = $this->renderFileButton(); | ||||
| $title = basename($this->getDiffusionRequest()->getPath()); | $title = basename($this->getDiffusionRequest()->getPath()); | ||||
| $icon = 'fa-file-code-o'; | $icon = 'fa-file-code-o'; | ||||
| $drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
| $actions = $this->getActions($drequest); | $this->buildActionButtons($drequest); | ||||
| $header = $this->buildPanelHeaderView($title, $icon, $actions); | $header = $this->buildPanelHeaderView($title, $icon); | ||||
| $header->addActionLink($file); | |||||
| $corpus = id(new PHUIObjectBoxView()) | $corpus = id(new PHUIObjectBoxView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->appendChild($corpus) | ->appendChild($corpus) | ||||
| ->setCollapsed(true); | ->setCollapsed(true); | ||||
| $messages = array(); | $messages = array(); | ||||
| Show All 22 Lines | if ($messages) { | ||||
| id(new PHUIInfoView()) | id(new PHUIInfoView()) | ||||
| ->setSeverity(PHUIInfoView::SEVERITY_WARNING) | ->setSeverity(PHUIInfoView::SEVERITY_WARNING) | ||||
| ->setErrors($messages)); | ->setErrors($messages)); | ||||
| } | } | ||||
| return $corpus; | return $corpus; | ||||
| } | } | ||||
| private function buildCurtain( | private function buildButtonBar( | ||||
| DiffusionRequest $drequest, | DiffusionRequest $drequest, | ||||
| $show_blame, | $show_blame, | ||||
| $show_editor) { | $show_editor) { | ||||
| $curtain = $this->newCurtainView($drequest); | |||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $base_uri = $this->getRequest()->getRequestURI(); | $base_uri = $this->getRequest()->getRequestURI(); | ||||
| $user = $this->getRequest()->getUser(); | $user = $this->getRequest()->getUser(); | ||||
| $repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
| $path = $drequest->getPath(); | $path = $drequest->getPath(); | ||||
| $line = nonempty((int)$drequest->getLine(), 1); | $line = nonempty((int)$drequest->getLine(), 1); | ||||
| $buttons = array(); | |||||
| $editor_link = $user->loadEditorLink($path, $line, $repository); | $editor_link = $user->loadEditorLink($path, $line, $repository); | ||||
| $template = $user->loadEditorLink($path, '%l', $repository); | $template = $user->loadEditorLink($path, '%l', $repository); | ||||
| $curtain->addAction( | $buttons[] = | ||||
| id(new PhabricatorActionView()) | id(new PHUIButtonView()) | ||||
| ->setName(pht('Show Last Change')) | ->setText(pht('Last Change')) | ||||
| ->setColor(PHUIButtonView::GREY) | |||||
| ->setHref( | ->setHref( | ||||
| $drequest->generateURI( | $drequest->generateURI( | ||||
| array( | array( | ||||
| 'action' => 'change', | 'action' => 'change', | ||||
| ))) | ))) | ||||
| ->setIcon('fa-backward')); | ->setIcon('fa-backward'); | ||||
| if ($show_blame) { | if ($show_blame) { | ||||
| $blame_text = pht('Disable Blame'); | $blame_text = pht('Disable Blame'); | ||||
| $blame_icon = 'fa-exclamation-circle lightgreytext'; | $blame_icon = 'fa-exclamation-circle lightgreytext'; | ||||
| $blame_value = 0; | $blame_value = 0; | ||||
| } else { | } else { | ||||
| $blame_text = pht('Enable Blame'); | $blame_text = pht('Enable Blame'); | ||||
| $blame_icon = 'fa-exclamation-circle'; | $blame_icon = 'fa-exclamation-circle'; | ||||
| $blame_value = 1; | $blame_value = 1; | ||||
| } | } | ||||
| $curtain->addAction( | $blame = id(new PHUIButtonView()) | ||||
| id(new PhabricatorActionView()) | ->setText($blame_text) | ||||
| ->setName($blame_text) | |||||
| ->setHref($base_uri->alter('blame', $blame_value)) | |||||
| ->setIcon($blame_icon) | ->setIcon($blame_icon) | ||||
| ->setUser($viewer) | ->setUser($viewer) | ||||
| ->setRenderAsForm($viewer->isLoggedIn())); | ->setColor(PHUIButtonView::GREY); | ||||
| $curtain->addAction( | if ($viewer->isLoggedIn()) { | ||||
| id(new PhabricatorActionView()) | $blame = phabricator_form( | ||||
| ->setName(pht('Open in Editor')) | $viewer, | ||||
| array( | |||||
| 'action' => $base_uri->alter('blame', $blame_value), | |||||
| 'method' => 'POST', | |||||
| 'style' => 'display: inline-block;', | |||||
| ), | |||||
| $blame); | |||||
| } else { | |||||
| $blame->setTag('a'); | |||||
| $blame->setHref($base_uri->alter('blame', $blame_value)); | |||||
| } | |||||
| $buttons[] = $blame; | |||||
| if ($editor_link) { | |||||
| $buttons[] = | |||||
| id(new PHUIButtonView()) | |||||
| ->setTag('a') | |||||
| ->setText(pht('Open File')) | |||||
| ->setHref($editor_link) | ->setHref($editor_link) | ||||
| ->setIcon('fa-pencil') | ->setIcon('fa-pencil') | ||||
| ->setID('editor_link') | ->setID('editor_link') | ||||
| ->setMetadata(array('link_template' => $template)) | ->setMetadata(array('link_template' => $template)) | ||||
| ->setDisabled(!$editor_link)); | ->setDisabled(!$editor_link) | ||||
| ->setColor(PHUIButtonView::GREY); | |||||
| } | |||||
| $href = null; | $href = null; | ||||
| $show_lint = true; | |||||
| if ($this->getRequest()->getStr('lint') !== null) { | if ($this->getRequest()->getStr('lint') !== null) { | ||||
| $lint_text = pht('Hide %d Lint Message(s)', count($this->lintMessages)); | $lint_text = pht('Hide Lint'); | ||||
| $href = $base_uri->alter('lint', null); | $href = $base_uri->alter('lint', null); | ||||
| } else if ($this->lintCommit === null) { | } else if ($this->lintCommit === null) { | ||||
| $lint_text = pht('Lint not Available'); | $show_lint = false; | ||||
| } else { | } else { | ||||
| $lint_text = pht( | $lint_text = pht('Show Lint'); | ||||
| 'Show %d Lint Message(s)', | |||||
| count($this->lintMessages)); | |||||
| $href = $this->getDiffusionRequest()->generateURI(array( | $href = $this->getDiffusionRequest()->generateURI(array( | ||||
| 'action' => 'browse', | 'action' => 'browse', | ||||
| 'commit' => $this->lintCommit, | 'commit' => $this->lintCommit, | ||||
| ))->alter('lint', ''); | ))->alter('lint', ''); | ||||
| } | } | ||||
| $curtain->addAction( | if ($show_lint) { | ||||
| id(new PhabricatorActionView()) | $buttons[] = | ||||
| ->setName($lint_text) | id(new PHUIButtonView()) | ||||
| ->setTag('a') | |||||
| ->setText($lint_text) | |||||
| ->setHref($href) | ->setHref($href) | ||||
| ->setIcon('fa-exclamation-triangle') | ->setIcon('fa-exclamation-triangle') | ||||
| ->setDisabled(!$href)); | ->setDisabled(!$href) | ||||
| ->setColor(PHUIButtonView::GREY); | |||||
| } | |||||
| $bar = id(new PHUILeftRightView()) | |||||
| ->setLeft($buttons) | |||||
| ->addClass('diffusion-action-bar full-mobile-buttons'); | |||||
| return $bar; | |||||
| } | |||||
| private function buildOwnersList(DiffusionRequest $drequest) { | |||||
| $viewer = $this->getViewer(); | |||||
| $repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
| $owners = 'PhabricatorOwnersApplication'; | $owners = 'PhabricatorOwnersApplication'; | ||||
| if (PhabricatorApplication::isClassInstalled($owners)) { | if (PhabricatorApplication::isClassInstalled($owners)) { | ||||
| $package_query = id(new PhabricatorOwnersPackageQuery()) | $package_query = id(new PhabricatorOwnersPackageQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE)) | ->withStatuses(array(PhabricatorOwnersPackage::STATUS_ACTIVE)) | ||||
| ->withControl( | ->withControl( | ||||
| $repository->getPHID(), | $repository->getPHID(), | ||||
| array( | array( | ||||
| $drequest->getPath(), | $drequest->getPath(), | ||||
| )); | )); | ||||
| $package_query->execute(); | $package_query->execute(); | ||||
| $packages = $package_query->getControllingPackagesForPath( | $packages = $package_query->getControllingPackagesForPath( | ||||
| $repository->getPHID(), | $repository->getPHID(), | ||||
| $drequest->getPath()); | $drequest->getPath()); | ||||
| if ($packages) { | $ownership = id(new PHUIObjectItemListView()) | ||||
| $ownership = id(new PHUIStatusListView()) | ->setUser($viewer) | ||||
| ->setUser($viewer); | ->setNoDataString(pht('No Owners')); | ||||
| if ($packages) { | |||||
| foreach ($packages as $package) { | foreach ($packages as $package) { | ||||
| $icon = 'fa-list-alt'; | $item = id(new PHUIObjectItemView()) | ||||
| $color = 'grey'; | ->setObject($package) | ||||
| ->setObjectName($package->getMonogram()) | |||||
| ->setHeader($package->getName()) | |||||
| ->setHref($package->getURI()); | |||||
| $owners = $package->getOwners(); | |||||
| if ($owners) { | |||||
| $owner_list = $viewer->renderHandleList( | |||||
| mpull($owners, 'getUserPHID')); | |||||
| } else { | |||||
| $owner_list = phutil_tag('em', array(), pht('None')); | |||||
| } | |||||
| $item->addAttribute(pht('Owners: %s', $owner_list)); | |||||
| $auto = $package->getAutoReview(); | |||||
| $autoreview_map = PhabricatorOwnersPackage::getAutoreviewOptionsMap(); | |||||
| $spec = idx($autoreview_map, $auto, array()); | |||||
| $name = idx($spec, 'name', $auto); | |||||
| $item->addIcon('fa-code', $name); | |||||
| if ($package->getAuditingEnabled()) { | |||||
| $item->addIcon('fa-check', pht('Auditing Enabled')); | |||||
| } else { | |||||
| $item->addIcon('fa-ban', pht('No Auditing')); | |||||
| } | |||||
| $item = id(new PHUIStatusItemView()) | if ($package->isArchived()) { | ||||
| ->setIcon($icon, $color) | $item->setDisabled(true); | ||||
| ->setTarget($viewer->renderHandle($package->getPHID())); | } | ||||
| $ownership->addItem($item); | $ownership->addItem($item); | ||||
| } | } | ||||
| } else { | |||||
| $ownership = phutil_tag('em', array(), pht('None')); | |||||
| } | } | ||||
| $curtain->newPanel() | $view = id(new PHUIObjectBoxView()) | ||||
| ->setHeaderText(pht('Owners')) | ->setHeaderText(pht('Owner Packages')) | ||||
| ->appendChild($ownership); | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->setObjectList($ownership); | |||||
| } | } | ||||
| return $curtain; | return $view; | ||||
| } | } | ||||
| private function renderFileButton($file_uri = null, $label = null) { | private function renderFileButton($file_uri = null, $label = null) { | ||||
| $base_uri = $this->getRequest()->getRequestURI(); | $base_uri = $this->getRequest()->getRequestURI(); | ||||
| if ($file_uri) { | if ($file_uri) { | ||||
| $text = pht('Download Raw'); | $text = pht('Download File'); | ||||
| $href = $file_uri; | $href = $file_uri; | ||||
| $icon = 'fa-download'; | $icon = 'fa-download'; | ||||
| } else { | } else { | ||||
| $text = pht('View Raw'); | $text = pht('Raw File'); | ||||
| $href = $base_uri->alter('view', 'raw'); | $href = $base_uri->alter('view', 'raw'); | ||||
| $icon = 'fa-file-text'; | $icon = 'fa-file-text'; | ||||
| } | } | ||||
| if ($label !== null) { | if ($label !== null) { | ||||
| $text = $label; | $text = $label; | ||||
| } | } | ||||
| $button = id(new PHUIButtonView()) | $button = id(new PHUIButtonView()) | ||||
| ->setTag('a') | ->setTag('a') | ||||
| ->setText($text) | ->setText($text) | ||||
| ->setHref($href) | ->setHref($href) | ||||
| ->setIcon($icon); | ->setIcon($icon) | ||||
| ->setColor(PHUIButtonView::GREY); | |||||
| return $button; | return $button; | ||||
| } | } | ||||
| private function renderGitLFSButton() { | private function renderGitLFSButton() { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $uri = $this->getRequest()->getRequestURI(); | $uri = $this->getRequest()->getRequestURI(); | ||||
| ▲ Show 20 Lines • Show All 412 Lines • ▼ Show 20 Lines | private function buildImageCorpus($file_uri) { | ||||
| $properties->addImageContent( | $properties->addImageContent( | ||||
| phutil_tag( | phutil_tag( | ||||
| 'img', | 'img', | ||||
| array( | array( | ||||
| 'src' => $file_uri, | 'src' => $file_uri, | ||||
| ))); | ))); | ||||
| $file = $this->renderFileButton($file_uri); | $this->corpusButtons[] = $this->renderFileButton($file_uri); | ||||
| $title = basename($this->getDiffusionRequest()->getPath()); | $title = basename($this->getDiffusionRequest()->getPath()); | ||||
| $icon = 'fa-file-image-o'; | $icon = 'fa-file-image-o'; | ||||
| $drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
| $actions = $this->getActions($drequest); | $this->buildActionButtons($drequest); | ||||
| $header = $this->buildPanelHeaderView($title, $icon, $actions); | $header = $this->buildPanelHeaderView($title, $icon); | ||||
| $header->addActionLink($file); | |||||
| return id(new PHUIObjectBoxView()) | return id(new PHUIObjectBoxView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->addPropertyList($properties); | ->addPropertyList($properties); | ||||
| } | } | ||||
| private function buildBinaryCorpus($file_uri, $data) { | private function buildBinaryCorpus($file_uri, $data) { | ||||
| $size = new PhutilNumber(strlen($data)); | $size = new PhutilNumber(strlen($data)); | ||||
| $text = pht('This is a binary file. It is %s byte(s) in length.', $size); | $text = pht('This is a binary file. It is %s byte(s) in length.', $size); | ||||
| $text = id(new PHUIBoxView()) | $text = id(new PHUIBoxView()) | ||||
| ->addPadding(PHUI::PADDING_LARGE) | ->addPadding(PHUI::PADDING_LARGE) | ||||
| ->appendChild($text); | ->appendChild($text); | ||||
| $file = $this->renderFileButton($file_uri); | $this->corpusButtons[] = $this->renderFileButton($file_uri); | ||||
| $title = basename($this->getDiffusionRequest()->getPath()); | $title = basename($this->getDiffusionRequest()->getPath()); | ||||
| $icon = 'fa-file'; | $icon = 'fa-file'; | ||||
| $drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
| $actions = $this->getActions($drequest); | $this->buildActionButtons($drequest); | ||||
| $header = $this->buildPanelHeaderView($title, $icon, $actions); | $header = $this->buildPanelHeaderView($title, $icon); | ||||
| $header->addActionLink($file); | |||||
| $box = id(new PHUIObjectBoxView()) | $box = id(new PHUIObjectBoxView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->appendChild($text); | ->appendChild($text); | ||||
| return $box; | return $box; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | protected function buildHeaderView(DiffusionRequest $drequest) { | ||||
| if (!$repository->isSVN()) { | if (!$repository->isSVN()) { | ||||
| $branch_tag = $this->renderBranchTag($drequest); | $branch_tag = $this->renderBranchTag($drequest); | ||||
| $header->addTag($branch_tag); | $header->addTag($branch_tag); | ||||
| } | } | ||||
| return $header; | return $header; | ||||
| } | } | ||||
| protected function buildPanelHeaderView($title, $icon, array $actions) { | protected function buildPanelHeaderView($title, $icon) { | ||||
| $header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
| ->setHeader($title) | ->setHeader($title) | ||||
| ->setHeaderIcon($icon) | ->setHeaderIcon($icon) | ||||
| ->addClass('diffusion-panel-header-view'); | ->addClass('diffusion-panel-header-view'); | ||||
| foreach ($actions as $action_link) { | |||||
| if ($action_link) { | |||||
| $header->addActionLink($action_link); | |||||
| } | |||||
| } | |||||
| return $header; | return $header; | ||||
| } | } | ||||
| protected function getActions(DiffusionRequest $drequest) { | protected function buildActionButtons( | ||||
| DiffusionRequest $drequest, | |||||
| $is_directory = false) { | |||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $repository = $drequest->getRepository(); | $repository = $drequest->getRepository(); | ||||
| $history_uri = $drequest->generateURI(array('action' => 'history')); | $history_uri = $drequest->generateURI(array('action' => 'history')); | ||||
| $behind_head = $drequest->getSymbolicCommit(); | $behind_head = $drequest->getSymbolicCommit(); | ||||
| $compare = null; | $compare = null; | ||||
| $head_uri = $drequest->generateURI( | $head_uri = $drequest->generateURI( | ||||
| array( | array( | ||||
| 'commit' => '', | 'commit' => '', | ||||
| 'action' => 'browse', | 'action' => 'browse', | ||||
| )); | )); | ||||
| if ($repository->supportsBranchComparison()) { | if ($repository->supportsBranchComparison() && $is_directory) { | ||||
| $compare_uri = $drequest->generateURI(array('action' => 'compare')); | $compare_uri = $drequest->generateURI(array('action' => 'compare')); | ||||
| $compare = id(new PHUIButtonView()) | $compare = id(new PHUIButtonView()) | ||||
| ->setText(pht('Compare')) | ->setText(pht('Compare')) | ||||
| ->setIcon('fa-code-fork') | ->setIcon('fa-code-fork') | ||||
| ->setWorkflow(true) | ->setWorkflow(true) | ||||
| ->setTag('a') | ->setTag('a') | ||||
| ->setHref($compare_uri) | ->setHref($compare_uri) | ||||
| ->setColor(PHUIButtonView::GREY); | ->setColor(PHUIButtonView::GREY); | ||||
| $this->corpusButtons[] = $compare; | |||||
| } | } | ||||
| $head = null; | $head = null; | ||||
| if ($behind_head) { | if ($behind_head) { | ||||
| $head = id(new PHUIButtonView()) | $head = id(new PHUIButtonView()) | ||||
| ->setText(pht('Back to HEAD')) | ->setText(pht('Back to HEAD')) | ||||
| ->setHref($head_uri) | ->setHref($head_uri) | ||||
| ->setIcon('fa-home') | ->setIcon('fa-home') | ||||
| ->setColor(PHUIButtonView::GREY); | ->setColor(PHUIButtonView::GREY); | ||||
| $this->corpusButtons[] = $head; | |||||
| } | } | ||||
| $history = id(new PHUIButtonView()) | $history = id(new PHUIButtonView()) | ||||
| ->setText(pht('History')) | ->setText(pht('History')) | ||||
| ->setHref($history_uri) | ->setHref($history_uri) | ||||
| ->setTag('a') | ->setTag('a') | ||||
| ->setIcon('fa-history') | ->setIcon('fa-history') | ||||
| ->setColor(PHUIButtonView::GREY); | ->setColor(PHUIButtonView::GREY); | ||||
| $this->corpusButtons[] = $history; | |||||
| return array($history, $compare, $head); | |||||
| } | } | ||||
| protected function buildPropertyView( | protected function buildPropertyView( | ||||
| DiffusionRequest $drequest) { | DiffusionRequest $drequest) { | ||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $view = id(new PHUIPropertyListView()) | $view = id(new PHUIPropertyListView()) | ||||
| ->setUser($viewer); | ->setUser($viewer); | ||||
| ▲ Show 20 Lines • Show All 187 Lines • ▼ Show 20 Lines | |||||
| private function buildGitLFSCorpus(PhabricatorRepositoryGitLFSRef $ref) { | private function buildGitLFSCorpus(PhabricatorRepositoryGitLFSRef $ref) { | ||||
| // TODO: We should probably test if we can load the file PHID here and | // TODO: We should probably test if we can load the file PHID here and | ||||
| // show the user an error if we can't, rather than making them click | // show the user an error if we can't, rather than making them click | ||||
| // through to hit an error. | // through to hit an error. | ||||
| $title = basename($this->getDiffusionRequest()->getPath()); | $title = basename($this->getDiffusionRequest()->getPath()); | ||||
| $icon = 'fa-archive'; | $icon = 'fa-archive'; | ||||
| $drequest = $this->getDiffusionRequest(); | $drequest = $this->getDiffusionRequest(); | ||||
| $actions = $this->getActions($drequest); | $this->buildActionButtons($drequest); | ||||
| $header = $this->buildPanelHeaderView($title, $icon, $actions); | $header = $this->buildPanelHeaderView($title, $icon); | ||||
| $severity = PHUIInfoView::SEVERITY_NOTICE; | $severity = PHUIInfoView::SEVERITY_NOTICE; | ||||
| $messages = array(); | $messages = array(); | ||||
| $messages[] = pht( | $messages[] = pht( | ||||
| 'This %s file is stored in Git Large File Storage.', | 'This %s file is stored in Git Large File Storage.', | ||||
| phutil_format_bytes($ref->getByteSize())); | phutil_format_bytes($ref->getByteSize())); | ||||
| try { | try { | ||||
| $file = $this->loadGitLFSFile($ref); | $file = $this->loadGitLFSFile($ref); | ||||
| $data = $this->renderGitLFSButton(); | $data = $this->renderGitLFSButton(); | ||||
| $header->addActionLink($data); | |||||
| } catch (Exception $ex) { | } catch (Exception $ex) { | ||||
| $severity = PHUIInfoView::SEVERITY_ERROR; | $severity = PHUIInfoView::SEVERITY_ERROR; | ||||
| $messages[] = pht('The data for this file could not be loaded.'); | $messages[] = pht('The data for this file could not be loaded.'); | ||||
| } | } | ||||
| $raw = $this->renderFileButton(null, pht('View Raw LFS Pointer')); | $this->corpusButtons[] = $this->renderFileButton( | ||||
| $header->addActionLink($raw); | null, pht('View Raw LFS Pointer')); | ||||
| $corpus = id(new PHUIObjectBoxView()) | $corpus = id(new PHUIObjectBoxView()) | ||||
| ->setHeader($header) | ->setHeader($header) | ||||
| ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | ||||
| ->setCollapsed(true); | ->setCollapsed(true); | ||||
| if ($messages) { | if ($messages) { | ||||
| $corpus->setInfoView( | $corpus->setInfoView( | ||||
| ▲ Show 20 Lines • Show All 84 Lines • Show Last 20 Lines | |||||