86 Commits

Author SHA1 Message Date
Becky Siegel
a638c38bce Merge "Update comment thread creation/removal to no longer use locationRange" 2018-02-13 17:27:54 +00:00
Becky Siegel
bbde672af0 Update comment thread creation/removal to no longer use locationRange
Follow-up to https://gerrit-review.googlesource.com/c/gerrit/+/157590
which no longer used locationRange to group comments together into
threads. However, locationRange was still used for a few other things
including thread removal, which could result in a bug if there were
two threads that had the same locationRange and the wrong one was
found first.

Things included in this change:
1. Determine whether a thread group exists
   - This is identified as it was before. The thread group now gets a
     commentSide attribute, as it can pass it to all of its children
     (the same for all).
2. Determine if a thread exists within the group for a given range in a
   group
   - The range object is now included as an attribute on the comment
     thread instead of the locationRange string.
3. Be able to remove a thread group
   - A rootId attribute is now stored on the comment thread, which is
     data bound to each comment. When a comment is removed, it finds the
     thread with the rootId within the thread group to remove.
   - In the event that a thread group only contains a single draft,
     there is no roottId.

Change-Id: I4f7804ac02f4259b4964c6333d258f0fc3b29d24
2018-02-12 17:36:33 -08:00
Kasper Nilsson
8f9664b7b7 Disallow commenting on an edit base
Bug: Issue 8289
Change-Id: I934f8b4ac2a6f1993ddb1ad55c3c05f9fd0182f9
2018-02-08 11:28:52 -08:00
Wyatt Allen
fcc3cf8c1d Cancel diff rendering when diffs are collapsed or detached
Formerly, if diff rendering is started, but then unloaded or navigated
away from, the rendering work would needlessly continue in the
background. Cancel rendering when a diff will not be used.

Bug: Issue 6061
Change-Id: I695281229335e84f2d5c802c1fa971842c588330
2018-02-07 17:02:07 -08:00
Thomas Shafer
fbeb8c929a Swap baseCommit and commit for weblinks
The baseCommit should be used to generate the left side of the weblinks.

Change-Id: I9ab3aaae5a13acb6b581713308b38beddcd7750a
2018-02-05 10:11:49 -08:00
Wyatt Allen
e515ff6c12 Do not collapse line numbers that are indicated in the URL
When users navigate to the diff view with a line number specified at the
end, depending on their context preference, the line might be in a
shared region that gets collapsed when the diff renders. With this
change, the location specified in the URL is prevented from being
collapsed by marking it as a "key" location.

Bug: Issue 5247
Change-Id: Ifd5827cd922b022cddb1601911a9ecea6a054f35
2018-01-22 14:03:24 -08:00
Becky Siegel
721361e16c Fix diff flashing when expand inline diffs
There was an issue where when a diff was expanded that had previously
been expanded, its old content was displayed, then cleared, then
reloaded.

Fix this by clearing diffs when they are collapsed.

Bug: Issue 7986
Change-Id: I3dc6460ff6fba4ff9f2cbd4b004b1e50d4b75814
2017-12-20 16:12:41 -08:00
Viktar Donich
a28dee069f Weblinks API for embedded scenario using Gerrit.Nav interface
Gerrit.Nav.setup() now takes a weblinks generator function as a third
parameter. Here's the function signature:

``` js
Gerrit.Nav.setup(navigate, generateUrl, generateWeblinks)
```

Weblinks generator function takes single payload parameter with
`type` property that determines which part of the UI is the consumer of
the weblinks. `type` property can be one of `file`, `change`, or
`patchset`.

For `file` type, payload will also contain string properties:
`repo`, `commit`, `file`.

For `pachset` type, payload will also contain string properties:
`repo`, `commit`.

For `change` type, payload will also contain string properties:
`repo`, `commit`.

If server provides weblinks, those will be passed as `options.weblinks`
property on the main payload object.

Change-Id: I0d9de3a295435304e2b6aad551112440075cf098
2017-12-08 20:20:10 -08:00
Wyatt Allen
617adb42a6 Merge "Add ability to add annotation layers from plugins" 2017-12-01 17:46:24 +00:00
Ravi Mistry
af1e0f8bf6 Add ability to add annotation layers from plugins
Highlights:
* Adds a new getDiffLayers function to gr-js-api-interface.js. This is
  invoked by gr-diff-builder.html when gathering annotation layers.
* New annotationApi function in gr-public-js-api.js for plugins to call.
* The annotationApi function returns an instance of the new
  GrAnnotationActionsInterface in gr-annotation-actions-js-api.js
* GrAnnotationActionsInterface has an API for the plugin to register an
  addLayerFunction and an optional method to call to get a notify callback.
* The new samples/coverage-plugin.html is an end-to-end example of how
  to invoke the new APIs to annotate lines.

Bug: Issue 7339
Change-Id: Ie51845e0b3564953aba5d7d41986cedce0337073
2017-11-29 12:27:51 -05:00
Wyatt Allen
c56ece73e2 Support creating comments on merge parents
Bug: Issue 4760
Change-Id: I66ced578819b6f48d7d1535a54f1debf0e35374e
2017-11-27 11:09:58 -08:00
Wyatt Allen
ed628d7f37 Show blame in diff
With this change a blame column is added to the left side of diff
tables. The column is empty and hidden until blame is loaded. A button
is added to the change view to trigger a load of the blame for that
diff, as well as a unload it if already loaded. In this stage, the blame
information is non-interactive and only displays the SHA, date and
commit author.

Feature: Issue 6075
Change-Id: Ifcb951265d0e6339094e6b7c9574ec9c69e60b51
2017-09-27 18:55:42 -04:00
Becky Siegel
273b7ee2a2 Fix inability to leave multiple comments on line of code
This appears to have broke in I0428fead7a9d1f1dc5d6aa9efc3d81ecbe6b5c64

The computation to get the comment thread used to pass the range object,
but stopped doing so in the above change. This change adds it back in
and also separates the range string computation so that additional
unit tests can be added.

Bug: Issue 7081
Change-Id: I846d0c24b894fa0577f4fefaf8dcf4fc751daa15
2017-08-28 15:38:41 -07:00
Becky Siegel
8d92d53db5 Annotation updates
Change-Id: I146f76b9dcc1a92e18acec01481ad280fb431868
2017-08-12 11:49:52 -07:00
Kasper Nilsson
380bf8ba6b Disable diff comments on edit patchsets
Includes a minor refactor of gr-diff comment construction logic.

Bug: Issue 4437
Change-Id: I0428fead7a9d1f1dc5d6aa9efc3d81ecbe6b5c64
2017-08-09 21:17:31 +00:00
Wyatt Allen
f0eb4bbf53 Harden gr-formatted-text agains slow/failed project configs
Formerly, if a formatted text component tried to render without the
project config (used by inner linked text components) it would
temporarily fall-back to rendering the unformatted (and un-linkified)
text via `.textContent` -- mirroring the behavior of gr-linked-text.

The result is formatted text elements (when rendered without a project
config) appear as one long line of text. Unlike linkification, however,
text can be accurately formatted with or without the project config --
so this disruptive, poor UX is unnecessary.

The formatted text component is updated to format text when the project
config has not provided, and to re-render when the config has been
provided.

In order to propagate project config loads to the formatted text
components hosted by diff comments, the REST calls must be made by the
diff thread component. To make this call, the thread must have the
project's name, so gr-diff-builder is updated to provide this name to
thread components.

Bug: Issue 6686
Change-Id: I8d09c740930500e99cb5f87b92f4d72f3f50a9ce
2017-08-01 16:14:45 -07:00
Wyatt Allen
dc8782d762 Centralized comment requests
Formerly, gr-diff would make its own REST calls for diff comments in the
patch range and path being viewed. However, these calls by the diff view
were redundant to the more general comment requests made by either
gr-diff-view (which requests all comments to support skipping to the
next file with comments) or gr-change-view (which requests comments
individually for each inline diff).

With this change, the diff component no longer loads comments for
itself, but is rather provided the comments from its host view via a
public property. In this way the host view can load the more-general
comment data, and filter it down for the diff view's params.

Introduces the gr-comment-api component to simplify loading and
filtering diff comments for use by diff views. By using this new
component:
* The diff view makes only one request for comments (including drafts
  and robot comments) to support skipping to the next comment and
  displaying comments in the diff view.
* The change view makes only one request for comments for all inline
  diffs.

Bug: Issue 5299
Change-Id: Ia14a01619f1f9881aa0d253fd3f49af9a17f3dce
2017-08-01 14:15:38 -07:00
Becky Siegel
27a376907b Use updateStyles instead of customStyle
customStyle was removed in Polymer 2. Use updateStyles instead.

https://www.polymer-project.org/2.0/docs/upgrade#use-updatestyles-instead-of-customstyle

Change-Id: If89441dda76c39ed3b1db89a123100c06d5c3532
2017-07-17 11:11:27 -07:00
Wyatt Allen
6df3f492b9 Confirmation for rendering large diffs with whole file
If the user views a very large diff while "Whole file" is enabled in
their preferences, rendering may lock up their browser. With this
change, instead of rendering, users are warned and allowed to bypass the
warning (risking browser lock up) or render with a context that is less
than whole file.

Bug: Issue 6402
Change-Id: I6e97c06598fb5f6900c925127ab6a99693b8aa7f
2017-06-15 12:02:35 -07:00
Wyatt Allen
21e6b7f207 Close race condition that mixed content from other diffs
Previously, when a diff was reloaded, it would clear the diff content
(the previous diff) and open requests for the data regarding the new
diff. When the requests finished, it would cancel async processing and
start it again on the new data. In this arrangement, a narrow race
condition was present where the async rendering could emit a diff from
the previous diff after the diff table had been cleared, but before the
network requests resolved -- resulting is content form the previous diff
appearing in the new one.

With this change, the async processing is cancelled at the same time
that the diff content is cleared.

Bug: Issue 6170
Change-Id: Ie5a807082ab51156595f9eeb9ba6c958d41e890a
2017-06-05 09:19:00 -07:00
Kasper Nilsson
a2c965985f ES6ify /gr-diff/*
Bug: Issue 6179
Change-Id: I198da73316e0c5cb7cda91cf845a174667eee2bb
2017-05-17 11:44:39 -07:00
Viktar Donich
1057e0505f Add padding to diff when scrollbar is inline
Inline scrollbars are invisible until scrolling starts, or, for
ChromeOS, scrollbar area is hovered.
When scrollbar appears, it overlaps last line of diff.
This change adds a padding to prevent scrollbar overlapping last line of
diff.

Bug: Issue 5964
Change-Id: I072f8e8a4d4d2750f122bc6177b8db492b258f5f
2017-05-12 11:24:31 -07:00
Wyatt Allen
75bf2ce32e Merge "Remove polyfilled image API" 2017-05-11 17:27:41 +00:00
Wyatt Allen
26880b6f09 Remove polyfilled image API
Bug: Issue 5751
Change-Id: Ie668e79dfe5762799f46e9f77fbb8239155a08de
2017-05-11 17:27:03 +00:00
Becky Siegel
70a8269b52 Add diff preferences to change view
Noteworthy decisions:
- Preferences are hidden when diff prefs are not loaded or the user is not
logged in.
- Preferences are hidden on small screens
- The trigger button is in gr-change-view but the gr-diff-preferences
  is part of gr-file-list. This is because gr-file-list because diff
  preferences and local preferences are more closely tied with that
  than the change view. In order to put it in the change view, local
  prefs would also have to be two-way bound back.

Also fixes computePrefsButtonHidden in gr-diff-view as well. The
function did not work as intended before. If preferences didn't exist,
the function would not get called, and the container would not be
hidden.

Bug: Issue 5426
Change-Id: I361cdf132c6e15b5ae2f15e62af318cfa05161ce
2017-05-10 15:55:57 -07:00
Becky Siegel
2fcd34c1ba Merge "Fix diff cursor in file list" 2017-04-17 23:40:07 +00:00
Becky Siegel
eccee3ce49 Fix diff cursor in file list
There was an issue where line numbers would not properly highlight in
inline-diffs rendered in the file view.

There were two separate issues that contributed to this problem:
1 - The diff cursor was not notified of the line being selected and
    needing to move to that cursor stop.
2 - The diff cursor was not properly updated after being moved inside
    a dom-if statement.

Additionally, the way that line selection was previously done was not
extendable to a diff cursor that stored multiple files. It queried
stops based on line number and side. This change also stores the
path of the file in the cursor stop so that the correct diff/line is
selected in the case of multiples.

Bug: Issue 5977
Change-Id: I7496293e19a4e59a3855dc78e273de6a9852e556
2017-04-14 18:00:15 -07:00
Kasper Nilsson
b4893d0ae6 Add header to diff
Adds the header section to the diff. The header is only displayed when
relevant information is contained within, e.g. when a file is renamed
but otherwise left unchanged.

Feature: Issue 5752
Change-Id: I5f8cb56522decd8d3c57bb403cb43f87203d5c6a
2017-04-12 16:15:33 -07:00
Viktar Donich
7354e48b3c Show "Not logged in" toast when action requires being logged in
Show "Error: not logged in" error toast with a "Log in" link when one of
the following actions taken while not being logged in:
- reply hotkey pressed (A)
- create comment hotkey pressed (C)

Bug: Issue 4818
Change-Id: I4ceaf12888b8cb2aae9da7ab2fdd47eb409dd984
2017-03-23 13:16:08 -07:00
Wyatt Allen
81ef082667 Merge "Reduce confusion between side and commentSide" 2017-03-16 00:17:47 +00:00
Viktar Donich
af42cc6676 Make gr-diff provide cursor stops for gr-file-list unless hidden
This fixes line navigation for inline diff view when all files are
expanded.

Bug: Issue 5773
Change-Id: Ia089483364befd10a4169673ecf09d120c7f3fbe
2017-03-15 14:14:05 -07:00
Becky Siegel
cd2d4232f1 Reduce confusion between side and commentSide
Use '__isOnParent' as a boolean in place if 'side' ('PARENT vs
'REVISION').  In doing so, it's necessary to convert to/from 'side'
whenever interacting with the REST API.

Change-Id: Ic023c9be1969597e4b9c73a51cfed9f5eb9bc23e
2017-03-15 13:50:21 -07:00
Becky Siegel
2c602323e1 Move reply buttons to comment thread
Move all buttons that generate a reply of some sort (done, ack, reply,
quote) to the comment thread instead of the comment [1].

When there is a draft for a particular comment thread, all reply buttons
are hidden [2].  For example, if you click reply, you cannot click done
on the same thread, unless you remove the draft.

Each thread can have up to 1 draft. It's also worth noting that if a
thread has a draft, and the user clicks on the line or 'c' at the same
range, the existing draft will switch to 'editing' form.

[1] With the exception of "please fix" for robot comments.
[2] In this case, The please fix button will be disabled when other
reply buttons are hidden.

Feature: Issue 5410
Change-Id: Id847ee0cba0d0ce4e5b6476f58141866d41ffdad
2017-02-09 16:07:32 -08:00
Wyatt Allen
3d8dc2edda Merge "Render inline diffs sequentially" 2017-02-08 00:42:09 +00:00
Wyatt Allen
206966a5ae Render inline diffs sequentially
Changes with large numbers of files could overwhelm PolyGerrit when a
user selects [Expand all] for inline diffs. This was because the
asynchronous processing/rendering/annotating process would be kicked off
for all unexpanded diffs simultaneously, resulting in browser lock-up
and general slowness even after rendering had completed.

With this change, inline diffs are rendered in serial rather than
parallel. In this way the benefits of the async features of diff
rendering extend to the file list, even for changes with many large
diffs (such as the one in the linked issue).

With this change, the `__expanded` property is removed from file objects
in GR-FILE-LIST. Instead, that element maintains a list
(`_expandedFilePaths`) which records the same information. Because the
expanded files are recorded in a list, however, splices on the list can
be observed, batch diff expansion can be handled sequentially.

Tests are updated to respect the new expanded paths list.

Bug: Issue 5396
Change-Id: Ib83ff5157177e1c890db8a82fbc25df8fecbe065
2017-02-07 16:17:56 -08:00
Becky Siegel
41bdc04cb8 Don't merge threads on same line left/right
Goes along with c/95273/. Adds commentSide attribute to comments to see
which side of the diff view they belong on. This is also used as part
of the locationRange for the gr-diff-comment-thread-group, so that two
thread groups can be on the same line or range for the unified group (
one for the right, one for the left).

Note: there is already a 'side' attribute on the gr-diff-comment, which
is confusing. This side actually references 'PARENT' or 'REVISION', to
identify whether the comment belongs to the parent or any revision. On
diffs where two revisions are compared to each other, this cannot be
used to determine left/right. However, because 'side' is part of
the CommentInfo entity[1], it is difficult to change the name and make
more sense out of that.

[1] https://gerrit-review.googlesource.com/Documentation/rest-api-changes.html#comment-info

Bug: Issue 5114
Change-Id: I5cc4c17d4bb134e31e5cc07ff9b08ed349488c97
2017-02-07 21:00:52 +00:00
Becky Siegel
562a30493e Allow multiple threads per line, with different ranges
- Add concept of diff comment thread groups, which are all of the
  threads at a particular line number.

- The thread group is responsible for breaking up comments into threads
  based on the range of the comment.

- Thread groups are ordered by the updated time of the first comment in
  the group.

- Thread groups are given a key, based on comment range, which is used
  to determine what thread group a new comment should go in (or if it
  needs a new one).

Feature: Issue 5292
Change-Id: If544e8bb879262de3ce5397e86124837b66ada04
2017-02-01 16:10:08 -08:00
Becky Siegel
35a7682262 Add robot comments to PolyGerrit
This change adds an API request to get robot comments for displaying
inline in the diff view. They are styled in a different color, contain
build and robotId information, and a "please fix" action rather than the
standard set of actions.

Feature: Issue 5089
Change-Id: I1f5954a2ed01920bb7c3dc897e3285687ff7d3ca
2016-12-15 11:20:25 -08:00
Becky Siegel
6a7085e5ab Make line marker more distinguished
Previously, the line marker was only subtly visible by the highlighted
line number. This change adds a bottom border to the selected line if
the user is using keycodes (j, k, up, down) to more the cursor. When
the escape key is pressed, the distinguished line marker will dissapear.

Feature: Issue 4739
Change-Id: If8c751efc137ef87cfdad1c8bf7d905de1219107
2016-11-03 13:34:07 -07:00
Becky Siegel
e7d19a9976 Add preference for line wrapping in diff preferences
Previously in Polygerrit, diff views were always displayed in the width
specified in diff preferences. This change gives the option to wrap
lines instead, which takes precedence over column width (the column
width option is hidden when line wrapping is selected), and fits the
diff view to screen.

The gerrit API already supports the 'lineWrapping' preference so this
change uses that already existing option.

Feature: Issue 4809
Change-Id: I0d9e292739b5910abfd04af63ec4c745bf06e446
2016-10-31 17:35:21 -07:00
Urs Wolfer
a010547eef Fix issues detected by 'JSHint' and 'JSCS'
Change-Id: Id16d7abe53d5f65c97bf778dc532e404b41283d8
2016-10-20 20:41:00 +02:00
Becky Siegel
1f5a8510b7 Safeguard for font preferences if server has skew
Added temporary safeguard for the font preferences change so that inputs
are hidden and custom styles are not set if font-size was not part of
the preferneces response.

Change-Id: I5b34b317bf953591889fa25e1c351d4f490d989e
2016-10-14 14:13:36 -07:00
Andrew Bonventre
0c03db348c Merge "Add a diff preference for font size" 2016-10-14 17:53:05 +00:00
Wyatt Allen
1be7c31e66 Gracefully handle HTTP 409 for diff API
If a file is too large for the server to deliver the diff, the API will
respond with HTTP 409. PolyGerrit interprets th this as a network error
and covers the entire page with an error message. Furthermore, the
handler for loading the diff is not written for this kind of failure and
tries to dereference the diff object -- null in that case.

With this change, the 409 message does not block use of the whole page
and the handler does not break when the diff is null.

Issue: Bug 4770
Change-Id: I68fe50c474fc03d4217e969649f62df38ca5b632
2016-10-13 11:50:14 -07:00
Becky Siegel
d7dbed640c Add a diff preference for font size
This change adds a font size field in diff preferences in both the
generic preferences page and also the preferences modal from the diff
view. The new field allows users to update their preferred font size
for the diff view to be displayed. This updates both the line number
font size as well as the diff font size.

Feature: Issue 4417
Change-Id: I0fb75fd2186d2ff63b3627e8b0f15f2b3cddbfa3
2016-10-12 16:31:24 -07:00
Wyatt Allen
056e40c01c Fix diff expanded/collapsed binding
Refactors bindings in file lists to change the expanded state of a diff
using a property name that does not collide with the hidden attribute.

Change-Id: I7f7e38a910a8d4dd19be2d591033be6f6d3cb7a1
2016-10-05 21:49:33 -07:00
Kasper Nilsson
bf457dd412 Fix data binding in gr-file-list, introduced in 86117
In https://gerrit-review.googlesource.com/c/86117/ the data binding
between the _files array and the dom-repeat in gr-file-list was not
properly enforced. This change fixes that, and also properly
references a static file-list property.

In addition, tests were implemented to ensure this regression is caught
in the future.

Bug: Issue 4575
Change-Id: I32a5645ec47d953ee6a7a71f4b14fc8c9483df3d
2016-09-30 13:04:15 -07:00
Kasper Nilsson
93b0ad4964 Add expand inline functionality to diffs
This commit enables the user to manually expand individual diffs
inline in the file list of the change view.

Bug: Issue 4382
Change-Id: I87d5af9971fed3aa5e1eb64523f4623a5ff2ac8d
2016-08-26 10:36:30 -07:00
Viktar Donich
c282d7b282 Toggle left diff on Shift+A
Feature: Issue 3926
Change-Id: Ia52334f2aefeae4b3f115e5779da3b61af25ba11
2016-08-10 12:54:49 -07:00
Wyatt Allen
9f7e37cbf7 Fixes an if-else chain
Change-Id: I5181644364a959461a4ad5fdc23e24a57ffe5052
2016-08-08 14:36:24 -07:00