Utilize patch set description in PG

This change adds the patch set description, if it exists, in every patch
set select in the change view and the diff view. Also includes
refactoring of an existing function into a behavior for use in other
files, and removes some unnecessary DOM nodes from the change-view.

http://imgur.com/a/rEhOF

Feature: Issue 4544
Change-Id: Id5f8d2d5750f3f7afc677e16c411327f53487b19
This commit is contained in:
Kasper Nilsson
2016-11-09 12:24:49 -08:00
parent 4807acbf50
commit 3ea4311f66
10 changed files with 146 additions and 25 deletions

View File

@@ -0,0 +1,44 @@
<!--
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.
-->
<script>
(function(window) {
'use strict';
/** @polymerBehavior Gerrit.PatchSetBehavior */
var PatchSetBehavior = {
/**
* Given an object of revisions, get a particular revision based on patch
* num.
*
* @param {Object} revisions
* @param {number|string} patchNum
* @return {Object}
*/
getRevisionNumber: function(revisions, patchNum) {
patchNum = parseInt(patchNum, 10);
for (var rev in revisions) {
if (revisions.hasOwnProperty(rev) &&
revisions[rev]._number === patchNum) {
return revisions[rev];
}
}
},
};
window.Gerrit = window.Gerrit || {};
window.Gerrit.PatchSetBehavior = PatchSetBehavior;
})(window);
</script>

View File

@@ -0,0 +1,38 @@
<!--
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.
-->
<!-- Polymer included for the html import polyfill. -->
<script src="../../../bower_components/webcomponentsjs/webcomponents.min.js"></script>
<script src="../../bower_components/web-component-tester/browser.js"></script>
<title>gr-patch-set-behavior</title>
<link rel="import" href="../../bower_components/iron-test-helpers/iron-test-helpers.html">
<link rel="import" href="gr-patch-set-behavior.html">
<script>
suite('gr-path-list-behavior tests', function() {
test('getRevisionNumber', function() {
var get = Gerrit.PatchSetBehavior.getRevisionNumber;
var revisions = [
{_number: 0},
{_number: 1},
{_number: 2},
];
assert.deepEqual(get(revisions, '1'), revisions[1]);
assert.deepEqual(get(revisions, 2), revisions[2]);
assert.equal(get(revisions, '3'), undefined);
});
});
</script>

View File

@@ -15,6 +15,7 @@ limitations under the License.
-->
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html">
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
<link rel="import" href="../../../behaviors/rest-client-behavior.html">
<link rel="import" href="../../shared/gr-account-link/gr-account-link.html">
@@ -159,6 +160,9 @@ limitations under the License.
.latestPatchContainer {
display: none;
}
.patchSetSelect {
max-width: 25em;
}
@media screen and (max-width: 50em) {
.header {
align-items: flex-start;
@@ -218,8 +222,8 @@ limitations under the License.
<gr-change-star change="{{_change}}" hidden$="[[!_loggedIn]]"></gr-change-star>
<a href$="[[_computeChangePermalink(_change._number)]]">[[_change._number]]</a><!--
--><span class="changeStatus">[[_computeChangeStatus(_change, _patchRange.patchNum)]]</span><!--
--><span>:</span>
<span>[[_change.subject]]</span>
-->:
[[_change.subject]]
</span>
</div>
<section class="changeInfo">
@@ -279,14 +283,19 @@ limitations under the License.
<label class="patchSelectLabel" for="patchSetSelect">
Patch set
</label>
<select id="patchSetSelect" bind-value="{{_selectedPatchSet}}"
is="gr-select" on-change="_handlePatchChange">
<select
is="gr-select"
id="patchSetSelect"
bind-value="{{_selectedPatchSet}}"
class="patchSetSelect"
on-change="_handlePatchChange">
<template is="dom-repeat" items="[[_allPatchSets]]"
as="patchNumber">
<option value$="[[patchNumber]]">
<span>[[patchNumber]]</span>
[[patchNumber]]
/
<span>[[_computeLatestPatchNum(_allPatchSets)]]</span>
[[_computeLatestPatchNum(_allPatchSets)]]
[[_computePatchSetDescription(_change, patchNumber)]]
</option>
</template>
</select>

View File

@@ -101,6 +101,7 @@
behaviors: [
Gerrit.KeyboardShortcutBehavior,
Gerrit.PatchSetBehavior,
Gerrit.RESTClientBehavior,
],
@@ -495,7 +496,7 @@
_computeChangeStatus: function(change, patchNum) {
var statusString;
if (change.status === this.ChangeStatus.NEW) {
var rev = this._getRevisionNumber(change, patchNum);
var rev = this.getRevisionNumber(change.revisions, patchNum);
if (rev && rev.draft === true) {
statusString = 'Draft';
}
@@ -527,14 +528,6 @@
});
},
_getRevisionNumber: function(change, patchNum) {
for (var rev in change.revisions) {
if (change.revisions[rev]._number == patchNum) {
return change.revisions[rev];
}
}
},
_computeLabelNames: function(labels) {
return Object.keys(labels).sort();
},
@@ -783,5 +776,10 @@
_updateSelected: function() {
this._selectedPatchSet = this._patchRange.patchNum;
},
_computePatchSetDescription: function(change, patchNum) {
var rev = this.getRevisionNumber(change.revisions, patchNum);
return (rev && rev.description) ? rev.description : '';
},
});
})();

View File

@@ -15,6 +15,7 @@ limitations under the License.
-->
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior.html">
<link rel="import" href="../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html">
<link rel="import" href="../../../behaviors/gr-url-encoding-behavior.html">
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../diff/gr-diff/gr-diff.html">
@@ -140,6 +141,9 @@ limitations under the License.
display: block;
margin: .25em 0 1em;
}
.patchSetSelect {
max-width: 25em;
}
@media screen and (max-width: 50em) {
.row[selected] {
background-color: transparent;
@@ -184,15 +188,16 @@ limitations under the License.
<label>
Diff against
<select id="patchChange" bind-value="{{_diffAgainst}}" is="gr-select"
on-change="_handlePatchChange">
class="patchSetSelect" on-change="_handlePatchChange">
<option value="PARENT">Base</option>
<template
is="dom-repeat"
<template
is="dom-repeat"
items="[[_computePatchSets(revisions, patchRange.*)]]"
as="patchNum">
<option value$="[[patchNum]]" disabled$=
"[[_computePatchSetDisabled(patchNum, patchRange.patchNum)]]">
<option value$="[[patchNum]]"
disabled$="[[_computePatchSetDisabled(patchNum, patchRange.patchNum)]]">
[[patchNum]]
[[_computePatchSetDescription(revisions, patchNum)]]
</option>
</template>
</select>

View File

@@ -102,6 +102,7 @@
behaviors: [
Gerrit.KeyboardShortcutBehavior,
Gerrit.PatchSetBehavior,
Gerrit.URLEncodingBehavior,
],
@@ -561,5 +562,10 @@
_fileListActionsVisible: function(numFilesShown, maxFilesForBulkActions) {
return numFilesShown <= maxFilesForBulkActions;
},
_computePatchSetDescription: function(revisions, patchNum) {
var rev = this.getRevisionNumber(revisions, patchNum);
return (rev && rev.description) ? rev.description : '';
},
});
})();

View File

@@ -203,7 +203,8 @@ limitations under the License.
change-num="[[_changeNum]]"
patch-range="[[_patchRange]]"
files-weblinks="[[_filesWeblinks]]"
available-patches="[[_computeAvailablePatches(_change.revisions)]]">
available-patches="[[_computeAvailablePatches(_change.revisions)]]"
revisions="[[_change.revisions]]">
</gr-patch-range-select>
<span class="separator">/</span>
<a class="downloadLink"

View File

@@ -13,8 +13,10 @@ 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="../../shared/gr-select/gr-select.html">
<link rel="import" href="../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html">
<link rel="import" href="../../../bower_components/polymer/polymer.html">
<link rel="import" href="../../shared/gr-select/gr-select.html">
<dom-module id="gr-patch-range-select">
<template>
@@ -25,6 +27,9 @@ limitations under the License.
.patchRange {
display: inline-block;
}
select {
max-width: 25em;
}
</style>
Patch set:
<span class="patchRange">
@@ -33,7 +38,10 @@ limitations under the License.
<option value="PARENT">Base</option>
<template is="dom-repeat" items="{{availablePatches}}" as="patchNum">
<option value$="[[patchNum]]"
disabled$="[[_computeLeftDisabled(patchNum, patchRange)]]">[[patchNum]]</option>
disabled$="[[_computeLeftDisabled(patchNum, patchRange)]]">
[[patchNum]]
[[_computePatchSetDescription(revisions, patchNum)]]
</option>
</template>
</select>
</span>
@@ -49,7 +57,10 @@ limitations under the License.
on-change="_handlePatchChange" is="gr-select">
<template is="dom-repeat" items="{{availablePatches}}" as="patchNum">
<option value$="[[patchNum]]"
disabled$="[[_computeRightDisabled(patchNum, patchRange)]]">[[patchNum]]</option>
disabled$="[[_computeRightDisabled(patchNum, patchRange)]]">
[[patchNum]]
[[_computePatchSetDescription(revisions, patchNum)]]
</option>
</template>
</select>
<span is="dom-if" if="[[filesWeblinks.meta_b]]">

View File

@@ -24,12 +24,15 @@
path: String,
patchRange: {
type: Object,
observer: '_updateSelected'
observer: '_updateSelected',
},
revisions: Object,
_rightSelected: String,
_leftSelected: String,
},
behaviors: [Gerrit.PatchSetBehavior],
_updateSelected: function() {
this._rightSelected = this.patchRange.patchNum;
this._leftSelected = this.patchRange.basePatchNum;
@@ -67,5 +70,10 @@
_synchronizeSelectionLeft: function() {
this.$.leftPatchSelect.value = this._leftSelected;
},
_computePatchSetDescription: function(revisions, patchNum) {
var rev = this.getRevisionNumber(revisions, patchNum);
return (rev && rev.description) ? rev.description : '';
},
});
})();

View File

@@ -104,6 +104,7 @@ limitations under the License.
// Behaviors tests.
[
'gr-patch-set-behavior/gr-patch-set-behavior_test.html',
'gr-path-list-behavior/gr-path-list-behavior_test.html',
].forEach(function(file) {
file = behaviorsPath + file;