1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-10 23:01:04 +01:00

Split Diffusion "view" preference into blame and color preferences

Summary:
We have this silly "view" preference which has a variety of silly values: "plain", "plainblame", "highlighted", and "blame", and then also "raw", which is magical. This is really just two flags: color on/off, and blame on/off (plus a separate mode for raw).

Express the code in terms of the flags and, e.g., get rid of the state transition tables we had before.

Test Plan: Viewed code in all four modes.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D7046
This commit is contained in:
epriestley 2013-09-19 16:01:58 -07:00
parent 0139fb9178
commit 424f7545fc
3 changed files with 127 additions and 116 deletions

View file

@ -82,7 +82,7 @@ abstract class DiffusionBrowseController extends DiffusionController {
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setName(pht('View History')) ->setName(pht('View History'))
->setHref($history_uri) ->setHref($history_uri)
->setIcon('perflab')); ->setIcon('history'));
$behind_head = $drequest->getRawCommit(); $behind_head = $drequest->getRawCommit();
$head_uri = $drequest->generateURI( $head_uri = $drequest->generateURI(

View file

@ -18,26 +18,42 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
$path = $drequest->getPath(); $path = $drequest->getPath();
$selected = $request->getStr('view');
$preferences = $request->getUser()->loadPreferences(); $preferences = $request->getUser()->loadPreferences();
if (!$selected) {
$selected = $preferences->getPreference( $show_blame = $request->getBool(
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW, 'blame',
'highlighted'); $preferences->getPreference(
} else if ($request->isFormPost() && $selected != 'raw') { PhabricatorUserPreferences::PREFERENCE_DIFFUSION_BLAME,
false));
$show_color = $request->getBool(
'color',
$preferences->getPreference(
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_COLOR,
true));
$view = $request->getStr('view');
if ($request->isFormPost() && $view != 'raw') {
$preferences->setPreference( $preferences->setPreference(
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_VIEW, PhabricatorUserPreferences::PREFERENCE_DIFFUSION_BLAME,
$selected); $show_blame);
$preferences->setPreference(
PhabricatorUserPreferences::PREFERENCE_DIFFUSION_COLOR,
$show_color);
$preferences->save(); $preferences->save();
return id(new AphrontRedirectResponse()) $uri = $request->getRequestURI()
->setURI($request->getRequestURI()->alter('view', $selected)); ->alter('blame', null)
->alter('color', null);
return id(new AphrontRedirectResponse())->setURI($uri);
} }
$needs_blame = ($selected == 'plainblame'); // We need the blame information if blame is on and we're building plain
if ($selected == 'blame' && $request->isAjax()) { // text, or blame is on and this is an Ajax request. If blame is on and
$needs_blame = true; // this is a colorized request, we don't show blame at first (we ajax it
} // in afterward) so we don't need to query for it.
$needs_blame = ($show_blame && !$show_color) ||
($show_blame && $request->isAjax());
$file_content = DiffusionFileContent::newFromConduit( $file_content = DiffusionFileContent::newFromConduit(
$this->callConduitWithDiffusionRequest( $this->callConduitWithDiffusionRequest(
@ -49,7 +65,7 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
))); )));
$data = $file_content->getCorpus(); $data = $file_content->getCorpus();
if ($selected === 'raw') { if ($view === 'raw') {
return $this->buildRawResponse($path, $data); return $this->buildRawResponse($path, $data);
} }
@ -57,7 +73,8 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
// Build the content of the file. // Build the content of the file.
$corpus = $this->buildCorpus( $corpus = $this->buildCorpus(
$selected, $show_blame,
$show_color,
$file_content, $file_content,
$needs_blame, $needs_blame,
$drequest, $drequest,
@ -75,7 +92,11 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
$content[] = $this->buildHeaderView($drequest); $content[] = $this->buildHeaderView($drequest);
$view = $this->buildActionView($drequest); $view = $this->buildActionView($drequest);
$content[] = $this->enrichActionView($view, $drequest, $selected); $content[] = $this->enrichActionView(
$view,
$drequest,
$show_blame,
$show_color);
$content[] = $this->buildPropertyView($drequest); $content[] = $this->buildPropertyView($drequest);
$follow = $request->getStr('follow'); $follow = $request->getStr('follow');
@ -161,7 +182,8 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
} }
private function buildCorpus( private function buildCorpus(
$selected, $show_blame,
$show_color,
DiffusionFileContent $file_content, DiffusionFileContent $file_content,
$needs_blame, $needs_blame,
DiffusionRequest $drequest, DiffusionRequest $drequest,
@ -181,22 +203,17 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
} }
} }
switch ($selected) { if (!$show_color) {
case 'plain':
$style = $style =
"margin: 1em 2em; width: 90%; height: 80em; font-family: monospace"; "margin: 1em 2em; width: 90%; height: 80em; font-family: monospace";
if (!$show_blame) {
$corpus = phutil_tag( $corpus = phutil_tag(
'textarea', 'textarea',
array( array(
'style' => $style, 'style' => $style,
), ),
$file_content->getCorpus()); $file_content->getCorpus());
} else {
break;
case 'plainblame':
$style =
"margin: 1em 2em; width: 90%; height: 80em; font-family: monospace";
$text_list = $file_content->getTextList(); $text_list = $file_content->getTextList();
$rev_list = $file_content->getRevList(); $rev_list = $file_content->getRevList();
$blame_dict = $file_content->getBlameDict(); $blame_dict = $file_content->getBlameDict();
@ -215,11 +232,8 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
'style' => $style, 'style' => $style,
), ),
implode("\n", $rows)); implode("\n", $rows));
break; }
} else {
case 'highlighted':
case 'blame':
default:
require_celerity_resource('syntax-highlighting-css'); require_celerity_resource('syntax-highlighting-css');
$text_list = $file_content->getTextList(); $text_list = $file_content->getTextList();
$rev_list = $file_content->getRevList(); $rev_list = $file_content->getRevList();
@ -232,7 +246,7 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
$text_list = explode("\n", $text_list); $text_list = explode("\n", $text_list);
$rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict, $rows = $this->buildDisplayRows($text_list, $rev_list, $blame_dict,
$needs_blame, $drequest, $selected); $needs_blame, $drequest, $show_blame, $show_color);
$corpus_table = javelin_tag( $corpus_table = javelin_tag(
'table', 'table',
@ -286,8 +300,6 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
$corpus_table); $corpus_table);
Javelin::initBehavior('load-blame', array('id' => $id)); Javelin::initBehavior('load-blame', array('id' => $id));
break;
} }
return $corpus; return $corpus;
@ -296,58 +308,55 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
private function enrichActionView( private function enrichActionView(
PhabricatorActionListView $view, PhabricatorActionListView $view,
DiffusionRequest $drequest, DiffusionRequest $drequest,
$selected) { $show_blame,
$show_color) {
$viewer = $this->getRequest()->getUser(); $viewer = $this->getRequest()->getUser();
$base_uri = $this->getRequest()->getRequestURI(); $base_uri = $this->getRequest()->getRequestURI();
$toggle_blame = array( $view->addAction(
'highlighted' => 'blame', id(new PhabricatorActionView())
'blame' => 'highlighted', ->setName(pht('Show Last Change'))
'plain' => 'plainblame', ->setHref(
'plainblame' => 'plain', $drequest->generateURI(
'raw' => 'raw', // not a real case. array(
); 'action' => 'change',
)))
->setIcon('new'));
$toggle_highlight = array( if ($show_blame) {
'highlighted' => 'plain',
'blame' => 'plainblame',
'plain' => 'highlighted',
'plainblame' => 'blame',
'raw' => 'raw', // not a real case.
);
$blame_on = ($selected == 'blame' || $selected == 'plainblame');
if ($blame_on) {
$blame_text = pht('Disable Blame'); $blame_text = pht('Disable Blame');
$blame_icon = 'blame-grey'; $blame_icon = 'blame-grey';
$blame_value = 0;
} else { } else {
$blame_text = pht('Enable Blame'); $blame_text = pht('Enable Blame');
$blame_icon = 'blame'; $blame_icon = 'blame';
$blame_value = 1;
} }
$view->addAction( $view->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setName($blame_text) ->setName($blame_text)
->setHref($base_uri->alter('view', $toggle_blame[$selected])) ->setHref($base_uri->alter('blame', $blame_value))
->setIcon($blame_icon) ->setIcon($blame_icon)
->setUser($viewer) ->setUser($viewer)
->setRenderAsForm(true)); ->setRenderAsForm(true));
$highlight_on = ($selected == 'blame' || $selected == 'highlighted'); if ($show_color) {
if ($highlight_on) {
$highlight_text = pht('Disable Highlighting'); $highlight_text = pht('Disable Highlighting');
$highlight_icon = 'highlight-grey'; $highlight_icon = 'highlight-grey';
$highlight_value = 0;
} else { } else {
$highlight_text = pht('Enable Highlighting'); $highlight_text = pht('Enable Highlighting');
$highlight_icon = 'highlight'; $highlight_icon = 'highlight';
$highlight_value = 1;
} }
$view->addAction( $view->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setName($highlight_text) ->setName($highlight_text)
->setHref($base_uri->alter('view', $toggle_highlight[$selected])) ->setHref($base_uri->alter('color', $highlight_value))
->setIcon($highlight_icon) ->setIcon($highlight_icon)
->setUser($viewer) ->setUser($viewer)
->setRenderAsForm(true)); ->setRenderAsForm(true));
@ -417,7 +426,8 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
array $blame_dict, array $blame_dict,
$needs_blame, $needs_blame,
DiffusionRequest $drequest, DiffusionRequest $drequest,
$selected) { $show_blame,
$show_color) {
$handles = array(); $handles = array();
if ($blame_dict) { if ($blame_dict) {
@ -464,7 +474,7 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
'data' => $line, 'data' => $line,
); );
if ($selected == 'blame') { if ($show_blame) {
// If the line's rev is same as the line above, show empty content // If the line's rev is same as the line above, show empty content
// with same color; otherwise generate blame info. The newer a change // with same color; otherwise generate blame info. The newer a change
// is, the more saturated the color. // is, the more saturated the color.
@ -574,7 +584,7 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
$rows = $this->renderInlines( $rows = $this->renderInlines(
idx($inlines, 0, array()), idx($inlines, 0, array()),
($selected == 'blame'), ($show_blame),
$engine); $engine);
foreach ($display as $line) { foreach ($display as $line) {
@ -764,7 +774,7 @@ final class DiffusionBrowseFileController extends DiffusionBrowseController {
$rows = array_merge($rows, $this->renderInlines( $rows = array_merge($rows, $this->renderInlines(
idx($inlines, $line['line'], array()), idx($inlines, $line['line'], array()),
($selected == 'blame'), ($show_blame),
$engine)); $engine));
} }

View file

@ -18,7 +18,8 @@ final class PhabricatorUserPreferences extends PhabricatorUserDAO {
const PREFERENCE_SEARCHBAR_JUMP = 'searchbar-jump'; const PREFERENCE_SEARCHBAR_JUMP = 'searchbar-jump';
const PREFERENCE_SEARCH_SHORTCUT = 'search-shortcut'; const PREFERENCE_SEARCH_SHORTCUT = 'search-shortcut';
const PREFERENCE_DIFFUSION_VIEW = 'diffusion-view'; const PREFERENCE_DIFFUSION_BLAME = 'diffusion-blame';
const PREFERENCE_DIFFUSION_COLOR = 'diffusion-color';
const PREFERENCE_NAV_COLLAPSED = 'nav-collapsed'; const PREFERENCE_NAV_COLLAPSED = 'nav-collapsed';
const PREFERENCE_NAV_WIDTH = 'nav-width'; const PREFERENCE_NAV_WIDTH = 'nav-width';