Add support for downloading binary files
This change uses a dropdown to be able to download either the patch, left side content or right side content. Screenshot: https://imgur.com/a/D2ffRX7 Bug: Issue 6029 Bug: Issue 7867 Change-Id: I4e05dba0dcfaf8699e20f151a6949ffb08701bbe
This commit is contained in:
@@ -26,6 +26,7 @@ limitations under the License.
|
|||||||
<link rel="import" href="../../core/gr-reporting/gr-reporting.html">
|
<link rel="import" href="../../core/gr-reporting/gr-reporting.html">
|
||||||
<link rel="import" href="../../shared/gr-button/gr-button.html">
|
<link rel="import" href="../../shared/gr-button/gr-button.html">
|
||||||
<link rel="import" href="../../shared/gr-count-string-formatter/gr-count-string-formatter.html">
|
<link rel="import" href="../../shared/gr-count-string-formatter/gr-count-string-formatter.html">
|
||||||
|
<link rel="import" href="../../shared/gr-dropdown/gr-dropdown.html">
|
||||||
<link rel="import" href="../../shared/gr-dropdown-list/gr-dropdown-list.html">
|
<link rel="import" href="../../shared/gr-dropdown-list/gr-dropdown-list.html">
|
||||||
<link rel="import" href="../../shared/gr-fixed-panel/gr-fixed-panel.html">
|
<link rel="import" href="../../shared/gr-fixed-panel/gr-fixed-panel.html">
|
||||||
<link rel="import" href="../../shared/gr-icons/gr-icons.html">
|
<link rel="import" href="../../shared/gr-icons/gr-icons.html">
|
||||||
@@ -75,8 +76,7 @@ limitations under the License.
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
display: flex;
|
display: flex;
|
||||||
}
|
}
|
||||||
.navLink:not([href]),
|
.navLink:not([href]) {
|
||||||
.downloadLink:not([href]) {
|
|
||||||
color: var(--deemphasized-text-color);
|
color: var(--deemphasized-text-color);
|
||||||
}
|
}
|
||||||
.navLinks {
|
.navLinks {
|
||||||
@@ -266,12 +266,15 @@ limitations under the License.
|
|||||||
</gr-patch-range-select>
|
</gr-patch-range-select>
|
||||||
<span class="download desktop">
|
<span class="download desktop">
|
||||||
<span class="separator"></span>
|
<span class="separator"></span>
|
||||||
<a
|
<gr-dropdown
|
||||||
class="downloadLink"
|
link
|
||||||
download
|
down-arrow
|
||||||
href$="[[_computeDownloadLink(_change.project, _changeNum, _patchRange, _path)]]">
|
items="[[_computeDownloadDropdownLinks(_change.project, _changeNum, _patchRange, _path)]]"
|
||||||
Download
|
horizontal-align="left">
|
||||||
</a>
|
<span class="downloadTitle">
|
||||||
|
Download
|
||||||
|
</span>
|
||||||
|
</gr-dropdown>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="rightControls">
|
<div class="rightControls">
|
||||||
|
|||||||
@@ -880,7 +880,36 @@
|
|||||||
history.replaceState(null, '', url);
|
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);
|
let url = this.changeBaseURL(project, changeNum, patchRange.patchNum);
|
||||||
url += '/patch?zip&path=' + encodeURIComponent(path);
|
url += '/patch?zip&path=' + encodeURIComponent(path);
|
||||||
return url;
|
return url;
|
||||||
|
|||||||
@@ -556,22 +556,6 @@ limitations under the License.
|
|||||||
element._path, '1', 'PARENT'));
|
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', () => {
|
test('_prefs.manual_review is respected', () => {
|
||||||
const saveReviewedStub = sandbox.stub(element, '_saveReviewedState',
|
const saveReviewedStub = sandbox.stub(element, '_saveReviewedState',
|
||||||
() => Promise.resolve());
|
() => Promise.resolve());
|
||||||
@@ -1124,5 +1108,47 @@ limitations under the License.
|
|||||||
1,
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user