Merge "Update all the plugin examples" into stable-3.4
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This plugin will a button to quickly add favorite reviewers to
|
* This plugin will a button to quickly add favorite reviewers to
|
||||||
* reviewers in reply dialog.
|
* reviewers in reply dialog.
|
||||||
@@ -142,4 +143,4 @@ Gerrit.install(plugin => {
|
|||||||
'reply-reviewers', ReviewerShortcut.is, {slot: 'right'});
|
'reply-reviewers', ReviewerShortcut.is, {slot: 'right'});
|
||||||
plugin.registerCustomComponent(
|
plugin.registerCustomComponent(
|
||||||
'reply-reviewers', ReviewerShortcutContent.is, {slot: 'below'});
|
'reply-reviewers', ReviewerShortcutContent.is, {slot: 'below'});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,15 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
class MyBindSample extends Polymer.Element {
|
||||||
// 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 {
|
|
||||||
static get is() { return 'my-bind-sample'; }
|
static get is() { return 'my-bind-sample'; }
|
||||||
|
|
||||||
static get properties() {
|
static get properties() {
|
||||||
@@ -39,7 +31,7 @@ class MyBindSample extends PolymerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get template() {
|
static get template() {
|
||||||
return html`
|
return Polymer.html`
|
||||||
Template example: Patchset number [[revision._number]]. <br/>
|
Template example: Patchset number [[revision._number]]. <br/>
|
||||||
Computed example: [[computedExample]].
|
Computed example: [[computedExample]].
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -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');
|
|
||||||
});
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This plugin will an extra column to file list on change page to show
|
* This plugin will an extra column to file list on change page to show
|
||||||
* the first character of the path.
|
* the first character of the path.
|
||||||
@@ -74,4 +75,4 @@ Gerrit.install(plugin => {
|
|||||||
'change-view-file-list-header-prepend', ColumnHeader.is);
|
'change-view-file-list-header-prepend', ColumnHeader.is);
|
||||||
plugin.registerDynamicCustomComponent(
|
plugin.registerDynamicCustomComponent(
|
||||||
'change-view-file-list-content-prepend', ColumnContent.is);
|
'change-view-file-list-content-prepend', ColumnContent.is);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,8 +14,9 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* 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.
|
* LGTM as start of your reply.
|
||||||
*/
|
*/
|
||||||
Gerrit.install(plugin => {
|
Gerrit.install(plugin => {
|
||||||
@@ -29,4 +30,4 @@ Gerrit.install(plugin => {
|
|||||||
replyApi.setLabelValue(label, '+1');
|
replyApi.setLabelValue(label, '+1');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,14 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Element class exists in all browsers:
|
class RepoCommandLow extends Polymer.Element {
|
||||||
// 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 {
|
|
||||||
static get is() { return 'repo-command-low'; }
|
static get is() { return 'repo-command-low'; }
|
||||||
|
|
||||||
static get properties() {
|
static get properties() {
|
||||||
@@ -32,20 +25,16 @@ class RepoCommandLow extends PolymerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get template() {
|
static get template() {
|
||||||
return html`
|
return Polymer.html`
|
||||||
<style include="shared-styles">
|
<style include="shared-styles">
|
||||||
:host {
|
:host {
|
||||||
display: block;
|
display: block;
|
||||||
margin-bottom: var(--spacing-xxl);
|
margin-bottom: var(--spacing-xxl);
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<h3>Low-level bork</h3>
|
<h3>Plugin Bork</h3>
|
||||||
<gr-button
|
<gr-button on-click="_handleCommandTap">Bork</gr-button>
|
||||||
on-click="_handleCommandTap"
|
`;
|
||||||
>
|
|
||||||
Low-level bork
|
|
||||||
</gr-button>
|
|
||||||
`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
@@ -56,32 +45,16 @@ class RepoCommandLow extends PolymerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_handleCommandTap() {
|
_handleCommandTap() {
|
||||||
alert('(softly) bork, bork.');
|
alert('bork');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// register the custom component
|
|
||||||
customElements.define(RepoCommandLow.is, RepoCommandLow);
|
customElements.define(RepoCommandLow.is, RepoCommandLow);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This plugin will add two new commands in command page for
|
* This plugin adds a new command to the command page of the repo All-Projects.
|
||||||
* All-Projects.
|
|
||||||
*
|
|
||||||
* The added commands will simply alert you when click.
|
|
||||||
*/
|
*/
|
||||||
Gerrit.install(plugin => {
|
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(
|
plugin.registerCustomComponent(
|
||||||
'repo-command', 'repo-command-low');
|
'repo-command', 'repo-command-low');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -15,14 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Element class exists in all browsers:
|
class SomeScreenMain extends Polymer.Element {
|
||||||
// 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 {
|
|
||||||
static get is() { return 'some-screen-main'; }
|
static get is() { return 'some-screen-main'; }
|
||||||
|
|
||||||
static get properties() {
|
static get properties() {
|
||||||
@@ -32,7 +25,7 @@ class SomeScreenMain extends PolymerElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static get template() {
|
static get template() {
|
||||||
return html`
|
return Polymer.html`
|
||||||
This is the <b>main</b> plugin screen at [[token]]
|
This is the <b>main</b> plugin screen at [[token]]
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href$="[[rootUrl]]/bar">without component</a></li>
|
<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);
|
customElements.define(SomeScreenMain.is, SomeScreenMain);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This plugin will upgrade your +1 on Code-Review label
|
* This plugin will upgrade your +1 on Code-Review label
|
||||||
* to +2 and show a message below the voting labels.
|
* to +2 and show a message below the voting labels.
|
||||||
@@ -29,8 +30,7 @@ Gerrit.install(plugin => {
|
|||||||
if (wasSuggested && name === CODE_REVIEW) {
|
if (wasSuggested && name === CODE_REVIEW) {
|
||||||
replyApi.showMessage('');
|
replyApi.showMessage('');
|
||||||
wasSuggested = false;
|
wasSuggested = false;
|
||||||
} else if (replyApi.getLabelValue(CODE_REVIEW) === '+1' &&
|
} else if (replyApi.getLabelValue(CODE_REVIEW) === '+1' && !wasSuggested) {
|
||||||
!wasSuggested) {
|
|
||||||
replyApi.setLabelValue(CODE_REVIEW, '+2');
|
replyApi.setLabelValue(CODE_REVIEW, '+2');
|
||||||
replyApi.showMessage(`Suggested ${CODE_REVIEW} upgrade: +2`);
|
replyApi.showMessage(`Suggested ${CODE_REVIEW} upgrade: +2`);
|
||||||
wasSuggested = true;
|
wasSuggested = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user