1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-09 16:32:39 +01:00

Fix "Actions" button on Phame standalone/live pages (bonus: JX.sprintf())

Summary:
See <https://discourse.phabricator-community.org/t/non-functional-actions-menu-on-live-phame-views/2593>. Several layers here:

The "Actions" button is broken because a menu behavior is failing, since we aren't rendering the menu.

When a behavior fails to initialize, catch and log the exception and continue. Previously, we stopped initializing behaviors if any failed, but behaviors are usually independent and continuing with an explicit exception seems reasonable.

Give "JX.log()" some "sprintf()" semantics to make logging the behavior failure easier. We can probably afford these extra 200 bytes now in 2019.

This fixes the button and gives us explicit errors in the log. So far, so good.

Then, when a page won't render chrome, don't try to render the main menu. This fixes the actual errors (we no longer try to initialize menu behaviors for nodes which don't exist).

Completely hide the "Actions" and "Comment" flows if the viewer isn't logged in. Although this isn't completely consistent with other applications, I think it's more appropriate for Phame. In applications like Maniphest, we show a full set of controls (but disable them) so that users who are not currently logged in have a clear path to interact with the content, under the assumption that this is a relatively common workflow. This is probably less common for Phame, where we expect most anonymous viewers not to log in or interact.

Finally, parametrize a one-off border color and add a border under the crumbs at the top of the page.

Test Plan:
  - Viewed a "Live" Phame blog post page, clicked "Actions", got a dropdown.

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D20378
This commit is contained in:
epriestley 2019-04-03 09:56:49 -07:00
parent 18732a0d2f
commit 248d79f36d
8 changed files with 91 additions and 15 deletions

View file

@ -10,7 +10,7 @@ return array(
'conpherence.pkg.css' => '3c8a0668',
'conpherence.pkg.js' => '020aebcf',
'core.pkg.css' => 'a1c2d49b',
'core.pkg.js' => 'a747b035',
'core.pkg.js' => 'a568e834',
'differential.pkg.css' => '8d8360fb',
'differential.pkg.js' => '67e02996',
'diffusion.pkg.css' => '42c75c37',
@ -86,7 +86,7 @@ return array(
'rsrc/css/application/paste/paste.css' => 'b37bcd38',
'rsrc/css/application/people/people-picture-menu-item.css' => 'fe8e07cf',
'rsrc/css/application/people/people-profile.css' => '2ea2daa1',
'rsrc/css/application/phame/phame.css' => '799febf9',
'rsrc/css/application/phame/phame.css' => 'bb442327',
'rsrc/css/application/pholio/pholio-edit.css' => '4df55b3b',
'rsrc/css/application/pholio/pholio-inline-comments.css' => '722b48c2',
'rsrc/css/application/pholio/pholio.css' => '88ef5ef1',
@ -217,7 +217,7 @@ return array(
'rsrc/externals/javelin/core/init.js' => '98e6504a',
'rsrc/externals/javelin/core/init_node.js' => '16961339',
'rsrc/externals/javelin/core/install.js' => '5902260c',
'rsrc/externals/javelin/core/util.js' => '22ae1776',
'rsrc/externals/javelin/core/util.js' => 'edb4d8c9',
'rsrc/externals/javelin/docs/Base.js' => '5a401d7d',
'rsrc/externals/javelin/docs/onload.js' => 'ee58fb62',
'rsrc/externals/javelin/ext/fx/Color.js' => '78f811c9',
@ -259,7 +259,7 @@ return array(
'rsrc/externals/javelin/lib/__tests__/JSON.js' => '710377ae',
'rsrc/externals/javelin/lib/__tests__/URI.js' => '6fff0c2b',
'rsrc/externals/javelin/lib/__tests__/behavior.js' => '8426ebeb',
'rsrc/externals/javelin/lib/behavior.js' => 'fce5d170',
'rsrc/externals/javelin/lib/behavior.js' => '1b6acc2a',
'rsrc/externals/javelin/lib/control/tokenizer/Tokenizer.js' => '89a1ae3a',
'rsrc/externals/javelin/lib/control/typeahead/Typeahead.js' => 'a4356cde',
'rsrc/externals/javelin/lib/control/typeahead/normalizer/TypeaheadNormalizer.js' => 'a241536a',
@ -571,7 +571,7 @@ return array(
'herald-test-css' => 'e004176f',
'inline-comment-summary-css' => '81eb368d',
'javelin-aphlict' => '022516b4',
'javelin-behavior' => 'fce5d170',
'javelin-behavior' => '1b6acc2a',
'javelin-behavior-aphlict-dropdown' => 'e9a2940f',
'javelin-behavior-aphlict-listen' => '4e61fa88',
'javelin-behavior-aphlict-status' => 'c3703a16',
@ -729,7 +729,7 @@ return array(
'javelin-typeahead-source' => '8badee71',
'javelin-typeahead-static-source' => '80bff3af',
'javelin-uri' => '2e255291',
'javelin-util' => '22ae1776',
'javelin-util' => 'edb4d8c9',
'javelin-vector' => 'e9c80beb',
'javelin-view' => '289bf236',
'javelin-view-html' => 'f8c4e135',
@ -798,7 +798,7 @@ return array(
'phabricator-tooltip' => '83754533',
'phabricator-ui-example-css' => 'b4795059',
'phabricator-zindex-css' => '99c0f5eb',
'phame-css' => '799febf9',
'phame-css' => 'bb442327',
'pholio-css' => '88ef5ef1',
'pholio-edit-css' => '4df55b3b',
'pholio-inline-comments-css' => '722b48c2',
@ -1029,6 +1029,10 @@ return array(
'javelin-stratcom',
'javelin-util',
),
'1b6acc2a' => array(
'javelin-magical-init',
'javelin-util',
),
'1c850a26' => array(
'javelin-install',
'javelin-util',
@ -2175,10 +2179,6 @@ return array(
'phabricator-keyboard-shortcut',
'conpherence-thread-manager',
),
'fce5d170' => array(
'javelin-magical-init',
'javelin-util',
),
'fdc13e4e' => array(
'javelin-install',
),

View file

@ -238,6 +238,7 @@ final class CelerityDefaultPostprocessor
'grey.button.gradient' => 'linear-gradient(to bottom, #ffffff, #f1f0f1)',
'grey.button.hover' => 'linear-gradient(to bottom, #ffffff, #eeebec)',
'document.border' => '#dedee1',
);
}

View file

@ -24,7 +24,7 @@ final class PhamePostViewController
$hero = $this->buildPhamePostHeader($post);
if (!$is_external) {
if (!$is_external && $viewer->isLoggedIn()) {
$actions = $this->renderActions($post);
$header->setPolicyObject($post);
$header->setActionList($actions);
@ -136,7 +136,7 @@ final class PhamePostViewController
->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)));
$timeline->setQuoteRef($monogram);
if ($is_external) {
if ($is_external || !$viewer->isLoggedIn()) {
$add_comment = null;
} else {
$add_comment = $this->buildCommentForm($post, $timeline);

View file

@ -304,6 +304,12 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
));
}
// If we aren't showing the page chrome, skip rendering DarkConsole and the
// main menu, since they won't be visible on the page.
if (!$this->getShowChrome()) {
return;
}
if ($console) {
require_celerity_resource('aphront-dark-console-css');
@ -347,6 +353,7 @@ final class PhabricatorStandardPageView extends PhabricatorBarePageView
$menu->setApplicationMenu($application_menu);
}
$this->menuContent = $menu->render();
}

View file

@ -284,6 +284,7 @@
text-align: center;
background: {$page.content};
padding: 16px 0 24px;
border-top: 1px solid {$document.border};
}
.device-phone .phame-mega-header {

View file

@ -56,7 +56,7 @@
.phui-document-container {
background-color: {$page.content};
position: relative;
border-bottom: 1px solid #dedee1;
border-bottom: 1px solid {$document.border};
}
.phui-document-view-pro-box,

View file

@ -295,9 +295,69 @@ if (!window.console || !window.console.log) {
* @return void
*/
JX.log = function(message) {
// "JX.log()" accepts "Error" in addition to "string". Only try to
// treat the argument as a "sprintf()" pattern if it's a string.
if (typeof message === 'string') {
message = JX.sprintf.apply(null, arguments);
}
window.console.log(message);
};
JX.sprintf = function(pattern) {
var argv = Array.prototype.slice.call(arguments);
argv.reverse();
// Pop off the pattern argument.
argv.pop();
var len = pattern.length;
var output = '';
for (var ii = 0; ii < len; ii++) {
var c = pattern.charAt(ii);
if (c !== '%') {
output += c;
continue;
}
ii++;
var next = pattern.charAt(ii);
if (next === '%') {
// This is "%%" (that is, an escaped "%" symbol), so just add a literal
// "%" to the result.
output += '%';
continue;
}
if (next === 's') {
if (!argv.length) {
throw new Error(
'Too few arguments to "JX.sprintf(...)" for pattern: ' + pattern);
}
output += '' + argv.pop();
continue;
}
if (next === '') {
throw new Error(
'Pattern passed to "JX.sprintf(...)" ends with "%": ' + pattern);
}
throw new Error(
'Unknown conversion "%' + c + '" passed to "JX.sprintf(...)" in ' +
'pattern: ' + pattern);
}
if (argv.length) {
throw new Error(
'Too many arguments to "JX.sprintf()" for pattern: ' + pattern);
}
return output;
};
if (__DEV__) {
window.alert = (function(native_alert) {

View file

@ -91,7 +91,14 @@ JX.initBehaviors = function(map) {
configs = [null];
}
for (var ii = 0; ii < configs.length; ii++) {
JX.behavior._behaviors[name](configs[ii], JX.behavior._statics[name]);
try {
JX.behavior._behaviors[name](configs[ii], JX.behavior._statics[name]);
} catch (behavior_exception) {
JX.log(
'JX.initBehaviors(...): behavior "%s" raised an error during setup.',
name);
JX.log(behavior_exception);
}
}
JX.behavior._initialized[name] = true;
}