Merge "ES6ify /gr-download-dialog/*"
diff --git a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js
index f843ee8..b26802d 100644
--- a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js
+++ b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog.js
@@ -35,7 +35,7 @@
_schemes: {
type: Array,
- value: function() { return []; },
+ value() { return []; },
computed: '_computeSchemes(change, patchNum)',
observer: '_schemesChanged',
},
@@ -50,7 +50,7 @@
Gerrit.RESTClientBehavior,
],
- focus: function() {
+ focus() {
if (this._schemes.length) {
this.$$('.copyToClipboard').focus();
} else {
@@ -58,59 +58,60 @@
}
},
- getFocusStops: function() {
- var links = this.$$('#archives').querySelectorAll('a');
+ getFocusStops() {
+ const links = this.$$('#archives').querySelectorAll('a');
return {
start: this.$.closeButton,
end: links[links.length - 1],
};
},
- _loggedInChanged: function(loggedIn) {
+ _loggedInChanged(loggedIn) {
if (!loggedIn) { return; }
- this.$.restAPI.getPreferences().then(function(prefs) {
+ this.$.restAPI.getPreferences().then(prefs => {
if (prefs.download_scheme) {
// Note (issue 5180): normalize the download scheme with lower-case.
this._selectedScheme = prefs.download_scheme.toLowerCase();
}
- }.bind(this));
+ });
},
- _computeDownloadCommands: function(change, patchNum, _selectedScheme) {
- var commandObj;
- for (var rev in change.revisions) {
+ _computeDownloadCommands(change, patchNum, _selectedScheme) {
+ let commandObj;
+ for (const rev in change.revisions) {
if (change.revisions[rev]._number === patchNum &&
change.revisions[rev].fetch.hasOwnProperty(_selectedScheme)) {
commandObj = change.revisions[rev].fetch[_selectedScheme].commands;
break;
}
}
- var commands = [];
- for (var title in commandObj) {
+ const commands = [];
+ for (const title in commandObj) {
+ if (!commandObj.hasOwnProperty(title)) { continue; }
commands.push({
- title: title,
+ title,
command: commandObj[title],
});
}
return commands;
},
- _computeZipDownloadLink: function(change, patchNum) {
+ _computeZipDownloadLink(change, patchNum) {
return this._computeDownloadLink(change, patchNum, true);
},
- _computeZipDownloadFilename: function(change, patchNum) {
+ _computeZipDownloadFilename(change, patchNum) {
return this._computeDownloadFilename(change, patchNum, true);
},
- _computeDownloadLink: function(change, patchNum, zip) {
+ _computeDownloadLink(change, patchNum, zip) {
return this.changeBaseURL(change._number, patchNum) + '/patch?' +
(zip ? 'zip' : 'download');
},
- _computeDownloadFilename: function(change, patchNum, zip) {
- var shortRev;
- for (var rev in change.revisions) {
+ _computeDownloadFilename(change, patchNum, zip) {
+ let shortRev;
+ for (const rev in change.revisions) {
if (change.revisions[rev]._number === patchNum) {
shortRev = rev.substr(0, 7);
break;
@@ -119,15 +120,15 @@
return shortRev + '.diff.' + (zip ? 'zip' : 'base64');
},
- _computeArchiveDownloadLink: function(change, patchNum, format) {
+ _computeArchiveDownloadLink(change, patchNum, format) {
return this.changeBaseURL(change._number, patchNum) +
'/archive?format=' + format;
},
- _computeSchemes: function(change, patchNum) {
- for (var rev in change.revisions) {
+ _computeSchemes(change, patchNum) {
+ for (const rev in change.revisions) {
if (change.revisions[rev]._number === patchNum) {
- var fetch = change.revisions[rev].fetch;
+ const fetch = change.revisions[rev].fetch;
if (fetch) {
return Object.keys(fetch).sort();
}
@@ -137,47 +138,47 @@
return [];
},
- _computePatchSetQuantity: function(revisions) {
+ _computePatchSetQuantity(revisions) {
if (!revisions) { return 0; }
return Object.keys(revisions).length;
},
- _computeSchemeSelected: function(scheme, selectedScheme) {
+ _computeSchemeSelected(scheme, selectedScheme) {
return scheme === selectedScheme;
},
- _handleSchemeTap: function(e) {
+ _handleSchemeTap(e) {
e.preventDefault();
- var el = Polymer.dom(e).rootTarget;
+ const el = Polymer.dom(e).rootTarget;
this._selectedScheme = el.getAttribute('data-scheme');
if (this.loggedIn) {
this.$.restAPI.savePreferences({download_scheme: this._selectedScheme});
}
},
- _handleInputTap: function(e) {
+ _handleInputTap(e) {
e.preventDefault();
Polymer.dom(e).rootTarget.select();
},
- _handleCloseTap: function(e) {
+ _handleCloseTap(e) {
e.preventDefault();
this.fire('close', null, {bubbles: false});
},
- _schemesChanged: function(schemes) {
+ _schemesChanged(schemes) {
if (schemes.length === 0) { return; }
- if (schemes.indexOf(this._selectedScheme) === -1) {
+ if (!schemes.includes(this._selectedScheme)) {
this._selectedScheme = schemes.sort()[0];
}
},
- _copyToClipboard: function(e) {
+ _copyToClipboard(e) {
e.target.parentElement.querySelector('.copyCommand').select();
document.execCommand('copy');
getSelection().removeAllRanges();
e.target.textContent = 'done';
- setTimeout(function() { e.target.textContent = 'copy'; }, 1000);
+ setTimeout(() => { e.target.textContent = 'copy'; }, 1000);
},
});
})();
diff --git a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html
index 0635d6d..4a8d2d9 100644
--- a/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html
+++ b/polygerrit-ui/app/elements/change/gr-download-dialog/gr-download-dialog_test.html
@@ -48,8 +48,8 @@
fetch: {
repo: {
commands: {
- repo: 'repo download test-project 5/1'
- }
+ repo: 'repo download test-project 5/1',
+ },
},
ssh: {
commands: {
@@ -69,8 +69,8 @@
'Pull':
'git pull ' +
'ssh://andybons@localhost:29418/test-project ' +
- 'refs/changes/05/5/1'
- }
+ 'refs/changes/05/5/1',
+ },
},
http: {
commands: {
@@ -90,12 +90,12 @@
'Pull':
'git pull ' +
'http://andybons@localhost:8080/a/test-project ' +
- 'refs/changes/05/5/1'
- }
- }
- }
- }
- }
+ 'refs/changes/05/5/1',
+ },
+ },
+ },
+ },
+ },
};
}
@@ -106,74 +106,74 @@
'34685798fe548b6d17d1e8e5edc43a26d055cc72': {
_number: 1,
fetch: {},
- }
- }
+ },
+ },
};
}
- suite('gr-download-dialog tests with no fetch options', function() {
- var element;
+ suite('gr-download-dialog tests with no fetch options', () => {
+ let element;
- setup(function() {
+ setup(() => {
element = fixture('basic');
element.change = getChangeObjectNoFetch();
element.patchNum = 1;
element.config = {
schemes: {
'anonymous http': {},
- http: {},
- repo: {},
- ssh: {},
+ 'http': {},
+ 'repo': {},
+ 'ssh': {},
},
archives: ['tgz', 'tar', 'tbz2', 'txz'],
};
});
- test('focuses on first download link if no copy links', function() {
+ test('focuses on first download link if no copy links', () => {
flushAsynchronousOperations();
- var focusStub = sinon.stub(element.$.download, 'focus');
+ const focusStub = sinon.stub(element.$.download, 'focus');
element.focus();
assert.isTrue(focusStub.called);
focusStub.restore();
});
});
- suite('gr-download-dialog tests', function() {
- var element;
+ suite('gr-download-dialog tests', () => {
+ let element;
- setup(function() {
+ setup(() => {
element = fixture('basic');
element.change = getChangeObject();
element.patchNum = 1;
element.config = {
schemes: {
'anonymous http': {},
- http: {},
- repo: {},
- ssh: {},
+ 'http': {},
+ 'repo': {},
+ 'ssh': {},
},
archives: ['tgz', 'tar', 'tbz2', 'txz'],
};
});
- test('focuses on first copy link', function() {
+ test('focuses on first copy link', () => {
flushAsynchronousOperations();
- var focusStub = sinon.stub(element.$$('.copyToClipboard'), 'focus');
+ const focusStub = sinon.stub(element.$$('.copyToClipboard'), 'focus');
element.focus();
flushAsynchronousOperations();
assert.isTrue(focusStub.called);
focusStub.restore();
});
- test('copy to clipboard', function() {
+ test('copy to clipboard', () => {
flushAsynchronousOperations();
- var clipboardSpy = sinon.spy(element, '_copyToClipboard');
- var copyBtn = element.$$('.copyToClipboard');
+ const clipboardSpy = sinon.spy(element, '_copyToClipboard');
+ const copyBtn = element.$$('.copyToClipboard');
MockInteractions.tap(copyBtn);
assert.isTrue(clipboardSpy.called);
});
- test('element visibility', function() {
+ test('element visibility', () => {
assert.isFalse(element.$$('ul').hasAttribute('hidden'));
assert.isFalse(element.$$('main').hasAttribute('hidden'));
assert.isFalse(element.$$('.archivesContainer').hasAttribute('hidden'));
@@ -182,40 +182,40 @@
assert.isTrue(element.$$('.archivesContainer').hasAttribute('hidden'));
});
- test('computed fields', function() {
+ test('computed fields', () => {
assert.equal(element._computeArchiveDownloadLink(
{_number: 123}, 2, 'tgz'),
'/changes/123/revisions/2/archive?format=tgz');
});
- test('close event', function(done) {
- element.addEventListener('close', function() {
+ test('close event', done => {
+ element.addEventListener('close', () => {
done();
});
MockInteractions.tap(element.$$('.closeButtonContainer gr-button'));
});
- test('tab selection', function() {
+ test('tab selection', () => {
flushAsynchronousOperations();
- var el = element.$$('[data-scheme="http"]').parentElement;
+ let el = element.$$('[data-scheme="http"]').parentElement;
assert.isTrue(el.hasAttribute('selected'));
- ['repo', 'ssh'].forEach(function(scheme) {
- var el = element.$$('[data-scheme="' + scheme + '"]').parentElement;
+ for (const scheme of ['repo', 'ssh']) {
+ const el = element.$$('[data-scheme="' + scheme + '"]').parentElement;
assert.isFalse(el.hasAttribute('selected'));
- });
+ }
MockInteractions.tap(element.$$('[data-scheme="ssh"]'));
el = element.$$('[data-scheme="ssh"]').parentElement;
assert.isTrue(el.hasAttribute('selected'));
- ['http', 'repo'].forEach(function(scheme) {
- var el = element.$$('[data-scheme="' + scheme + '"]').parentElement;
+ for (const scheme of ['http', 'repo']) {
+ const el = element.$$('[data-scheme="' + scheme + '"]').parentElement;
assert.isFalse(el.hasAttribute('selected'));
- });
+ }
});
- test('loads scheme from preferences w/o initial login', function(done) {
+ test('loads scheme from preferences w/o initial login', done => {
stub('gr-rest-api-interface', {
- getPreferences: function() {
+ getPreferences() {
return Promise.resolve({download_scheme: 'repo'});
},
});
@@ -223,19 +223,19 @@
element.loggedIn = true;
assert.isTrue(element.$.restAPI.getPreferences.called);
- element.$.restAPI.getPreferences.lastCall.returnValue.then(function() {
+ element.$.restAPI.getPreferences.lastCall.returnValue.then(() => {
assert.equal(element._selectedScheme, 'repo');
done();
});
});
});
- suite('gr-download-dialog tests', function() {
- var element;
+ suite('gr-download-dialog tests', () => {
+ let element;
- setup(function() {
+ setup(() => {
stub('gr-rest-api-interface', {
- getPreferences: function() {
+ getPreferences() {
return Promise.resolve({download_scheme: 'repo'});
},
});
@@ -246,28 +246,28 @@
element.config = {
schemes: {
'anonymous http': {},
- http: {},
- repo: {},
- ssh: {},
+ 'http': {},
+ 'repo': {},
+ 'ssh': {},
},
archives: ['tgz', 'tar', 'tbz2', 'txz'],
};
});
- test('loads scheme from preferences', function(done) {
- element.$.restAPI.getPreferences.lastCall.returnValue.then(function() {
+ test('loads scheme from preferences', done => {
+ element.$.restAPI.getPreferences.lastCall.returnValue.then(() => {
assert.equal(element._selectedScheme, 'repo');
done();
});
});
- test('saves scheme to preferences', function() {
- var savePrefsStub = sinon.stub(element.$.restAPI, 'savePreferences',
- function() { return Promise.resolve(); });
+ test('saves scheme to preferences', () => {
+ const savePrefsStub = sinon.stub(element.$.restAPI, 'savePreferences',
+ () => { return Promise.resolve(); });
Polymer.dom.flush();
- var firstSchemeButton = element.$$('li gr-button[data-scheme]');
+ const firstSchemeButton = element.$$('li gr-button[data-scheme]');
MockInteractions.tap(firstSchemeButton);
@@ -277,9 +277,9 @@
});
});
- test('normalize scheme from preferences', function(done) {
+ test('normalize scheme from preferences', done => {
stub('gr-rest-api-interface', {
- getPreferences: function() {
+ getPreferences() {
return Promise.resolve({download_scheme: 'REPO'});
},
});
@@ -287,10 +287,10 @@
element.change = getChangeObject();
element.patchNum = 1;
element.config = {
- schemes: {'anonymous http': {}, http: {}, repo: {}, ssh: {}},
+ schemes: {'anonymous http': {}, 'http': {}, 'repo': {}, 'ssh': {}},
archives: ['tgz', 'tar', 'tbz2', 'txz'],
};
- element.$.restAPI.getPreferences.lastCall.returnValue.then(function() {
+ element.$.restAPI.getPreferences.lastCall.returnValue.then(() => {
assert.equal(element._selectedScheme, 'repo');
done();
});