diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html index 06658da29f..3a5b3a153a 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html +++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.html @@ -26,6 +26,7 @@ limitations under the License. + @@ -75,8 +76,7 @@ limitations under the License. align-items: center; display: flex; } - .navLink:not([href]), - .downloadLink:not([href]) { + .navLink:not([href]) { color: var(--deemphasized-text-color); } .navLinks { @@ -266,12 +266,15 @@ limitations under the License. - - Download - + + + Download + +
diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js index 89ad2d2508..76a0bef9eb 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js +++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view.js @@ -880,7 +880,36 @@ history.replaceState(null, '', url); }, - _computeDownloadLink(project, changeNum, patchRange, path) { + _computeDownloadDropdownLinks(project, changeNum, patchRange, path) { + if (!patchRange || !patchRange.patchNum) { return []; } + + return [ + { + url: this._computeDownloadPatchLink( + project, changeNum, patchRange, path), + name: 'Patch', + }, + { + // We pass 1 here to indicate this is parent 1. + url: this._computeDownloadFileLink( + project, changeNum, patchRange, path, 1), + name: 'Left Content', + }, + { + // We pass 0 here to indicate this is parent 0. + url: this._computeDownloadFileLink( + project, changeNum, patchRange, path, 0), + name: 'Right Content', + }, + ]; + }, + + _computeDownloadFileLink(project, changeNum, patchRange, path, parent) { + return this.changeBaseURL(project, changeNum, patchRange.patchNum) + + `/files/${encodeURIComponent(path)}/download?parent=${parent}`; + }, + + _computeDownloadPatchLink(project, changeNum, patchRange, path) { let url = this.changeBaseURL(project, changeNum, patchRange.patchNum); url += '/patch?zip&path=' + encodeURIComponent(path); return url; diff --git a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html index 354bfef6c9..92e2c52130 100644 --- a/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html +++ b/polygerrit-ui/app/elements/diff/gr-diff-view/gr-diff-view_test.html @@ -556,22 +556,6 @@ limitations under the License. element._path, '1', 'PARENT')); }); - test('download link', () => { - element._change = {project: 'test'}, - element._changeNum = '42'; - element._patchRange = { - basePatchNum: PARENT, - patchNum: '10', - }; - element._fileList = ['chell.go', 'glados.txt', 'wheatley.md']; - element._path = 'glados.txt'; - flushAsynchronousOperations(); - const link = element.$$('.downloadLink'); - assert.equal(link.getAttribute('href'), - '/changes/test~42/revisions/10/patch?zip&path=glados.txt'); - assert.isTrue(link.hasAttribute('download')); - }); - test('_prefs.manual_review is respected', () => { const saveReviewedStub = sandbox.stub(element, '_saveReviewedState', () => Promise.resolve()); @@ -1124,5 +1108,47 @@ limitations under the License. 1, ]); }); + + test('_computeDownloadDropdownLinks', () => { + const downloadLinks = [ + { + url: '/changes/test~12/revisions/1/patch?zip&path=index.php', + name: 'Patch', + }, + { + url: '/changes/test~12/revisions/1' + + '/files/index.php/download?parent=1', + name: 'Left Content', + }, + { + url: '/changes/test~12/revisions/1' + + '/files/index.php/download?parent=0', + name: 'Right Content', + }, + ]; + assert.deepEqual( + element._computeDownloadDropdownLinks( + 'test', 12, {patchNum: 1}, 'index.php'), + downloadLinks); + }); + + test('_computeDownloadFileLink', () => { + assert.equal( + element._computeDownloadFileLink( + 'test', 12, {patchNum: 1}, 'index.php', 1), + '/changes/test~12/revisions/1/files/index.php/download?parent=1'); + + assert.equal( + element._computeDownloadFileLink( + 'test', 12, {patchNum: 1}, 'index.php', 0), + '/changes/test~12/revisions/1/files/index.php/download?parent=0'); + }); + + test('_computeDownloadPatchLink', () => { + assert.equal( + element._computeDownloadPatchLink( + 'test', 12, {patchNum: 1}, 'index.php'), + '/changes/test~12/revisions/1/patch?zip&path=index.php'); + }); });