diff --git a/resources/celerity/map.php b/resources/celerity/map.php index ff7b2f300f..2e5ad39f62 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -12,7 +12,7 @@ return array( 'core.pkg.css' => 'c69171e6', 'core.pkg.js' => '6e5c894f', 'differential.pkg.css' => 'eef74643', - 'differential.pkg.js' => '0b037a4f', + 'differential.pkg.js' => '49515551', 'diffusion.pkg.css' => '42c75c37', 'diffusion.pkg.js' => 'a98c0bf7', 'maniphest.pkg.css' => '35995d6d', @@ -376,8 +376,8 @@ return array( 'rsrc/js/application/dashboard/behavior-dashboard-move-panels.js' => 'a2ab19be', 'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '1e413dc9', 'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8', - 'rsrc/js/application/diff/DiffChangeset.js' => 'd0a85a85', - 'rsrc/js/application/diff/DiffChangesetList.js' => '04023d82', + 'rsrc/js/application/diff/DiffChangeset.js' => 'a31ffc00', + 'rsrc/js/application/diff/DiffChangesetList.js' => '40850e53', 'rsrc/js/application/diff/DiffInline.js' => 'a4a14a94', 'rsrc/js/application/diff/behavior-preview-link.js' => 'f51e9c17', 'rsrc/js/application/differential/behavior-diff-radios.js' => '925fe8cd', @@ -773,8 +773,8 @@ return array( 'phabricator-darklog' => '3b869402', 'phabricator-darkmessage' => '26cd4b73', 'phabricator-dashboard-css' => '5a205b9d', - 'phabricator-diff-changeset' => 'd0a85a85', - 'phabricator-diff-changeset-list' => '04023d82', + 'phabricator-diff-changeset' => 'a31ffc00', + 'phabricator-diff-changeset-list' => '40850e53', 'phabricator-diff-inline' => 'a4a14a94', 'phabricator-drag-and-drop-file-upload' => '4370900d', 'phabricator-draggable-list' => 'c9ad6f70', @@ -944,10 +944,6 @@ return array( '03e8891f' => array( 'javelin-install', ), - '04023d82' => array( - 'javelin-install', - 'phuix-button-view', - ), '04f8a1e3' => array( 'javelin-behavior', 'javelin-stratcom', @@ -1263,6 +1259,10 @@ return array( 'javelin-behavior', 'javelin-uri', ), + '40850e53' => array( + 'javelin-install', + 'phuix-button-view', + ), '4234f572' => array( 'syntax-default-css', ), @@ -1788,6 +1788,17 @@ return array( 'javelin-workflow', 'phabricator-draggable-list', ), + 'a31ffc00' => array( + 'javelin-dom', + 'javelin-util', + 'javelin-stratcom', + 'javelin-install', + 'javelin-workflow', + 'javelin-router', + 'javelin-behavior-device', + 'javelin-vector', + 'phabricator-diff-inline', + ), 'a4356cde' => array( 'javelin-install', 'javelin-dom', @@ -2034,17 +2045,6 @@ return array( 'javelin-dom', 'javelin-stratcom', ), - 'd0a85a85' => array( - 'javelin-dom', - 'javelin-util', - 'javelin-stratcom', - 'javelin-install', - 'javelin-workflow', - 'javelin-router', - 'javelin-behavior-device', - 'javelin-vector', - 'phabricator-diff-inline', - ), 'd12d214f' => array( 'javelin-install', 'javelin-dom', diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 1ea9d9f67d..b6929ca9ce 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -4876,6 +4876,7 @@ phutil_register_library_map(array( 'PhabricatorSystemRemoveWorkflow' => 'applications/system/management/PhabricatorSystemRemoveWorkflow.php', 'PhabricatorSystemSelectEncodingController' => 'applications/system/controller/PhabricatorSystemSelectEncodingController.php', 'PhabricatorSystemSelectHighlightController' => 'applications/system/controller/PhabricatorSystemSelectHighlightController.php', + 'PhabricatorSystemSelectViewAsController' => 'applications/system/controller/PhabricatorSystemSelectViewAsController.php', 'PhabricatorTOTPAuthFactor' => 'applications/auth/factor/PhabricatorTOTPAuthFactor.php', 'PhabricatorTOTPAuthFactorTestCase' => 'applications/auth/factor/__tests__/PhabricatorTOTPAuthFactorTestCase.php', 'PhabricatorTaskmasterDaemon' => 'infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php', @@ -11503,6 +11504,7 @@ phutil_register_library_map(array( 'PhabricatorSystemRemoveWorkflow' => 'PhabricatorManagementWorkflow', 'PhabricatorSystemSelectEncodingController' => 'PhabricatorController', 'PhabricatorSystemSelectHighlightController' => 'PhabricatorController', + 'PhabricatorSystemSelectViewAsController' => 'PhabricatorController', 'PhabricatorTOTPAuthFactor' => 'PhabricatorAuthFactor', 'PhabricatorTOTPAuthFactorTestCase' => 'PhabricatorTestCase', 'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon', diff --git a/src/applications/differential/parser/DifferentialChangesetParser.php b/src/applications/differential/parser/DifferentialChangesetParser.php index 88ab8c7bd6..9492b6901a 100644 --- a/src/applications/differential/parser/DifferentialChangesetParser.php +++ b/src/applications/differential/parser/DifferentialChangesetParser.php @@ -59,6 +59,7 @@ final class DifferentialChangesetParser extends Phobject { private $highlightEngine; private $viewer; + private $documentEngineKey; public function setRange($start, $end) { $this->rangeStart = $start; @@ -159,6 +160,15 @@ final class DifferentialChangesetParser extends Phobject { return $this->viewer; } + public function setDocumentEngineKey($document_engine_key) { + $this->documentEngineKey = $document_engine_key; + return $this; + } + + public function getDocumentEngineKey() { + return $this->documentEngineKey; + } + public static function getDefaultRendererForViewer(PhabricatorUser $viewer) { $is_unified = $viewer->compareUserSetting( PhabricatorUnifiedDiffsSetting::SETTINGKEY, @@ -174,6 +184,7 @@ final class DifferentialChangesetParser extends Phobject { public function readParametersFromRequest(AphrontRequest $request) { $this->setCharacterEncoding($request->getStr('encoding')); $this->setHighlightAs($request->getStr('highlight')); + $this->setDocumentEngineKey($request->getStr('engine')); $renderer = null; @@ -1695,14 +1706,22 @@ final class DifferentialChangesetParser extends Phobject { $shared_engines = array_intersect_key($old_engines, $new_engines); - $document_engine = null; - foreach ($shared_engines as $shared_engine) { - if ($shared_engine->canDiffDocuments($old_ref, $new_ref)) { - $document_engine = $shared_engine; - break; + foreach ($shared_engines as $key => $shared_engine) { + if (!$shared_engine->canDiffDocuments($old_ref, $new_ref)) { + unset($shared_engines[$key]); } } + $engine_key = $this->getDocumentEngineKey(); + if (strlen($engine_key)) { + if (isset($shared_engines[$engine_key])) { + $document_engine = $shared_engines[$engine_key]; + } else { + $document_engine = null; + } + } else { + $document_engine = head($shared_engines); + } if ($document_engine) { return $document_engine->newDiffView( diff --git a/src/applications/differential/view/DifferentialChangesetListView.php b/src/applications/differential/view/DifferentialChangesetListView.php index 67568005fa..353457ef04 100644 --- a/src/applications/differential/view/DifferentialChangesetListView.php +++ b/src/applications/differential/view/DifferentialChangesetListView.php @@ -240,6 +240,7 @@ final class DifferentialChangesetListView extends AphrontView { 'View Unified' => pht('View Unified'), 'Change Text Encoding...' => pht('Change Text Encoding...'), 'Highlight As...' => pht('Highlight As...'), + 'View As...' => pht('View As...'), 'Loading...' => pht('Loading...'), diff --git a/src/applications/system/application/PhabricatorSystemApplication.php b/src/applications/system/application/PhabricatorSystemApplication.php index 3fa40b3912..b6cc13050f 100644 --- a/src/applications/system/application/PhabricatorSystemApplication.php +++ b/src/applications/system/application/PhabricatorSystemApplication.php @@ -22,6 +22,7 @@ final class PhabricatorSystemApplication extends PhabricatorApplication { '/services/' => array( 'encoding/' => 'PhabricatorSystemSelectEncodingController', 'highlight/' => 'PhabricatorSystemSelectHighlightController', + 'viewas/' => 'PhabricatorSystemSelectViewAsController', ), '/readonly/' => array( '(?P[^/]+)/' => 'PhabricatorSystemReadOnlyController', diff --git a/src/applications/system/controller/PhabricatorSystemSelectViewAsController.php b/src/applications/system/controller/PhabricatorSystemSelectViewAsController.php new file mode 100644 index 0000000000..19f800f820 --- /dev/null +++ b/src/applications/system/controller/PhabricatorSystemSelectViewAsController.php @@ -0,0 +1,63 @@ +getViewer(); + $v_engine = $request->getStr('engine'); + + if ($request->isFormPost()) { + $result = array('engine' => $v_engine); + return id(new AphrontAjaxResponse())->setContent($result); + } + + $engines = PhabricatorDocumentEngine::getAllEngines(); + + + // TODO: This controller isn't very good because the valid options depend + // on the file being rendered and most of them can't even diff anything, + // and this ref is completely bogus. + + // For now, we just show everything. + $ref = new PhabricatorDocumentRef(); + + $map = array(); + foreach ($engines as $engine) { + $key = $engine->getDocumentEngineKey(); + $label = $engine->getViewAsLabel($ref); + + if (!strlen($label)) { + continue; + } + + $map[$key] = $label; + } + + asort($map); + + $map = array( + '' => pht('(Use Default)'), + ) + $map; + + $form = id(new AphrontFormView()) + ->setViewer($viewer) + ->appendRemarkupInstructions(pht('Choose a document engine to use.')) + ->appendChild( + id(new AphrontFormSelectControl()) + ->setLabel(pht('View As')) + ->setName('engine') + ->setValue($v_engine) + ->setOptions($map)); + + return $this->newDialog() + ->setTitle(pht('Select Document Engine')) + ->appendForm($form) + ->addSubmitButton(pht('Choose Engine')) + ->addCancelButton('/'); + } +} diff --git a/webroot/rsrc/js/application/diff/DiffChangeset.js b/webroot/rsrc/js/application/diff/DiffChangeset.js index 754f3b16e4..9a1e5d12c2 100644 --- a/webroot/rsrc/js/application/diff/DiffChangeset.js +++ b/webroot/rsrc/js/application/diff/DiffChangeset.js @@ -24,6 +24,7 @@ JX.install('DiffChangeset', { this._ref = data.ref; this._renderer = data.renderer; this._highlight = data.highlight; + this._documentEngine = data.documentEngine; this._encoding = data.encoding; this._loaded = data.loaded; this._treeNodeID = data.treeNodeID; @@ -47,6 +48,7 @@ JX.install('DiffChangeset', { _ref: null, _renderer: null, _highlight: null, + _documentEngine: null, _encoding: null, _undoTemplates: null, @@ -310,6 +312,7 @@ JX.install('DiffChangeset', { ref: this._ref, renderer: this.getRenderer() || '', highlight: this._highlight || '', + engine: this._documentEngine || '', encoding: this._encoding || '' }; }, @@ -366,6 +369,14 @@ JX.install('DiffChangeset', { return this._highlight; }, + setDocumentEngine: function(engine) { + this._documentEngine = engine; + }, + + getDocumentEngine: function(engine) { + return this._documentEngine; + }, + getSelectableItems: function() { var items = []; diff --git a/webroot/rsrc/js/application/diff/DiffChangesetList.js b/webroot/rsrc/js/application/diff/DiffChangesetList.js index 572faad987..4060438cb0 100644 --- a/webroot/rsrc/js/application/diff/DiffChangesetList.js +++ b/webroot/rsrc/js/application/diff/DiffChangesetList.js @@ -827,6 +827,26 @@ JX.install('DiffChangesetList', { }); list.addItem(highlight_item); + var engine_item = new JX.PHUIXActionView() + .setIcon('fa-file-image-o') + .setName(pht('View As...')) + .setHandler(function(e) { + var params = { + engine: changeset.getDocumentEngine(), + }; + + new JX.Workflow('/services/viewas/', params) + .setHandler(function(r) { + changeset.setDocumentEngine(r.engine); + changeset.reload(); + }) + .start(); + + e.prevent(); + menu.close(); + }); + list.addItem(engine_item); + add_link('fa-arrow-left', pht('Show Raw File (Left)'), data.leftURI); add_link('fa-arrow-right', pht('Show Raw File (Right)'), data.rightURI); add_link('fa-pencil', pht('Open in Editor'), data.editor, true); @@ -860,6 +880,7 @@ JX.install('DiffChangesetList', { encoding_item.setDisabled(!changeset.isLoaded()); highlight_item.setDisabled(!changeset.isLoaded()); + engine_item.setDisabled(!changeset.isLoaded()); if (changeset.isLoaded()) { if (changeset.getRenderer() == '2up') {