PolyGerrit: Add support for "Included In"

Bug: Issue 6112
Change-Id: I033e3f248a404813b5bc46eeef6bf25b7153bc1a
This commit is contained in:
Paladox none
2017-09-21 17:27:04 +00:00
parent 63489d858c
commit cae06e030e
9 changed files with 292 additions and 0 deletions

View File

@@ -42,6 +42,7 @@ limitations under the License.
<link rel="import" href="../gr-download-dialog/gr-download-dialog.html"> <link rel="import" href="../gr-download-dialog/gr-download-dialog.html">
<link rel="import" href="../gr-file-list-header/gr-file-list-header.html"> <link rel="import" href="../gr-file-list-header/gr-file-list-header.html">
<link rel="import" href="../gr-file-list/gr-file-list.html"> <link rel="import" href="../gr-file-list/gr-file-list.html">
<link rel="import" href="../gr-included-in-dialog/gr-included-in-dialog.html">
<link rel="import" href="../gr-messages-list/gr-messages-list.html"> <link rel="import" href="../gr-messages-list/gr-messages-list.html">
<link rel="import" href="../gr-related-changes-list/gr-related-changes-list.html"> <link rel="import" href="../gr-related-changes-list/gr-related-changes-list.html">
<link rel="import" href="../gr-reply-dialog/gr-reply-dialog.html"> <link rel="import" href="../gr-reply-dialog/gr-reply-dialog.html">
@@ -259,6 +260,10 @@ limitations under the License.
#messageList.visible { #messageList.visible {
display: block; display: block;
} }
#includedInOverlay {
padding: 2em;
width: 65em;
}
@media screen and (min-width: 80em) { @media screen and (min-width: 80em) {
.commitMessage { .commitMessage {
max-width: var(--commit-message-max-width, 100ch); max-width: var(--commit-message-max-width, 100ch);
@@ -516,6 +521,7 @@ limitations under the License.
files-expanded="[[_filesExpanded]]" files-expanded="[[_filesExpanded]]"
on-open-diff-prefs="_handleOpenDiffPrefs" on-open-diff-prefs="_handleOpenDiffPrefs"
on-open-download-dialog="_handleOpenDownloadDialog" on-open-download-dialog="_handleOpenDownloadDialog"
on-open-included-in-dialog="_handleOpenIncludedInDialog"
on-expand-diffs="_expandAllDiffs" on-expand-diffs="_expandAllDiffs"
on-collapse-diffs="_collapseAllDiffs"> on-collapse-diffs="_collapseAllDiffs">
</gr-file-list-header> </gr-file-list-header>
@@ -578,6 +584,12 @@ limitations under the License.
config="[[_serverConfig.download]]" config="[[_serverConfig.download]]"
on-close="_handleDownloadDialogClose"></gr-download-dialog> on-close="_handleDownloadDialogClose"></gr-download-dialog>
</gr-overlay> </gr-overlay>
<gr-overlay id="includedInOverlay" with-backdrop>
<gr-included-in-dialog
id="includedInDialog"
change-num="[[_changeNum]]"
on-close="_handleIncludedInDialogClose"></gr-included-in-dialog>
</gr-overlay>
<gr-overlay id="replyOverlay" <gr-overlay id="replyOverlay"
class="scrollable" class="scrollable"
no-cancel-on-outside-click no-cancel-on-outside-click

View File

@@ -512,6 +512,18 @@
this.$.fileList.openDiffPrefs(); this.$.fileList.openDiffPrefs();
}, },
_handleOpenIncludedInDialog() {
this.$.includedInDialog.loadData().then(() => {
Polymer.dom.flush();
this.$.includedInOverlay.refit();
});
this.$.includedInOverlay.open();
},
_handleIncludedInDialogClose(e) {
this.$.includedInOverlay.close();
},
_handleOpenDownloadDialog() { _handleOpenDownloadDialog() {
this.$.downloadOverlay.open().then(() => { this.$.downloadOverlay.open().then(() => {
this.$.downloadOverlay this.$.downloadOverlay

View File

@@ -80,6 +80,12 @@ limitations under the License.
.downloadContainer { .downloadContainer {
margin-right: 16px; margin-right: 16px;
} }
.includedInContainer {
margin-right: 16px;
}
.includedInContainer.hide {
display: none;
}
.rightControls { .rightControls {
align-self: flex-end; align-self: flex-end;
margin: auto 0 auto auto; margin: auto 0 auto auto;
@@ -209,6 +215,11 @@ limitations under the License.
class="download" class="download"
on-tap="_handleDownloadTap">Download</gr-button> on-tap="_handleDownloadTap">Download</gr-button>
</span> </span>
<span class$="includedInContainer [[_hideIncludedIn(change)]] desktop">
<gr-button link
class="includedIn"
on-tap="_handleIncludedInTap">Included In</gr-button>
</span>
<template is="dom-if" <template is="dom-if"
if="[[_fileListActionsVisible(shownFileCount, _maxFilesForBulkActions)]]"> if="[[_fileListActionsVisible(shownFileCount, _maxFilesForBulkActions)]]">
<gr-button <gr-button

View File

@@ -179,6 +179,11 @@
this.fire('open-diff-prefs'); this.fire('open-diff-prefs');
}, },
_handleIncludedInTap(e) {
e.preventDefault();
this.fire('open-included-in-dialog');
},
_handleDownloadTap(e) { _handleDownloadTap(e) {
e.preventDefault(); e.preventDefault();
this.fire('open-download-dialog'); this.fire('open-download-dialog');
@@ -199,5 +204,9 @@
_getRevisionInfo(change) { _getRevisionInfo(change) {
return new Gerrit.RevisionInfo(change); return new Gerrit.RevisionInfo(change);
}, },
_hideIncludedIn(change) {
return change && change.status === 'MERGED' ? '' : 'hide';
},
}); });
})(); })();

View File

@@ -0,0 +1,84 @@
<!--
Copyright (C) 2018 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="../../../styles/shared-styles.html">
<link rel="import" href="../../shared/gr-rest-api-interface/gr-rest-api-interface.html">
<dom-module id="gr-included-in-dialog">
<template>
<style include="shared-styles">
:host {
display: block;
padding: 1em;
}
h1 {
font-size: 1.2rem;
}
h2 {
font-size: 1rem;
}
.closeButtonContainer {
position: absolute;
right: 2em;
top: 2em;
}
.container {
max-height: 80vh;
overflow-y: scroll;
}
ul {
margin-bottom: 1em;
}
ul li {
border-radius: .2em;
background: #eee;
display: inline-block;
margin: 0 .2em .4em .2em;
padding: .2em .4em;
}
.loading.loaded {
display: none;
}
</style>
<header>
<h1>Included In:</h1>
<span class="closeButtonContainer">
<gr-button id="closeButton"
link
on-tap="_handleCloseTap">Close</gr-button>
</span>
</header>
<div class$="[[_computeLoadingClass(_loaded)]]">Loading...</div>
<div class="container">
<template
is="dom-repeat"
items="[[_computeGroups(_includedIn)]]"
as="group">
<div>
<h2>[[group.title]]:</h2>
<ul>
<template is="dom-repeat" items="[[group.items]]">
<li>[[item]]</li>
</template>
</ul>
</div>
</template>
</div>
<gr-rest-api-interface id="restAPI"></gr-rest-api-interface>
</template>
<script src="gr-included-in-dialog.js"></script>
</dom-module>

View File

@@ -0,0 +1,82 @@
// Copyright (C) 2018 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.
(function() {
'use strict';
Polymer({
is: 'gr-included-in-dialog',
/**
* Fired when the user presses the close button.
*
* @event close
*/
properties: {
/** @type {?} */
changeNum: {
type: Object,
observer: '_resetData',
},
/** @type {?} */
_includedIn: Object,
_loaded: {
type: Boolean,
value: false,
},
},
loadData() {
if (!this.changeNum) { return; }
return this.$.restAPI.getChangeIncludedIn(this.changeNum).then(
configs => {
if (!configs) { return; }
this._includedIn = configs;
this._loaded = true;
});
},
_resetData() {
this._includedIn = null;
this._loaded = false;
},
_computeGroups(includedIn) {
if (!includedIn) { return []; }
const groups = [
{title: 'Branches', items: includedIn.branches},
{title: 'Tags', items: includedIn.tags},
];
if (includedIn.external) {
for (const externalKey of Object.keys(includedIn.external)) {
groups.push({
title: externalKey,
items: includedIn.external[externalKey],
});
}
}
return groups;
},
_handleCloseTap(e) {
e.preventDefault();
this.fire('close', null, {bubbles: false});
},
_computeLoadingClass(loaded) {
return loaded ? 'loading loaded' : 'loading';
},
});
})();

View File

@@ -0,0 +1,74 @@
<!DOCTYPE html>
<!--
Copyright (C) 2018 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.
-->
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, user-scalable=yes">
<title>gr-included-in-dialog</title>
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<link rel="import" href="../../../test/common-test-setup.html"/>
<link rel="import" href="gr-included-in-dialog.html">
<script>void(0);</script>
<test-fixture id="basic">
<template>
<gr-included-in-dialog></gr-included-in-dialog>
</template>
</test-fixture>
<script>
suite('gr-included-in-dialog', () => {
let element;
let sandbox;
setup(() => {
sandbox = sinon.sandbox.create();
element = fixture('basic');
});
teardown(() => { sandbox.restore(); });
test('_computeGroups', () => {
const includedIn = {branches: [], tags: []};
assert.deepEqual(element._computeGroups(includedIn), [
{title: 'Branches', items: []},
{title: 'Tags', items: []},
]);
includedIn.branches.push('master', 'development', 'stable-2.0');
includedIn.tags.push('v1.9', 'v2.0', 'v2.1');
assert.deepEqual(element._computeGroups(includedIn), [
{title: 'Branches', items: ['master', 'development', 'stable-2.0']},
{title: 'Tags', items: ['v1.9', 'v2.0', 'v2.1']},
]);
includedIn.external = {};
assert.deepEqual(element._computeGroups(includedIn), [
{title: 'Branches', items: ['master', 'development', 'stable-2.0']},
{title: 'Tags', items: ['v1.9', 'v2.0', 'v2.1']},
]);
includedIn.external.foo = ['abc', 'def', 'ghi'];
assert.deepEqual(element._computeGroups(includedIn), [
{title: 'Branches', items: ['master', 'development', 'stable-2.0']},
{title: 'Tags', items: ['v1.9', 'v2.0', 'v2.1']},
{title: 'foo', items: ['abc', 'def', 'ghi']},
]);
});
});
</script>

View File

@@ -1105,6 +1105,13 @@
opt_errFn, null, params); opt_errFn, null, params);
}, },
/**
* @param {number|string} changeNum
*/
getChangeIncludedIn(changeNum) {
return this._getChangeURLAndFetch(changeNum, '/in', null);
},
_computeFilter(filter) { _computeFilter(filter) {
if (filter && filter.startsWith('^')) { if (filter && filter.startsWith('^')) {
filter = '&r=' + encodeURIComponent(filter); filter = '&r=' + encodeURIComponent(filter);

View File

@@ -73,6 +73,7 @@ limitations under the License.
'change/gr-download-dialog/gr-download-dialog_test.html', 'change/gr-download-dialog/gr-download-dialog_test.html',
'change/gr-file-list-header/gr-file-list-header_test.html', 'change/gr-file-list-header/gr-file-list-header_test.html',
'change/gr-file-list/gr-file-list_test.html', 'change/gr-file-list/gr-file-list_test.html',
'change/gr-included-in-dialog/gr-included-in-dialog_test.html',
'change/gr-label-score-row/gr-label-score-row_test.html', 'change/gr-label-score-row/gr-label-score-row_test.html',
'change/gr-label-scores/gr-label-scores_test.html', 'change/gr-label-scores/gr-label-scores_test.html',
'change/gr-message/gr-message_test.html', 'change/gr-message/gr-message_test.html',