Files
gerrit/polygerrit-ui/app/elements/gr-download-dialog.html
Andrew Bonventre f88ba8cb53 Add dialog aria roles to PolyGerrit dialogs
Change-Id: Ibfb8508f99a2f0013dc16c300fe01643463b6aeb
2016-02-19 17:20:32 +00:00

270 lines
7.3 KiB
HTML

<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/iron-input/iron-input.html">
<link rel="import" href="../behaviors/rest-client-behavior.html">
<link rel="import" href="gr-button.html">
<dom-module id="gr-download-dialog">
<template>
<style>
:host {
display: block;
padding: 1em;
}
ul {
list-style: none;
margin-bottom: .5em;
}
li {
display: inline-block;
margin: 0;
padding: 0;
}
li gr-button {
margin-right: 1em;
}
label,
input {
display: block;
}
label {
font-weight: bold;
}
input {
font-family: var(--monospace-font-family);
font-size: inherit;
margin-bottom: .5em;
width: 60em;
}
li[selected] gr-button {
color: #000;
font-weight: bold;
text-decoration: none;
}
header {
display: flex;
justify-content: space-between;
}
main {
border-bottom: 1px solid #ddd;
border-top: 1px solid #ddd;
padding: .5em;
}
footer {
display: flex;
justify-content: space-between;
padding-top: .75em;
}
.closeButtonContainer {
display: flex;
flex: 1;
justify-content: flex-end;
}
.patchFiles {
margin-right: 2em;
}
.patchFiles a,
.archives a {
display: inline-block;
margin-right: 1em;
}
.patchFiles a:last-of-type,
.archives a:last-of-type {
margin-right: 0;
}
</style>
<header>
<ul hidden$="[[!_schemes.length]]" hidden>
<template is="dom-repeat" items="[[_schemes]]" as="scheme">
<li selected$="[[_computeSchemeSelected(scheme, _selectedScheme)]]">
<gr-button link data-scheme$="[[scheme]]" on-tap="_handleSchemeTap">
[[scheme]]
</gr-button>
</li>
</template>
</ul>
<span class="closeButtonContainer">
<gr-button link on-tap="_handleCloseTap">Close</gr-button>
</span>
</header>
<main hidden$="[[!_schemes.length]]" hidden>
<template is="dom-repeat"
items="[[_computeDownloadCommands(change, patchNum, _selectedScheme)]]"
as="command">
<div class="command">
<label>[[command.title]]</label>
<input is="iron-input"
type="text"
bind-value="[[command.command]]"
on-tap="_handleInputTap"
readonly>
</div>
</template>
</main>
<footer>
<div class="patchFiles">
<label>Patch file</label>
<div>
<a href$="[[_computeDownloadLink(change, patchNum)]]">
[[_computeDownloadFilename(change, patchNum)]]
</a>
<a href$="[[_computeZipDownloadLink(change, patchNum)]]">
[[_computeZipDownloadFilename(change, patchNum)]]
</a>
</div>
</div>
<div class="archivesContainer" hidden$="[[!config.archives.length]]" hidden>
<label>Archive</label>
<div class="archives">
<template is="dom-repeat" items="[[config.archives]]" as="format">
<a href$="[[_computeArchiveDownloadLink(change, patchNum, format)]]">
[[format]]
</a>
</template>
</div>
</div>
</footer>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'gr-download-dialog',
/**
* Fired when the user presses the close button.
*
* @event close
*/
properties: {
change: Object,
patchNum: String,
config: Object,
_schemes: {
type: Array,
value: function() { return []; },
computed: '_computeSchemes(change, patchNum)',
observer: '_schemesChanged',
},
_selectedScheme: String,
},
hostAttributes: {
role: 'dialog',
},
behaviors: [
Gerrit.RESTClientBehavior,
],
_computeDownloadCommands: function(change, patchNum, _selectedScheme) {
var commandObj;
for (var rev in change.revisions) {
if (change.revisions[rev]._number == patchNum) {
commandObj = change.revisions[rev].fetch[_selectedScheme].commands;
break;
}
}
var commands = [];
for (var title in commandObj) {
commands.push({
title: title,
command: commandObj[title],
});
}
return commands;
},
_computeZipDownloadLink: function(change, patchNum) {
return this._computeDownloadLink(change, patchNum, true);
},
_computeZipDownloadFilename: function(change, patchNum) {
return this._computeDownloadFilename(change, patchNum, true);
},
_computeDownloadLink: function(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) {
if (change.revisions[rev]._number == patchNum) {
shortRev = rev.substr(0, 7);
break;
}
}
return shortRev + '.diff.' + (zip ? 'zip' : 'base64');
},
_computeArchiveDownloadLink: function(change, patchNum, format) {
return this.changeBaseURL(change._number, patchNum) +
'/archive?format=' + format;
},
_computeSchemes: function(change, patchNum) {
for (var rev in change.revisions) {
if (change.revisions[rev]._number == patchNum) {
var fetch = change.revisions[rev].fetch;
if (fetch) {
return Object.keys(fetch).sort();
}
break;
}
}
return [];
},
_computeSchemeSelected: function(scheme, selectedScheme) {
return scheme == selectedScheme;
},
_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');
},
_handleInputTap: function(e) {
e.preventDefault();
Polymer.dom(e).rootTarget.select();
},
_handleCloseTap: function(e) {
e.preventDefault();
this.fire('close', null, {bubbles: false});
},
_schemesChanged: function(schemes) {
if (schemes.length == 0) { return; }
if (schemes.indexOf(this._selectedScheme) == -1) {
this._selectedScheme = schemes.sort()[0];
}
},
});
})();
</script>
</dom-module>