mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
Add a "View as..." option to diff dropdowns for selecting between document engines
Summary: Depends on D20831. Ref T13425. As an escape hatch to get out of future DocumentEngine rendering behavior, provide a "View As.." option. Now I can break DocumentEngine real bad and no one can complain. Test Plan: Used "View As" to swap document engines for image files. Maniphest Tasks: T13425 Differential Revision: https://secure.phabricator.com/D20832
This commit is contained in:
parent
bb71ef6ad6
commit
7ae711ed3e
8 changed files with 143 additions and 25 deletions
|
@ -12,7 +12,7 @@ return array(
|
||||||
'core.pkg.css' => 'c69171e6',
|
'core.pkg.css' => 'c69171e6',
|
||||||
'core.pkg.js' => '6e5c894f',
|
'core.pkg.js' => '6e5c894f',
|
||||||
'differential.pkg.css' => 'eef74643',
|
'differential.pkg.css' => 'eef74643',
|
||||||
'differential.pkg.js' => '0b037a4f',
|
'differential.pkg.js' => '49515551',
|
||||||
'diffusion.pkg.css' => '42c75c37',
|
'diffusion.pkg.css' => '42c75c37',
|
||||||
'diffusion.pkg.js' => 'a98c0bf7',
|
'diffusion.pkg.js' => 'a98c0bf7',
|
||||||
'maniphest.pkg.css' => '35995d6d',
|
'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-move-panels.js' => 'a2ab19be',
|
||||||
'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '1e413dc9',
|
'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '1e413dc9',
|
||||||
'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8',
|
'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => '0116d3e8',
|
||||||
'rsrc/js/application/diff/DiffChangeset.js' => 'd0a85a85',
|
'rsrc/js/application/diff/DiffChangeset.js' => 'a31ffc00',
|
||||||
'rsrc/js/application/diff/DiffChangesetList.js' => '04023d82',
|
'rsrc/js/application/diff/DiffChangesetList.js' => '40850e53',
|
||||||
'rsrc/js/application/diff/DiffInline.js' => 'a4a14a94',
|
'rsrc/js/application/diff/DiffInline.js' => 'a4a14a94',
|
||||||
'rsrc/js/application/diff/behavior-preview-link.js' => 'f51e9c17',
|
'rsrc/js/application/diff/behavior-preview-link.js' => 'f51e9c17',
|
||||||
'rsrc/js/application/differential/behavior-diff-radios.js' => '925fe8cd',
|
'rsrc/js/application/differential/behavior-diff-radios.js' => '925fe8cd',
|
||||||
|
@ -773,8 +773,8 @@ return array(
|
||||||
'phabricator-darklog' => '3b869402',
|
'phabricator-darklog' => '3b869402',
|
||||||
'phabricator-darkmessage' => '26cd4b73',
|
'phabricator-darkmessage' => '26cd4b73',
|
||||||
'phabricator-dashboard-css' => '5a205b9d',
|
'phabricator-dashboard-css' => '5a205b9d',
|
||||||
'phabricator-diff-changeset' => 'd0a85a85',
|
'phabricator-diff-changeset' => 'a31ffc00',
|
||||||
'phabricator-diff-changeset-list' => '04023d82',
|
'phabricator-diff-changeset-list' => '40850e53',
|
||||||
'phabricator-diff-inline' => 'a4a14a94',
|
'phabricator-diff-inline' => 'a4a14a94',
|
||||||
'phabricator-drag-and-drop-file-upload' => '4370900d',
|
'phabricator-drag-and-drop-file-upload' => '4370900d',
|
||||||
'phabricator-draggable-list' => 'c9ad6f70',
|
'phabricator-draggable-list' => 'c9ad6f70',
|
||||||
|
@ -944,10 +944,6 @@ return array(
|
||||||
'03e8891f' => array(
|
'03e8891f' => array(
|
||||||
'javelin-install',
|
'javelin-install',
|
||||||
),
|
),
|
||||||
'04023d82' => array(
|
|
||||||
'javelin-install',
|
|
||||||
'phuix-button-view',
|
|
||||||
),
|
|
||||||
'04f8a1e3' => array(
|
'04f8a1e3' => array(
|
||||||
'javelin-behavior',
|
'javelin-behavior',
|
||||||
'javelin-stratcom',
|
'javelin-stratcom',
|
||||||
|
@ -1263,6 +1259,10 @@ return array(
|
||||||
'javelin-behavior',
|
'javelin-behavior',
|
||||||
'javelin-uri',
|
'javelin-uri',
|
||||||
),
|
),
|
||||||
|
'40850e53' => array(
|
||||||
|
'javelin-install',
|
||||||
|
'phuix-button-view',
|
||||||
|
),
|
||||||
'4234f572' => array(
|
'4234f572' => array(
|
||||||
'syntax-default-css',
|
'syntax-default-css',
|
||||||
),
|
),
|
||||||
|
@ -1788,6 +1788,17 @@ return array(
|
||||||
'javelin-workflow',
|
'javelin-workflow',
|
||||||
'phabricator-draggable-list',
|
'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(
|
'a4356cde' => array(
|
||||||
'javelin-install',
|
'javelin-install',
|
||||||
'javelin-dom',
|
'javelin-dom',
|
||||||
|
@ -2034,17 +2045,6 @@ return array(
|
||||||
'javelin-dom',
|
'javelin-dom',
|
||||||
'javelin-stratcom',
|
'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(
|
'd12d214f' => array(
|
||||||
'javelin-install',
|
'javelin-install',
|
||||||
'javelin-dom',
|
'javelin-dom',
|
||||||
|
|
|
@ -4876,6 +4876,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSystemRemoveWorkflow' => 'applications/system/management/PhabricatorSystemRemoveWorkflow.php',
|
'PhabricatorSystemRemoveWorkflow' => 'applications/system/management/PhabricatorSystemRemoveWorkflow.php',
|
||||||
'PhabricatorSystemSelectEncodingController' => 'applications/system/controller/PhabricatorSystemSelectEncodingController.php',
|
'PhabricatorSystemSelectEncodingController' => 'applications/system/controller/PhabricatorSystemSelectEncodingController.php',
|
||||||
'PhabricatorSystemSelectHighlightController' => 'applications/system/controller/PhabricatorSystemSelectHighlightController.php',
|
'PhabricatorSystemSelectHighlightController' => 'applications/system/controller/PhabricatorSystemSelectHighlightController.php',
|
||||||
|
'PhabricatorSystemSelectViewAsController' => 'applications/system/controller/PhabricatorSystemSelectViewAsController.php',
|
||||||
'PhabricatorTOTPAuthFactor' => 'applications/auth/factor/PhabricatorTOTPAuthFactor.php',
|
'PhabricatorTOTPAuthFactor' => 'applications/auth/factor/PhabricatorTOTPAuthFactor.php',
|
||||||
'PhabricatorTOTPAuthFactorTestCase' => 'applications/auth/factor/__tests__/PhabricatorTOTPAuthFactorTestCase.php',
|
'PhabricatorTOTPAuthFactorTestCase' => 'applications/auth/factor/__tests__/PhabricatorTOTPAuthFactorTestCase.php',
|
||||||
'PhabricatorTaskmasterDaemon' => 'infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php',
|
'PhabricatorTaskmasterDaemon' => 'infrastructure/daemon/workers/PhabricatorTaskmasterDaemon.php',
|
||||||
|
@ -11503,6 +11504,7 @@ phutil_register_library_map(array(
|
||||||
'PhabricatorSystemRemoveWorkflow' => 'PhabricatorManagementWorkflow',
|
'PhabricatorSystemRemoveWorkflow' => 'PhabricatorManagementWorkflow',
|
||||||
'PhabricatorSystemSelectEncodingController' => 'PhabricatorController',
|
'PhabricatorSystemSelectEncodingController' => 'PhabricatorController',
|
||||||
'PhabricatorSystemSelectHighlightController' => 'PhabricatorController',
|
'PhabricatorSystemSelectHighlightController' => 'PhabricatorController',
|
||||||
|
'PhabricatorSystemSelectViewAsController' => 'PhabricatorController',
|
||||||
'PhabricatorTOTPAuthFactor' => 'PhabricatorAuthFactor',
|
'PhabricatorTOTPAuthFactor' => 'PhabricatorAuthFactor',
|
||||||
'PhabricatorTOTPAuthFactorTestCase' => 'PhabricatorTestCase',
|
'PhabricatorTOTPAuthFactorTestCase' => 'PhabricatorTestCase',
|
||||||
'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon',
|
'PhabricatorTaskmasterDaemon' => 'PhabricatorDaemon',
|
||||||
|
|
|
@ -59,6 +59,7 @@ final class DifferentialChangesetParser extends Phobject {
|
||||||
|
|
||||||
private $highlightEngine;
|
private $highlightEngine;
|
||||||
private $viewer;
|
private $viewer;
|
||||||
|
private $documentEngineKey;
|
||||||
|
|
||||||
public function setRange($start, $end) {
|
public function setRange($start, $end) {
|
||||||
$this->rangeStart = $start;
|
$this->rangeStart = $start;
|
||||||
|
@ -159,6 +160,15 @@ final class DifferentialChangesetParser extends Phobject {
|
||||||
return $this->viewer;
|
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) {
|
public static function getDefaultRendererForViewer(PhabricatorUser $viewer) {
|
||||||
$is_unified = $viewer->compareUserSetting(
|
$is_unified = $viewer->compareUserSetting(
|
||||||
PhabricatorUnifiedDiffsSetting::SETTINGKEY,
|
PhabricatorUnifiedDiffsSetting::SETTINGKEY,
|
||||||
|
@ -174,6 +184,7 @@ final class DifferentialChangesetParser extends Phobject {
|
||||||
public function readParametersFromRequest(AphrontRequest $request) {
|
public function readParametersFromRequest(AphrontRequest $request) {
|
||||||
$this->setCharacterEncoding($request->getStr('encoding'));
|
$this->setCharacterEncoding($request->getStr('encoding'));
|
||||||
$this->setHighlightAs($request->getStr('highlight'));
|
$this->setHighlightAs($request->getStr('highlight'));
|
||||||
|
$this->setDocumentEngineKey($request->getStr('engine'));
|
||||||
|
|
||||||
$renderer = null;
|
$renderer = null;
|
||||||
|
|
||||||
|
@ -1695,14 +1706,22 @@ final class DifferentialChangesetParser extends Phobject {
|
||||||
|
|
||||||
$shared_engines = array_intersect_key($old_engines, $new_engines);
|
$shared_engines = array_intersect_key($old_engines, $new_engines);
|
||||||
|
|
||||||
$document_engine = null;
|
foreach ($shared_engines as $key => $shared_engine) {
|
||||||
foreach ($shared_engines as $shared_engine) {
|
if (!$shared_engine->canDiffDocuments($old_ref, $new_ref)) {
|
||||||
if ($shared_engine->canDiffDocuments($old_ref, $new_ref)) {
|
unset($shared_engines[$key]);
|
||||||
$document_engine = $shared_engine;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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) {
|
if ($document_engine) {
|
||||||
return $document_engine->newDiffView(
|
return $document_engine->newDiffView(
|
||||||
|
|
|
@ -240,6 +240,7 @@ final class DifferentialChangesetListView extends AphrontView {
|
||||||
'View Unified' => pht('View Unified'),
|
'View Unified' => pht('View Unified'),
|
||||||
'Change Text Encoding...' => pht('Change Text Encoding...'),
|
'Change Text Encoding...' => pht('Change Text Encoding...'),
|
||||||
'Highlight As...' => pht('Highlight As...'),
|
'Highlight As...' => pht('Highlight As...'),
|
||||||
|
'View As...' => pht('View As...'),
|
||||||
|
|
||||||
'Loading...' => pht('Loading...'),
|
'Loading...' => pht('Loading...'),
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@ final class PhabricatorSystemApplication extends PhabricatorApplication {
|
||||||
'/services/' => array(
|
'/services/' => array(
|
||||||
'encoding/' => 'PhabricatorSystemSelectEncodingController',
|
'encoding/' => 'PhabricatorSystemSelectEncodingController',
|
||||||
'highlight/' => 'PhabricatorSystemSelectHighlightController',
|
'highlight/' => 'PhabricatorSystemSelectHighlightController',
|
||||||
|
'viewas/' => 'PhabricatorSystemSelectViewAsController',
|
||||||
),
|
),
|
||||||
'/readonly/' => array(
|
'/readonly/' => array(
|
||||||
'(?P<reason>[^/]+)/' => 'PhabricatorSystemReadOnlyController',
|
'(?P<reason>[^/]+)/' => 'PhabricatorSystemReadOnlyController',
|
||||||
|
|
|
@ -0,0 +1,63 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PhabricatorSystemSelectViewAsController
|
||||||
|
extends PhabricatorController {
|
||||||
|
|
||||||
|
public function shouldRequireLogin() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handleRequest(AphrontRequest $request) {
|
||||||
|
$viewer = $this->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('/');
|
||||||
|
}
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ JX.install('DiffChangeset', {
|
||||||
this._ref = data.ref;
|
this._ref = data.ref;
|
||||||
this._renderer = data.renderer;
|
this._renderer = data.renderer;
|
||||||
this._highlight = data.highlight;
|
this._highlight = data.highlight;
|
||||||
|
this._documentEngine = data.documentEngine;
|
||||||
this._encoding = data.encoding;
|
this._encoding = data.encoding;
|
||||||
this._loaded = data.loaded;
|
this._loaded = data.loaded;
|
||||||
this._treeNodeID = data.treeNodeID;
|
this._treeNodeID = data.treeNodeID;
|
||||||
|
@ -47,6 +48,7 @@ JX.install('DiffChangeset', {
|
||||||
_ref: null,
|
_ref: null,
|
||||||
_renderer: null,
|
_renderer: null,
|
||||||
_highlight: null,
|
_highlight: null,
|
||||||
|
_documentEngine: null,
|
||||||
_encoding: null,
|
_encoding: null,
|
||||||
_undoTemplates: null,
|
_undoTemplates: null,
|
||||||
|
|
||||||
|
@ -310,6 +312,7 @@ JX.install('DiffChangeset', {
|
||||||
ref: this._ref,
|
ref: this._ref,
|
||||||
renderer: this.getRenderer() || '',
|
renderer: this.getRenderer() || '',
|
||||||
highlight: this._highlight || '',
|
highlight: this._highlight || '',
|
||||||
|
engine: this._documentEngine || '',
|
||||||
encoding: this._encoding || ''
|
encoding: this._encoding || ''
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -366,6 +369,14 @@ JX.install('DiffChangeset', {
|
||||||
return this._highlight;
|
return this._highlight;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
setDocumentEngine: function(engine) {
|
||||||
|
this._documentEngine = engine;
|
||||||
|
},
|
||||||
|
|
||||||
|
getDocumentEngine: function(engine) {
|
||||||
|
return this._documentEngine;
|
||||||
|
},
|
||||||
|
|
||||||
getSelectableItems: function() {
|
getSelectableItems: function() {
|
||||||
var items = [];
|
var items = [];
|
||||||
|
|
||||||
|
|
|
@ -827,6 +827,26 @@ JX.install('DiffChangesetList', {
|
||||||
});
|
});
|
||||||
list.addItem(highlight_item);
|
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-left', pht('Show Raw File (Left)'), data.leftURI);
|
||||||
add_link('fa-arrow-right', pht('Show Raw File (Right)'), data.rightURI);
|
add_link('fa-arrow-right', pht('Show Raw File (Right)'), data.rightURI);
|
||||||
add_link('fa-pencil', pht('Open in Editor'), data.editor, true);
|
add_link('fa-pencil', pht('Open in Editor'), data.editor, true);
|
||||||
|
@ -860,6 +880,7 @@ JX.install('DiffChangesetList', {
|
||||||
|
|
||||||
encoding_item.setDisabled(!changeset.isLoaded());
|
encoding_item.setDisabled(!changeset.isLoaded());
|
||||||
highlight_item.setDisabled(!changeset.isLoaded());
|
highlight_item.setDisabled(!changeset.isLoaded());
|
||||||
|
engine_item.setDisabled(!changeset.isLoaded());
|
||||||
|
|
||||||
if (changeset.isLoaded()) {
|
if (changeset.isLoaded()) {
|
||||||
if (changeset.getRenderer() == '2up') {
|
if (changeset.getRenderer() == '2up') {
|
||||||
|
|
Loading…
Reference in a new issue