Respects the default download scheme in user preferences

When the gr-download-dialog is rendered for a logged-in user who has a
default download scheme saved in their preferences, that scheme is used
as the default. If a user selects a different scheme, that scheme is
saved in preferences.

Bug: Issue 4203
Change-Id: I59a01cdade12d9d1051b691194a032fa5628c42f
This commit is contained in:
Wyatt Allen
2016-06-21 16:48:47 -07:00
parent 66bfe0005d
commit 350506539b
4 changed files with 132 additions and 58 deletions

View File

@@ -18,6 +18,7 @@ limitations under the License.
<link rel="import" href="../../../bower_components/iron-input/iron-input.html">
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
<link rel="import" href="../../shared/gr-button/gr-button.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<dom-module id="gr-download-dialog">
<template>
@@ -139,6 +140,7 @@ limitations under the License.
</div>
</div>
</footer>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
</template>
<script src="gr-download-dialog.js"></script>
</dom-module>

View File

@@ -27,6 +27,10 @@
change: Object,
patchNum: String,
config: Object,
loggedIn: {
type: Boolean,
value: false,
},
_schemes: {
type: Array,
@@ -45,6 +49,15 @@
Gerrit.RESTClientBehavior,
],
attached: function() {
if (!this.loggedIn) { return; }
this.$.restAPI.getPreferences().then(function(prefs) {
if (prefs.download_scheme) {
this._selectedScheme = prefs.download_scheme;
}
}.bind(this));
},
_computeDownloadCommands: function(change, patchNum, _selectedScheme) {
var commandObj;
for (var rev in change.revisions) {
@@ -112,8 +125,10 @@
_handleSchemeTap: function(e) {
e.preventDefault();
var el = Polymer.dom(e).rootTarget;
// TODO(andybons): Save as default scheme in preferences.
this._selectedScheme = el.getAttribute('data-scheme');
if (this.loggedIn) {
this.$.restAPI.savePreferences({download_scheme: this._selectedScheme});
}
},
_handleInputTap: function(e) {

View File

@@ -30,69 +30,79 @@ limitations under the License.
</template>
</test-fixture>
<test-fixture id="loggedIn">
<template>
<gr-download-dialog logged-in></gr-download-dialog>
</template>
</test-fixture>
<script>
function getChangeObject() {
return {
current_revision: '34685798fe548b6d17d1e8e5edc43a26d055cc72',
revisions: {
'34685798fe548b6d17d1e8e5edc43a26d055cc72': {
_number: 1,
fetch: {
repo: {
commands: {
repo: 'repo download test-project 5/1'
}
},
ssh: {
commands: {
'Checkout':
'git fetch ' +
'ssh://andybons@localhost:29418/test-project ' +
'refs/changes/05/5/1 && git checkout FETCH_HEAD',
'Cherry Pick':
'git fetch ' +
'ssh://andybons@localhost:29418/test-project ' +
'refs/changes/05/5/1 && git cherry-pick FETCH_HEAD',
'Format Patch':
'git fetch ' +
'ssh://andybons@localhost:29418/test-project ' +
'refs/changes/05/5/1 ' +
'&& git format-patch -1 --stdout FETCH_HEAD',
'Pull':
'git pull ' +
'ssh://andybons@localhost:29418/test-project ' +
'refs/changes/05/5/1'
}
},
http: {
commands: {
'Checkout':
'git fetch ' +
'http://andybons@localhost:8080/a/test-project ' +
'refs/changes/05/5/1 && git checkout FETCH_HEAD',
'Cherry Pick':
'git fetch ' +
'http://andybons@localhost:8080/a/test-project ' +
'refs/changes/05/5/1 && git cherry-pick FETCH_HEAD',
'Format Patch':
'git fetch ' +
'http://andybons@localhost:8080/a/test-project ' +
'refs/changes/05/5/1 && ' +
'git format-patch -1 --stdout FETCH_HEAD',
'Pull':
'git pull ' +
'http://andybons@localhost:8080/a/test-project ' +
'refs/changes/05/5/1'
}
}
}
}
}
};
}
suite('gr-download-dialog tests', function() {
var element;
setup(function() {
element = fixture('basic');
element.change = {
current_revision: '34685798fe548b6d17d1e8e5edc43a26d055cc72',
revisions: {
'34685798fe548b6d17d1e8e5edc43a26d055cc72': {
_number: 1,
fetch: {
repo: {
commands: {
repo: 'repo download test-project 5/1'
}
},
ssh: {
commands: {
'Checkout':
'git fetch ' +
'ssh://andybons@localhost:29418/test-project ' +
'refs/changes/05/5/1 && git checkout FETCH_HEAD',
'Cherry Pick':
'git fetch ' +
'ssh://andybons@localhost:29418/test-project ' +
'refs/changes/05/5/1 && git cherry-pick FETCH_HEAD',
'Format Patch':
'git fetch ' +
'ssh://andybons@localhost:29418/test-project ' +
'refs/changes/05/5/1 ' +
'&& git format-patch -1 --stdout FETCH_HEAD',
'Pull':
'git pull ' +
'ssh://andybons@localhost:29418/test-project ' +
'refs/changes/05/5/1'
}
},
http: {
commands: {
'Checkout':
'git fetch ' +
'http://andybons@localhost:8080/a/test-project ' +
'refs/changes/05/5/1 && git checkout FETCH_HEAD',
'Cherry Pick':
'git fetch ' +
'http://andybons@localhost:8080/a/test-project ' +
'refs/changes/05/5/1 && git cherry-pick FETCH_HEAD',
'Format Patch':
'git fetch ' +
'http://andybons@localhost:8080/a/test-project ' +
'refs/changes/05/5/1 && ' +
'git format-patch -1 --stdout FETCH_HEAD',
'Pull':
'git pull ' +
'http://andybons@localhost:8080/a/test-project ' +
'refs/changes/05/5/1'
}
}
}
}
}
};
element.change = getChangeObject();
element.patchNum = 1;
element.config = {
schemes: {
@@ -146,4 +156,50 @@ limitations under the License.
});
});
suite('gr-download-dialog tests', function() {
var element;
var getPrefsStub;
setup(function() {
stub('gr-rest-api-interface', { getPreferences: function() {
return Promise.resolve({download_scheme: 'repo'});
}});
element = fixture('loggedIn');
element.change = getChangeObject();
element.patchNum = 1;
element.config = {
schemes: {
'anonymous http': {},
http: {},
repo: {},
ssh: {},
},
archives: ['tgz', 'tar', 'tbz2', 'txz'],
};
});
test('loads scheme from preferences', function(done) {
element.$.restAPI.getPreferences.lastCall.returnValue.then(function() {
assert.equal(element._selectedScheme, 'repo');
done();
});
});
test('saves scheme to preferences', function() {
var savePrefsStub = sinon.stub(element.$.restAPI, 'savePreferences',
function() { return Promise.resolve(); });
Polymer.dom.flush();
var firstSchemeButton = element.$$('li gr-button[data-scheme]');
MockInteractions.tap(firstSchemeButton);
assert.isTrue(savePrefsStub.called);
assert.equal(savePrefsStub.lastCall.args[0].download_scheme,
firstSchemeButton.getAttribute('data-scheme'));
});
});
</script>