Merge "Update all the plugin examples" into stable-3.4

This commit is contained in:
Ben Rohlfs
2021-04-29 20:34:18 +00:00
committed by Gerrit Code Review
8 changed files with 26 additions and 142 deletions

View File

@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This plugin will a button to quickly add favorite reviewers to
* reviewers in reply dialog.
@@ -142,4 +143,4 @@ Gerrit.install(plugin => {
'reply-reviewers', ReviewerShortcut.is, {slot: 'right'});
plugin.registerCustomComponent(
'reply-reviewers', ReviewerShortcutContent.is, {slot: 'below'});
});
});

View File

@@ -14,15 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Element class exists in all browsers:
// https://developer.mozilla.org/en-US/docs/Web/API/Element
// Rename it to PolymerElement to avoid conflicts. Also,
// typescript reports the following error:
// error TS2451: Cannot redeclare block-scoped variable 'Element'.
const {html, Element: PolymerElement} = Polymer;
class MyBindSample extends PolymerElement {
class MyBindSample extends Polymer.Element {
static get is() { return 'my-bind-sample'; }
static get properties() {
@@ -39,7 +31,7 @@ class MyBindSample extends PolymerElement {
}
static get template() {
return html`
return Polymer.html`
Template example: Patchset number [[revision._number]]. <br/>
Computed example: [[computedExample]].
`;

View File

@@ -1,76 +0,0 @@
/**
* @license
* Copyright (C) 2020 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 populateWithDummyData(coverageData) {
coverageData['/COMMIT_MSG'] = {
linesMissingCoverage: [3, 4, 7, 14],
totalLines: 14,
changeNum: 94,
patchNum: 2,
};
// more coverage info on other files
}
/**
* This plugin will add a toggler on file diff page to
* display fake coverage data.
*
* As the fake coverage data only provided for COMMIT_MSG file,
* so it will only work for COMMIT_MSG file diff.
*/
Gerrit.install(plugin => {
const coverageData = {};
let displayCoverage = false;
const annotationApi = plugin.annotationApi();
const styleApi = plugin.styles();
const coverageStyle = styleApi.css('background-color: #EF9B9B !important');
const emptyStyle = styleApi.css('');
annotationApi.setLayer(context => {
if (Object.keys(coverageData).length === 0) {
// Coverage data is not ready yet.
return;
}
const path = context.path;
const line = context.line;
// Highlight lines missing coverage with this background color if
// coverage should be displayed, else do nothing.
const annotationStyle = displayCoverage
? coverageStyle
: emptyStyle;
// ideally should check to make sure its the same patch for same change
// for demo purpose, this is only checking to make sure we have fake data
if (coverageData[path]) {
const linesMissingCoverage = coverageData[path].linesMissingCoverage;
if (linesMissingCoverage.includes(line.afterNumber)) {
context.annotateRange(0, line.text.length, annotationStyle, 'right');
context.annotateLineNumber(annotationStyle, 'right');
}
}
}).enableToggleCheckbox('Display Coverage', checkbox => {
populateWithDummyData(coverageData);
checkbox.disabled = false;
checkbox.onclick = e => {
displayCoverage = e.target.checked;
Object.keys(coverageData).forEach(file => {
annotationApi.notify(file, 0, coverageData[file].totalLines, 'right');
});
};
});
});

View File

@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This plugin will an extra column to file list on change page to show
* the first character of the path.
@@ -74,4 +75,4 @@ Gerrit.install(plugin => {
'change-view-file-list-header-prepend', ColumnHeader.is);
plugin.registerDynamicCustomComponent(
'change-view-file-list-content-prepend', ColumnContent.is);
});
});

View File

@@ -14,8 +14,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This plugin will +1 on Code-Review label if detect that you have
* This plugin will +1 on Code-Review label if it detects that you have
* LGTM as start of your reply.
*/
Gerrit.install(plugin => {
@@ -29,4 +30,4 @@ Gerrit.install(plugin => {
replyApi.setLabelValue(label, '+1');
}
});
});
});

View File

@@ -15,14 +15,7 @@
* limitations under the License.
*/
// Element class exists in all browsers:
// https://developer.mozilla.org/en-US/docs/Web/API/Element
// Rename it to PolymerElement to avoid conflicts. Also,
// typescript reports the following error:
// error TS2451: Cannot redeclare block-scoped variable 'Element'.
const {html, Element: PolymerElement} = Polymer;
class RepoCommandLow extends PolymerElement {
class RepoCommandLow extends Polymer.Element {
static get is() { return 'repo-command-low'; }
static get properties() {
@@ -32,20 +25,16 @@ class RepoCommandLow extends PolymerElement {
}
static get template() {
return html`
<style include="shared-styles">
:host {
display: block;
margin-bottom: var(--spacing-xxl);
}
</style>
<h3>Low-level bork</h3>
<gr-button
on-click="_handleCommandTap"
>
Low-level bork
</gr-button>
`;
return Polymer.html`
<style include="shared-styles">
:host {
display: block;
margin-bottom: var(--spacing-xxl);
}
</style>
<h3>Plugin Bork</h3>
<gr-button on-click="_handleCommandTap">Bork</gr-button>
`;
}
connectedCallback() {
@@ -56,32 +45,16 @@ class RepoCommandLow extends PolymerElement {
}
_handleCommandTap() {
alert('(softly) bork, bork.');
alert('bork');
}
}
// register the custom component
customElements.define(RepoCommandLow.is, RepoCommandLow);
/**
* This plugin will add two new commands in command page for
* All-Projects.
*
* The added commands will simply alert you when click.
* This plugin adds a new command to the command page of the repo All-Projects.
*/
Gerrit.install(plugin => {
// High-level API
plugin.project()
.createCommand('Bork', (repoName, projectConfig) => {
if (repoName !== 'All-Projects') {
return false;
}
})
.onTap(() => {
alert('Bork, bork!');
});
// Low-level API
plugin.registerCustomComponent(
'repo-command', 'repo-command-low');
});

View File

@@ -15,14 +15,7 @@
* limitations under the License.
*/
// Element class exists in all browsers:
// https://developer.mozilla.org/en-US/docs/Web/API/Element
// Rename it to PolymerElement to avoid conflicts. Also,
// typescript reports the following error:
// error TS2451: Cannot redeclare block-scoped variable 'Element'.
const {html, Element: PolymerElement} = Polymer;
class SomeScreenMain extends PolymerElement {
class SomeScreenMain extends Polymer.Element {
static get is() { return 'some-screen-main'; }
static get properties() {
@@ -32,7 +25,7 @@ class SomeScreenMain extends PolymerElement {
}
static get template() {
return html`
return Polymer.html`
This is the <b>main</b> plugin screen at [[token]]
<ul>
<li><a href$="[[rootUrl]]/bar">without component</a></li>
@@ -46,7 +39,6 @@ class SomeScreenMain extends PolymerElement {
}
}
// register the custom component
customElements.define(SomeScreenMain.is, SomeScreenMain);
/**

View File

@@ -14,6 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This plugin will upgrade your +1 on Code-Review label
* to +2 and show a message below the voting labels.
@@ -29,8 +30,7 @@ Gerrit.install(plugin => {
if (wasSuggested && name === CODE_REVIEW) {
replyApi.showMessage('');
wasSuggested = false;
} else if (replyApi.getLabelValue(CODE_REVIEW) === '+1' &&
!wasSuggested) {
} else if (replyApi.getLabelValue(CODE_REVIEW) === '+1' && !wasSuggested) {
replyApi.setLabelValue(CODE_REVIEW, '+2');
replyApi.showMessage(`Suggested ${CODE_REVIEW} upgrade: +2`);
wasSuggested = true;