1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42:41 +01:00

Add an "Unsaved" button to the Differential persistent header

Summary: Ref T12733.

Test Plan: {F4987956}

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T12733

Differential Revision: https://secure.phabricator.com/D18070
This commit is contained in:
epriestley 2017-06-03 06:21:45 -07:00
parent 65c9d789d2
commit 48c6ca40c4
6 changed files with 181 additions and 45 deletions

View file

@ -12,8 +12,8 @@ return array(
'core.pkg.css' => '5284a0e0', 'core.pkg.css' => '5284a0e0',
'core.pkg.js' => '1475bd91', 'core.pkg.js' => '1475bd91',
'darkconsole.pkg.js' => '1f9a31bc', 'darkconsole.pkg.js' => '1f9a31bc',
'differential.pkg.css' => 'a2755617', 'differential.pkg.css' => '1ccbf3a9',
'differential.pkg.js' => '9cab3335', 'differential.pkg.js' => 'b453b745',
'diffusion.pkg.css' => 'b93d9b8c', 'diffusion.pkg.css' => 'b93d9b8c',
'diffusion.pkg.js' => '84c8f8fd', 'diffusion.pkg.js' => '84c8f8fd',
'favicon.ico' => '30672e08', 'favicon.ico' => '30672e08',
@ -64,7 +64,7 @@ return array(
'rsrc/css/application/dashboard/dashboard.css' => 'fe5b1869', 'rsrc/css/application/dashboard/dashboard.css' => 'fe5b1869',
'rsrc/css/application/diff/inline-comment-summary.css' => '51efda3a', 'rsrc/css/application/diff/inline-comment-summary.css' => '51efda3a',
'rsrc/css/application/differential/add-comment.css' => 'c47f8c40', 'rsrc/css/application/differential/add-comment.css' => 'c47f8c40',
'rsrc/css/application/differential/changeset-view.css' => '983751ee', 'rsrc/css/application/differential/changeset-view.css' => 'c3f44655',
'rsrc/css/application/differential/core.css' => '5b7b8ff4', 'rsrc/css/application/differential/core.css' => '5b7b8ff4',
'rsrc/css/application/differential/phui-inline-comment.css' => 'ffd1a542', 'rsrc/css/application/differential/phui-inline-comment.css' => 'ffd1a542',
'rsrc/css/application/differential/revision-comment.css' => '14b8565a', 'rsrc/css/application/differential/revision-comment.css' => '14b8565a',
@ -393,8 +393,8 @@ return array(
'rsrc/js/application/dashboard/behavior-dashboard-move-panels.js' => '408bf173', 'rsrc/js/application/dashboard/behavior-dashboard-move-panels.js' => '408bf173',
'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '453c5375', 'rsrc/js/application/dashboard/behavior-dashboard-query-panel-select.js' => '453c5375',
'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => 'd4eecc63', 'rsrc/js/application/dashboard/behavior-dashboard-tab-panel.js' => 'd4eecc63',
'rsrc/js/application/diff/DiffChangeset.js' => 'aaaf4cb5', 'rsrc/js/application/diff/DiffChangeset.js' => 'fc3919c8',
'rsrc/js/application/diff/DiffChangesetList.js' => '85abc805', 'rsrc/js/application/diff/DiffChangesetList.js' => 'ffa063d8',
'rsrc/js/application/diff/DiffInline.js' => '1d17130f', 'rsrc/js/application/diff/DiffInline.js' => '1d17130f',
'rsrc/js/application/diff/behavior-preview-link.js' => '051c7832', 'rsrc/js/application/diff/behavior-preview-link.js' => '051c7832',
'rsrc/js/application/differential/behavior-comment-preview.js' => '51c5ad07', 'rsrc/js/application/differential/behavior-comment-preview.js' => '51c5ad07',
@ -526,7 +526,7 @@ return array(
'rsrc/js/phuix/PHUIXActionListView.js' => 'b5c256b8', 'rsrc/js/phuix/PHUIXActionListView.js' => 'b5c256b8',
'rsrc/js/phuix/PHUIXActionView.js' => 'b3465b9b', 'rsrc/js/phuix/PHUIXActionView.js' => 'b3465b9b',
'rsrc/js/phuix/PHUIXAutocomplete.js' => 'f6699267', 'rsrc/js/phuix/PHUIXAutocomplete.js' => 'f6699267',
'rsrc/js/phuix/PHUIXButtonView.js' => '0f13520b', 'rsrc/js/phuix/PHUIXButtonView.js' => 'b3c515be',
'rsrc/js/phuix/PHUIXDropdownMenu.js' => '8018ee50', 'rsrc/js/phuix/PHUIXDropdownMenu.js' => '8018ee50',
'rsrc/js/phuix/PHUIXExample.js' => '68af71ca', 'rsrc/js/phuix/PHUIXExample.js' => '68af71ca',
'rsrc/js/phuix/PHUIXFormControl.js' => '83e03671', 'rsrc/js/phuix/PHUIXFormControl.js' => '83e03671',
@ -560,7 +560,7 @@ return array(
'conpherence-thread-manager' => '4d863052', 'conpherence-thread-manager' => '4d863052',
'conpherence-transaction-css' => '85129c68', 'conpherence-transaction-css' => '85129c68',
'd3' => 'a11a5ff2', 'd3' => 'a11a5ff2',
'differential-changeset-view-css' => '983751ee', 'differential-changeset-view-css' => 'c3f44655',
'differential-core-view-css' => '5b7b8ff4', 'differential-core-view-css' => '5b7b8ff4',
'differential-revision-add-comment-css' => 'c47f8c40', 'differential-revision-add-comment-css' => 'c47f8c40',
'differential-revision-comment-css' => '14b8565a', 'differential-revision-comment-css' => '14b8565a',
@ -772,8 +772,8 @@ return array(
'phabricator-darklog' => 'c8e1ffe3', 'phabricator-darklog' => 'c8e1ffe3',
'phabricator-darkmessage' => 'c48cccdd', 'phabricator-darkmessage' => 'c48cccdd',
'phabricator-dashboard-css' => 'fe5b1869', 'phabricator-dashboard-css' => 'fe5b1869',
'phabricator-diff-changeset' => 'aaaf4cb5', 'phabricator-diff-changeset' => 'fc3919c8',
'phabricator-diff-changeset-list' => '85abc805', 'phabricator-diff-changeset-list' => 'ffa063d8',
'phabricator-diff-inline' => '1d17130f', 'phabricator-diff-inline' => '1d17130f',
'phabricator-drag-and-drop-file-upload' => '58dea2fa', 'phabricator-drag-and-drop-file-upload' => '58dea2fa',
'phabricator-draggable-list' => 'bea6e7f4', 'phabricator-draggable-list' => 'bea6e7f4',
@ -878,7 +878,7 @@ return array(
'phuix-action-list-view' => 'b5c256b8', 'phuix-action-list-view' => 'b5c256b8',
'phuix-action-view' => 'b3465b9b', 'phuix-action-view' => 'b3465b9b',
'phuix-autocomplete' => 'f6699267', 'phuix-autocomplete' => 'f6699267',
'phuix-button-view' => '0f13520b', 'phuix-button-view' => 'b3c515be',
'phuix-dropdown-menu' => '8018ee50', 'phuix-dropdown-menu' => '8018ee50',
'phuix-form-control-view' => '83e03671', 'phuix-form-control-view' => '83e03671',
'phuix-icon-view' => 'bff6884b', 'phuix-icon-view' => 'bff6884b',
@ -960,10 +960,6 @@ return array(
'javelin-dom', 'javelin-dom',
'javelin-router', 'javelin-router',
), ),
'0f13520b' => array(
'javelin-install',
'javelin-dom',
),
'0f764c35' => array( '0f764c35' => array(
'javelin-install', 'javelin-install',
'javelin-util', 'javelin-util',
@ -1514,9 +1510,6 @@ return array(
'javelin-dom', 'javelin-dom',
'javelin-stratcom', 'javelin-stratcom',
), ),
'85abc805' => array(
'javelin-install',
),
'85ee8ce6' => array( '85ee8ce6' => array(
'aphront-dialog-view-css', 'aphront-dialog-view-css',
), ),
@ -1621,9 +1614,6 @@ return array(
'javelin-mask', 'javelin-mask',
'phabricator-drag-and-drop-file-upload', 'phabricator-drag-and-drop-file-upload',
), ),
'983751ee' => array(
'phui-inline-comment-view-css',
),
'9a6dd75c' => array( '9a6dd75c' => array(
'javelin-behavior', 'javelin-behavior',
'javelin-stratcom', 'javelin-stratcom',
@ -1716,17 +1706,6 @@ return array(
'javelin-util', 'javelin-util',
'phabricator-prefab', 'phabricator-prefab',
), ),
'aaaf4cb5' => array(
'javelin-dom',
'javelin-util',
'javelin-stratcom',
'javelin-install',
'javelin-workflow',
'javelin-router',
'javelin-behavior-device',
'javelin-vector',
'phabricator-diff-inline',
),
'ab2f381b' => array( 'ab2f381b' => array(
'javelin-request', 'javelin-request',
'javelin-behavior', 'javelin-behavior',
@ -1785,6 +1764,10 @@ return array(
'javelin-behavior', 'javelin-behavior',
'phabricator-prefab', 'phabricator-prefab',
), ),
'b3c515be' => array(
'javelin-install',
'javelin-dom',
),
'b3e7d692' => array( 'b3e7d692' => array(
'javelin-install', 'javelin-install',
), ),
@ -1877,6 +1860,9 @@ return array(
'javelin-dom', 'javelin-dom',
'javelin-vector', 'javelin-vector',
), ),
'c3f44655' => array(
'phui-inline-comment-view-css',
),
'c420b0b9' => array( 'c420b0b9' => array(
'javelin-behavior', 'javelin-behavior',
'javelin-behavior-device', 'javelin-behavior-device',
@ -2155,6 +2141,17 @@ return array(
'javelin-behavior-device', 'javelin-behavior-device',
'phabricator-keyboard-shortcut', 'phabricator-keyboard-shortcut',
), ),
'fc3919c8' => array(
'javelin-dom',
'javelin-util',
'javelin-stratcom',
'javelin-install',
'javelin-workflow',
'javelin-router',
'javelin-behavior-device',
'javelin-vector',
'phabricator-diff-inline',
),
'fc91ab6c' => array( 'fc91ab6c' => array(
'javelin-behavior', 'javelin-behavior',
'javelin-dom', 'javelin-dom',
@ -2166,6 +2163,10 @@ return array(
'javelin-view-visitor', 'javelin-view-visitor',
'javelin-util', 'javelin-util',
), ),
'ffa063d8' => array(
'javelin-install',
'phuix-button-view',
),
), ),
'packages' => array( 'packages' => array(
'conpherence.pkg.css' => array( 'conpherence.pkg.css' => array(

View file

@ -275,6 +275,10 @@ final class DifferentialChangesetListView extends AphrontView {
pht('Hide or show the current file.'), pht('Hide or show the current file.'),
'You must select a file to hide or show.' => 'You must select a file to hide or show.' =>
pht('You must select a file to hide or show.'), pht('You must select a file to hide or show.'),
'Unsaved' => pht('Unsaved'),
'Unsubmitted' => pht('Unsubmitted'),
'Comments' => pht('Comments'),
), ),
)); ));

View file

@ -413,3 +413,7 @@ tr.differential-inline-loading {
.diff-banner-has-unsubmitted { .diff-banner-has-unsubmitted {
background: {$sh-yellowbackground}; background: {$sh-yellowbackground};
} }
.diff-banner-buttons {
float: right;
}

View file

@ -403,6 +403,8 @@ JX.install('DiffChangeset', {
block.items.push(rows[ii]); block.items.push(rows[ii]);
} }
var last_inline = null;
var last_inline_item = null;
for (ii = 0; ii < blocks.length; ii++) { for (ii = 0; ii < blocks.length; ii++) {
block = blocks[ii]; block = blocks[ii];
@ -422,16 +424,38 @@ JX.install('DiffChangeset', {
for (var jj = 0; jj < block.items.length; jj++) { for (var jj = 0; jj < block.items.length; jj++) {
var inline = this.getInlineForRow(block.items[jj]); var inline = this.getInlineForRow(block.items[jj]);
items.push({ // When comments are being edited, they have a hidden row with
// the actual comment and then a visible row with the editor.
// In this case, we only want to generate one item, but it should
// use the editor as a scroll target. To accomplish this, check if
// this row has the same inline as the previous row. If so, update
// the last item to use this row's nodes.
if (inline === last_inline) {
last_inline_item.nodes.begin = block.items[jj];
last_inline_item.nodes.end = block.items[jj];
continue;
} else {
last_inline = inline;
}
last_inline_item = {
type: block.type, type: block.type,
changeset: this, changeset: this,
target: inline, target: inline,
hidden: inline.isHidden(), hidden: inline.isHidden(),
deleted: !inline.getID() && !inline.isEditing(),
nodes: { nodes: {
begin: block.items[jj], begin: block.items[jj],
end: block.items[jj] end: block.items[jj]
},
attributes: {
unsaved: inline.isEditing()
} }
}); };
items.push(last_inline_item);
} }
} }
} }

View file

@ -1,6 +1,7 @@
/** /**
* @provides phabricator-diff-changeset-list * @provides phabricator-diff-changeset-list
* @requires javelin-install * @requires javelin-install
* phuix-button-view
* @javelin * @javelin
*/ */
@ -111,6 +112,7 @@ JX.install('DiffChangesetList', {
_rangeTarget: null, _rangeTarget: null,
_bannerNode: null, _bannerNode: null,
_unsavedButton: null,
sleep: function() { sleep: function() {
this._asleep = true; this._asleep = true;
@ -258,7 +260,13 @@ JX.install('DiffChangesetList', {
_installJumpKey: function(key, label, delta, filter, show_hidden) { _installJumpKey: function(key, label, delta, filter, show_hidden) {
filter = filter || null; filter = filter || null;
var handler = JX.bind(this, this._onjumpkey, delta, filter, show_hidden);
var options = {
filter: filter,
hidden: show_hidden
};
var handler = JX.bind(this, this._onjumpkey, delta, options);
return this._installKey(key, label, handler); return this._installKey(key, label, handler);
}, },
@ -440,9 +448,14 @@ JX.install('DiffChangesetList', {
.show(); .show();
}, },
_onjumpkey: function(delta, filter, show_hidden, manager) { _onjumpkey: function(delta, options) {
var state = this._getSelectionState(); var state = this._getSelectionState();
var filter = options.filter || null;
var hidden = options.hidden || false;
var wrap = options.wrap || false;
var attribute = options.attribute || null;
var cursor = state.cursor; var cursor = state.cursor;
var items = state.items; var items = state.items;
@ -452,6 +465,7 @@ JX.install('DiffChangesetList', {
return; return;
} }
var did_wrap = false;
while (true) { while (true) {
if (cursor === null) { if (cursor === null) {
cursor = 0; cursor = 0;
@ -464,9 +478,22 @@ JX.install('DiffChangesetList', {
return; return;
} }
// If we've gone forward off the end of the list, bail out. // If we've gone forward off the end of the list, figure out where we
// should end up.
if (cursor >= items.length) { if (cursor >= items.length) {
return; if (!wrap) {
// If we aren't wrapping around, we're done.
return;
}
if (did_wrap) {
// If we're already wrapped around, we're done.
return;
}
// Otherwise, wrap the cursor back to the top.
cursor = 0;
did_wrap = true;
} }
// If we're selecting things of a particular type (like only files) // If we're selecting things of a particular type (like only files)
@ -479,17 +506,31 @@ JX.install('DiffChangesetList', {
// If the item is hidden, don't select it when iterating with jump // If the item is hidden, don't select it when iterating with jump
// keys. It can still potentially be selected in other ways. // keys. It can still potentially be selected in other ways.
if (!show_hidden) { if (!hidden) {
if (items[cursor].hidden) { if (items[cursor].hidden) {
continue; continue;
} }
} }
// If the item has been deleted, don't select it when iterating. The
// cursor may remain on it until it is removed.
if (items[cursor].deleted) {
continue;
}
// If we're selecting things with a particular attribute, like
// "unsaved", skip items without the attribute.
if (attribute !== null) {
if (!(items[cursor].attributes || {})[attribute]) {
continue;
}
}
// Otherwise, we've found a valid item to select. // Otherwise, we've found a valid item to select.
break; break;
} }
this._setSelectionState(items[cursor], manager); this._setSelectionState(items[cursor]);
}, },
_getSelectionState: function() { _getSelectionState: function() {
@ -512,24 +553,34 @@ JX.install('DiffChangesetList', {
}; };
}, },
_setSelectionState: function(item, manager) { _setSelectionState: function(item) {
this._cursorItem = item; this._cursorItem = item;
this._redrawSelection(manager, true); this._redrawSelection(true);
return this; return this;
}, },
_redrawSelection: function(manager, scroll) { _redrawSelection: function(scroll) {
var cursor = this._cursorItem; var cursor = this._cursorItem;
if (!cursor) { if (!cursor) {
this.setFocus(null); this.setFocus(null);
return; return;
} }
// If this item has been removed from the document (for example: create
// a new empty comment, then use the "Unsaved" button to select it, then
// cancel it), we can still keep the cursor here but do not want to show
// a selection reticle over an invisible node.
if (cursor.deleted) {
this.setFocus(null);
return;
}
this.setFocus(cursor.nodes.begin, cursor.nodes.end); this.setFocus(cursor.nodes.begin, cursor.nodes.end);
if (manager && scroll) { if (scroll) {
manager.scrollTo(cursor.nodes.begin); var pos = JX.$V(cursor.nodes.begin);
JX.DOM.scrollToPosition(0, pos.y - 60);
} }
return this; return this;
@ -1320,14 +1371,65 @@ JX.install('DiffChangesetList', {
'diff-banner-has-unsubmitted', 'diff-banner-has-unsubmitted',
!!unsubmitted.length); !!unsubmitted.length);
var unsaved_button = this._getUnsavedButton();
var pht = this.getTranslations();
if (unsaved.length) {
unsaved_button.setText(unsaved.length + ' ' + pht('Unsaved'));
JX.DOM.show(unsaved_button.getNode());
} else {
JX.DOM.hide(unsaved_button.getNode());
}
var path_view = [icon, ' ', changeset.getDisplayPath()];
var buttons_attrs = {
className: 'diff-banner-buttons'
};
var buttons_list = [
unsaved_button.getNode()
];
var buttons_view = JX.$N('div', buttons_attrs, buttons_list);
var icon = new JX.PHUIXIconView() var icon = new JX.PHUIXIconView()
.setIcon(changeset.getIcon()) .setIcon(changeset.getIcon())
.getNode(); .getNode();
JX.DOM.setContent(node, [icon, ' ', changeset.getDisplayPath()]); JX.DOM.setContent(node, [buttons_view, path_view]);
document.body.appendChild(node); document.body.appendChild(node);
}, },
_getUnsavedButton: function() {
if (!this._unsavedButton) {
var button = new JX.PHUIXButtonView()
.setIcon('fa-commenting-o')
.setButtonType(JX.PHUIXButtonView.BUTTONTYPE_SIMPLE);
var node = button.getNode();
var onunsaved = JX.bind(this, this._onunsavedclick);
JX.DOM.listen(node, 'click', null, onunsaved);
this._unsavedButton = button;
}
return this._unsavedButton;
},
_onunsavedclick: function(e) {
e.kill();
var options = {
filter: 'comment',
wrap: true,
attribute: 'unsaved'
};
this._onjumpkey(1, options);
},
_getBannerNode: function() { _getBannerNode: function() {
if (!this._bannerNode) { if (!this._bannerNode) {
var attributes = { var attributes = {

View file

@ -57,6 +57,7 @@ JX.install('PHUIXButtonView', {
setText: function(text) { setText: function(text) {
JX.DOM.setContent(this._getTextNode(), text); JX.DOM.setContent(this._getTextNode(), text);
this._redraw();
return this; return this;
}, },