From 28c9607fd06ebdf676b75f4dc75d6f0ae0c83bfd Mon Sep 17 00:00:00 2001 From: Nick Harper Date: Tue, 31 Jan 2012 16:32:49 -0800 Subject: [PATCH] Provide better UX when trying to view binary file from differential Summary: When a user selects "show raw file (right)" from the dropdown of a binary file in differential, they should get more than a blank page. Test Plan: Loaded a raw binary file from differential Reviewers: tuomaspelkonen, epriestley, jungejason Reviewed By: epriestley CC: aran, epriestley Differential Revision: https://secure.phabricator.com/D1533 --- .../DifferentialChangesetViewController.php | 21 ++++++++++++------- .../controller/changesetview/__init__.php | 2 ++ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php b/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php index 3b16aa3c8f..75975104ee 100644 --- a/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php +++ b/src/applications/differential/controller/changesetview/DifferentialChangesetViewController.php @@ -48,13 +48,20 @@ class DifferentialChangesetViewController extends DifferentialController { $view = $request->getStr('view'); if ($view) { $changeset->attachHunks($changeset->loadHunks()); - switch ($view) { - case 'new': - return $this->buildRawFileResponse($changeset->makeNewFile()); - case 'old': - return $this->buildRawFileResponse($changeset->makeOldFile()); - default: - return new Aphront400Response(); + $type = $changeset->getFileType(); + if ($type === DifferentialChangeType::FILE_TEXT) { + switch ($view) { + case 'new': + return $this->buildRawFileResponse($changeset->makeNewFile()); + case 'old': + return $this->buildRawFileResponse($changeset->makeOldFile()); + default: + return new Aphront400Response(); + } + } else if ($type === DifferentialChangeType::FILE_IMAGE || + $type === DifferentialChangeType::FILE_BINARY) { + $phid = idx($changeset->getMetadata(), "$view:binary-phid"); + return id(new AphrontRedirectResponse())->setURI("/file/info/$phid/"); } } diff --git a/src/applications/differential/controller/changesetview/__init__.php b/src/applications/differential/controller/changesetview/__init__.php index f7457700a8..dd03e94eeb 100644 --- a/src/applications/differential/controller/changesetview/__init__.php +++ b/src/applications/differential/controller/changesetview/__init__.php @@ -12,6 +12,8 @@ phutil_require_module('phabricator', 'aphront/response/400'); phutil_require_module('phabricator', 'aphront/response/404'); phutil_require_module('phabricator', 'aphront/response/ajax'); phutil_require_module('phabricator', 'aphront/response/file'); +phutil_require_module('phabricator', 'aphront/response/redirect'); +phutil_require_module('phabricator', 'applications/differential/constants/changetype'); phutil_require_module('phabricator', 'applications/differential/controller/base'); phutil_require_module('phabricator', 'applications/differential/parser/changeset'); phutil_require_module('phabricator', 'applications/differential/storage/changeset');