Convert legacy Polyemer elements to class-based
This commit converts almost all Polymer elements from Polymer-function
based components to class-based components. There are few files which
should be converted manually after this commit.
Change-Id: I9e597e79053e0a6b5d5c0f1b54676d11b9d81db7
diff --git a/polygerrit-ui/app/elements/shared/gr-account-chip/gr-account-chip.js b/polygerrit-ui/app/elements/shared/gr-account-chip/gr-account-chip.js
index 10c876d..27b1cc4 100644
--- a/polygerrit-ui/app/elements/shared/gr-account-chip/gr-account-chip.js
+++ b/polygerrit-ui/app/elements/shared/gr-account-chip/gr-account-chip.js
@@ -14,13 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
(function() {
'use strict';
- Polymer({
- is: 'gr-account-chip',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ */
+ class GrAccountChip extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-account-chip'; }
/**
* Fired to indicate a key was pressed while this chip was focused.
*
@@ -34,51 +39,52 @@
* @event remove
*/
- properties: {
- account: Object,
- additionalText: String,
- disabled: {
- type: Boolean,
- value: false,
- reflectToAttribute: true,
- },
- removable: {
- type: Boolean,
- value: false,
- },
- showAvatar: {
- type: Boolean,
- reflectToAttribute: true,
- },
- transparentBackground: {
- type: Boolean,
- value: false,
- },
- },
-
- behaviors: [
- Gerrit.FireBehavior,
- ],
+ static get properties() {
+ return {
+ account: Object,
+ additionalText: String,
+ disabled: {
+ type: Boolean,
+ value: false,
+ reflectToAttribute: true,
+ },
+ removable: {
+ type: Boolean,
+ value: false,
+ },
+ showAvatar: {
+ type: Boolean,
+ reflectToAttribute: true,
+ },
+ transparentBackground: {
+ type: Boolean,
+ value: false,
+ },
+ };
+ }
ready() {
+ super.ready();
this._getHasAvatars().then(hasAvatars => {
this.showAvatar = hasAvatars;
});
- },
+ }
_getBackgroundClass(transparent) {
return transparent ? 'transparentBackground' : '';
- },
+ }
_handleRemoveTap(e) {
e.preventDefault();
this.fire('remove', {account: this.account});
- },
+ }
_getHasAvatars() {
return this.$.restAPI.getConfig().then(cfg => {
return Promise.resolve(!!(cfg && cfg.plugin && cfg.plugin.has_avatars));
});
- },
- });
+ }
+ }
+
+ customElements.define(GrAccountChip.is, GrAccountChip);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-account-entry/gr-account-entry.js b/polygerrit-ui/app/elements/shared/gr-account-entry/gr-account-entry.js
index b2e0973..0ed3f19 100644
--- a/polygerrit-ui/app/elements/shared/gr-account-entry/gr-account-entry.js
+++ b/polygerrit-ui/app/elements/shared/gr-account-entry/gr-account-entry.js
@@ -21,9 +21,10 @@
* gr-account-entry is an element for entering account
* and/or group with autocomplete support.
*/
- Polymer({
- is: 'gr-account-entry',
-
+ class GrAccountEntry extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-account-entry'; }
/**
* Fired when an account is entered.
*
@@ -37,65 +38,70 @@
*
* @event account-text-changed
*/
- properties: {
- allowAnyInput: Boolean,
- borderless: Boolean,
- placeholder: String,
- // suggestFrom = 0 to enable default suggestions.
- suggestFrom: {
- type: Number,
- value: 0,
- },
+ static get properties() {
+ return {
+ allowAnyInput: Boolean,
+ borderless: Boolean,
+ placeholder: String,
- /** @type {!function(string): !Promise<Array<{name, value}>>} */
- querySuggestions: {
- type: Function,
- notify: true,
- value() {
- return input => Promise.resolve([]);
+ // suggestFrom = 0 to enable default suggestions.
+ suggestFrom: {
+ type: Number,
+ value: 0,
},
- },
- _config: Object,
- /** The value of the autocomplete entry. */
- _inputText: {
- type: String,
- observer: '_inputTextChanged',
- },
+ /** @type {!function(string): !Promise<Array<{name, value}>>} */
+ querySuggestions: {
+ type: Function,
+ notify: true,
+ value() {
+ return input => Promise.resolve([]);
+ },
+ },
- },
+ _config: Object,
+ /** The value of the autocomplete entry. */
+ _inputText: {
+ type: String,
+ observer: '_inputTextChanged',
+ },
+
+ };
+ }
get focusStart() {
return this.$.input.focusStart;
- },
+ }
focus() {
this.$.input.focus();
- },
+ }
clear() {
this.$.input.clear();
- },
+ }
setText(text) {
this.$.input.setText(text);
- },
+ }
getText() {
return this.$.input.text;
- },
+ }
_handleInputCommit(e) {
this.fire('add', {value: e.detail.value});
this.$.input.focus();
- },
+ }
_inputTextChanged(text) {
if (text.length && this.allowAnyInput) {
this.dispatchEvent(new CustomEvent(
'account-text-changed', {bubbles: true, composed: true}));
}
- },
- });
+ }
+ }
+
+ customElements.define(GrAccountEntry.is, GrAccountEntry);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-account-label/gr-account-label.js b/polygerrit-ui/app/elements/shared/gr-account-label/gr-account-label.js
index 418d2ea..3d96421 100644
--- a/polygerrit-ui/app/elements/shared/gr-account-label/gr-account-label.js
+++ b/polygerrit-ui/app/elements/shared/gr-account-label/gr-account-label.js
@@ -17,58 +17,65 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-account-label',
+ /**
+ * @appliesMixin Gerrit.DisplayNameMixin
+ * @appliesMixin Gerrit.TooltipMixin
+ */
+ class GrAccountLabel extends Polymer.mixinBehaviors( [
+ Gerrit.DisplayNameBehavior,
+ Gerrit.TooltipBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-account-label'; }
- properties: {
+ static get properties() {
+ return {
/**
* @type {{ name: string, status: string }}
*/
- account: Object,
- avatarImageSize: {
- type: Number,
- value: 32,
- },
- title: {
- type: String,
- reflectToAttribute: true,
- computed: '_computeAccountTitle(account, additionalText)',
- },
- additionalText: String,
- hasTooltip: {
- type: Boolean,
- reflectToAttribute: true,
- computed: '_computeHasTooltip(account)',
- },
- hideAvatar: {
- type: Boolean,
- value: false,
- },
- _serverConfig: {
- type: Object,
- value: null,
- },
- },
-
- behaviors: [
- Gerrit.DisplayNameBehavior,
- Gerrit.TooltipBehavior,
- ],
+ account: Object,
+ avatarImageSize: {
+ type: Number,
+ value: 32,
+ },
+ title: {
+ type: String,
+ reflectToAttribute: true,
+ computed: '_computeAccountTitle(account, additionalText)',
+ },
+ additionalText: String,
+ hasTooltip: {
+ type: Boolean,
+ reflectToAttribute: true,
+ computed: '_computeHasTooltip(account)',
+ },
+ hideAvatar: {
+ type: Boolean,
+ value: false,
+ },
+ _serverConfig: {
+ type: Object,
+ value: null,
+ },
+ };
+ }
ready() {
+ super.ready();
if (!this.additionalText) { this.additionalText = ''; }
this.$.restAPI.getConfig()
.then(config => { this._serverConfig = config; });
- },
+ }
_computeName(account, config) {
return this.getUserName(config, account, false);
- },
+ }
_computeStatusTextLength(account, config) {
// 35 as the max length of the name + status
return Math.max(10, 35 - this._computeName(account, config).length);
- },
+ }
_computeAccountTitle(account, tooltip) {
// Polymer 2: check for undefined
@@ -98,12 +105,12 @@
}
return result;
- },
+ }
_computeShowEmailClass(account) {
if (!account || account.name || !account.email) { return ''; }
return 'showEmail';
- },
+ }
_computeEmailStr(account) {
if (!account || !account.email) {
@@ -113,11 +120,13 @@
return '(' + account.email + ')';
}
return account.email;
- },
+ }
_computeHasTooltip(account) {
// If an account has loaded to fire this method, then set to true.
return !!account;
- },
- });
+ }
+ }
+
+ customElements.define(GrAccountLabel.is, GrAccountLabel);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-account-link/gr-account-link.js b/polygerrit-ui/app/elements/shared/gr-account-link/gr-account-link.js
index faaf9c3..0764669 100644
--- a/polygerrit-ui/app/elements/shared/gr-account-link/gr-account-link.js
+++ b/polygerrit-ui/app/elements/shared/gr-account-link/gr-account-link.js
@@ -17,27 +17,34 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-account-link',
+ /**
+ * @appliesMixin Gerrit.BaseUrlMixin
+ */
+ class GrAccountLink extends Polymer.mixinBehaviors( [
+ Gerrit.BaseUrlBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-account-link'; }
- properties: {
- additionalText: String,
- account: Object,
- avatarImageSize: {
- type: Number,
- value: 32,
- },
- },
-
- behaviors: [
- Gerrit.BaseUrlBehavior,
- ],
+ static get properties() {
+ return {
+ additionalText: String,
+ account: Object,
+ avatarImageSize: {
+ type: Number,
+ value: 32,
+ },
+ };
+ }
_computeOwnerLink(account) {
if (!account) { return; }
return Gerrit.Nav.getUrlForOwner(
account.email || account.username || account.name ||
account._account_id);
- },
- });
+ }
+ }
+
+ customElements.define(GrAccountLink.is, GrAccountLink);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.js b/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.js
index 9897105..48dddb0 100644
--- a/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.js
+++ b/polygerrit-ui/app/elements/shared/gr-account-list/gr-account-list.js
@@ -19,95 +19,101 @@
const VALID_EMAIL_ALERT = 'Please input a valid email.';
- Polymer({
- is: 'gr-account-list',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ */
+ class GrAccountList extends Polymer.mixinBehaviors( [
+ // Used in the tests for gr-account-list and other elements tests.
+ Gerrit.FireBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-account-list'; }
/**
* Fired when user inputs an invalid email address.
*
* @event show-alert
*/
- properties: {
- accounts: {
- type: Array,
- value() { return []; },
- notify: true,
- },
- change: Object,
- filter: Function,
- placeholder: String,
- disabled: {
- type: Function,
- value: false,
- },
+ static get properties() {
+ return {
+ accounts: {
+ type: Array,
+ value() { return []; },
+ notify: true,
+ },
+ change: Object,
+ filter: Function,
+ placeholder: String,
+ disabled: {
+ type: Function,
+ value: false,
+ },
- /**
+ /**
* Returns suggestions and convert them to list item
* @type {Gerrit.GrSuggestionsProvider}
*/
- suggestionsProvider: {
- type: Object,
- },
+ suggestionsProvider: {
+ type: Object,
+ },
- /**
+ /**
* Needed for template checking since value is initially set to null.
* @type {?Object} */
- pendingConfirmation: {
- type: Object,
- value: null,
- notify: true,
- },
- readonly: {
- type: Boolean,
- value: false,
- },
- /**
+ pendingConfirmation: {
+ type: Object,
+ value: null,
+ notify: true,
+ },
+ readonly: {
+ type: Boolean,
+ value: false,
+ },
+ /**
* When true, allows for non-suggested inputs to be added.
*/
- allowAnyInput: {
- type: Boolean,
- value: false,
- },
+ allowAnyInput: {
+ type: Boolean,
+ value: false,
+ },
- /**
+ /**
* Array of values (groups/accounts) that are removable. When this prop is
* undefined, all values are removable.
*/
- removableValues: Array,
- maxCount: {
- type: Number,
- value: 0,
- },
+ removableValues: Array,
+ maxCount: {
+ type: Number,
+ value: 0,
+ },
- /** Returns suggestion items
+ /** Returns suggestion items
* @type {!function(string): Promise<Array<Gerrit.GrSuggestionItem>>}
*/
- _querySuggestions: {
- type: Function,
- value() {
- return this._getSuggestions.bind(this);
+ _querySuggestions: {
+ type: Function,
+ value() {
+ return this._getSuggestions.bind(this);
+ },
},
- },
- },
+ };
+ }
- behaviors: [
- // Used in the tests for gr-account-list and other elements tests.
- Gerrit.FireBehavior,
- ],
-
- listeners: {
- remove: '_handleRemove',
- },
+ created() {
+ super.created();
+ this.addEventListener('remove',
+ e => this._handleRemove(e));
+ }
get accountChips() {
return Array.from(
Polymer.dom(this.root).querySelectorAll('gr-account-chip'));
- },
+ }
get focusStart() {
return this.$.entry.focusStart;
- },
+ }
_getSuggestions(input) {
const provider = this.suggestionsProvider;
@@ -122,11 +128,11 @@
return suggestions.map(suggestion =>
provider.makeSuggestionItem(suggestion));
});
- },
+ }
_handleAdd(e) {
this._addAccountItem(e.detail.value);
- },
+ }
_addAccountItem(item) {
// Append new account or group to the accounts property. We add our own
@@ -162,14 +168,14 @@
}
this.pendingConfirmation = null;
return true;
- },
+ }
confirmGroup(group) {
group = Object.assign(
{}, group, {confirmed: true, _pendingAdd: true, _group: true});
this.push('accounts', group);
this.pendingConfirmation = null;
- },
+ }
_computeChipClass(account) {
const classes = [];
@@ -180,7 +186,7 @@
classes.push('pendingAdd');
}
return classes.join(' ');
- },
+ }
_accountMatches(a, b) {
if (a && b) {
@@ -192,7 +198,7 @@
}
}
return a === b;
- },
+ }
_computeRemovable(account, readonly) {
if (readonly) { return false; }
@@ -205,13 +211,13 @@
return !!account._pendingAdd;
}
return true;
- },
+ }
_handleRemove(e) {
const toRemove = e.detail.account;
this._removeAccount(toRemove);
this.$.entry.focus();
- },
+ }
_removeAccount(toRemove) {
if (!toRemove || !this._computeRemovable(toRemove, this.readonly)) {
@@ -231,12 +237,12 @@
}
}
console.warn('received remove event for missing account', toRemove);
- },
+ }
_getNativeInput(paperInput) {
// In Polymer 2 inputElement isn't nativeInput anymore
return paperInput.$.nativeInput || paperInput.inputElement;
- },
+ }
_handleInputKeydown(e) {
const input = this._getNativeInput(e.detail.input);
@@ -254,7 +260,7 @@
}
break;
}
- },
+ }
_handleChipKeydown(e) {
const chip = e.target;
@@ -292,7 +298,7 @@
}
break;
}
- },
+ }
/**
* Submit the text of the entry as a reviewer value, if it exists. If it is
@@ -308,7 +314,7 @@
const wasSubmitted = this._addAccountItem(text);
if (wasSubmitted) { this.$.entry.clear(); }
return wasSubmitted;
- },
+ }
additions() {
return this.accounts.filter(account => {
@@ -320,10 +326,12 @@
return {account};
}
});
- },
+ }
_computeEntryHidden(maxCount, accountsRecord, readonly) {
return (maxCount && maxCount <= accountsRecord.base.length) || readonly;
- },
- });
+ }
+ }
+
+ customElements.define(GrAccountList.is, GrAccountList);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.js b/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.js
index e7c8b2c..433a57b 100644
--- a/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.js
+++ b/polygerrit-ui/app/elements/shared/gr-alert/gr-alert.js
@@ -17,46 +17,51 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-alert',
-
+ class GrAlert extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-alert'; }
/**
* Fired when the action button is pressed.
*
* @event action
*/
- properties: {
- text: String,
- actionText: String,
- shown: {
- type: Boolean,
- value: true,
- readOnly: true,
- reflectToAttribute: true,
- },
- toast: {
- type: Boolean,
- value: true,
- reflectToAttribute: true,
- },
+ static get properties() {
+ return {
+ text: String,
+ actionText: String,
+ shown: {
+ type: Boolean,
+ value: true,
+ readOnly: true,
+ reflectToAttribute: true,
+ },
+ toast: {
+ type: Boolean,
+ value: true,
+ reflectToAttribute: true,
+ },
- _hideActionButton: Boolean,
- _boundTransitionEndHandler: {
- type: Function,
- value() { return this._handleTransitionEnd.bind(this); },
- },
- _actionCallback: Function,
- },
+ _hideActionButton: Boolean,
+ _boundTransitionEndHandler: {
+ type: Function,
+ value() { return this._handleTransitionEnd.bind(this); },
+ },
+ _actionCallback: Function,
+ };
+ }
attached() {
+ super.attached();
this.addEventListener('transitionend', this._boundTransitionEndHandler);
- },
+ }
detached() {
+ super.detached();
this.removeEventListener('transitionend',
this._boundTransitionEndHandler);
- },
+ }
show(text, opt_actionText, opt_actionCallback) {
this.text = text;
@@ -65,31 +70,33 @@
this._actionCallback = opt_actionCallback;
Gerrit.getRootElement().appendChild(this);
this._setShown(true);
- },
+ }
hide() {
this._setShown(false);
if (this._hasZeroTransitionDuration()) {
Gerrit.getRootElement().removeChild(this);
}
- },
+ }
_hasZeroTransitionDuration() {
const style = window.getComputedStyle(this);
// transitionDuration is always given in seconds.
const duration = Math.round(parseFloat(style.transitionDuration) * 100);
return duration === 0;
- },
+ }
_handleTransitionEnd(e) {
if (this.shown) { return; }
Gerrit.getRootElement().removeChild(this);
- },
+ }
_handleActionTap(e) {
e.preventDefault();
if (this._actionCallback) { this._actionCallback(); }
- },
- });
+ }
+ }
+
+ customElements.define(GrAlert.is, GrAlert);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete-dropdown/gr-autocomplete-dropdown.html b/polygerrit-ui/app/elements/shared/gr-autocomplete-dropdown/gr-autocomplete-dropdown.html
index 9208068..2afbd82 100644
--- a/polygerrit-ui/app/elements/shared/gr-autocomplete-dropdown/gr-autocomplete-dropdown.html
+++ b/polygerrit-ui/app/elements/shared/gr-autocomplete-dropdown/gr-autocomplete-dropdown.html
@@ -17,6 +17,7 @@
<link rel="import" href="/bower_components/polymer/polymer.html">
+<link rel="import" href="../../../types/polymer-behaviors.js">
<link rel="import" href="../../../behaviors/fire-behavior/fire-behavior.html">
<link rel="import" href="../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.html">
<link rel="import" href="/bower_components/iron-dropdown/iron-dropdown.html">
diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete-dropdown/gr-autocomplete-dropdown.js b/polygerrit-ui/app/elements/shared/gr-autocomplete-dropdown/gr-autocomplete-dropdown.js
index b8c76ff..707c426 100644
--- a/polygerrit-ui/app/elements/shared/gr-autocomplete-dropdown/gr-autocomplete-dropdown.js
+++ b/polygerrit-ui/app/elements/shared/gr-autocomplete-dropdown/gr-autocomplete-dropdown.js
@@ -17,9 +17,19 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-autocomplete-dropdown',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ * @appliesMixin Gerrit.KeyboardShortcutMixin
+ * @appliesMixin Polymer.IronFitMixin
+ */
+ class GrAutocompleteDropdown extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ Gerrit.KeyboardShortcutBehavior,
+ Polymer.IronFitBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-autocomplete-dropdown'; }
/**
* Fired when the dropdown is closed.
*
@@ -32,57 +42,55 @@
* @event item-selected
*/
- properties: {
- index: Number,
- isHidden: {
- type: Boolean,
- value: true,
- reflectToAttribute: true,
- },
- verticalOffset: {
- type: Number,
- value: null,
- },
- horizontalOffset: {
- type: Number,
- value: null,
- },
- suggestions: {
- type: Array,
- value: () => [],
- observer: '_resetCursorStops',
- },
- _suggestionEls: Array,
- },
+ static get properties() {
+ return {
+ index: Number,
+ isHidden: {
+ type: Boolean,
+ value: true,
+ reflectToAttribute: true,
+ },
+ verticalOffset: {
+ type: Number,
+ value: null,
+ },
+ horizontalOffset: {
+ type: Number,
+ value: null,
+ },
+ suggestions: {
+ type: Array,
+ value: () => [],
+ observer: '_resetCursorStops',
+ },
+ _suggestionEls: Array,
+ };
+ }
- behaviors: [
- Gerrit.FireBehavior,
- Gerrit.KeyboardShortcutBehavior,
- Polymer.IronFitBehavior,
- ],
-
- keyBindings: {
- up: '_handleUp',
- down: '_handleDown',
- enter: '_handleEnter',
- esc: '_handleEscape',
- tab: '_handleTab',
- },
+ get keyBindings() {
+ return {
+ up: '_handleUp',
+ down: '_handleDown',
+ enter: '_handleEnter',
+ esc: '_handleEscape',
+ tab: '_handleTab',
+ };
+ }
close() {
this.isHidden = true;
- },
+ }
open() {
this.isHidden = false;
this._resetCursorStops();
// Refit should run after we call Polymer.flush inside _resetCursorStops
this.refit();
- },
+ }
getCurrentText() {
return this.getCursorTarget().dataset.value;
- },
+ }
_handleUp(e) {
if (!this.isHidden) {
@@ -90,7 +98,7 @@
e.stopPropagation();
this.cursorUp();
}
- },
+ }
_handleDown(e) {
if (!this.isHidden) {
@@ -98,19 +106,19 @@
e.stopPropagation();
this.cursorDown();
}
- },
+ }
cursorDown() {
if (!this.isHidden) {
this.$.cursor.next();
}
- },
+ }
cursorUp() {
if (!this.isHidden) {
this.$.cursor.previous();
}
- },
+ }
_handleTab(e) {
e.preventDefault();
@@ -119,7 +127,7 @@
trigger: 'tab',
selected: this.$.cursor.target,
});
- },
+ }
_handleEnter(e) {
e.preventDefault();
@@ -128,12 +136,12 @@
trigger: 'enter',
selected: this.$.cursor.target,
});
- },
+ }
_handleEscape() {
this._fireClose();
this.close();
- },
+ }
_handleClickItem(e) {
e.preventDefault();
@@ -147,15 +155,15 @@
trigger: 'click',
selected,
});
- },
+ }
_fireClose() {
this.fire('dropdown-closed');
- },
+ }
getCursorTarget() {
return this.$.cursor.target;
- },
+ }
_resetCursorStops() {
if (this.suggestions.length > 0) {
@@ -168,14 +176,16 @@
} else {
this._suggestionEls = [];
}
- },
+ }
_resetCursorIndex() {
this.$.cursor.setCursorAtIndex(0);
- },
+ }
_computeLabelClass(item) {
return item.label ? '' : 'hide';
- },
- });
+ }
+ }
+
+ customElements.define(GrAutocompleteDropdown.is, GrAutocompleteDropdown);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js
index da16e2b..a2c908a 100644
--- a/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js
+++ b/polygerrit-ui/app/elements/shared/gr-autocomplete/gr-autocomplete.js
@@ -20,9 +20,17 @@
const TOKENIZE_REGEX = /(?:[^\s"]+|"[^"]*")+/g;
const DEBOUNCE_WAIT_MS = 200;
- Polymer({
- is: 'gr-autocomplete',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ * @appliesMixin Gerrit.KeyboardShortcutMixin
+ */
+ class GrAutocomplete extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ Gerrit.KeyboardShortcutBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-autocomplete'; }
/**
* Fired when a value is chosen.
*
@@ -42,9 +50,10 @@
* @event input-keydown
*/
- properties: {
+ static get properties() {
+ return {
- /**
+ /**
* Query for requesting autocomplete suggestions. The function should
* accept the input as a string parameter and return a promise. The
* promise yields an array of suggestion objects with "name", "label",
@@ -55,170 +64,170 @@
*
* @type {function(string): Promise<?>}
*/
- query: {
- type: Function,
- value() {
- return function() {
- return Promise.resolve([]);
- };
+ query: {
+ type: Function,
+ value() {
+ return function() {
+ return Promise.resolve([]);
+ };
+ },
},
- },
- /**
+ /**
* The number of characters that must be typed before suggestions are
* made. If threshold is zero, default suggestions are enabled.
*/
- threshold: {
- type: Number,
- value: 1,
- },
+ threshold: {
+ type: Number,
+ value: 1,
+ },
- allowNonSuggestedValues: Boolean,
- borderless: Boolean,
- disabled: Boolean,
- showSearchIcon: {
- type: Boolean,
- value: false,
- },
- // Vertical offset needed for a 1em font-size with no vertical padding.
- // Inputs with additional padding will need to increase vertical offset.
- verticalOffset: {
- type: Number,
- value: 20,
- },
+ allowNonSuggestedValues: Boolean,
+ borderless: Boolean,
+ disabled: Boolean,
+ showSearchIcon: {
+ type: Boolean,
+ value: false,
+ },
+ // Vertical offset needed for a 1em font-size with no vertical padding.
+ // Inputs with additional padding will need to increase vertical offset.
+ verticalOffset: {
+ type: Number,
+ value: 20,
+ },
- text: {
- type: String,
- value: '',
- notify: true,
- },
+ text: {
+ type: String,
+ value: '',
+ notify: true,
+ },
- placeholder: String,
+ placeholder: String,
- clearOnCommit: {
- type: Boolean,
- value: false,
- },
+ clearOnCommit: {
+ type: Boolean,
+ value: false,
+ },
- /**
+ /**
* When true, tab key autocompletes but does not fire the commit event.
* When false, tab key not caught, and focus is removed from the element.
* See Issue 4556, Issue 6645.
*/
- tabComplete: {
- type: Boolean,
- value: false,
- },
+ tabComplete: {
+ type: Boolean,
+ value: false,
+ },
- value: {
- type: String,
- notify: true,
- },
+ value: {
+ type: String,
+ notify: true,
+ },
- /**
+ /**
* Multi mode appends autocompleted entries to the value.
* If false, autocompleted entries replace value.
*/
- multi: {
- type: Boolean,
- value: false,
- },
+ multi: {
+ type: Boolean,
+ value: false,
+ },
- /**
+ /**
* When true and uncommitted text is left in the autocomplete input after
* blurring, the text will appear red.
*/
- warnUncommitted: {
- type: Boolean,
- value: false,
- },
+ warnUncommitted: {
+ type: Boolean,
+ value: false,
+ },
- /**
+ /**
* When true, querying for suggestions is not debounced w/r/t keypresses
*/
- noDebounce: {
- type: Boolean,
- value: false,
- },
+ noDebounce: {
+ type: Boolean,
+ value: false,
+ },
- /** @type {?} */
- _suggestions: {
- type: Array,
- value() { return []; },
- },
+ /** @type {?} */
+ _suggestions: {
+ type: Array,
+ value() { return []; },
+ },
- _suggestionEls: {
- type: Array,
- value() { return []; },
- },
+ _suggestionEls: {
+ type: Array,
+ value() { return []; },
+ },
- _index: Number,
- _disableSuggestions: {
- type: Boolean,
- value: false,
- },
- _focused: {
- type: Boolean,
- value: false,
- },
+ _index: Number,
+ _disableSuggestions: {
+ type: Boolean,
+ value: false,
+ },
+ _focused: {
+ type: Boolean,
+ value: false,
+ },
- /** The DOM element of the selected suggestion. */
- _selected: Object,
- },
+ /** The DOM element of the selected suggestion. */
+ _selected: Object,
+ };
+ }
- behaviors: [
- Gerrit.FireBehavior,
- Gerrit.KeyboardShortcutBehavior,
- ],
-
- observers: [
- '_maybeOpenDropdown(_suggestions, _focused)',
- '_updateSuggestions(text, threshold, noDebounce)',
- ],
+ static get observers() {
+ return [
+ '_maybeOpenDropdown(_suggestions, _focused)',
+ '_updateSuggestions(text, threshold, noDebounce)',
+ ];
+ }
get _nativeInput() {
// In Polymer 2 inputElement isn't nativeInput anymore
return this.$.input.$.nativeInput || this.$.input.inputElement;
- },
+ }
attached() {
+ super.attached();
this.listen(document.body, 'click', '_handleBodyClick');
- },
+ }
detached() {
+ super.detached();
this.unlisten(document.body, 'click', '_handleBodyClick');
this.cancelDebouncer('update-suggestions');
- },
+ }
get focusStart() {
return this.$.input;
- },
+ }
focus() {
this._nativeInput.focus();
- },
+ }
selectAll() {
const nativeInputElement = this._nativeInput;
if (!this.$.input.value) { return; }
nativeInputElement.setSelectionRange(0, this.$.input.value.length);
- },
+ }
clear() {
this.text = '';
- },
+ }
_handleItemSelect(e) {
// Let _handleKeydown deal with keyboard interaction.
if (e.detail.trigger !== 'click') { return; }
this._selected = e.detail.selected;
this._commit();
- },
+ }
get _inputElement() {
// Polymer2: this.$ can be undefined when this is first evaluated.
return this.$ && this.$.input;
- },
+ }
/**
* Set the text of the input without triggering the suggestion dropdown.
@@ -228,7 +237,7 @@
this._disableSuggestions = true;
this.text = text;
this._disableSuggestions = false;
- },
+ }
_onInputFocus() {
this._focused = true;
@@ -236,14 +245,14 @@
this.$.input.classList.remove('warnUncommitted');
// Needed so that --paper-input-container-input updated style is applied.
this.updateStyles();
- },
+ }
_onInputBlur() {
this.$.input.classList.toggle('warnUncommitted',
this.warnUncommitted && this.text.length && !this._focused);
// Needed so that --paper-input-container-input updated style is applied.
this.updateStyles();
- },
+ }
_updateSuggestions(text, threshold, noDebounce) {
// Polymer 2: check for undefined
@@ -280,18 +289,18 @@
} else {
this.debounce('update-suggestions', update, DEBOUNCE_WAIT_MS);
}
- },
+ }
_maybeOpenDropdown(suggestions, focused) {
if (suggestions.length > 0 && focused) {
return this.$.suggestions.open();
}
return this.$.suggestions.close();
- },
+ }
_computeClass(borderless) {
return borderless ? 'borderless' : '';
- },
+ }
/**
* _handleKeydown used for key handling in the this.$.input AND all child
@@ -338,7 +347,7 @@
this._suggestions = [];
}
this.fire('input-keydown', {keyCode: e.keyCode, input: this.$.input});
- },
+ }
_cancel() {
if (this._suggestions.length) {
@@ -346,7 +355,7 @@
} else {
this.fire('cancel');
}
- },
+ }
/**
* @param {boolean=} opt_tabComplete
@@ -358,7 +367,7 @@
this._selected = this.$.suggestions.getCursorTarget();
this._commit(opt_tabComplete);
- },
+ }
_updateValue(suggestion, suggestions) {
if (!suggestion) { return; }
@@ -372,7 +381,7 @@
} else {
this.value = completed;
}
- },
+ }
_handleBodyClick(e) {
const eventPath = Polymer.dom(e).path;
@@ -382,13 +391,13 @@
}
}
this._focused = false;
- },
+ }
_handleSuggestionTap(e) {
e.stopPropagation();
this.$.cursor.setCursor(e.target);
this._commit();
- },
+ }
/**
* Commits the suggestion, optionally firing the commit event.
@@ -424,10 +433,12 @@
}
this._textChangedSinceCommit = false;
- },
+ }
_computeShowSearchIconClass(showSearchIcon) {
return showSearchIcon ? 'showSearchIcon' : '';
- },
- });
+ }
+ }
+
+ customElements.define(GrAutocomplete.is, GrAutocomplete);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js b/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js
index bf56382..e57ba33 100644
--- a/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js
+++ b/polygerrit-ui/app/elements/shared/gr-avatar/gr-avatar.js
@@ -17,29 +17,35 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-avatar',
+ /**
+ * @appliesMixin Gerrit.BaseUrlMixin
+ */
+ class GrAvatar extends Polymer.mixinBehaviors( [
+ Gerrit.BaseUrlBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-avatar'; }
- properties: {
- account: {
- type: Object,
- observer: '_accountChanged',
- },
- imageSize: {
- type: Number,
- value: 16,
- },
- _hasAvatars: {
- type: Boolean,
- value: false,
- },
- },
-
- behaviors: [
- Gerrit.BaseUrlBehavior,
- ],
+ static get properties() {
+ return {
+ account: {
+ type: Object,
+ observer: '_accountChanged',
+ },
+ imageSize: {
+ type: Number,
+ value: 16,
+ },
+ _hasAvatars: {
+ type: Boolean,
+ value: false,
+ },
+ };
+ }
attached() {
+ super.attached();
Promise.all([
this._getConfig(),
Gerrit.awaitPluginsLoaded(),
@@ -48,15 +54,15 @@
this._updateAvatarURL();
});
- },
+ }
_getConfig() {
return this.$.restAPI.getConfig();
- },
+ }
_accountChanged(account) {
this._updateAvatarURL();
- },
+ }
_updateAvatarURL() {
if (!this._hasAvatars || !this.account) {
@@ -69,12 +75,12 @@
if (url) {
this.style.backgroundImage = 'url("' + url + '")';
}
- },
+ }
_getAccounts(account) {
return account._account_id || account.email || account.username ||
account.name;
- },
+ }
_buildAvatarURL(account) {
if (!account) { return ''; }
@@ -87,6 +93,8 @@
return this.getBaseUrl() + '/accounts/' +
encodeURIComponent(this._getAccounts(account)) +
'/avatar?s=' + this.imageSize;
- },
- });
+ }
+ }
+
+ customElements.define(GrAvatar.is, GrAvatar);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-button/gr-button.js b/polygerrit-ui/app/elements/shared/gr-button/gr-button.js
index 99d4fe4..1de704a 100644
--- a/polygerrit-ui/app/elements/shared/gr-button/gr-button.js
+++ b/polygerrit-ui/app/elements/shared/gr-button/gr-button.js
@@ -17,65 +17,77 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-button',
+ /**
+ * @appliesMixin Gerrit.KeyboardShortcutMixin
+ * @appliesMixin Gerrit.TooltipMixin
+ */
+ class GrButton extends Polymer.mixinBehaviors( [
+ Gerrit.KeyboardShortcutBehavior,
+ Gerrit.TooltipBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-button'; }
- properties: {
- tooltip: String,
- downArrow: {
- type: Boolean,
- reflectToAttribute: true,
- },
- link: {
- type: Boolean,
- value: false,
- reflectToAttribute: true,
- },
- loading: {
- type: Boolean,
- value: false,
- reflectToAttribute: true,
- },
- disabled: {
- type: Boolean,
- observer: '_disabledChanged',
- reflectToAttribute: true,
- },
- noUppercase: {
- type: Boolean,
- value: false,
- },
- _enabledTabindex: {
- type: String,
- value: '0',
- },
- },
+ static get properties() {
+ return {
+ tooltip: String,
+ downArrow: {
+ type: Boolean,
+ reflectToAttribute: true,
+ },
+ link: {
+ type: Boolean,
+ value: false,
+ reflectToAttribute: true,
+ },
+ loading: {
+ type: Boolean,
+ value: false,
+ reflectToAttribute: true,
+ },
+ disabled: {
+ type: Boolean,
+ observer: '_disabledChanged',
+ reflectToAttribute: true,
+ },
+ noUppercase: {
+ type: Boolean,
+ value: false,
+ },
+ _enabledTabindex: {
+ type: String,
+ value: '0',
+ },
+ };
+ }
- listeners: {
- click: '_handleAction',
- keydown: '_handleKeydown',
- },
+ static get observers() {
+ return [
+ '_computeDisabled(disabled, loading)',
+ ];
+ }
- observers: [
- '_computeDisabled(disabled, loading)',
- ],
+ created() {
+ super.created();
+ this.addEventListener('click',
+ e => this._handleAction(e));
+ this.addEventListener('keydown',
+ e => this._handleKeydown(e));
+ }
- behaviors: [
- Gerrit.KeyboardShortcutBehavior,
- Gerrit.TooltipBehavior,
- ],
-
- hostAttributes: {
- role: 'button',
- tabindex: '0',
- },
+ ready() {
+ super.ready();
+ this._ensureAttribute('role', 'button');
+ this._ensureAttribute('tabindex', '0');
+ }
_handleAction(e) {
if (this.disabled) {
e.preventDefault();
e.stopImmediatePropagation();
}
- },
+ }
_disabledChanged(disabled) {
if (disabled) {
@@ -83,11 +95,11 @@
}
this.setAttribute('tabindex', disabled ? '-1' : this._enabledTabindex);
this.updateStyles();
- },
+ }
_computeDisabled(disabled, loading) {
return disabled || loading;
- },
+ }
_handleKeydown(e) {
if (this.modifierPressed(e)) { return; }
@@ -98,6 +110,8 @@
e.stopPropagation();
this.click();
}
- },
- });
+ }
+ }
+
+ customElements.define(GrButton.is, GrButton);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-change-star/gr-change-star.js b/polygerrit-ui/app/elements/shared/gr-change-star/gr-change-star.js
index a83bc2b..05e759f 100644
--- a/polygerrit-ui/app/elements/shared/gr-change-star/gr-change-star.js
+++ b/polygerrit-ui/app/elements/shared/gr-change-star/gr-change-star.js
@@ -17,31 +17,34 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-change-star',
-
+ class GrChangeStar extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-change-star'; }
/**
* Fired when star state is toggled.
*
* @event toggle-star
*/
- properties: {
+ static get properties() {
+ return {
/** @type {?} */
- change: {
- type: Object,
- notify: true,
- },
- },
+ change: {
+ type: Object,
+ notify: true,
+ },
+ };
+ }
_computeStarClass(starred) {
return starred ? 'active' : '';
- },
+ }
_computeStarIcon(starred) {
// Hollow star is used to indicate inactive state.
return `gr-icons:star${starred ? '' : '-border'}`;
- },
+ }
toggleStar() {
const newVal = !this.change.starred;
@@ -51,6 +54,8 @@
composed: true,
detail: {change: this.change, starred: newVal},
}));
- },
- });
+ }
+ }
+
+ customElements.define(GrChangeStar.is, GrChangeStar);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-change-status/gr-change-status.js b/polygerrit-ui/app/elements/shared/gr-change-status/gr-change-status.js
index 3afbe54..01af9eb 100644
--- a/polygerrit-ui/app/elements/shared/gr-change-status/gr-change-status.js
+++ b/polygerrit-ui/app/elements/shared/gr-change-status/gr-change-status.js
@@ -32,35 +32,39 @@
const PRIVATE_TOOLTIP = 'This change is only visible to its owner and ' +
'current reviewers (or anyone with "View Private Changes" permission).';
- Polymer({
- is: 'gr-change-status',
+ class GrChangeStatus extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-change-status'; }
- properties: {
- flat: {
- type: Boolean,
- value: false,
- reflectToAttribute: true,
- },
- status: {
- type: String,
- observer: '_updateChipDetails',
- },
- tooltipText: {
- type: String,
- value: '',
- },
- },
+ static get properties() {
+ return {
+ flat: {
+ type: Boolean,
+ value: false,
+ reflectToAttribute: true,
+ },
+ status: {
+ type: String,
+ observer: '_updateChipDetails',
+ },
+ tooltipText: {
+ type: String,
+ value: '',
+ },
+ };
+ }
_computeStatusString(status) {
if (status === ChangeStates.WIP && !this.flat) {
return 'Work in Progress';
}
return status;
- },
+ }
_toClassName(str) {
return str.toLowerCase().replace(/\s/g, '-');
- },
+ }
_updateChipDetails(status, previousStatus) {
if (previousStatus) {
@@ -79,6 +83,8 @@
this.tooltipText = '';
break;
}
- },
- });
+ }
+ }
+
+ customElements.define(GrChangeStatus.is, GrChangeStatus);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread.js b/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread.js
index ff5576cb..c106acd 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread.js
+++ b/polygerrit-ui/app/elements/shared/gr-comment-thread/gr-comment-thread.js
@@ -20,9 +20,22 @@
const UNRESOLVED_EXPAND_COUNT = 5;
const NEWLINE_PATTERN = /\n/g;
- Polymer({
- is: 'gr-comment-thread',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ * @appliesMixin Gerrit.KeyboardShortcutMixin
+ * @appliesMixin Gerrit.PathListMixin
+ */
+ class GrCommentThread extends Polymer.mixinBehaviors( [
+ /**
+ * Not used in this element rather other elements tests
+ */
+ Gerrit.FireBehavior,
+ Gerrit.KeyboardShortcutBehavior,
+ Gerrit.PathListBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-comment-thread'; }
/**
* Fired when the thread should be discarded.
*
@@ -36,122 +49,122 @@
*/
/**
- * gr-comment-thread exposes the following attributes that allow a
- * diff widget like gr-diff to show the thread in the right location:
- *
- * line-num:
- * 1-based line number or undefined if it refers to the entire file.
- *
- * comment-side:
- * "left" or "right". These indicate which of the two diffed versions
- * the comment relates to. In the case of unified diff, the left
- * version is the one whose line number column is further to the left.
- *
- * range:
- * The range of text that the comment refers to (start_line,
- * start_character, end_line, end_character), serialized as JSON. If
- * set, range's end_line will have the same value as line-num. Line
- * numbers are 1-based, char numbers are 0-based. The start position
- * (start_line, start_character) is inclusive, and the end position
- * (end_line, end_character) is exclusive.
- */
- properties: {
- changeNum: String,
- comments: {
- type: Array,
- value() { return []; },
- },
- /**
+ * gr-comment-thread exposes the following attributes that allow a
+ * diff widget like gr-diff to show the thread in the right location:
+ *
+ * line-num:
+ * 1-based line number or undefined if it refers to the entire file.
+ *
+ * comment-side:
+ * "left" or "right". These indicate which of the two diffed versions
+ * the comment relates to. In the case of unified diff, the left
+ * version is the one whose line number column is further to the left.
+ *
+ * range:
+ * The range of text that the comment refers to (start_line,
+ * start_character, end_line, end_character), serialized as JSON. If
+ * set, range's end_line will have the same value as line-num. Line
+ * numbers are 1-based, char numbers are 0-based. The start position
+ * (start_line, start_character) is inclusive, and the end position
+ * (end_line, end_character) is exclusive.
+ */
+ static get properties() {
+ return {
+ changeNum: String,
+ comments: {
+ type: Array,
+ value() { return []; },
+ },
+ /**
* @type {?{start_line: number, start_character: number, end_line: number,
* end_character: number}}
*/
- range: {
- type: Object,
- reflectToAttribute: true,
- },
- keyEventTarget: {
- type: Object,
- value() { return document.body; },
- },
- commentSide: {
- type: String,
- reflectToAttribute: true,
- },
- patchNum: String,
- path: String,
- projectName: {
- type: String,
- observer: '_projectNameChanged',
- },
- hasDraft: {
- type: Boolean,
- notify: true,
- reflectToAttribute: true,
- },
- isOnParent: {
- type: Boolean,
- value: false,
- },
- parentIndex: {
- type: Number,
- value: null,
- },
- rootId: {
- type: String,
- notify: true,
- computed: '_computeRootId(comments.*)',
- },
- /**
+ range: {
+ type: Object,
+ reflectToAttribute: true,
+ },
+ keyEventTarget: {
+ type: Object,
+ value() { return document.body; },
+ },
+ commentSide: {
+ type: String,
+ reflectToAttribute: true,
+ },
+ patchNum: String,
+ path: String,
+ projectName: {
+ type: String,
+ observer: '_projectNameChanged',
+ },
+ hasDraft: {
+ type: Boolean,
+ notify: true,
+ reflectToAttribute: true,
+ },
+ isOnParent: {
+ type: Boolean,
+ value: false,
+ },
+ parentIndex: {
+ type: Number,
+ value: null,
+ },
+ rootId: {
+ type: String,
+ notify: true,
+ computed: '_computeRootId(comments.*)',
+ },
+ /**
* If this is true, the comment thread also needs to have the change and
* line properties property set
*/
- showFilePath: {
- type: Boolean,
- value: false,
- },
- /** Necessary only if showFilePath is true or when used with gr-diff */
- lineNum: {
- type: Number,
- reflectToAttribute: true,
- },
- unresolved: {
- type: Boolean,
- notify: true,
- reflectToAttribute: true,
- },
- _showActions: Boolean,
- _lastComment: Object,
- _orderedComments: Array,
- _projectConfig: Object,
- },
+ showFilePath: {
+ type: Boolean,
+ value: false,
+ },
+ /** Necessary only if showFilePath is true or when used with gr-diff */
+ lineNum: {
+ type: Number,
+ reflectToAttribute: true,
+ },
+ unresolved: {
+ type: Boolean,
+ notify: true,
+ reflectToAttribute: true,
+ },
+ _showActions: Boolean,
+ _lastComment: Object,
+ _orderedComments: Array,
+ _projectConfig: Object,
+ };
+ }
- behaviors: [
- /**
- * Not used in this element rather other elements tests
- */
- Gerrit.FireBehavior,
- Gerrit.KeyboardShortcutBehavior,
- Gerrit.PathListBehavior,
- ],
+ static get observers() {
+ return [
+ '_commentsChanged(comments.*)',
+ ];
+ }
- listeners: {
- 'comment-update': '_handleCommentUpdate',
- },
+ get keyBindings() {
+ return {
+ 'e shift+e': '_handleEKey',
+ };
+ }
- observers: [
- '_commentsChanged(comments.*)',
- ],
-
- keyBindings: {
- 'e shift+e': '_handleEKey',
- },
+ created() {
+ super.created();
+ this.addEventListener('comment-update',
+ e => this._handleCommentUpdate(e));
+ }
attached() {
+ super.attached();
this._getLoggedIn().then(loggedIn => {
this._showActions = loggedIn;
});
this._setInitialExpandedState();
- },
+ }
addOrEditDraft(opt_lineNum, opt_range) {
const lastComment = this.comments[this.comments.length - 1] || {};
@@ -169,39 +182,39 @@
const unresolved = lastComment ? lastComment.unresolved : undefined;
this.addDraft(opt_lineNum, range, unresolved);
}
- },
+ }
addDraft(opt_lineNum, opt_range, opt_unresolved) {
const draft = this._newDraft(opt_lineNum, opt_range);
draft.__editing = true;
draft.unresolved = opt_unresolved === false ? opt_unresolved : true;
this.push('comments', draft);
- },
+ }
fireRemoveSelf() {
this.dispatchEvent(new CustomEvent('thread-discard',
{detail: {rootId: this.rootId}, bubbles: false}));
- },
+ }
_getDiffUrlForComment(projectName, changeNum, path, patchNum) {
return Gerrit.Nav.getUrlForDiffById(changeNum,
projectName, path, patchNum,
null, this.lineNum);
- },
+ }
_computeDisplayPath(path) {
const lineString = this.lineNum ? `#${this.lineNum}` : '';
return this.computeDisplayPath(path) + lineString;
- },
+ }
_getLoggedIn() {
return this.$.restAPI.getLoggedIn();
- },
+ }
_commentsChanged() {
this._orderedComments = this._sortedComments(this.comments);
this.updateThreadProperties();
- },
+ }
updateThreadProperties() {
if (this._orderedComments.length) {
@@ -209,16 +222,16 @@
this.unresolved = this._lastComment.unresolved;
this.hasDraft = this._lastComment.__draft;
}
- },
+ }
_hideActions(_showActions, _lastComment) {
return !_showActions || !_lastComment || !!_lastComment.__draft ||
!!_lastComment.robot_id;
- },
+ }
_getLastComment() {
return this._orderedComments[this._orderedComments.length - 1] || {};
- },
+ }
_handleEKey(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
@@ -231,7 +244,7 @@
if (this.modifierPressed(e)) { return; }
this._expandCollapseComments(false);
}
- },
+ }
_expandCollapseComments(actionIsCollapse) {
const comments =
@@ -239,7 +252,7 @@
for (const comment of comments) {
comment.collapsed = actionIsCollapse;
}
- },
+ }
/**
* Sets the initial state of the comment thread.
@@ -259,7 +272,7 @@
comment.collapsed = !isRobotComment && resolvedThread;
}
}
- },
+ }
_sortedComments(comments) {
return comments.slice().sort((c1, c2) => {
@@ -275,7 +288,7 @@
// If same date, fall back to sorting by id.
return dateCompare ? dateCompare : c1.id.localeCompare(c2.id);
});
- },
+ }
_createReplyComment(parent, content, opt_isEditing,
opt_unresolved) {
@@ -309,11 +322,11 @@
commentEl.save();
}, 1);
}
- },
+ }
_isDraft(comment) {
return !!comment.__draft;
- },
+ }
/**
* @param {boolean=} opt_quote
@@ -326,25 +339,25 @@
quoteStr = '> ' + msg.replace(NEWLINE_PATTERN, '\n> ') + '\n\n';
}
this._createReplyComment(comment, quoteStr, true, comment.unresolved);
- },
+ }
_handleCommentReply(e) {
this._processCommentReply();
- },
+ }
_handleCommentQuote(e) {
this._processCommentReply(true);
- },
+ }
_handleCommentAck(e) {
const comment = this._lastComment;
this._createReplyComment(comment, 'Ack', false, false);
- },
+ }
_handleCommentDone(e) {
const comment = this._lastComment;
this._createReplyComment(comment, 'Done', false, false);
- },
+ }
_handleCommentFix(e) {
const comment = e.detail.comment;
@@ -352,7 +365,7 @@
const quoteStr = '> ' + msg.replace(NEWLINE_PATTERN, '\n> ') + '\n\n';
const response = quoteStr + 'Please Fix';
this._createReplyComment(comment, response, false, true);
- },
+ }
_commentElWithDraftID(id) {
const els = Polymer.dom(this.root).querySelectorAll('gr-comment');
@@ -362,7 +375,7 @@
}
}
return null;
- },
+ }
_newReply(inReplyTo, opt_lineNum, opt_message, opt_unresolved,
opt_range) {
@@ -376,7 +389,7 @@
d.unresolved = opt_unresolved;
}
return d;
- },
+ }
/**
* @param {number=} opt_lineNum
@@ -402,12 +415,12 @@
d.parent = this.parentIndex;
}
return d;
- },
+ }
_getSide(isOnParent) {
if (isOnParent) { return 'PARENT'; }
return 'REVISION';
- },
+ }
_computeRootId(comments) {
// Keep the root ID even if the comment was removed, so that notification
@@ -415,7 +428,7 @@
if (!comments.base.length) { return this.rootId; }
const rootComment = comments.base[0];
return rootComment.id || rootComment.__draftID;
- },
+ }
_handleCommentDiscard(e) {
const diffCommentEl = Polymer.dom(e).rootTarget;
@@ -445,13 +458,13 @@
changeComment.message);
}
}
- },
+ }
_handleCommentSavedOrDiscarded(e) {
this.dispatchEvent(new CustomEvent('thread-changed',
{detail: {rootId: this.rootId, path: this.path},
bubbles: false}));
- },
+ }
_handleCommentUpdate(e) {
const comment = e.detail.comment;
@@ -467,7 +480,7 @@
// observers, the this.set() call above will not cause a thread update in
// some situations.
this.updateThreadProperties();
- },
+ }
_indexOf(comment, arr) {
for (let i = 0; i < arr.length; i++) {
@@ -478,11 +491,11 @@
}
}
return -1;
- },
+ }
_computeHostClass(unresolved) {
return unresolved ? 'unresolved' : '';
- },
+ }
/**
* Load the project config when a project name has been provided.
@@ -493,6 +506,8 @@
this.$.restAPI.getProjectConfig(name).then(config => {
this._projectConfig = config;
});
- },
- });
+ }
+ }
+
+ customElements.define(GrCommentThread.is, GrCommentThread);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.js b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.js
index a5c0c0b..dd2855c 100644
--- a/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.js
+++ b/polygerrit-ui/app/elements/shared/gr-comment/gr-comment.js
@@ -31,9 +31,17 @@
const FILE = 'FILE';
- Polymer({
- is: 'gr-comment',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ * @appliesMixin Gerrit.KeyboardShortcutMixin
+ */
+ class GrComment extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ Gerrit.KeyboardShortcutBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-comment'; }
/**
* Fired when the create fix comment action is triggered.
*
@@ -64,109 +72,111 @@
* @event comment-anchor-tap
*/
- properties: {
- changeNum: String,
- /** @type {?} */
- comment: {
- type: Object,
- notify: true,
- observer: '_commentChanged',
- },
- isRobotComment: {
- type: Boolean,
- value: false,
- reflectToAttribute: true,
- },
- disabled: {
- type: Boolean,
- value: false,
- reflectToAttribute: true,
- },
- draft: {
- type: Boolean,
- value: false,
- observer: '_draftChanged',
- },
- editing: {
- type: Boolean,
- value: false,
- observer: '_editingChanged',
- },
- discarding: {
- type: Boolean,
- value: false,
- reflectToAttribute: true,
- },
- hasChildren: Boolean,
- patchNum: String,
- showActions: Boolean,
- _showHumanActions: Boolean,
- _showRobotActions: Boolean,
- collapsed: {
- type: Boolean,
- value: true,
- observer: '_toggleCollapseClass',
- },
- /** @type {?} */
- projectConfig: Object,
- robotButtonDisabled: Boolean,
- _isAdmin: {
- type: Boolean,
- value: false,
- },
+ static get properties() {
+ return {
+ changeNum: String,
+ /** @type {?} */
+ comment: {
+ type: Object,
+ notify: true,
+ observer: '_commentChanged',
+ },
+ isRobotComment: {
+ type: Boolean,
+ value: false,
+ reflectToAttribute: true,
+ },
+ disabled: {
+ type: Boolean,
+ value: false,
+ reflectToAttribute: true,
+ },
+ draft: {
+ type: Boolean,
+ value: false,
+ observer: '_draftChanged',
+ },
+ editing: {
+ type: Boolean,
+ value: false,
+ observer: '_editingChanged',
+ },
+ discarding: {
+ type: Boolean,
+ value: false,
+ reflectToAttribute: true,
+ },
+ hasChildren: Boolean,
+ patchNum: String,
+ showActions: Boolean,
+ _showHumanActions: Boolean,
+ _showRobotActions: Boolean,
+ collapsed: {
+ type: Boolean,
+ value: true,
+ observer: '_toggleCollapseClass',
+ },
+ /** @type {?} */
+ projectConfig: Object,
+ robotButtonDisabled: Boolean,
+ _isAdmin: {
+ type: Boolean,
+ value: false,
+ },
- _xhrPromise: Object, // Used for testing.
- _messageText: {
- type: String,
- value: '',
- observer: '_messageTextChanged',
- },
- commentSide: String,
- side: String,
+ _xhrPromise: Object, // Used for testing.
+ _messageText: {
+ type: String,
+ value: '',
+ observer: '_messageTextChanged',
+ },
+ commentSide: String,
+ side: String,
- resolved: Boolean,
+ resolved: Boolean,
- _numPendingDraftRequests: {
- type: Object,
- value:
+ _numPendingDraftRequests: {
+ type: Object,
+ value:
{number: 0}, // Intentional to share the object across instances.
- },
+ },
- _enableOverlay: {
- type: Boolean,
- value: false,
- },
+ _enableOverlay: {
+ type: Boolean,
+ value: false,
+ },
- /**
+ /**
* Property for storing references to overlay elements. When the overlays
* are moved to Gerrit.getRootElement() to be shown they are no-longer
* children, so they can't be queried along the tree, so they are stored
* here.
*/
- _overlays: {
- type: Object,
- value: () => ({}),
- },
- },
+ _overlays: {
+ type: Object,
+ value: () => ({}),
+ },
+ };
+ }
- observers: [
- '_commentMessageChanged(comment.message)',
- '_loadLocalDraft(changeNum, patchNum, comment)',
- '_isRobotComment(comment)',
- '_calculateActionstoShow(showActions, isRobotComment)',
- ],
+ static get observers() {
+ return [
+ '_commentMessageChanged(comment.message)',
+ '_loadLocalDraft(changeNum, patchNum, comment)',
+ '_isRobotComment(comment)',
+ '_calculateActionstoShow(showActions, isRobotComment)',
+ ];
+ }
- behaviors: [
- Gerrit.FireBehavior,
- Gerrit.KeyboardShortcutBehavior,
- ],
-
- keyBindings: {
- 'ctrl+enter meta+enter ctrl+s meta+s': '_handleSaveKey',
- 'esc': '_handleEsc',
- },
+ get keyBindings() {
+ return {
+ 'ctrl+enter meta+enter ctrl+s meta+s': '_handleSaveKey',
+ 'esc': '_handleEsc',
+ };
+ }
attached() {
+ super.attached();
if (this.editing) {
this.collapsed = false;
} else if (this.comment) {
@@ -175,18 +185,19 @@
this._getIsAdmin().then(isAdmin => {
this._isAdmin = isAdmin;
});
- },
+ }
detached() {
+ super.detached();
this.cancelDebouncer('fire-update');
if (this.textarea) {
this.textarea.closeDropdown();
}
- },
+ }
get textarea() {
return this.$$('#editTextarea');
- },
+ }
get confirmDeleteOverlay() {
if (!this._overlays.confirmDelete) {
@@ -195,7 +206,7 @@
this._overlays.confirmDelete = this.$$('#confirmDeleteOverlay');
}
return this._overlays.confirmDelete;
- },
+ }
get confirmDiscardOverlay() {
if (!this._overlays.confirmDiscard) {
@@ -204,11 +215,11 @@
this._overlays.confirmDiscard = this.$$('#confirmDiscardOverlay');
}
return this._overlays.confirmDiscard;
- },
+ }
_computeShowHideIcon(collapsed) {
return collapsed ? 'gr-icons:expand-more' : 'gr-icons:expand-less';
- },
+ }
_calculateActionstoShow(showActions, isRobotComment) {
// Polymer 2: check for undefined
@@ -218,19 +229,19 @@
this._showHumanActions = showActions && !isRobotComment;
this._showRobotActions = showActions && isRobotComment;
- },
+ }
_isRobotComment(comment) {
this.isRobotComment = !!comment.robot_id;
- },
+ }
isOnParent() {
return this.side === 'PARENT';
- },
+ }
_getIsAdmin() {
return this.$.restAPI.getIsAdmin();
- },
+ }
/**
* @param {*=} opt_comment
@@ -273,7 +284,7 @@
});
return this._xhrPromise;
- },
+ }
_eraseDraftComment() {
// Prevents a race condition in which removing the draft comment occurs
@@ -287,7 +298,7 @@
line: this.comment.line,
range: this.comment.range,
});
- },
+ }
_commentChanged(comment) {
this.editing = !!comment.__editing;
@@ -295,7 +306,7 @@
if (this.editing) { // It's a new draft/reply, notify.
this._fireUpdate();
}
- },
+ }
/**
* @param {!Object=} opt_mixin
@@ -307,21 +318,21 @@
comment: this.comment,
patchNum: this.patchNum,
});
- },
+ }
_fireSave() {
this.fire('comment-save', this._getEventPayload());
- },
+ }
_fireUpdate() {
this.debounce('fire-update', () => {
this.fire('comment-update', this._getEventPayload());
});
- },
+ }
_draftChanged(draft) {
this.$.container.classList.toggle('draft', draft);
- },
+ }
_editingChanged(editing, previousValue) {
// Polymer 2: observer fires when at least one property is defined.
@@ -346,11 +357,11 @@
this.textarea.putCursorAtEnd();
}, 1);
}
- },
+ }
_computeDeleteButtonClass(isAdmin, draft) {
return isAdmin && !draft ? 'showDeleteButtons' : '';
- },
+ }
_computeSaveDisabled(draft, comment, resolved) {
// If resolved state has changed and a msg exists, save should be enabled.
@@ -358,7 +369,7 @@
return false;
}
return !draft || draft.trim() === '';
- },
+ }
_handleSaveKey(e) {
if (!this._computeSaveDisabled(this._messageText, this.comment,
@@ -366,18 +377,18 @@
e.preventDefault();
this._handleSave(e);
}
- },
+ }
_handleEsc(e) {
if (!this._messageText.length) {
e.preventDefault();
this._handleCancel(e);
}
- },
+ }
_handleToggleCollapsed() {
this.collapsed = !this.collapsed;
- },
+ }
_toggleCollapseClass(collapsed) {
if (collapsed) {
@@ -385,11 +396,11 @@
} else {
this.$.container.classList.remove('collapsed');
}
- },
+ }
_commentMessageChanged(message) {
this._messageText = message || '';
- },
+ }
_messageTextChanged(newValue, oldValue) {
if (!this.comment || (this.comment && this.comment.id)) {
@@ -414,7 +425,7 @@
this.$.storage.setDraftComment(commentLocation, message);
}
}, STORAGE_DEBOUNCE_INTERVAL);
- },
+ }
_handleAnchorClick(e) {
e.preventDefault();
@@ -429,14 +440,14 @@
side: this.side,
},
}));
- },
+ }
_handleEdit(e) {
e.preventDefault();
this._messageText = this.comment.message;
this.editing = true;
this.$.reporting.recordDraftInteraction();
- },
+ }
_handleSave(e) {
e.preventDefault();
@@ -450,7 +461,7 @@
const timer = this.$.reporting.getTimer(timingLabel);
this.set('comment.__editing', false);
return this.save().then(() => { timer.end(); });
- },
+ }
_handleCancel(e) {
e.preventDefault();
@@ -463,12 +474,12 @@
}
this._messageText = this.comment.message;
this.editing = false;
- },
+ }
_fireDiscard() {
this.cancelDebouncer('fire-update');
this.fire('comment-discard', this._getEventPayload());
- },
+ }
_handleFix() {
this.dispatchEvent(new CustomEvent('create-fix-comment', {
@@ -476,7 +487,7 @@
composed: true,
detail: this._getEventPayload(),
}));
- },
+ }
_handleDiscard(e) {
e.preventDefault();
@@ -491,14 +502,14 @@
this.confirmDiscardOverlay.querySelector('#confirmDiscardDialog')
.resetFocus();
});
- },
+ }
_handleConfirmDiscard(e) {
e.preventDefault();
const timer = this.$.reporting.getTimer(REPORT_DISCARD_DRAFT);
this._closeConfirmDiscardOverlay();
return this._discardDraft().then(() => { timer.end(); });
- },
+ }
_discardDraft() {
if (!this.comment.__draft) {
@@ -529,11 +540,11 @@
});
return this._xhrPromise;
- },
+ }
_closeConfirmDiscardOverlay() {
this._closeOverlay(this.confirmDiscardOverlay);
- },
+ }
_getSavingMessage(numPending) {
if (numPending === 0) {
@@ -544,17 +555,17 @@
numPending,
numPending === 1 ? DRAFT_SINGULAR : DRAFT_PLURAL,
].join(' ');
- },
+ }
_showStartRequest() {
const numPending = ++this._numPendingDraftRequests.number;
this._updateRequestToast(numPending);
- },
+ }
_showEndRequest() {
const numPending = --this._numPendingDraftRequests.number;
this._updateRequestToast(numPending);
- },
+ }
_handleFailedDraftRequest() {
this._numPendingDraftRequests.number--;
@@ -562,7 +573,7 @@
// Cancel the debouncer so that error toasts from the error-manager will
// not be overridden.
this.cancelDebouncer('draft-toast');
- },
+ }
_updateRequestToast(numPending) {
const message = this._getSavingMessage(numPending);
@@ -573,7 +584,7 @@
document.body.dispatchEvent(new CustomEvent(
'show-alert', {detail: {message}, bubbles: true, composed: true}));
}, TOAST_DEBOUNCE_INTERVAL);
- },
+ }
_saveDraft(draft) {
this._showStartRequest();
@@ -586,7 +597,7 @@
}
return result;
});
- },
+ }
_deleteDraft(draft) {
this._showStartRequest();
@@ -599,11 +610,11 @@
}
return result;
});
- },
+ }
_getPatchNum() {
return this.isOnParent() ? 'PARENT' : this.patchNum;
- },
+ }
_loadLocalDraft(changeNum, patchNum, comment) {
// Polymer 2: check for undefined
@@ -632,7 +643,7 @@
if (draft) {
this.set('comment.message', draft.message);
}
- },
+ }
_handleToggleResolved() {
this.$.reporting.recordDraftInteraction();
@@ -646,25 +657,25 @@
// Save the resolved state immediately.
this.save(payload.comment);
}
- },
+ }
_handleCommentDelete() {
this._openOverlay(this.confirmDeleteOverlay);
- },
+ }
_handleCancelDeleteComment() {
this._closeOverlay(this.confirmDeleteOverlay);
- },
+ }
_openOverlay(overlay) {
Polymer.dom(Gerrit.getRootElement()).appendChild(overlay);
return overlay.open();
- },
+ }
_closeOverlay(overlay) {
Polymer.dom(Gerrit.getRootElement()).removeChild(overlay);
overlay.close();
- },
+ }
_handleConfirmDeleteComment() {
const dialog =
@@ -675,6 +686,8 @@
this._handleCancelDeleteComment();
this.comment = newComment;
});
- },
- });
+ }
+ }
+
+ customElements.define(GrComment.is, GrComment);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-confirm-delete-comment-dialog/gr-confirm-delete-comment-dialog.js b/polygerrit-ui/app/elements/shared/gr-confirm-delete-comment-dialog/gr-confirm-delete-comment-dialog.js
index c2075f0..79cd251 100644
--- a/polygerrit-ui/app/elements/shared/gr-confirm-delete-comment-dialog/gr-confirm-delete-comment-dialog.js
+++ b/polygerrit-ui/app/elements/shared/gr-confirm-delete-comment-dialog/gr-confirm-delete-comment-dialog.js
@@ -17,9 +17,15 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-confirm-delete-comment-dialog',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ */
+ class GrConfirmDeleteCommentDialog extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-confirm-delete-comment-dialog'; }
/**
* Fired when the confirm button is pressed.
*
@@ -32,28 +38,29 @@
* @event cancel
*/
- properties: {
- message: String,
- },
-
- behaviors: [
- Gerrit.FireBehavior,
- ],
+ static get properties() {
+ return {
+ message: String,
+ };
+ }
resetFocus() {
this.$.messageInput.textarea.focus();
- },
+ }
_handleConfirmTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('confirm', {reason: this.message}, {bubbles: false});
- },
+ }
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('cancel', null, {bubbles: false});
- },
- });
+ }
+ }
+
+ customElements.define(GrConfirmDeleteCommentDialog.is,
+ GrConfirmDeleteCommentDialog);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-copy-clipboard/gr-copy-clipboard.js b/polygerrit-ui/app/elements/shared/gr-copy-clipboard/gr-copy-clipboard.js
index 3e87202..6c062f6 100644
--- a/polygerrit-ui/app/elements/shared/gr-copy-clipboard/gr-copy-clipboard.js
+++ b/polygerrit-ui/app/elements/shared/gr-copy-clipboard/gr-copy-clipboard.js
@@ -19,34 +19,38 @@
const COPY_TIMEOUT_MS = 1000;
- Polymer({
- is: 'gr-copy-clipboard',
+ class GrCopyClipboard extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-copy-clipboard'; }
- properties: {
- text: String,
- buttonTitle: String,
- hasTooltip: {
- type: Boolean,
- value: false,
- },
- hideInput: {
- type: Boolean,
- value: false,
- },
- },
+ static get properties() {
+ return {
+ text: String,
+ buttonTitle: String,
+ hasTooltip: {
+ type: Boolean,
+ value: false,
+ },
+ hideInput: {
+ type: Boolean,
+ value: false,
+ },
+ };
+ }
focusOnCopy() {
this.$.button.focus();
- },
+ }
_computeInputClass(hideInput) {
return hideInput ? 'hideInput' : '';
- },
+ }
_handleInputClick(e) {
e.preventDefault();
Polymer.dom(e).rootTarget.select();
- },
+ }
_copyToClipboard() {
if (this.hideInput) {
@@ -62,6 +66,8 @@
this.async(
() => this.$.icon.icon = 'gr-icons:content-copy',
COPY_TIMEOUT_MS);
- },
- });
+ }
+ }
+
+ customElements.define(GrCopyClipboard.is, GrCopyClipboard);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js b/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js
index 4e9ff76..4232ef9 100644
--- a/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js
+++ b/polygerrit-ui/app/elements/shared/gr-cursor-manager/gr-cursor-manager.js
@@ -22,72 +22,77 @@
KEEP_VISIBLE: 'keep-visible',
};
- Polymer({
- is: 'gr-cursor-manager',
+ class GrCursorManager extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-cursor-manager'; }
- properties: {
- stops: {
- type: Array,
- value() {
- return [];
+ static get properties() {
+ return {
+ stops: {
+ type: Array,
+ value() {
+ return [];
+ },
+ observer: '_updateIndex',
},
- observer: '_updateIndex',
- },
- /**
+ /**
* @type (?Object)
*/
- target: {
- type: Object,
- notify: true,
- observer: '_scrollToTarget',
- },
- /**
+ target: {
+ type: Object,
+ notify: true,
+ observer: '_scrollToTarget',
+ },
+ /**
* The height of content intended to be included with the target.
* @type (?number)
*/
- _targetHeight: Number,
+ _targetHeight: Number,
- /**
+ /**
* The index of the current target (if any). -1 otherwise.
*/
- index: {
- type: Number,
- value: -1,
- notify: true,
- },
+ index: {
+ type: Number,
+ value: -1,
+ notify: true,
+ },
- /**
+ /**
* The class to apply to the current target. Use null for no class.
*/
- cursorTargetClass: {
- type: String,
- value: null,
- },
+ cursorTargetClass: {
+ type: String,
+ value: null,
+ },
- /**
+ /**
* The scroll behavior for the cursor. Values are 'never' and
* 'keep-visible'. 'keep-visible' will only scroll if the cursor is beyond
* the viewport.
* TODO (beckysiegel) figure out why it can be undefined
* @type (string|undefined)
*/
- scrollBehavior: {
- type: String,
- value: ScrollBehavior.NEVER,
- },
+ scrollBehavior: {
+ type: String,
+ value: ScrollBehavior.NEVER,
+ },
- /**
+ /**
* When true, will call element.focus() during scrolling.
*/
- focusOnMove: {
- type: Boolean,
- value: false,
- },
- },
+ focusOnMove: {
+ type: Boolean,
+ value: false,
+ },
+ };
+ }
detached() {
+ super.detached();
this.unsetCursor();
- },
+ }
/**
* Move the cursor forward. Clipped to the ends of the stop list.
@@ -104,11 +109,11 @@
next(opt_condition, opt_getTargetHeight, opt_clipToTop) {
this._moveCursor(1, opt_condition, opt_getTargetHeight, opt_clipToTop);
- },
+ }
previous(opt_condition) {
this._moveCursor(-1, opt_condition);
- },
+ }
/**
* Set the cursor to an arbitrary element.
@@ -129,32 +134,32 @@
this._decorateTarget();
if (opt_noScroll) { this.scrollBehavior = behavior; }
- },
+ }
unsetCursor() {
this._unDecorateTarget();
this.index = -1;
this.target = null;
this._targetHeight = null;
- },
+ }
isAtStart() {
return this.index === 0;
- },
+ }
isAtEnd() {
return this.index === this.stops.length - 1;
- },
+ }
moveToStart() {
if (this.stops.length) {
this.setCursor(this.stops[0]);
}
- },
+ }
setCursorAtIndex(index, opt_noScroll) {
this.setCursor(this.stops[index], opt_noScroll);
- },
+ }
/**
* Move the cursor forward or backward by delta. Clipped to the beginning or
@@ -199,19 +204,19 @@
if (this.focusOnMove) { this.target.focus(); }
this._decorateTarget();
- },
+ }
_decorateTarget() {
if (this.target && this.cursorTargetClass) {
this.target.classList.add(this.cursorTargetClass);
}
- },
+ }
_unDecorateTarget() {
if (this.target && this.cursorTargetClass) {
this.target.classList.remove(this.cursorTargetClass);
}
- },
+ }
/**
* Get the next stop index indicated by the delta direction.
@@ -247,7 +252,7 @@
}
return newIndex;
- },
+ }
_updateIndex() {
if (!this.target) {
@@ -261,7 +266,7 @@
} else {
this.index = newIndex;
}
- },
+ }
/**
* Calculate where the element is relative to the window.
@@ -276,7 +281,7 @@
top += offsetParent.offsetTop;
}
return top;
- },
+ }
/**
* @return {boolean}
@@ -286,12 +291,12 @@
return this.scrollBehavior === ScrollBehavior.KEEP_VISIBLE &&
top > dims.pageYOffset &&
top < dims.pageYOffset + dims.innerHeight;
- },
+ }
_calculateScrollToValue(top, target) {
const dims = this._getWindowDims();
return top - (dims.innerHeight / 3) + (target.offsetHeight / 2);
- },
+ }
_scrollToTarget() {
if (!this.target || this.scrollBehavior === ScrollBehavior.NEVER) {
@@ -319,7 +324,7 @@
// element appears to be below the center of the window even when it
// isn't.
window.scrollTo(dims.scrollX, scrollToValue);
- },
+ }
_getWindowDims() {
return {
@@ -328,6 +333,8 @@
innerHeight: window.innerHeight,
pageYOffset: window.pageYOffset,
};
- },
- });
+ }
+ }
+
+ customElements.define(GrCursorManager.is, GrCursorManager);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-date-formatter/gr-date-formatter.js b/polygerrit-ui/app/elements/shared/gr-date-formatter/gr-date-formatter.js
index 5b1ef7f..f79c1b6 100644
--- a/polygerrit-ui/app/elements/shared/gr-date-formatter/gr-date-formatter.js
+++ b/polygerrit-ui/app/elements/shared/gr-date-formatter/gr-date-formatter.js
@@ -31,50 +31,56 @@
MONTH_DAY_YEAR: 'MMM DD, YYYY', // Aug 29, 1997
};
- Polymer({
- is: 'gr-date-formatter',
+ /**
+ * @appliesMixin Gerrit.TooltipMixin
+ */
+ class GrDateFormatter extends Polymer.mixinBehaviors( [
+ Gerrit.TooltipBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-date-formatter'; }
- properties: {
- dateStr: {
- type: String,
- value: null,
- notify: true,
- },
- showDateAndTime: {
- type: Boolean,
- value: false,
- },
+ static get properties() {
+ return {
+ dateStr: {
+ type: String,
+ value: null,
+ notify: true,
+ },
+ showDateAndTime: {
+ type: Boolean,
+ value: false,
+ },
- /**
+ /**
* When true, the detailed date appears in a GR-TOOLTIP rather than in the
* native browser tooltip.
*/
- hasTooltip: Boolean,
+ hasTooltip: Boolean,
- /**
+ /**
* The title to be used as the native tooltip or by the tooltip behavior.
*/
- title: {
- type: String,
- reflectToAttribute: true,
- computed: '_computeFullDateStr(dateStr, _timeFormat)',
- },
+ title: {
+ type: String,
+ reflectToAttribute: true,
+ computed: '_computeFullDateStr(dateStr, _timeFormat)',
+ },
- _timeFormat: String, // No default value to prevent flickering.
- _relative: Boolean, // No default value to prevent flickering.
- },
-
- behaviors: [
- Gerrit.TooltipBehavior,
- ],
+ _timeFormat: String, // No default value to prevent flickering.
+ _relative: Boolean, // No default value to prevent flickering.
+ };
+ }
attached() {
+ super.attached();
this._loadPreferences();
- },
+ }
_getUtcOffsetString() {
return ' UTC' + moment().format('Z');
- },
+ }
_loadPreferences() {
return this._getLoggedIn().then(loggedIn => {
@@ -88,7 +94,7 @@
this._loadRelative(),
]);
});
- },
+ }
_loadTimeFormat() {
return this._getPreferences().then(preferences => {
@@ -104,22 +110,22 @@
throw Error('Invalid time format: ' + timeFormat);
}
});
- },
+ }
_loadRelative() {
return this._getPreferences().then(prefs => {
// prefs.relative_date_in_change_table is not set when false.
this._relative = !!(prefs && prefs.relative_date_in_change_table);
});
- },
+ }
_getLoggedIn() {
return this.$.restAPI.getLoggedIn();
- },
+ }
_getPreferences() {
return this.$.restAPI.getPreferences();
- },
+ }
/**
* Return true if date is within 24 hours and on the same day.
@@ -127,7 +133,7 @@
_isWithinDay(now, date) {
const diff = -date.diff(now);
return diff < Duration.DAY && date.day() === now.getDay();
- },
+ }
/**
* Returns true if date is from one to six months.
@@ -136,7 +142,7 @@
const diff = -date.diff(now);
return (date.day() !== now.getDay() || diff >= Duration.DAY) &&
diff < 180 * Duration.DAY;
- },
+ }
_computeDateStr(dateStr, timeFormat, relative, showDateAndTime) {
if (!dateStr) { return ''; }
@@ -163,13 +169,13 @@
}
}
return date.format(format);
- },
+ }
_timeToSecondsFormat(timeFormat) {
return timeFormat === TimeFormats.TIME_12 ?
TimeFormats.TIME_12_WITH_SEC :
TimeFormats.TIME_24_WITH_SEC;
- },
+ }
_computeFullDateStr(dateStr, timeFormat) {
// Polymer 2: check for undefined
@@ -186,6 +192,8 @@
let format = TimeFormats.MONTH_DAY_YEAR + ', ';
format += this._timeToSecondsFormat(timeFormat);
return date.format(format) + this._getUtcOffsetString();
- },
- });
+ }
+ }
+
+ customElements.define(GrDateFormatter.is, GrDateFormatter);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-dialog/gr-dialog.js b/polygerrit-ui/app/elements/shared/gr-dialog/gr-dialog.js
index 68dc537..b84434e 100644
--- a/polygerrit-ui/app/elements/shared/gr-dialog/gr-dialog.js
+++ b/polygerrit-ui/app/elements/shared/gr-dialog/gr-dialog.js
@@ -17,9 +17,15 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-dialog',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ */
+ class GrDialog extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-dialog'; }
/**
* Fired when the confirm button is pressed.
*
@@ -32,33 +38,32 @@
* @event cancel
*/
- properties: {
- confirmLabel: {
- type: String,
- value: 'Confirm',
- },
- // Supplying an empty cancel label will hide the button completely.
- cancelLabel: {
- type: String,
- value: 'Cancel',
- },
- disabled: {
- type: Boolean,
- value: false,
- },
- confirmOnEnter: {
- type: Boolean,
- value: false,
- },
- },
+ static get properties() {
+ return {
+ confirmLabel: {
+ type: String,
+ value: 'Confirm',
+ },
+ // Supplying an empty cancel label will hide the button completely.
+ cancelLabel: {
+ type: String,
+ value: 'Cancel',
+ },
+ disabled: {
+ type: Boolean,
+ value: false,
+ },
+ confirmOnEnter: {
+ type: Boolean,
+ value: false,
+ },
+ };
+ }
- behaviors: [
- Gerrit.FireBehavior,
- ],
-
- hostAttributes: {
- role: 'dialog',
- },
+ ready() {
+ super.ready();
+ this._ensureAttribute('role', 'dialog');
+ }
_handleConfirm(e) {
if (this.disabled) { return; }
@@ -66,24 +71,26 @@
e.preventDefault();
e.stopPropagation();
this.fire('confirm', null, {bubbles: false});
- },
+ }
_handleCancelTap(e) {
e.preventDefault();
e.stopPropagation();
this.fire('cancel', null, {bubbles: false});
- },
+ }
_handleKeydown(e) {
if (this.confirmOnEnter && e.keyCode === 13) { this._handleConfirm(e); }
- },
+ }
resetFocus() {
this.$.confirm.focus();
- },
+ }
_computeCancelClass(cancelLabel) {
return cancelLabel.length ? '' : 'hidden';
- },
- });
+ }
+ }
+
+ customElements.define(GrDialog.is, GrDialog);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.js b/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.js
index 36fdf5b..6e34bbc 100644
--- a/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.js
+++ b/polygerrit-ui/app/elements/shared/gr-diff-preferences/gr-diff-preferences.js
@@ -17,62 +17,68 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-diff-preferences',
+ class GrDiffPreferences extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-diff-preferences'; }
- properties: {
- hasUnsavedChanges: {
- type: Boolean,
- notify: true,
- value: false,
- },
+ static get properties() {
+ return {
+ hasUnsavedChanges: {
+ type: Boolean,
+ notify: true,
+ value: false,
+ },
- /** @type {?} */
- diffPrefs: Object,
- },
+ /** @type {?} */
+ diffPrefs: Object,
+ };
+ }
loadData() {
return this.$.restAPI.getDiffPreferences().then(prefs => {
this.diffPrefs = prefs;
});
- },
+ }
_handleDiffPrefsChanged() {
this.hasUnsavedChanges = true;
- },
+ }
_handleLineWrappingTap() {
this.set('diffPrefs.line_wrapping', this.$.lineWrappingInput.checked);
this._handleDiffPrefsChanged();
- },
+ }
_handleShowTabsTap() {
this.set('diffPrefs.show_tabs', this.$.showTabsInput.checked);
this._handleDiffPrefsChanged();
- },
+ }
_handleShowTrailingWhitespaceTap() {
this.set('diffPrefs.show_whitespace_errors',
this.$.showTrailingWhitespaceInput.checked);
this._handleDiffPrefsChanged();
- },
+ }
_handleSyntaxHighlightTap() {
this.set('diffPrefs.syntax_highlighting',
this.$.syntaxHighlightInput.checked);
this._handleDiffPrefsChanged();
- },
+ }
_handleAutomaticReviewTap() {
this.set('diffPrefs.manual_review',
!this.$.automaticReviewInput.checked);
this._handleDiffPrefsChanged();
- },
+ }
save() {
return this.$.restAPI.saveDiffPreferences(this.diffPrefs).then(res => {
this.hasUnsavedChanges = false;
});
- },
- });
+ }
+ }
+
+ customElements.define(GrDiffPreferences.is, GrDiffPreferences);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-download-commands/gr-download-commands.js b/polygerrit-ui/app/elements/shared/gr-download-commands/gr-download-commands.js
index 121aa35..8ee4820 100644
--- a/polygerrit-ui/app/elements/shared/gr-download-commands/gr-download-commands.js
+++ b/polygerrit-ui/app/elements/shared/gr-download-commands/gr-download-commands.js
@@ -17,40 +17,46 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-download-commands',
+ /**
+ * @appliesMixin Gerrit.RESTClientMixin
+ */
+ class GrDownloadCommands extends Polymer.mixinBehaviors( [
+ Gerrit.RESTClientBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-download-commands'; }
- properties: {
- commands: Array,
- _loggedIn: {
- type: Boolean,
- value: false,
- observer: '_loggedInChanged',
- },
- schemes: Array,
- selectedScheme: {
- type: String,
- notify: true,
- },
- },
-
- behaviors: [
- Gerrit.RESTClientBehavior,
- ],
+ static get properties() {
+ return {
+ commands: Array,
+ _loggedIn: {
+ type: Boolean,
+ value: false,
+ observer: '_loggedInChanged',
+ },
+ schemes: Array,
+ selectedScheme: {
+ type: String,
+ notify: true,
+ },
+ };
+ }
attached() {
+ super.attached();
this._getLoggedIn().then(loggedIn => {
this._loggedIn = loggedIn;
});
- },
+ }
focusOnCopy() {
this.$$('gr-shell-command').focusOnCopy();
- },
+ }
_getLoggedIn() {
return this.$.restAPI.getLoggedIn();
- },
+ }
_loggedInChanged(loggedIn) {
if (!loggedIn) { return; }
@@ -60,7 +66,7 @@
this.selectedScheme = prefs.download_scheme.toLowerCase();
}
});
- },
+ }
_handleTabChange(e) {
const scheme = this.schemes[e.detail.value];
@@ -71,15 +77,17 @@
{download_scheme: this.selectedScheme});
}
}
- },
+ }
_computeSelected(schemes, selectedScheme) {
return (schemes.findIndex(scheme => scheme === selectedScheme) || 0)
+ '';
- },
+ }
_computeShowTabs(schemes) {
return schemes.length > 1 ? '' : 'hidden';
- },
- });
+ }
+ }
+
+ customElements.define(GrDownloadCommands.is, GrDownloadCommands);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.js b/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.js
index 1f0d01c..2197733 100644
--- a/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.js
+++ b/polygerrit-ui/app/elements/shared/gr-dropdown-list/gr-dropdown-list.js
@@ -45,9 +45,10 @@
*/
Defs.item;
- Polymer({
- is: 'gr-dropdown-list',
-
+ class GrDropdownList extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-dropdown-list'; }
/**
* Fired when the selected value changes
*
@@ -56,24 +57,28 @@
* @property {string|number} value
*/
- properties: {
- initialCount: Number,
- /** @type {!Array<!Defs.item>} */
- items: Object,
- text: String,
- disabled: {
- type: Boolean,
- value: false,
- },
- value: {
- type: String,
- notify: true,
- },
- },
+ static get properties() {
+ return {
+ initialCount: Number,
+ /** @type {!Array<!Defs.item>} */
+ items: Object,
+ text: String,
+ disabled: {
+ type: Boolean,
+ value: false,
+ },
+ value: {
+ type: String,
+ notify: true,
+ },
+ };
+ }
- observers: [
- '_handleValueChange(value, items)',
- ],
+ static get observers() {
+ return [
+ '_handleValueChange(value, items)',
+ ];
+ }
/**
* Handle a click on the iron-dropdown element.
@@ -85,7 +90,7 @@
this.async(() => {
this.$.dropdown.close();
}, 1);
- },
+ }
/**
* Handle a click on the button to open the dropdown.
@@ -93,18 +98,18 @@
*/
_showDropdownTapHandler(e) {
this._open();
- },
+ }
/**
* Open the dropdown.
*/
_open() {
this.$.dropdown.open();
- },
+ }
_computeMobileText(item) {
return item.mobileText ? item.mobileText : item.text;
- },
+ }
_handleValueChange(value, items) {
// Polymer 2: check for undefined
@@ -123,6 +128,8 @@
detail: {value},
bubbles: false,
}));
- },
- });
+ }
+ }
+
+ customElements.define(GrDropdownList.is, GrDropdownList);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-dropdown/gr-dropdown.js b/polygerrit-ui/app/elements/shared/gr-dropdown/gr-dropdown.js
index 7273268..9725f0c 100644
--- a/polygerrit-ui/app/elements/shared/gr-dropdown/gr-dropdown.js
+++ b/polygerrit-ui/app/elements/shared/gr-dropdown/gr-dropdown.js
@@ -20,9 +20,17 @@
const REL_NOOPENER = 'noopener';
const REL_EXTERNAL = 'external';
- Polymer({
- is: 'gr-dropdown',
-
+ /**
+ * @appliesMixin Gerrit.BaseUrlMixin
+ * @appliesMixin Gerrit.KeyboardShortcutMixin
+ */
+ class GrDropdown extends Polymer.mixinBehaviors( [
+ Gerrit.BaseUrlBehavior,
+ Gerrit.KeyboardShortcutBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-dropdown'; }
/**
* Fired when a non-link dropdown item with the given ID is tapped.
*
@@ -35,60 +43,59 @@
* @event tap-item
*/
- properties: {
- items: {
- type: Array,
- observer: '_resetCursorStops',
- },
- downArrow: Boolean,
- topContent: Object,
- horizontalAlign: {
- type: String,
- value: 'left',
- },
+ static get properties() {
+ return {
+ items: {
+ type: Array,
+ observer: '_resetCursorStops',
+ },
+ downArrow: Boolean,
+ topContent: Object,
+ horizontalAlign: {
+ type: String,
+ value: 'left',
+ },
- /**
+ /**
* Style the dropdown trigger as a link (rather than a button).
*/
- link: {
- type: Boolean,
- value: false,
- },
+ link: {
+ type: Boolean,
+ value: false,
+ },
- verticalOffset: {
- type: Number,
- value: 40,
- },
+ verticalOffset: {
+ type: Number,
+ value: 40,
+ },
- /**
+ /**
* List the IDs of dropdown buttons to be disabled. (Note this only
* diisables bittons and not link entries.)
*/
- disabledIds: {
- type: Array,
- value() { return []; },
- },
+ disabledIds: {
+ type: Array,
+ value() { return []; },
+ },
- /**
+ /**
* The elements of the list.
*/
- _listElements: {
- type: Array,
- value() { return []; },
- },
- },
+ _listElements: {
+ type: Array,
+ value() { return []; },
+ },
+ };
+ }
- behaviors: [
- Gerrit.BaseUrlBehavior,
- Gerrit.KeyboardShortcutBehavior,
- ],
-
- keyBindings: {
- 'down': '_handleDown',
- 'enter space': '_handleEnter',
- 'tab': '_handleTab',
- 'up': '_handleUp',
- },
+ get keyBindings() {
+ return {
+ 'down': '_handleDown',
+ 'enter space': '_handleEnter',
+ 'tab': '_handleTab',
+ 'up': '_handleUp',
+ };
+ }
/**
* Handle the up key.
@@ -102,7 +109,7 @@
} else {
this._open();
}
- },
+ }
/**
* Handle the down key.
@@ -116,7 +123,7 @@
} else {
this._open();
}
- },
+ }
/**
* Handle the tab key.
@@ -128,7 +135,7 @@
e.preventDefault();
e.stopPropagation();
}
- },
+ }
/**
* Handle the enter key.
@@ -146,7 +153,7 @@
} else {
this._open();
}
- },
+ }
/**
* Handle a click on the iron-dropdown element.
@@ -154,7 +161,7 @@
*/
_handleDropdownTap(e) {
this._close();
- },
+ }
/**
* Hanlde a click on the button to open the dropdown.
@@ -168,7 +175,7 @@
} else {
this._open();
}
- },
+ }
/**
* Open the dropdown and initialize the cursor.
@@ -178,7 +185,7 @@
this._resetCursorStops();
this.$.cursor.setCursorAtIndex(0);
this.$.cursor.target.focus();
- },
+ }
_close() {
// async is needed so that that the click event is fired before the
@@ -186,7 +193,7 @@
this.async(() => {
this.$.dropdown.close();
}, 1);
- },
+ }
/**
* Get the class for a top-content item based on the given boolean.
@@ -195,7 +202,7 @@
*/
_getClassIfBold(bold) {
return bold ? 'bold-text' : '';
- },
+ }
/**
* Build a URL for the given host and path. The base URL will be only added,
@@ -208,7 +215,7 @@
const base = path.startsWith(this.getBaseUrl()) ?
'' : this.getBaseUrl();
return '//' + host + base + path;
- },
+ }
/**
* Build a scheme-relative URL for the current host. Will include the base
@@ -220,7 +227,7 @@
_computeRelativeURL(path) {
const host = window.location.host;
return this._computeURLHelper(host, path);
- },
+ }
/**
* Compute the URL for a link object.
@@ -235,7 +242,7 @@
return link.url;
}
return this._computeRelativeURL(link.url);
- },
+ }
/**
* Compute the value for the rel attribute of an anchor for the given link
@@ -249,7 +256,7 @@
if (link.target) { return REL_NOOPENER; }
if (link.external) { return REL_EXTERNAL; }
return null;
- },
+ }
/**
* Handle a click on an item of the dropdown.
@@ -264,7 +271,7 @@
}
this.dispatchEvent(new CustomEvent('tap-item-' + id));
}
- },
+ }
/**
* If a dropdown item is shown as a button, get the class for the button.
@@ -275,7 +282,7 @@
*/
_computeDisabledClass(id, disabledIdsRecord) {
return disabledIdsRecord.base.includes(id) ? 'disabled' : '';
- },
+ }
/**
* Recompute the stops for the dropdown item cursor.
@@ -286,14 +293,16 @@
this._listElements = Array.from(
Polymer.dom(this.root).querySelectorAll('li'));
}
- },
+ }
_computeHasTooltip(tooltip) {
return !!tooltip;
- },
+ }
_computeIsDownload(link) {
return !!link.download;
- },
- });
+ }
+ }
+
+ customElements.define(GrDropdown.is, GrDropdown);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-editable-content/gr-editable-content.js b/polygerrit-ui/app/elements/shared/gr-editable-content/gr-editable-content.js
index 75c0201..49b1025 100644
--- a/polygerrit-ui/app/elements/shared/gr-editable-content/gr-editable-content.js
+++ b/polygerrit-ui/app/elements/shared/gr-editable-content/gr-editable-content.js
@@ -20,9 +20,15 @@
const RESTORED_MESSAGE = 'Content restored from a previous edit.';
const STORAGE_DEBOUNCE_INTERVAL_MS = 400;
- Polymer({
- is: 'gr-editable-content',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ */
+ class GrEditableContent extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-editable-content'; }
/**
* Fired when the save button is pressed.
*
@@ -41,42 +47,40 @@
* @event show-alert
*/
- properties: {
- content: {
- notify: true,
- type: String,
- },
- disabled: {
- reflectToAttribute: true,
- type: Boolean,
- value: false,
- },
- editing: {
- observer: '_editingChanged',
- type: Boolean,
- value: false,
- },
- removeZeroWidthSpace: Boolean,
- // If no storage key is provided, content is not stored.
- storageKey: String,
- _saveDisabled: {
- computed: '_computeSaveDisabled(disabled, content, _newContent)',
- type: Boolean,
- value: true,
- },
- _newContent: {
- type: String,
- observer: '_newContentChanged',
- },
- },
-
- behaviors: [
- Gerrit.FireBehavior,
- ],
+ static get properties() {
+ return {
+ content: {
+ notify: true,
+ type: String,
+ },
+ disabled: {
+ reflectToAttribute: true,
+ type: Boolean,
+ value: false,
+ },
+ editing: {
+ observer: '_editingChanged',
+ type: Boolean,
+ value: false,
+ },
+ removeZeroWidthSpace: Boolean,
+ // If no storage key is provided, content is not stored.
+ storageKey: String,
+ _saveDisabled: {
+ computed: '_computeSaveDisabled(disabled, content, _newContent)',
+ type: Boolean,
+ value: true,
+ },
+ _newContent: {
+ type: String,
+ observer: '_newContentChanged',
+ },
+ };
+ }
focusTextarea() {
this.$$('iron-autogrow-textarea').textarea.focus();
- },
+ }
_newContentChanged(newContent, oldContent) {
if (!this.storageKey) { return; }
@@ -88,7 +92,7 @@
this.$.storage.eraseEditableContentItem(this.storageKey);
}
}, STORAGE_DEBOUNCE_INTERVAL_MS);
- },
+ }
_editingChanged(editing) {
if (!editing) { return; }
@@ -114,7 +118,7 @@
this._newContent = this.removeZeroWidthSpace ?
content.replace(/^R=\u200B/gm, 'R=') :
content;
- },
+ }
_computeSaveDisabled(disabled, content, newContent) {
// Polymer 2: check for undefined
@@ -127,17 +131,19 @@
}
return disabled || (content === newContent);
- },
+ }
_handleSave(e) {
e.preventDefault();
this.fire('editable-content-save', {content: this._newContent});
- },
+ }
_handleCancel(e) {
e.preventDefault();
this.editing = false;
this.fire('editable-content-cancel');
- },
- });
+ }
+ }
+
+ customElements.define(GrEditableContent.is, GrEditableContent);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-editable-label/gr-editable-label.js b/polygerrit-ui/app/elements/shared/gr-editable-label/gr-editable-label.js
index 4485551..b989401 100644
--- a/polygerrit-ui/app/elements/shared/gr-editable-label/gr-editable-label.js
+++ b/polygerrit-ui/app/elements/shared/gr-editable-label/gr-editable-label.js
@@ -20,76 +20,84 @@
const AWAIT_MAX_ITERS = 10;
const AWAIT_STEP = 5;
- Polymer({
- is: 'gr-editable-label',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ * @appliesMixin Gerrit.KeyboardShortcutMixin
+ */
+ class GrEditableLabel extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ Gerrit.KeyboardShortcutBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-editable-label'; }
/**
* Fired when the value is changed.
*
* @event changed
*/
- properties: {
- labelText: String,
- editing: {
- type: Boolean,
- value: false,
- },
- value: {
- type: String,
- notify: true,
- value: '',
- observer: '_updateTitle',
- },
- placeholder: {
- type: String,
- value: '',
- },
- readOnly: {
- type: Boolean,
- value: false,
- },
- uppercase: {
- type: Boolean,
- reflectToAttribute: true,
- value: false,
- },
- maxLength: Number,
- _inputText: String,
- // This is used to push the iron-input element up on the page, so
- // the input is placed in approximately the same position as the
- // trigger.
- _verticalOffset: {
- type: Number,
- readOnly: true,
- value: -30,
- },
- },
+ static get properties() {
+ return {
+ labelText: String,
+ editing: {
+ type: Boolean,
+ value: false,
+ },
+ value: {
+ type: String,
+ notify: true,
+ value: '',
+ observer: '_updateTitle',
+ },
+ placeholder: {
+ type: String,
+ value: '',
+ },
+ readOnly: {
+ type: Boolean,
+ value: false,
+ },
+ uppercase: {
+ type: Boolean,
+ reflectToAttribute: true,
+ value: false,
+ },
+ maxLength: Number,
+ _inputText: String,
+ // This is used to push the iron-input element up on the page, so
+ // the input is placed in approximately the same position as the
+ // trigger.
+ _verticalOffset: {
+ type: Number,
+ readOnly: true,
+ value: -30,
+ },
+ };
+ }
- behaviors: [
- Gerrit.FireBehavior,
- Gerrit.KeyboardShortcutBehavior,
- ],
+ ready() {
+ super.ready();
+ this._ensureAttribute('tabindex', '0');
+ }
- keyBindings: {
- enter: '_handleEnter',
- esc: '_handleEsc',
- },
-
- hostAttributes: {
- tabindex: '0',
- },
+ get keyBindings() {
+ return {
+ enter: '_handleEnter',
+ esc: '_handleEsc',
+ };
+ }
_usePlaceholder(value, placeholder) {
return (!value || !value.length) && placeholder;
- },
+ }
_computeLabel(value, placeholder) {
if (this._usePlaceholder(value, placeholder)) {
return placeholder;
}
return value;
- },
+ }
_showDropdown() {
if (this.readOnly || this.editing) { return; }
@@ -98,13 +106,13 @@
if (!this.$.input.value) { return; }
this._nativeInput.setSelectionRange(0, this.$.input.value.length);
});
- },
+ }
open() {
return this._open().then(() => {
this._nativeInput.focus();
});
- },
+ }
_open(...args) {
this.$.dropdown.open();
@@ -115,7 +123,7 @@
Polymer.IronOverlayBehaviorImpl.open.apply(this.$.dropdown, args);
this._awaitOpen(resolve);
});
- },
+ }
/**
* NOTE: (wyatta) Slightly hacky way to listen to the overlay actually
@@ -133,11 +141,11 @@
}, AWAIT_STEP);
};
step.call(this);
- },
+ }
_id() {
return this.getAttribute('id') || 'global';
- },
+ }
_save() {
if (!this.editing) { return; }
@@ -145,20 +153,20 @@
this.value = this._inputText;
this.editing = false;
this.fire('changed', this.value);
- },
+ }
_cancel() {
if (!this.editing) { return; }
this.$.dropdown.close();
this.editing = false;
this._inputText = this.value;
- },
+ }
get _nativeInput() {
// In Polymer 2, the namespace of nativeInput
// changed from input to nativeInput
return this.$.input.$.nativeInput || this.$.input.$.input;
- },
+ }
_handleEnter(e) {
e = this.getKeyboardEvent(e);
@@ -167,7 +175,7 @@
e.preventDefault();
this._save();
}
- },
+ }
_handleEsc(e) {
e = this.getKeyboardEvent(e);
@@ -176,7 +184,7 @@
e.preventDefault();
this._cancel();
}
- },
+ }
_computeLabelClass(readOnly, value, placeholder) {
const classes = [];
@@ -185,10 +193,12 @@
classes.push('placeholder');
}
return classes.join(' ');
- },
+ }
_updateTitle(value) {
this.setAttribute('title', this._computeLabel(value, this.placeholder));
- },
- });
+ }
+ }
+
+ customElements.define(GrEditableLabel.is, GrEditableLabel);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-fixed-panel/gr-fixed-panel.js b/polygerrit-ui/app/elements/shared/gr-fixed-panel/gr-fixed-panel.js
index 2c32709..af533bc 100644
--- a/polygerrit-ui/app/elements/shared/gr-fixed-panel/gr-fixed-panel.js
+++ b/polygerrit-ui/app/elements/shared/gr-fixed-panel/gr-fixed-panel.js
@@ -17,47 +17,52 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-fixed-panel',
+ class GrFixedPanel extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-fixed-panel'; }
- properties: {
- floatingDisabled: Boolean,
- readyForMeasure: {
- type: Boolean,
- observer: '_readyForMeasureObserver',
- },
- keepOnScroll: {
- type: Boolean,
- value: false,
- },
- _isMeasured: {
- type: Boolean,
- value: false,
- },
+ static get properties() {
+ return {
+ floatingDisabled: Boolean,
+ readyForMeasure: {
+ type: Boolean,
+ observer: '_readyForMeasureObserver',
+ },
+ keepOnScroll: {
+ type: Boolean,
+ value: false,
+ },
+ _isMeasured: {
+ type: Boolean,
+ value: false,
+ },
- /**
+ /**
* Initial offset from the top of the document, in pixels.
*/
- _topInitial: Number,
+ _topInitial: Number,
- /**
+ /**
* Current offset from the top of the window, in pixels.
*/
- _topLast: Number,
+ _topLast: Number,
- _headerHeight: Number,
- _headerFloating: {
- type: Boolean,
- value: false,
- },
- _observer: {
- type: Object,
- value: null,
- },
- _webComponentsReady: Boolean,
- },
+ _headerHeight: Number,
+ _headerFloating: {
+ type: Boolean,
+ value: false,
+ },
+ _observer: {
+ type: Object,
+ value: null,
+ },
+ _webComponentsReady: Boolean,
+ };
+ }
attached() {
+ super.attached();
if (this.floatingDisabled) {
return;
}
@@ -69,21 +74,22 @@
this.listen(window, 'scroll', '_updateOnScroll');
this._observer = new MutationObserver(this.update.bind(this));
this._observer.observe(this.$.header, {childList: true, subtree: true});
- },
+ }
detached() {
+ super.detached();
this.unlisten(window, 'scroll', '_updateOnScroll');
this.unlisten(window, 'resize', 'update');
if (this._observer) {
this._observer.disconnect();
}
- },
+ }
_readyForMeasureObserver(readyForMeasure) {
if (readyForMeasure) {
this.update();
}
- },
+ }
_computeHeaderClass(headerFloating, topLast) {
const fixedAtTop = this.keepOnScroll && topLast === 0;
@@ -91,7 +97,7 @@
headerFloating ? 'floating' : '',
fixedAtTop ? 'fixedAtTop' : '',
].join(' ');
- },
+ }
unfloat() {
if (this.floatingDisabled) {
@@ -100,19 +106,19 @@
this.$.header.style.top = '';
this._headerFloating = false;
this.updateStyles({'--header-height': ''});
- },
+ }
update() {
this.debounce('update', () => {
this._updateDebounced();
}, 100);
- },
+ }
_updateOnScroll() {
this.debounce('update', () => {
this._updateDebounced();
});
- },
+ }
_updateDebounced() {
if (this.floatingDisabled) {
@@ -121,11 +127,11 @@
this._isMeasured = false;
this._maybeFloatHeader();
this._reposition();
- },
+ }
_getElementTop() {
return this.getBoundingClientRect().top;
- },
+ }
_reposition() {
if (!this._headerFloating) {
@@ -155,7 +161,7 @@
}
this._topLast = newTop;
}
- },
+ }
_measure() {
if (this._isMeasured) {
@@ -171,12 +177,12 @@
this._topInitial =
this.getBoundingClientRect().top + document.body.scrollTop;
this._isMeasured = true;
- },
+ }
_isFloatingNeeded() {
return this.keepOnScroll ||
document.body.scrollWidth > document.body.clientWidth;
- },
+ }
_maybeFloatHeader() {
if (!this._isFloatingNeeded()) {
@@ -186,11 +192,13 @@
if (this._isMeasured) {
this._floatHeader();
}
- },
+ }
_floatHeader() {
this.updateStyles({'--header-height': this._headerHeight + 'px'});
this._headerFloating = true;
- },
- });
+ }
+ }
+
+ customElements.define(GrFixedPanel.is, GrFixedPanel);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.js b/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.js
index 4e68d42..7730a75 100644
--- a/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.js
+++ b/polygerrit-ui/app/elements/shared/gr-formatted-text/gr-formatted-text.js
@@ -20,30 +20,37 @@
// eslint-disable-next-line no-unused-vars
const QUOTE_MARKER_PATTERN = /\n\s?>\s/g;
- Polymer({
- is: 'gr-formatted-text',
+ class GrFormattedText extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-formatted-text'; }
- properties: {
- content: {
- type: String,
- observer: '_contentChanged',
- },
- config: Object,
- noTrailingMargin: {
- type: Boolean,
- value: false,
- },
- },
+ static get properties() {
+ return {
+ content: {
+ type: String,
+ observer: '_contentChanged',
+ },
+ config: Object,
+ noTrailingMargin: {
+ type: Boolean,
+ value: false,
+ },
+ };
+ }
- observers: [
- '_contentOrConfigChanged(content, config)',
- ],
+ static get observers() {
+ return [
+ '_contentOrConfigChanged(content, config)',
+ ];
+ }
ready() {
+ super.ready();
if (this.noTrailingMargin) {
this.classList.add('noTrailingMargin');
}
- },
+ }
/**
* Get the plain text as it appears in the generated DOM.
@@ -56,7 +63,7 @@
*/
getTextContent() {
return this._blocksToText(this._computeBlocks(this.content));
- },
+ }
_contentChanged(content) {
// In the case where the config may not be set (perhaps due to the
@@ -64,7 +71,7 @@
// prevent waiting on the config to display the text.
if (this.config) { return; }
this._contentOrConfigChanged(content);
- },
+ }
/**
* Given a source string, update the DOM inside #container.
@@ -81,7 +88,7 @@
for (const node of this._computeNodes(this._computeBlocks(content))) {
container.appendChild(node);
}
- },
+ }
/**
* Given a source string, parse into an array of block objects. Each block
@@ -127,7 +134,7 @@
}
}
return result;
- },
+ }
/**
* Take a block of comment text that contains a list and potentially
@@ -201,7 +208,7 @@
if (block !== null) {
out.push(block);
}
- },
+ }
_makeQuote(p) {
const quotedLines = p
@@ -212,21 +219,21 @@
type: 'quote',
blocks: this._computeBlocks(quotedLines),
};
- },
+ }
_isQuote(p) {
return p.startsWith('> ') || p.startsWith(' > ');
- },
+ }
_isPreFormat(p) {
return p.includes('\n ') || p.includes('\n\t') ||
p.startsWith(' ') || p.startsWith('\t');
- },
+ }
_isList(p) {
return p.includes('\n- ') || p.includes('\n* ') ||
p.startsWith('- ') || p.startsWith('* ');
- },
+ }
/**
* @param {string} content
@@ -241,7 +248,7 @@
text.classList.add('pre');
}
return text;
- },
+ }
/**
* Map an array of block objects to an array of DOM nodes.
@@ -278,7 +285,7 @@
return ul;
}
});
- },
+ }
_blocksToText(blocks) {
return blocks.map(block => {
@@ -292,6 +299,8 @@
return block.items.join('\n');
}
}).join('\n\n');
- },
- });
+ }
+ }
+
+ customElements.define(GrFormattedText.is, GrFormattedText);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-hovercard/gr-hovercard.js b/polygerrit-ui/app/elements/shared/gr-hovercard/gr-hovercard.js
index 3a43191..5e3cfb3 100644
--- a/polygerrit-ui/app/elements/shared/gr-hovercard/gr-hovercard.js
+++ b/polygerrit-ui/app/elements/shared/gr-hovercard/gr-hovercard.js
@@ -25,82 +25,90 @@
*/
const DIAGONAL_OVERFLOW = 15;
- Polymer({
- is: 'gr-hovercard',
+ class GrHovercard extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-hovercard'; }
- properties: {
+ static get properties() {
+ return {
/**
* @type {?}
*/
- _target: Object,
+ _target: Object,
- /**
+ /**
* Determines whether or not the hovercard is visible.
*
* @type {boolean}
*/
- _isShowing: {
- type: Boolean,
- value: false,
- },
- /**
+ _isShowing: {
+ type: Boolean,
+ value: false,
+ },
+ /**
* The `id` of the element that the hovercard is anchored to.
*
* @type {string}
*/
- for: {
- type: String,
- observer: '_forChanged',
- },
+ for: {
+ type: String,
+ observer: '_forChanged',
+ },
- /**
+ /**
* The spacing between the top of the hovercard and the element it is
* anchored to.
*
* @type {number}
*/
- offset: {
- type: Number,
- value: 14,
- },
+ offset: {
+ type: Number,
+ value: 14,
+ },
- /**
+ /**
* Positions the hovercard to the top, right, bottom, left, bottom-left,
* bottom-right, top-left, or top-right of its content.
*
* @type {string}
*/
- position: {
- type: String,
- value: 'bottom',
- },
+ position: {
+ type: String,
+ value: 'bottom',
+ },
- container: Object,
- /**
+ container: Object,
+ /**
* ID for the container element.
*
* @type {string}
*/
- containerId: {
- type: String,
- value: 'gr-hovercard-container',
- },
- },
-
- listeners: {
- mouseleave: 'hide',
- },
+ containerId: {
+ type: String,
+ value: 'gr-hovercard-container',
+ },
+ };
+ }
attached() {
+ super.attached();
if (!this._target) { this._target = this.target; }
this.listen(this._target, 'mouseenter', 'show');
this.listen(this._target, 'focus', 'show');
this.listen(this._target, 'mouseleave', 'hide');
this.listen(this._target, 'blur', 'hide');
this.listen(this._target, 'click', 'hide');
- },
+ }
+
+ created() {
+ super.created();
+ this.addEventListener('mouseleave',
+ e => this.hide(e));
+ }
ready() {
+ super.ready();
// First, check to see if the container has already been created.
this.container = Gerrit.getRootElement()
.querySelector('#' + this.containerId);
@@ -111,7 +119,7 @@
this.container = document.createElement('div');
this.container.setAttribute('id', this.containerId);
Gerrit.getRootElement().appendChild(this.container);
- },
+ }
removeListeners() {
this.unlisten(this._target, 'mouseenter', 'show');
@@ -119,7 +127,7 @@
this.unlisten(this._target, 'mouseleave', 'hide');
this.unlisten(this._target, 'blur', 'hide');
this.unlisten(this._target, 'click', 'hide');
- },
+ }
/**
* Returns the target element that the hovercard is anchored to (the `id` of
@@ -140,7 +148,7 @@
parentNode;
}
return target;
- },
+ }
/**
* Hides/closes the hovercard. This occurs when the user triggers the
@@ -184,7 +192,7 @@
if (this.container.contains(this)) {
this.container.removeChild(this);
}
- },
+ }
/**
* Shows/opens the hovercard. This occurs when the user triggers the
@@ -207,7 +215,7 @@
// Trigger the transition
this.classList.add(HOVER_CLASS);
- },
+ }
/**
* Updates the hovercard's position based on the `position` attribute
@@ -306,7 +314,7 @@
// Set the hovercard's position
cssText += `left:${hovercardLeft}px; top:${hovercardTop}px;`;
this.style.cssText = cssText;
- },
+ }
/**
* Responds to a change in the `for` value and gets the updated `target`
@@ -316,6 +324,8 @@
*/
_forChanged() {
this._target = this.target;
- },
- });
+ }
+ }
+
+ customElements.define(GrHovercard.is, GrHovercard);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js
index 2bc8898..1802a4a 100644
--- a/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js
+++ b/polygerrit-ui/app/elements/shared/gr-js-api-interface/gr-js-api-interface.js
@@ -37,26 +37,34 @@
REPLY_DIALOG: 'replydialog',
};
- Polymer({
- is: 'gr-js-api-interface',
+ /**
+ * @appliesMixin Gerrit.PatchSetMixin
+ */
+ class GrJsApiInterface extends Polymer.mixinBehaviors( [
+ Gerrit.PatchSetBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-js-api-interface'; }
- properties: {
- _elements: {
- type: Object,
- value: {}, // Shared across all instances.
- },
- _eventCallbacks: {
- type: Object,
- value: {}, // Shared across all instances.
- },
- },
+ constructor() {
+ super();
+ this.Element = Element;
+ this.EventType = EventType;
+ }
- behaviors: [
- Gerrit.PatchSetBehavior,
- ],
-
- Element,
- EventType,
+ static get properties() {
+ return {
+ _elements: {
+ type: Object,
+ value: {}, // Shared across all instances.
+ },
+ _eventCallbacks: {
+ type: Object,
+ value: {}, // Shared across all instances.
+ },
+ };
+ }
handleEvent(type, detail) {
Gerrit.awaitPluginsLoaded().then(() => {
@@ -82,22 +90,22 @@
break;
}
});
- },
+ }
addElement(key, el) {
this._elements[key] = el;
- },
+ }
getElement(key) {
return this._elements[key];
- },
+ }
addEventCallback(eventName, callback) {
if (!this._eventCallbacks[eventName]) {
this._eventCallbacks[eventName] = [];
}
this._eventCallbacks[eventName].push(callback);
- },
+ }
canSubmitChange(change, revision) {
const submitCallbacks = this._getEventCallbacks(EventType.SUBMIT_CHANGE);
@@ -111,14 +119,14 @@
});
return !cancelSubmit;
- },
+ }
_removeEventCallbacks() {
for (const k in EventType) {
if (!EventType.hasOwnProperty(k)) { continue; }
this._eventCallbacks[EventType[k]] = [];
}
- },
+ }
_handleHistory(detail) {
for (const cb of this._getEventCallbacks(EventType.HISTORY)) {
@@ -128,7 +136,7 @@
console.error(err);
}
}
- },
+ }
_handleShowChange(detail) {
// Note (issue 8221) Shallow clone the change object and add a mergeable
@@ -163,7 +171,7 @@
console.error(err);
}
}
- },
+ }
handleCommitMessage(change, msg) {
for (const cb of this._getEventCallbacks(EventType.COMMIT_MSG_EDIT)) {
@@ -173,7 +181,7 @@
console.error(err);
}
}
- },
+ }
_handleComment(detail) {
for (const cb of this._getEventCallbacks(EventType.COMMENT)) {
@@ -183,7 +191,7 @@
console.error(err);
}
}
- },
+ }
_handleLabelChange(detail) {
for (const cb of this._getEventCallbacks(EventType.LABEL_CHANGE)) {
@@ -193,7 +201,7 @@
console.error(err);
}
}
- },
+ }
_handleHighlightjsLoaded(detail) {
for (const cb of this._getEventCallbacks(EventType.HIGHLIGHTJS_LOADED)) {
@@ -203,7 +211,7 @@
console.error(err);
}
}
- },
+ }
modifyRevertMsg(change, revertMsg, origMsg) {
for (const cb of this._getEventCallbacks(EventType.REVERT)) {
@@ -214,7 +222,7 @@
}
}
return revertMsg;
- },
+ }
modifyRevertSubmissionMsg(change, revertSubmissionMsg, origMsg) {
for (const cb of this._getEventCallbacks(EventType.REVERT_SUBMISSION)) {
@@ -225,7 +233,7 @@
}
}
return revertSubmissionMsg;
- },
+ }
getDiffLayers(path, changeNum, patchNum) {
const layers = [];
@@ -239,7 +247,7 @@
}
}
return layers;
- },
+ }
/**
* Retrieves coverage data possibly provided by a plugin.
@@ -267,7 +275,7 @@
}
return [];
});
- },
+ }
getAdminMenuLinks() {
const links = [];
@@ -276,7 +284,7 @@
links.push(...adminApi.getMenuLinks());
}
return links;
- },
+ }
getLabelValuesPostRevert(change) {
let labels = {};
@@ -288,10 +296,12 @@
}
}
return labels;
- },
+ }
_getEventCallbacks(type) {
return this._eventCallbacks[type] || [];
- },
- });
+ }
+ }
+
+ customElements.define(GrJsApiInterface.is, GrJsApiInterface);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-label-info/gr-label-info.js b/polygerrit-ui/app/elements/shared/gr-label-info/gr-label-info.js
index 3c27c94..0e529b1 100644
--- a/polygerrit-ui/app/elements/shared/gr-label-info/gr-label-info.js
+++ b/polygerrit-ui/app/elements/shared/gr-label-info/gr-label-info.js
@@ -17,17 +17,21 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-label-info',
+ class GrLabelInfo extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-label-info'; }
- properties: {
- labelInfo: Object,
- label: String,
- /** @type {?} */
- change: Object,
- account: Object,
- mutable: Boolean,
- },
+ static get properties() {
+ return {
+ labelInfo: Object,
+ label: String,
+ /** @type {?} */
+ change: Object,
+ account: Object,
+ mutable: Boolean,
+ };
+ }
/**
* @param {!Object} labelInfo
@@ -85,7 +89,7 @@
}
}
return result;
- },
+ }
/**
* A user is able to delete a vote iff the mutable property is true and the
@@ -106,7 +110,7 @@
return '';
}
return 'hidden';
- },
+ }
/**
* Closure annotation for Polymer.prototype.splice is off.
@@ -133,14 +137,14 @@
target.disabled = false;
return;
});
- },
+ }
_computeValueTooltip(labelInfo, score) {
if (!labelInfo || !labelInfo.values || !labelInfo.values[score]) {
return '';
}
return labelInfo.values[score];
- },
+ }
/**
* @param {!Object} labelInfo
@@ -156,6 +160,8 @@
}
}
return '';
- },
- });
+ }
+ }
+
+ customElements.define(GrLabelInfo.is, GrLabelInfo);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-label/gr-label.js b/polygerrit-ui/app/elements/shared/gr-label/gr-label.js
index 0de0881..7d82c9c9 100644
--- a/polygerrit-ui/app/elements/shared/gr-label/gr-label.js
+++ b/polygerrit-ui/app/elements/shared/gr-label/gr-label.js
@@ -17,11 +17,16 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-label',
+ /**
+ * @appliesMixin Gerrit.TooltipMixin
+ */
+ class GrLabel extends Polymer.mixinBehaviors( [
+ Gerrit.TooltipBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-label'; }
+ }
- behaviors: [
- Gerrit.TooltipBehavior,
- ],
- });
+ customElements.define(GrLabel.is, GrLabel);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-labeled-autocomplete/gr-labeled-autocomplete.js b/polygerrit-ui/app/elements/shared/gr-labeled-autocomplete/gr-labeled-autocomplete.js
index fd0f228..d2646af 100644
--- a/polygerrit-ui/app/elements/shared/gr-labeled-autocomplete/gr-labeled-autocomplete.js
+++ b/polygerrit-ui/app/elements/shared/gr-labeled-autocomplete/gr-labeled-autocomplete.js
@@ -17,60 +17,65 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-labeled-autocomplete',
-
+ class GrLabeledAutocomplete extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-labeled-autocomplete'; }
/**
* Fired when a value is chosen.
*
* @event commit
*/
- properties: {
+ static get properties() {
+ return {
- /**
+ /**
* Used just like the query property of gr-autocomplete.
*
* @type {function(string): Promise<?>}
*/
- query: {
- type: Function,
- value() {
- return function() {
- return Promise.resolve([]);
- };
+ query: {
+ type: Function,
+ value() {
+ return function() {
+ return Promise.resolve([]);
+ };
+ },
},
- },
- text: {
- type: String,
- value: '',
- notify: true,
- },
- label: String,
- placeholder: String,
- disabled: Boolean,
+ text: {
+ type: String,
+ value: '',
+ notify: true,
+ },
+ label: String,
+ placeholder: String,
+ disabled: Boolean,
- _autocompleteThreshold: {
- type: Number,
- value: 0,
- readOnly: true,
- },
- },
+ _autocompleteThreshold: {
+ type: Number,
+ value: 0,
+ readOnly: true,
+ },
+ };
+ }
_handleTriggerClick(e) {
// Stop propagation here so we don't confuse gr-autocomplete, which
// listens for taps on body to try to determine when it's blurred.
e.stopPropagation();
this.$.autocomplete.focus();
- },
+ }
setText(text) {
this.$.autocomplete.setText(text);
- },
+ }
clear() {
this.setText('');
- },
- });
+ }
+ }
+
+ customElements.define(GrLabeledAutocomplete.is, GrLabeledAutocomplete);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-lib-loader/gr-lib-loader.js b/polygerrit-ui/app/elements/shared/gr-lib-loader/gr-lib-loader.js
index 260c819..1fd122c 100644
--- a/polygerrit-ui/app/elements/shared/gr-lib-loader/gr-lib-loader.js
+++ b/polygerrit-ui/app/elements/shared/gr-lib-loader/gr-lib-loader.js
@@ -20,21 +20,25 @@
const HLJS_PATH = 'bower_components/highlightjs/highlight.min.js';
const DARK_THEME_PATH = 'styles/themes/dark-theme.html';
- Polymer({
- is: 'gr-lib-loader',
+ class GrLibLoader extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-lib-loader'; }
- properties: {
- _hljsState: {
- type: Object,
+ static get properties() {
+ return {
+ _hljsState: {
+ type: Object,
- // NOTE: intended singleton.
- value: {
- configured: false,
- loading: false,
- callbacks: [],
+ // NOTE: intended singleton.
+ value: {
+ configured: false,
+ loading: false,
+ callbacks: [],
+ },
},
- },
- },
+ };
+ }
/**
* Get the HLJS library. Returns a promise that resolves with a reference to
@@ -59,7 +63,7 @@
this._hljsState.callbacks.push(resolve);
});
- },
+ }
/**
* Loads the dark theme document. Returns a promise that resolves with a
@@ -79,7 +83,7 @@
resolve(cs);
});
});
- },
+ }
/**
* Execute callbacks awaiting the HLJS lib load.
@@ -94,7 +98,7 @@
cb(lib);
}
this._hljsState.callbacks = [];
- },
+ }
/**
* Get the HLJS library, assuming it has been loaded. Configure the library
@@ -109,7 +113,7 @@
lib.configure({classPrefix: 'gr-diff gr-syntax gr-syntax-'});
}
return lib;
- },
+ }
/**
* Get the resource path used to load the application. If the application
@@ -121,7 +125,7 @@
return window.STATIC_RESOURCE_PATH + '/';
}
return '/';
- },
+ }
/**
* Load and execute a JS file from the lib root.
@@ -143,12 +147,14 @@
script.onerror = reject;
Polymer.dom(document.head).appendChild(script);
});
- },
+ }
_getHLJSUrl() {
const root = this._getLibRoot();
if (!root) { return null; }
return root + HLJS_PATH;
- },
- });
+ }
+ }
+
+ customElements.define(GrLibLoader.is, GrLibLoader);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-limited-text/gr-limited-text.js b/polygerrit-ui/app/elements/shared/gr-limited-text/gr-limited-text.js
index 048e4f5..9239866 100644
--- a/polygerrit-ui/app/elements/shared/gr-limited-text/gr-limited-text.js
+++ b/polygerrit-ui/app/elements/shared/gr-limited-text/gr-limited-text.js
@@ -17,57 +17,63 @@
(function() {
'use strict';
+ /**
+ * @appliesMixin Gerrit.TooltipMixin
+ */
/*
* The gr-limited-text element is for displaying text with a maximum length
* (in number of characters) to display. If the length of the text exceeds the
* configured limit, then an ellipsis indicates that the text was truncated
* and a tooltip containing the full text is enabled.
*/
+ class GrLimitedText extends Polymer.mixinBehaviors( [
+ Gerrit.TooltipBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-limited-text'; }
- Polymer({
- is: 'gr-limited-text',
-
- properties: {
+ static get properties() {
+ return {
/** The un-truncated text to display. */
- text: String,
+ text: String,
- /** The maximum length for the text to display before truncating. */
- limit: {
- type: Number,
- value: null,
- },
+ /** The maximum length for the text to display before truncating. */
+ limit: {
+ type: Number,
+ value: null,
+ },
- /** Boolean property used by Gerrit.TooltipBehavior. */
- hasTooltip: {
- type: Boolean,
- value: false,
- },
+ /** Boolean property used by Gerrit.TooltipBehavior. */
+ hasTooltip: {
+ type: Boolean,
+ value: false,
+ },
- /**
+ /**
* Disable the tooltip.
* When set to true, will not show tooltip even text is over limit
*/
- disableTooltip: {
- type: Boolean,
- value: false,
- },
+ disableTooltip: {
+ type: Boolean,
+ value: false,
+ },
- /**
+ /**
* The maximum number of characters to display in the tooltop.
*/
- tooltipLimit: {
- type: Number,
- value: 1024,
- },
- },
+ tooltipLimit: {
+ type: Number,
+ value: 1024,
+ },
+ };
+ }
- observers: [
- '_updateTitle(text, limit, tooltipLimit)',
- ],
-
- behaviors: [
- Gerrit.TooltipBehavior,
- ],
+ static get observers() {
+ return [
+ '_updateTitle(text, limit, tooltipLimit)',
+ ];
+ }
/**
* The text or limit have changed. Recompute whether a tooltip needs to be
@@ -85,13 +91,15 @@
} else {
this.removeAttribute('title');
}
- },
+ }
_computeDisplayText(text, limit) {
if (!!limit && !!text && text.length > limit) {
return text.substr(0, limit - 1) + '…';
}
return text;
- },
- });
+ }
+ }
+
+ customElements.define(GrLimitedText.is, GrLimitedText);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-linked-chip/gr-linked-chip.js b/polygerrit-ui/app/elements/shared/gr-linked-chip/gr-linked-chip.js
index 33a9c25..aaae3d1 100644
--- a/polygerrit-ui/app/elements/shared/gr-linked-chip/gr-linked-chip.js
+++ b/polygerrit-ui/app/elements/shared/gr-linked-chip/gr-linked-chip.js
@@ -17,41 +17,48 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-linked-chip',
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ */
+ class GrLinkedChip extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-linked-chip'; }
- properties: {
- href: String,
- disabled: {
- type: Boolean,
- value: false,
- reflectToAttribute: true,
- },
- removable: {
- type: Boolean,
- value: false,
- },
- text: String,
- transparentBackground: {
- type: Boolean,
- value: false,
- },
+ static get properties() {
+ return {
+ href: String,
+ disabled: {
+ type: Boolean,
+ value: false,
+ reflectToAttribute: true,
+ },
+ removable: {
+ type: Boolean,
+ value: false,
+ },
+ text: String,
+ transparentBackground: {
+ type: Boolean,
+ value: false,
+ },
- /** If provided, sets the maximum length of the content. */
- limit: Number,
- },
-
- behaviors: [
- Gerrit.FireBehavior,
- ],
+ /** If provided, sets the maximum length of the content. */
+ limit: Number,
+ };
+ }
_getBackgroundClass(transparent) {
return transparent ? 'transparentBackground' : '';
- },
+ }
_handleRemoveTap(e) {
e.preventDefault();
this.fire('remove');
- },
- });
+ }
+ }
+
+ customElements.define(GrLinkedChip.is, GrLinkedChip);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text.js b/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text.js
index e7247b9..d080999 100644
--- a/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text.js
+++ b/polygerrit-ui/app/elements/shared/gr-linked-text/gr-linked-text.js
@@ -14,13 +14,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-(function() {
+(function () {
'use strict';
+ class GrLinkedText extends Polymer.GestureEventListeners(
+Polymer.LegacyElementMixin(
+Polymer.Element)) {
+ static get is() { return "gr-linked-text"; }
- Polymer({
- is: 'gr-linked-text',
- properties: {
+ static get properties() { return {
removeZeroWidthSpace: Boolean,
content: {
type: String,
@@ -37,11 +39,10 @@
reflectToAttribute: true,
},
config: Object,
- },
-
- observers: [
+ }; }
+ static get observers() { return [
'_contentOrConfigChanged(content, config)',
- ],
+ ]; }
_contentChanged(content) {
// In the case where the config may not be set (perhaps due to the
@@ -49,7 +50,7 @@
// prevent waiting on the config to display the text.
if (this.config != null) { return; }
this.$.output.textContent = content;
- },
+ }
/**
* Because either the source text or the linkification config has changed,
@@ -74,7 +75,7 @@
anchor.setAttribute('target', '_blank');
anchor.setAttribute('rel', 'noopener');
});
- },
+ }
/**
* This method is called when the GrLikTextParser emits a partial result
@@ -100,6 +101,7 @@
} else if (fragment) {
output.appendChild(fragment);
}
- },
- });
+ }
+ }
+ customElements.define(GrLinkedText.is, GrLinkedText);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.js b/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.js
index 8d81030..9d5d8f5 100644
--- a/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.js
+++ b/polygerrit-ui/app/elements/shared/gr-list-view/gr-list-view.js
@@ -19,31 +19,39 @@
const REQUEST_DEBOUNCE_INTERVAL_MS = 200;
- Polymer({
- is: 'gr-list-view',
+ /**
+ * @appliesMixin Gerrit.BaseUrlMixin
+ * @appliesMixin Gerrit.FireMixin
+ * @appliesMixin Gerrit.URLEncodingMixin
+ */
+ class GrListView extends Polymer.mixinBehaviors( [
+ Gerrit.BaseUrlBehavior,
+ Gerrit.FireBehavior,
+ Gerrit.URLEncodingBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-list-view'; }
- properties: {
- createNew: Boolean,
- items: Array,
- itemsPerPage: Number,
- filter: {
- type: String,
- observer: '_filterChanged',
- },
- offset: Number,
- loading: Boolean,
- path: String,
- },
-
- behaviors: [
- Gerrit.BaseUrlBehavior,
- Gerrit.FireBehavior,
- Gerrit.URLEncodingBehavior,
- ],
+ static get properties() {
+ return {
+ createNew: Boolean,
+ items: Array,
+ itemsPerPage: Number,
+ filter: {
+ type: String,
+ observer: '_filterChanged',
+ },
+ offset: Number,
+ loading: Boolean,
+ path: String,
+ };
+ }
detached() {
+ super.detached();
this.cancelDebouncer('reload');
- },
+ }
_filterChanged(newFilter, oldFilter) {
if (!newFilter && !oldFilter) {
@@ -51,7 +59,7 @@
}
this._debounceReload(newFilter);
- },
+ }
_debounceReload(filter) {
this.debounce('reload', () => {
@@ -61,11 +69,11 @@
}
page.show(this.path);
}, REQUEST_DEBOUNCE_INTERVAL_MS);
- },
+ }
_createNewItem() {
this.fire('create-clicked');
- },
+ }
_computeNavLink(offset, direction, itemsPerPage, filter, path) {
// Offset could be a string when passed from the router.
@@ -79,15 +87,15 @@
href += ',' + newOffset;
}
return href;
- },
+ }
_computeCreateClass(createNew) {
return createNew ? 'show' : '';
- },
+ }
_hidePrevArrow(loading, offset) {
return loading || offset === 0;
- },
+ }
_hideNextArrow(loading, items) {
if (loading || !items || !items.length) {
@@ -95,6 +103,8 @@
}
const lastPage = items.length < this.itemsPerPage + 1;
return lastPage;
- },
- });
+ }
+ }
+
+ customElements.define(GrListView.is, GrListView);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-overlay/gr-overlay.js b/polygerrit-ui/app/elements/shared/gr-overlay/gr-overlay.js
index 8623458..9c7e680 100644
--- a/polygerrit-ui/app/elements/shared/gr-overlay/gr-overlay.js
+++ b/polygerrit-ui/app/elements/shared/gr-overlay/gr-overlay.js
@@ -21,9 +21,16 @@
const AWAIT_STEP = 5;
const BREAKPOINT_FULLSCREEN_OVERLAY = '50em';
- Polymer({
- is: 'gr-overlay',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ */
+ class GrOverlay extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ Polymer.IronOverlayBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-overlay'; }
/**
* Fired when a fullscreen overlay is closed
*
@@ -36,22 +43,22 @@
* @event fullscreen-overlay-opened
*/
- properties: {
- _fullScreenOpen: {
- type: Boolean,
- value: false,
- },
- },
+ static get properties() {
+ return {
+ _fullScreenOpen: {
+ type: Boolean,
+ value: false,
+ },
+ };
+ }
- behaviors: [
- Gerrit.FireBehavior,
- Polymer.IronOverlayBehavior,
- ],
-
- listeners: {
- 'iron-overlay-closed': '_close',
- 'iron-overlay-cancelled': '_close',
- },
+ created() {
+ super.created();
+ this.addEventListener('iron-overlay-closed',
+ () => this._close());
+ this.addEventListener('iron-overlay-cancelled',
+ () => this._close());
+ }
open(...args) {
return new Promise(resolve => {
@@ -62,18 +69,18 @@
}
this._awaitOpen(resolve);
});
- },
+ }
_isMobile() {
return window.matchMedia(`(max-width: ${BREAKPOINT_FULLSCREEN_OVERLAY})`);
- },
+ }
_close() {
if (this._fullScreenOpen) {
this.fire('fullscreen-overlay-closed');
this._fullScreenOpen = false;
}
- },
+ }
/**
* Override the focus stops that iron-overlay-behavior tries to find.
@@ -81,7 +88,7 @@
setFocusStops(stops) {
this.__firstFocusableNode = stops.start;
this.__lastFocusableNode = stops.end;
- },
+ }
/**
* NOTE: (wyatta) Slightly hacky way to listen to the overlay actually
@@ -99,10 +106,12 @@
}, AWAIT_STEP);
};
step.call(this);
- },
+ }
_id() {
return this.getAttribute('id') || 'global';
- },
- });
+ }
+ }
+
+ customElements.define(GrOverlay.is, GrOverlay);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-page-nav/gr-page-nav.js b/polygerrit-ui/app/elements/shared/gr-page-nav/gr-page-nav.js
index 2e05607..23389ee 100644
--- a/polygerrit-ui/app/elements/shared/gr-page-nav/gr-page-nav.js
+++ b/polygerrit-ui/app/elements/shared/gr-page-nav/gr-page-nav.js
@@ -17,20 +17,26 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-page-nav',
+ class GrPageNav extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-page-nav'; }
- properties: {
- _headerHeight: Number,
- },
+ static get properties() {
+ return {
+ _headerHeight: Number,
+ };
+ }
attached() {
+ super.attached();
this.listen(window, 'scroll', '_handleBodyScroll');
- },
+ }
detached() {
+ super.detached();
this.unlisten(window, 'scroll', '_handleBodyScroll');
- },
+ }
_handleBodyScroll() {
if (this._headerHeight === undefined) {
@@ -45,20 +51,22 @@
this.$.nav.classList.toggle('pinned',
this._getScrollY() >= this._headerHeight);
- },
+ }
/* Functions used for test purposes */
_getOffsetParent(element) {
if (!element || !element.offsetParent) { return ''; }
return element.offsetParent;
- },
+ }
_getOffsetTop(element) {
return element.offsetTop;
- },
+ }
_getScrollY() {
return window.scrollY;
- },
- });
+ }
+ }
+
+ customElements.define(GrPageNav.is, GrPageNav);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-repo-branch-picker/gr-repo-branch-picker.js b/polygerrit-ui/app/elements/shared/gr-repo-branch-picker/gr-repo-branch-picker.js
index e2298c3..47979f1 100644
--- a/polygerrit-ui/app/elements/shared/gr-repo-branch-picker/gr-repo-branch-picker.js
+++ b/polygerrit-ui/app/elements/shared/gr-repo-branch-picker/gr-repo-branch-picker.js
@@ -20,47 +20,54 @@
const SUGGESTIONS_LIMIT = 15;
const REF_PREFIX = 'refs/heads/';
- Polymer({
- is: 'gr-repo-branch-picker',
+ /**
+ * @appliesMixin Gerrit.URLEncodingMixin
+ */
+ class GrRepoBranchPicker extends Polymer.mixinBehaviors( [
+ Gerrit.URLEncodingBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-repo-branch-picker'; }
- properties: {
- repo: {
- type: String,
- notify: true,
- observer: '_repoChanged',
- },
- branch: {
- type: String,
- notify: true,
- },
- _branchDisabled: Boolean,
- _query: {
- type: Function,
- value() {
- return this._getRepoBranchesSuggestions.bind(this);
+ static get properties() {
+ return {
+ repo: {
+ type: String,
+ notify: true,
+ observer: '_repoChanged',
},
- },
- _repoQuery: {
- type: Function,
- value() {
- return this._getRepoSuggestions.bind(this);
+ branch: {
+ type: String,
+ notify: true,
},
- },
- },
-
- behaviors: [
- Gerrit.URLEncodingBehavior,
- ],
+ _branchDisabled: Boolean,
+ _query: {
+ type: Function,
+ value() {
+ return this._getRepoBranchesSuggestions.bind(this);
+ },
+ },
+ _repoQuery: {
+ type: Function,
+ value() {
+ return this._getRepoSuggestions.bind(this);
+ },
+ },
+ };
+ }
attached() {
+ super.attached();
if (this.repo) {
this.$.repoInput.setText(this.repo);
}
- },
+ }
ready() {
+ super.ready();
this._branchDisabled = !this.repo;
- },
+ }
_getRepoBranchesSuggestions(input) {
if (!this.repo) { return Promise.resolve([]); }
@@ -69,19 +76,19 @@
}
return this.$.restAPI.getRepoBranches(input, this.repo, SUGGESTIONS_LIMIT)
.then(this._branchResponseToSuggestions.bind(this));
- },
+ }
_getRepoSuggestions(input) {
return this.$.restAPI.getRepos(input, SUGGESTIONS_LIMIT)
.then(this._repoResponseToSuggestions.bind(this));
- },
+ }
_repoResponseToSuggestions(res) {
return res.map(repo => ({
name: repo.name,
value: this.singleDecodeURL(repo.id),
}));
- },
+ }
_branchResponseToSuggestions(res) {
return Object.keys(res).map(key => {
@@ -91,19 +98,21 @@
}
return {name: branch, value: branch};
});
- },
+ }
_repoCommitted(e) {
this.repo = e.detail.value;
- },
+ }
_branchCommitted(e) {
this.branch = e.detail.value;
- },
+ }
_repoChanged() {
this.$.branchInput.clear();
this._branchDisabled = !this.repo;
- },
- });
+ }
+ }
+
+ customElements.define(GrRepoBranchPicker.is, GrRepoBranchPicker);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
index 043a5ed..a1a7f90 100644
--- a/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
+++ b/polygerrit-ui/app/elements/shared/gr-rest-api-interface/gr-rest-api-interface.js
@@ -39,16 +39,21 @@
const ANONYMIZED_REVISION_BASE_URL = ANONYMIZED_CHANGE_BASE_URL +
'/revisions/*';
- Polymer({
- is: 'gr-rest-api-interface',
-
- behaviors: [
- Gerrit.FireBehavior,
- Gerrit.PathListBehavior,
- Gerrit.PatchSetBehavior,
- Gerrit.RESTClientBehavior,
- ],
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ * @appliesMixin Gerrit.PathListMixin
+ * @appliesMixin Gerrit.PatchSetMixin
+ * @appliesMixin Gerrit.RESTClientMixin
+ */
+ class GrRestApiInterface extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ Gerrit.PathListBehavior,
+ Gerrit.PatchSetBehavior,
+ Gerrit.RESTClientBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-rest-api-interface'; }
/**
* Fired when an server error occurs.
*
@@ -73,43 +78,49 @@
* @event rpc-log
*/
- properties: {
- _cache: {
- type: Object,
- value: new SiteBasedCache(), // Shared across instances.
- },
- _credentialCheck: {
- type: Object,
- value: {checking: false}, // Shared across instances.
- },
- _sharedFetchPromises: {
- type: Object,
- value: new FetchPromisesCache(), // Shared across instances.
- },
- _pendingRequests: {
- type: Object,
- value: {}, // Intentional to share the object across instances.
- },
- _etags: {
- type: Object,
- value: new GrEtagDecorator(), // Share across instances.
- },
- /**
+ constructor() {
+ super();
+ this.JSON_PREFIX = JSON_PREFIX;
+ }
+
+ static get properties() {
+ return {
+ _cache: {
+ type: Object,
+ value: new SiteBasedCache(), // Shared across instances.
+ },
+ _credentialCheck: {
+ type: Object,
+ value: {checking: false}, // Shared across instances.
+ },
+ _sharedFetchPromises: {
+ type: Object,
+ value: new FetchPromisesCache(), // Shared across instances.
+ },
+ _pendingRequests: {
+ type: Object,
+ value: {}, // Intentional to share the object across instances.
+ },
+ _etags: {
+ type: Object,
+ value: new GrEtagDecorator(), // Share across instances.
+ },
+ /**
* Used to maintain a mapping of changeNums to project names.
*/
- _projectLookup: {
- type: Object,
- value: {}, // Intentional to share the object across instances.
- },
- _auth: {
- type: Object,
- value: Gerrit.Auth, // Share across instances.
- },
- },
-
- JSON_PREFIX,
+ _projectLookup: {
+ type: Object,
+ value: {}, // Intentional to share the object across instances.
+ },
+ _auth: {
+ type: Object,
+ value: Gerrit.Auth, // Share across instances.
+ },
+ };
+ }
created() {
+ super.created();
/* Polymer 1 and Polymer 2 have slightly different lifecycle.
* Differences are not very well documented (see
* https://github.com/Polymer/old-docs-site/issues/2322).
@@ -130,12 +141,13 @@
//
this._initRestApiHelper();
- },
+ }
ready() {
+ super.ready();
// See comments in created()
this._initRestApiHelper();
- },
+ }
_initRestApiHelper() {
if (this._restApiHelper) {
@@ -146,12 +158,12 @@
this._restApiHelper = new GrRestApiHelper(this._cache, this._auth,
this._sharedFetchPromises, this._credentialCheck, this);
}
- },
+ }
_fetchSharedCacheURL(req) {
// Cache is shared across instances
return this._restApiHelper.fetchCacheURL(req);
- },
+ }
/**
* @param {!Object} response
@@ -159,7 +171,7 @@
*/
getResponseObject(response) {
return this._restApiHelper.getResponseObject(response);
- },
+ }
getConfig(noCache) {
if (!noCache) {
@@ -173,7 +185,7 @@
url: '/config/server/info',
reportUrlAsIs: true,
});
- },
+ }
getRepo(repo, opt_errFn) {
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
@@ -183,7 +195,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*',
});
- },
+ }
getProjectConfig(repo, opt_errFn) {
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
@@ -193,7 +205,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/config',
});
- },
+ }
getRepoAccess(repo) {
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
@@ -202,7 +214,7 @@
url: '/access/?project=' + encodeURIComponent(repo),
anonymizedUrl: '/access/?project=*',
});
- },
+ }
getRepoDashboards(repo, opt_errFn) {
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
@@ -212,7 +224,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/dashboards?inherited',
});
- },
+ }
saveRepoConfig(repo, config, opt_errFn) {
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
@@ -226,7 +238,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/config',
});
- },
+ }
runRepoGC(repo, opt_errFn) {
if (!repo) { return ''; }
@@ -240,7 +252,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/gc',
});
- },
+ }
/**
* @param {?Object} config
@@ -258,7 +270,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*',
});
- },
+ }
/**
* @param {?Object} config
@@ -274,7 +286,7 @@
errFn: opt_errFn,
anonymizedUrl: '/groups/*',
});
- },
+ }
getGroupConfig(group, opt_errFn) {
return this._restApiHelper.fetchJSON({
@@ -282,7 +294,7 @@
errFn: opt_errFn,
anonymizedUrl: '/groups/*/detail',
});
- },
+ }
/**
* @param {string} repo
@@ -302,7 +314,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/branches/*',
});
- },
+ }
/**
* @param {string} repo
@@ -322,7 +334,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/tags/*',
});
- },
+ }
/**
* @param {string} name
@@ -343,7 +355,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/branches/*',
});
- },
+ }
/**
* @param {string} name
@@ -364,7 +376,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/tags/*',
});
- },
+ }
/**
* @param {!string} groupName
@@ -378,7 +390,7 @@
};
return this._fetchSharedCacheURL(req)
.then(configs => configs.hasOwnProperty(groupName));
- },
+ }
getGroupMembers(groupName, opt_errFn) {
const encodeName = encodeURIComponent(groupName);
@@ -387,14 +399,14 @@
errFn: opt_errFn,
anonymizedUrl: '/groups/*/members',
});
- },
+ }
getIncludedGroup(groupName) {
return this._restApiHelper.fetchJSON({
url: `/groups/${encodeURIComponent(groupName)}/groups/`,
anonymizedUrl: '/groups/*/groups',
});
- },
+ }
saveGroupName(groupId, name) {
const encodeId = encodeURIComponent(groupId);
@@ -404,7 +416,7 @@
body: {name},
anonymizedUrl: '/groups/*/name',
});
- },
+ }
saveGroupOwner(groupId, ownerId) {
const encodeId = encodeURIComponent(groupId);
@@ -414,7 +426,7 @@
body: {owner: ownerId},
anonymizedUrl: '/groups/*/owner',
});
- },
+ }
saveGroupDescription(groupId, description) {
const encodeId = encodeURIComponent(groupId);
@@ -424,7 +436,7 @@
body: {description},
anonymizedUrl: '/groups/*/description',
});
- },
+ }
saveGroupOptions(groupId, options) {
const encodeId = encodeURIComponent(groupId);
@@ -434,7 +446,7 @@
body: options,
anonymizedUrl: '/groups/*/options',
});
- },
+ }
getGroupAuditLog(group, opt_errFn) {
return this._fetchSharedCacheURL({
@@ -442,7 +454,7 @@
errFn: opt_errFn,
anonymizedUrl: '/groups/*/log.audit',
});
- },
+ }
saveGroupMembers(groupName, groupMembers) {
const encodeName = encodeURIComponent(groupName);
@@ -453,7 +465,7 @@
parseResponse: true,
anonymizedUrl: '/groups/*/members/*',
});
- },
+ }
saveIncludedGroup(groupName, includedGroup, opt_errFn) {
const encodeName = encodeURIComponent(groupName);
@@ -469,7 +481,7 @@
return this.getResponseObject(response);
}
});
- },
+ }
deleteGroupMembers(groupName, groupMembers) {
const encodeName = encodeURIComponent(groupName);
@@ -479,7 +491,7 @@
url: `/groups/${encodeName}/members/${encodeMember}`,
anonymizedUrl: '/groups/*/members/*',
});
- },
+ }
deleteIncludedGroup(groupName, includedGroup) {
const encodeName = encodeURIComponent(groupName);
@@ -489,14 +501,14 @@
url: `/groups/${encodeName}/groups/${encodeIncludedGroup}`,
anonymizedUrl: '/groups/*/groups/*',
});
- },
+ }
getVersion() {
return this._fetchSharedCacheURL({
url: '/config/server/version',
reportUrlAsIs: true,
});
- },
+ }
getDiffPreferences() {
return this.getLoggedIn().then(loggedIn => {
@@ -527,7 +539,7 @@
theme: 'DEFAULT',
});
});
- },
+ }
getEditPreferences() {
return this.getLoggedIn().then(loggedIn => {
@@ -558,7 +570,7 @@
theme: 'DEFAULT',
});
});
- },
+ }
/**
* @param {?Object} prefs
@@ -578,7 +590,7 @@
errFn: opt_errFn,
reportUrlAsIs: true,
});
- },
+ }
/**
* @param {?Object} prefs
@@ -594,7 +606,7 @@
errFn: opt_errFn,
reportUrlAsIs: true,
});
- },
+ }
/**
* @param {?Object} prefs
@@ -610,7 +622,7 @@
errFn: opt_errFn,
reportUrlAsIs: true,
});
- },
+ }
getAccount() {
return this._fetchSharedCacheURL({
@@ -622,7 +634,7 @@
}
},
});
- },
+ }
getAvatarChangeUrl() {
return this._fetchSharedCacheURL({
@@ -634,14 +646,14 @@
}
},
});
- },
+ }
getExternalIds() {
return this._restApiHelper.fetchJSON({
url: '/accounts/self/external.ids',
reportUrlAsIs: true,
});
- },
+ }
deleteAccountIdentity(id) {
return this._restApiHelper.send({
@@ -651,7 +663,7 @@
parseResponse: true,
reportUrlAsIs: true,
});
- },
+ }
/**
* @param {string} userId the ID of the user usch as an email address.
@@ -662,14 +674,14 @@
url: `/accounts/${encodeURIComponent(userId)}/detail`,
anonymizedUrl: '/accounts/*/detail',
});
- },
+ }
getAccountEmails() {
return this._fetchSharedCacheURL({
url: '/accounts/self/emails',
reportUrlAsIs: true,
});
- },
+ }
/**
* @param {string} email
@@ -682,7 +694,7 @@
errFn: opt_errFn,
anonymizedUrl: '/account/self/emails/*',
});
- },
+ }
/**
* @param {string} email
@@ -695,7 +707,7 @@
errFn: opt_errFn,
anonymizedUrl: '/accounts/self/email/*',
});
- },
+ }
/**
* @param {string} email
@@ -724,7 +736,7 @@
this._cache.set('/accounts/self/emails', emails);
}
});
- },
+ }
/**
* @param {?Object} obj
@@ -738,7 +750,7 @@
this._cache.set('/accounts/self/detail',
Object.assign({}, cachedAccount, obj));
}
- },
+ }
/**
* @param {string} name
@@ -755,7 +767,7 @@
};
return this._restApiHelper.send(req)
.then(newName => this._updateCachedAccount({name: newName}));
- },
+ }
/**
* @param {string} username
@@ -772,7 +784,7 @@
};
return this._restApiHelper.send(req)
.then(newName => this._updateCachedAccount({username: newName}));
- },
+ }
/**
* @param {string} status
@@ -789,28 +801,28 @@
};
return this._restApiHelper.send(req)
.then(newStatus => this._updateCachedAccount({status: newStatus}));
- },
+ }
getAccountStatus(userId) {
return this._restApiHelper.fetchJSON({
url: `/accounts/${encodeURIComponent(userId)}/status`,
anonymizedUrl: '/accounts/*/status',
});
- },
+ }
getAccountGroups() {
return this._restApiHelper.fetchJSON({
url: '/accounts/self/groups',
reportUrlAsIs: true,
});
- },
+ }
getAccountAgreements() {
return this._restApiHelper.fetchJSON({
url: '/accounts/self/agreements',
reportUrlAsIs: true,
});
- },
+ }
saveAccountAgreement(name) {
return this._restApiHelper.send({
@@ -819,7 +831,7 @@
body: name,
reportUrlAsIs: true,
});
- },
+ }
/**
* @param {string=} opt_params
@@ -835,7 +847,7 @@
url: '/accounts/self/capabilities' + queryString,
anonymizedUrl: '/accounts/self/capabilities?q=*',
});
- },
+ }
getLoggedIn() {
return this.getAccount().then(account => {
@@ -843,7 +855,7 @@
}).catch(() => {
return false;
});
- },
+ }
getIsAdmin() {
return this.getLoggedIn().then(isLoggedIn => {
@@ -855,18 +867,18 @@
}).then(capabilities => {
return capabilities && capabilities.administrateServer;
});
- },
+ }
checkCredentials() {
return this._restApiHelper.checkCredentials();
- },
+ }
getDefaultPreferences() {
return this._fetchSharedCacheURL({
url: '/config/server/preferences',
reportUrlAsIs: true,
});
- },
+ }
getPreferences() {
return this.getLoggedIn().then(loggedIn => {
@@ -892,14 +904,14 @@
size_bar_in_change_table: true,
});
});
- },
+ }
getWatchedProjects() {
return this._fetchSharedCacheURL({
url: '/accounts/self/watched.projects',
reportUrlAsIs: true,
});
- },
+ }
/**
* @param {string} projects
@@ -914,7 +926,7 @@
parseResponse: true,
reportUrlAsIs: true,
});
- },
+ }
/**
* @param {string} projects
@@ -928,11 +940,11 @@
errFn: opt_errFn,
reportUrlAsIs: true,
});
- },
+ }
_isNarrowScreen() {
return window.innerWidth < MAX_UNIFIED_DEFAULT_WINDOW_WIDTH_PX;
- },
+ }
/**
* @param {number=} opt_changesPerPage
@@ -988,7 +1000,7 @@
}
return response;
});
- },
+ }
/**
* Inserts a change into _projectLookup iff it has a valid structure.
@@ -998,7 +1010,7 @@
if (change && change.project && change._number) {
this.setInProjectLookup(change._number, change.project);
}
- },
+ }
/**
* TODO (beckysiegel) this needs to be rewritten with the optional param
@@ -1012,7 +1024,7 @@
getChangeActionURL(changeNum, opt_patchNum, endpoint) {
return this._changeBaseURL(changeNum, opt_patchNum)
.then(url => url + endpoint);
- },
+ }
/**
* @param {number|string} changeNum
@@ -1043,7 +1055,7 @@
changeNum, optionsHex, opt_errFn, opt_cancelCondition)
.then(GrReviewerUpdatesParser.parse);
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1059,7 +1071,7 @@
);
return this._getChangeDetail(changeNum, optionsHex, opt_errFn,
opt_cancelCondition);
- },
+ }
/**
* @param {number|string} changeNum
@@ -1109,7 +1121,7 @@
});
});
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1122,7 +1134,7 @@
patchNum,
reportEndpointAsIs: true,
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1143,7 +1155,7 @@
params,
reportEndpointAsIs: true,
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1161,7 +1173,7 @@
endpoint,
anonymizedEndpoint,
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1176,7 +1188,7 @@
patchNum,
anonymizedEndpoint: '/files?q=*',
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1189,7 +1201,7 @@
res.files);
}
return this.getChangeFiles(changeNum, patchRange);
- },
+ }
/**
* The closure compiler doesn't realize this.specialFilePathCompare is
@@ -1201,7 +1213,7 @@
if (!files) return;
return Object.keys(files).sort(this.specialFilePathCompare);
});
- },
+ }
getChangeRevisionActions(changeNum, patchNum) {
const req = {
@@ -1219,7 +1231,7 @@
}
return revisionActions;
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1229,7 +1241,7 @@
getChangeSuggestedReviewers(changeNum, inputVal, opt_errFn) {
return this._getChangeSuggestedGroup('REVIEWER', changeNum, inputVal,
opt_errFn);
- },
+ }
/**
* @param {number|string} changeNum
@@ -1239,7 +1251,7 @@
getChangeSuggestedCCs(changeNum, inputVal, opt_errFn) {
return this._getChangeSuggestedGroup('CC', changeNum, inputVal,
opt_errFn);
- },
+ }
_getChangeSuggestedGroup(reviewerState, changeNum, inputVal, opt_errFn) {
// More suggestions may obscure content underneath in the reply dialog,
@@ -1253,7 +1265,7 @@
params,
reportEndpointAsIs: true,
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1264,7 +1276,7 @@
endpoint: '/in',
reportEndpointAsIs: true,
});
- },
+ }
_computeFilter(filter) {
if (filter && filter.startsWith('^')) {
@@ -1275,7 +1287,7 @@
filter = '';
}
return filter;
- },
+ }
/**
* @param {string} filter
@@ -1287,7 +1299,7 @@
return `/groups/?n=${groupsPerPage + 1}&S=${offset}` +
this._computeFilter(filter);
- },
+ }
/**
* @param {string} filter
@@ -1323,15 +1335,15 @@
return `/projects/?n=${reposPerPage + 1}&S=${offset}` +
`&query=${encodedFilter}`;
- },
+ }
invalidateGroupsCache() {
this._restApiHelper.invalidateFetchPromisesPrefix('/groups/?');
- },
+ }
invalidateReposCache() {
this._restApiHelper.invalidateFetchPromisesPrefix('/projects/?');
- },
+ }
/**
* @param {string} filter
@@ -1346,7 +1358,7 @@
url,
anonymizedUrl: '/groups/?*',
});
- },
+ }
/**
* @param {string} filter
@@ -1363,7 +1375,7 @@
url,
anonymizedUrl: '/projects/?*',
});
- },
+ }
setRepoHead(repo, ref) {
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
@@ -1374,7 +1386,7 @@
body: {ref},
anonymizedUrl: '/projects/*/HEAD',
});
- },
+ }
/**
* @param {string} filter
@@ -1397,7 +1409,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/branches?*',
});
- },
+ }
/**
* @param {string} filter
@@ -1421,7 +1433,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/tags',
});
- },
+ }
/**
* @param {string} filter
@@ -1440,7 +1452,7 @@
errFn: opt_errFn,
anonymizedUrl: '/plugins/?all',
});
- },
+ }
getRepoAccessRights(repoName, opt_errFn) {
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
@@ -1450,7 +1462,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/access',
});
- },
+ }
setRepoAccessRights(repoName, repoInfo) {
// TODO(kaspern): Rename rest api from /projects/ to /repos/ once backend
@@ -1461,7 +1473,7 @@
body: repoInfo,
anonymizedUrl: '/projects/*/access',
});
- },
+ }
setRepoAccessRightsForReview(projectName, projectInfo) {
return this._restApiHelper.send({
@@ -1471,7 +1483,7 @@
parseResponse: true,
anonymizedUrl: '/projects/*/access:review',
});
- },
+ }
/**
* @param {string} inputVal
@@ -1487,7 +1499,7 @@
params,
reportUrlAsIs: true,
});
- },
+ }
/**
* @param {string} inputVal
@@ -1507,7 +1519,7 @@
params,
reportUrlAsIs: true,
});
- },
+ }
/**
* @param {string} inputVal
@@ -1526,15 +1538,15 @@
params,
anonymizedUrl: '/accounts/?n=*',
});
- },
+ }
addChangeReviewer(changeNum, reviewerID) {
return this._sendChangeReviewerRequest('POST', changeNum, reviewerID);
- },
+ }
removeChangeReviewer(changeNum, reviewerID) {
return this._sendChangeReviewerRequest('DELETE', changeNum, reviewerID);
- },
+ }
_sendChangeReviewerRequest(method, changeNum, reviewerID) {
return this.getChangeActionURL(changeNum, null, '/reviewers')
@@ -1553,7 +1565,7 @@
return this._restApiHelper.send({method, url, body});
});
- },
+ }
getRelatedChanges(changeNum, patchNum) {
return this._getChangeURLAndFetch({
@@ -1562,7 +1574,7 @@
patchNum,
reportEndpointAsIs: true,
});
- },
+ }
getChangesSubmittedTogether(changeNum) {
return this._getChangeURLAndFetch({
@@ -1570,7 +1582,7 @@
endpoint: '/submitted_together?o=NON_VISIBLE_CHANGES',
reportEndpointAsIs: true,
});
- },
+ }
getChangeConflicts(changeNum) {
const options = this.listChangesOptionsToHex(
@@ -1586,7 +1598,7 @@
params,
anonymizedUrl: '/changes/conflicts:*',
});
- },
+ }
getChangeCherryPicks(project, changeID, changeNum) {
const options = this.listChangesOptionsToHex(
@@ -1608,7 +1620,7 @@
params,
anonymizedUrl: '/changes/change:*',
});
- },
+ }
getChangesWithSameTopic(topic, changeNum) {
const options = this.listChangesOptionsToHex(
@@ -1631,7 +1643,7 @@
params,
anonymizedUrl: '/changes/topic:*',
});
- },
+ }
getReviewedFiles(changeNum, patchNum) {
return this._getChangeURLAndFetch({
@@ -1640,7 +1652,7 @@
patchNum,
reportEndpointAsIs: true,
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1658,7 +1670,7 @@
errFn: opt_errFn,
anonymizedEndpoint: '/files/*/reviewed',
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1679,7 +1691,7 @@
errFn: opt_errFn,
});
});
- },
+ }
getChangeEdit(changeNum, opt_download_commands) {
const params = opt_download_commands ? {'download-commands': true} : null;
@@ -1692,7 +1704,7 @@
reportEndpointAsIs: true,
});
});
- },
+ }
/**
* @param {string} project
@@ -1722,7 +1734,7 @@
parseResponse: true,
reportUrlAsIs: true,
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1750,7 +1762,7 @@
return {content, type, ok: true};
});
});
- },
+ }
/**
* Gets a file in a specific change and revision.
@@ -1769,7 +1781,7 @@
headers: {Accept: 'application/json'},
anonymizedEndpoint: '/files/*/content',
});
- },
+ }
/**
* Gets a file in a change edit.
@@ -1784,7 +1796,7 @@
headers: {Accept: 'application/json'},
anonymizedEndpoint: '/edit/*',
});
- },
+ }
rebaseChangeEdit(changeNum) {
return this._getChangeURLAndSend({
@@ -1793,7 +1805,7 @@
endpoint: '/edit:rebase',
reportEndpointAsIs: true,
});
- },
+ }
deleteChangeEdit(changeNum) {
return this._getChangeURLAndSend({
@@ -1802,7 +1814,7 @@
endpoint: '/edit',
reportEndpointAsIs: true,
});
- },
+ }
restoreFileInChangeEdit(changeNum, restore_path) {
return this._getChangeURLAndSend({
@@ -1812,7 +1824,7 @@
body: {restore_path},
reportEndpointAsIs: true,
});
- },
+ }
renameFileInChangeEdit(changeNum, old_path, new_path) {
return this._getChangeURLAndSend({
@@ -1822,7 +1834,7 @@
body: {old_path, new_path},
reportEndpointAsIs: true,
});
- },
+ }
deleteFileInChangeEdit(changeNum, path) {
return this._getChangeURLAndSend({
@@ -1831,7 +1843,7 @@
endpoint: '/edit/' + encodeURIComponent(path),
anonymizedEndpoint: '/edit/*',
});
- },
+ }
saveChangeEdit(changeNum, path, contents) {
return this._getChangeURLAndSend({
@@ -1842,7 +1854,7 @@
contentType: 'text/plain',
anonymizedEndpoint: '/edit/*',
});
- },
+ }
// Deprecated, prefer to use putChangeCommitMessage instead.
saveChangeCommitMessageEdit(changeNum, message) {
@@ -1853,7 +1865,7 @@
body: {message},
reportEndpointAsIs: true,
});
- },
+ }
publishChangeEdit(changeNum) {
return this._getChangeURLAndSend({
@@ -1862,7 +1874,7 @@
endpoint: '/edit:publish',
reportEndpointAsIs: true,
});
- },
+ }
putChangeCommitMessage(changeNum, message) {
return this._getChangeURLAndSend({
@@ -1872,7 +1884,7 @@
body: {message},
reportEndpointAsIs: true,
});
- },
+ }
saveChangeStarred(changeNum, starred) {
// Some servers may require the project name to be provided
@@ -1887,7 +1899,7 @@
anonymizedUrl: '/accounts/self/starred.changes/*',
});
});
- },
+ }
saveChangeReviewed(changeNum, reviewed) {
return this._getChangeURLAndSend({
@@ -1895,7 +1907,7 @@
method: 'PUT',
endpoint: reviewed ? '/reviewed' : '/unreviewed',
});
- },
+ }
/**
* Public version of the _restApiHelper.send method preserved for plugins.
@@ -1919,7 +1931,7 @@
contentType: opt_contentType,
headers: opt_headers,
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -1961,7 +1973,7 @@
}
return this._getChangeURLAndFetch(req);
- },
+ }
/**
* @param {number|string} changeNum
@@ -1973,7 +1985,7 @@
getDiffComments(changeNum, opt_basePatchNum, opt_patchNum, opt_path) {
return this._getDiffComments(changeNum, '/comments', opt_basePatchNum,
opt_patchNum, opt_path);
- },
+ }
/**
* @param {number|string} changeNum
@@ -1985,7 +1997,7 @@
getDiffRobotComments(changeNum, opt_basePatchNum, opt_patchNum, opt_path) {
return this._getDiffComments(changeNum, '/robotcomments',
opt_basePatchNum, opt_patchNum, opt_path);
- },
+ }
/**
* If the user is logged in, fetch the user's draft diff comments. If there
@@ -2004,7 +2016,7 @@
return this._getDiffComments(changeNum, '/drafts', opt_basePatchNum,
opt_patchNum, opt_path);
});
- },
+ }
_setRange(comments, comment) {
if (comment.in_reply_to && !comment.range) {
@@ -2016,7 +2028,7 @@
}
}
return comment;
- },
+ }
_setRanges(comments) {
comments = comments || [];
@@ -2027,7 +2039,7 @@
this._setRange(comments, comment);
}
return comments;
- },
+ }
/**
* @param {number|string} changeNum
@@ -2100,7 +2112,7 @@
comments,
});
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -2110,15 +2122,15 @@
_getDiffCommentsFetchURL(changeNum, endpoint, opt_patchNum) {
return this._changeBaseURL(changeNum, opt_patchNum)
.then(url => url + endpoint);
- },
+ }
saveDiffDraft(changeNum, patchNum, draft) {
return this._sendDiffDraftRequest('PUT', changeNum, patchNum, draft);
- },
+ }
deleteDiffDraft(changeNum, patchNum, draft) {
return this._sendDiffDraftRequest('DELETE', changeNum, patchNum, draft);
- },
+ }
/**
* @returns {boolean} Whether there are pending diff draft sends.
@@ -2126,7 +2138,7 @@
hasPendingDiffDrafts() {
const promises = this._pendingRequests[Requests.SEND_DIFF_DRAFT];
return promises && promises.length;
- },
+ }
/**
* @returns {!Promise<undefined>} A promise that resolves when all pending
@@ -2137,7 +2149,7 @@
.then(() => {
this._pendingRequests[Requests.SEND_DIFF_DRAFT] = [];
});
- },
+ }
_sendDiffDraftRequest(method, changeNum, patchNum, draft) {
const isCreate = !draft.id && method === 'PUT';
@@ -2173,7 +2185,7 @@
}
return promise;
- },
+ }
getCommitInfo(project, commit) {
return this._restApiHelper.fetchJSON({
@@ -2181,7 +2193,7 @@
'/commits/' + encodeURIComponent(commit),
anonymizedUrl: '/projects/*/comments/*',
});
- },
+ }
_fetchB64File(url) {
return this._restApiHelper.fetch({url: this.getBaseUrl() + url})
@@ -2195,7 +2207,7 @@
return {body: text, type};
});
});
- },
+ }
/**
* @param {string} changeId
@@ -2210,7 +2222,7 @@
url = `${url}/files/${encodeURIComponent(path)}/content${parent}`;
return this._fetchB64File(url);
});
- },
+ }
getImagesForDiff(changeNum, diff, patchRange) {
let promiseA;
@@ -2252,7 +2264,7 @@
return {baseImage, revisionImage};
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -2273,7 +2285,7 @@
}
return url;
});
- },
+ }
/**
* @suppress {checkTypes}
@@ -2289,7 +2301,7 @@
parseResponse: true,
reportUrlAsIs: true,
});
- },
+ }
/**
* @suppress {checkTypes}
@@ -2305,7 +2317,7 @@
parseResponse: true,
reportUrlAsIs: true,
});
- },
+ }
deleteAccountHttpPassword() {
return this._restApiHelper.send({
@@ -2313,7 +2325,7 @@
url: '/accounts/self/password.http',
reportUrlAsIs: true,
});
- },
+ }
/**
* @suppress {checkTypes}
@@ -2328,14 +2340,14 @@
parseResponse: true,
reportUrlAsIs: true,
});
- },
+ }
getAccountSSHKeys() {
return this._fetchSharedCacheURL({
url: '/accounts/self/sshkeys',
reportUrlAsIs: true,
});
- },
+ }
addAccountSSHKey(key) {
const req = {
@@ -2356,7 +2368,7 @@
if (!obj.valid) { return Promise.reject(new Error('error')); }
return obj;
});
- },
+ }
deleteAccountSSHKey(id) {
return this._restApiHelper.send({
@@ -2364,14 +2376,14 @@
url: '/accounts/self/sshkeys/' + id,
anonymizedUrl: '/accounts/self/sshkeys/*',
});
- },
+ }
getAccountGPGKeys() {
return this._restApiHelper.fetchJSON({
url: '/accounts/self/gpgkeys',
reportUrlAsIs: true,
});
- },
+ }
addAccountGPGKey(key) {
const req = {
@@ -2391,7 +2403,7 @@
if (!obj) { return Promise.reject(new Error('error')); }
return obj;
});
- },
+ }
deleteAccountGPGKey(id) {
return this._restApiHelper.send({
@@ -2399,7 +2411,7 @@
url: '/accounts/self/gpgkeys/' + id,
anonymizedUrl: '/accounts/self/gpgkeys/*',
});
- },
+ }
deleteVote(changeNum, account, label) {
return this._getChangeURLAndSend({
@@ -2408,7 +2420,7 @@
endpoint: `/reviewers/${account}/votes/${encodeURIComponent(label)}`,
anonymizedEndpoint: '/reviewers/*/votes/*',
});
- },
+ }
setDescription(changeNum, patchNum, desc) {
return this._getChangeURLAndSend({
@@ -2418,7 +2430,7 @@
body: {description: desc},
reportUrlAsIs: true,
});
- },
+ }
confirmEmail(token) {
const req = {
@@ -2433,7 +2445,7 @@
}
return null;
});
- },
+ }
getCapabilities(opt_errFn) {
return this._restApiHelper.fetchJSON({
@@ -2441,7 +2453,7 @@
errFn: opt_errFn,
reportUrlAsIs: true,
});
- },
+ }
getTopMenus(opt_errFn) {
return this._fetchSharedCacheURL({
@@ -2449,7 +2461,7 @@
errFn: opt_errFn,
reportUrlAsIs: true,
});
- },
+ }
setAssignee(changeNum, assignee) {
return this._getChangeURLAndSend({
@@ -2459,7 +2471,7 @@
body: {assignee},
reportUrlAsIs: true,
});
- },
+ }
deleteAssignee(changeNum) {
return this._getChangeURLAndSend({
@@ -2468,14 +2480,14 @@
endpoint: '/assignee',
reportUrlAsIs: true,
});
- },
+ }
probePath(path) {
return fetch(new Request(path, {method: 'HEAD'}))
.then(response => {
return response.ok;
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -2498,7 +2510,7 @@
return 'Change marked as Work In Progress.';
}
});
- },
+ }
/**
* @param {number|string} changeNum
@@ -2514,7 +2526,7 @@
errFn: opt_errFn,
reportUrlAsIs: true,
});
- },
+ }
/**
* @suppress {checkTypes}
@@ -2531,7 +2543,7 @@
parseResponse: true,
anonymizedEndpoint: '/comments/*/delete',
});
- },
+ }
/**
* Given a changeNum, gets the change.
@@ -2550,7 +2562,7 @@
if (!res || !res.length) { return null; }
return res[0];
});
- },
+ }
/**
* @param {string|number} changeNum
@@ -2563,7 +2575,7 @@
'One of them must be invalid.');
}
this._projectLookup[changeNum] = project;
- },
+ }
/**
* Checks in _projectLookup for the changeNum. If it exists, returns the
@@ -2587,7 +2599,7 @@
this.setInProjectLookup(changeNum, change.project);
return change.project;
});
- },
+ }
/**
* Alias for _changeBaseURL.then(send).
@@ -2614,7 +2626,7 @@
(anonymizedBaseUrl + anonymizedEndpoint) : undefined,
});
});
- },
+ }
/**
* Alias for _changeBaseURL.then(_fetchJSON).
@@ -2636,7 +2648,7 @@
(anonymizedBaseUrl + anonymizedEndpoint) : undefined,
});
});
- },
+ }
/**
* Execute a change action or revision action on a change.
@@ -2658,7 +2670,7 @@
body: opt_payload,
errFn: opt_errFn,
});
- },
+ }
/**
* Get blame information for the given diff.
@@ -2678,7 +2690,7 @@
params: opt_base ? {base: 't'} : undefined,
anonymizedEndpoint: '/files/*/blame',
});
- },
+ }
/**
* Modify the given create draft request promise so that it fails and throws
@@ -2707,7 +2719,7 @@
}
return result;
});
- },
+ }
/**
* Fetch a project dashboard definition.
@@ -2726,7 +2738,7 @@
errFn: opt_errFn,
anonymizedUrl: '/projects/*/dashboards/*',
});
- },
+ }
/**
* @param {string} filter
@@ -2742,7 +2754,7 @@
url: `/Documentation/?q=${encodedFilter}`,
anonymizedUrl: '/Documentation/?*',
});
- },
+ }
getMergeable(changeNum) {
return this._getChangeURLAndFetch({
@@ -2751,7 +2763,7 @@
parseResponse: true,
reportEndpointAsIs: true,
});
- },
+ }
deleteDraftComments(query) {
return this._restApiHelper.send({
@@ -2759,6 +2771,8 @@
url: '/accounts/self/drafts:delete',
body: {query},
});
- },
- });
+ }
+ }
+
+ customElements.define(GrRestApiInterface.is, GrRestApiInterface);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-select/gr-select.js b/polygerrit-ui/app/elements/shared/gr-select/gr-select.js
index 05267ba..152834f 100644
--- a/polygerrit-ui/app/elements/shared/gr-select/gr-select.js
+++ b/polygerrit-ui/app/elements/shared/gr-select/gr-select.js
@@ -17,29 +17,29 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-select',
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ */
+ class GrSelect extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-select'; }
- properties: {
- bindValue: {
- type: String,
- notify: true,
- observer: '_updateValue',
- },
- },
-
- behaviors: [
- Gerrit.FireBehavior,
- ],
-
- listeners: {
- 'change': '_valueChanged',
- 'dom-change': '_updateValue',
- },
+ static get properties() {
+ return {
+ bindValue: {
+ type: String,
+ notify: true,
+ observer: '_updateValue',
+ },
+ };
+ }
get nativeSelect() {
return this.$$('select');
- },
+ }
_updateValue() {
// It's possible to have a value of 0.
@@ -53,21 +53,32 @@
this.nativeSelect.value = this.bindValue;
}, 1);
}
- },
+ }
_valueChanged() {
this.bindValue = this.nativeSelect.value;
- },
+ }
focus() {
this.nativeSelect.focus();
- },
+ }
+
+ created() {
+ super.created();
+ this.addEventListener('change',
+ () => this._valueChanged());
+ this.addEventListener('dom-change',
+ () => this._updateValue());
+ }
ready() {
+ super.ready();
// If not set via the property, set bind-value to the element value.
if (this.bindValue == undefined && this.nativeSelect.options.length > 0) {
this.bindValue = this.nativeSelect.value;
}
- },
- });
+ }
+ }
+
+ customElements.define(GrSelect.is, GrSelect);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-shell-command/gr-shell-command.js b/polygerrit-ui/app/elements/shared/gr-shell-command/gr-shell-command.js
index 2c546cc..9456991 100644
--- a/polygerrit-ui/app/elements/shared/gr-shell-command/gr-shell-command.js
+++ b/polygerrit-ui/app/elements/shared/gr-shell-command/gr-shell-command.js
@@ -17,16 +17,22 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-shell-command',
+ class GrShellCommand extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-shell-command'; }
- properties: {
- command: String,
- label: String,
- },
+ static get properties() {
+ return {
+ command: String,
+ label: String,
+ };
+ }
focusOnCopy() {
this.$$('gr-copy-clipboard').focusOnCopy();
- },
- });
+ }
+ }
+
+ customElements.define(GrShellCommand.is, GrShellCommand);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-storage/gr-storage.js b/polygerrit-ui/app/elements/shared/gr-storage/gr-storage.js
index f6ade6e..7950e51 100644
--- a/polygerrit-ui/app/elements/shared/gr-storage/gr-storage.js
+++ b/polygerrit-ui/app/elements/shared/gr-storage/gr-storage.js
@@ -28,52 +28,56 @@
'editablecontent:',
];
- Polymer({
- is: 'gr-storage',
+ class GrStorage extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-storage'; }
- properties: {
- _lastCleanup: Number,
- /** @type {?Storage} */
- _storage: {
- type: Object,
- value() {
- return window.localStorage;
+ static get properties() {
+ return {
+ _lastCleanup: Number,
+ /** @type {?Storage} */
+ _storage: {
+ type: Object,
+ value() {
+ return window.localStorage;
+ },
},
- },
- _exceededQuota: {
- type: Boolean,
- value: false,
- },
- },
+ _exceededQuota: {
+ type: Boolean,
+ value: false,
+ },
+ };
+ }
getDraftComment(location) {
this._cleanupItems();
return this._getObject(this._getDraftKey(location));
- },
+ }
setDraftComment(location, message) {
const key = this._getDraftKey(location);
this._setObject(key, {message, updated: Date.now()});
- },
+ }
eraseDraftComment(location) {
const key = this._getDraftKey(location);
this._storage.removeItem(key);
- },
+ }
getEditableContentItem(key) {
this._cleanupItems();
return this._getObject(this._getEditableContentKey(key));
- },
+ }
setEditableContentItem(key, message) {
this._setObject(this._getEditableContentKey(key),
{message, updated: Date.now()});
- },
+ }
eraseEditableContentItem(key) {
this._storage.removeItem(this._getEditableContentKey(key));
- },
+ }
_getDraftKey(location) {
const range = location.range ?
@@ -86,11 +90,11 @@
key = key + ':' + range;
}
return key;
- },
+ }
_getEditableContentKey(key) {
return `editablecontent:${key}`;
- },
+ }
_cleanupItems() {
// Throttle cleanup to the throttle interval.
@@ -113,13 +117,13 @@
}
}
}
- },
+ }
_getObject(key) {
const serial = this._storage.getItem(key);
if (!serial) { return null; }
return JSON.parse(serial);
- },
+ }
_setObject(key, obj) {
if (this._exceededQuota) { return; }
@@ -136,6 +140,8 @@
throw exc;
}
}
- },
- });
+ }
+ }
+
+ customElements.define(GrStorage.is, GrStorage);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-textarea/gr-textarea.js b/polygerrit-ui/app/elements/shared/gr-textarea/gr-textarea.js
index 4c4b038..5011067 100644
--- a/polygerrit-ui/app/elements/shared/gr-textarea/gr-textarea.js
+++ b/polygerrit-ui/app/elements/shared/gr-textarea/gr-textarea.js
@@ -52,73 +52,81 @@
{value: '😜', match: 'winking tongue ;)'},
];
- Polymer({
- is: 'gr-textarea',
-
+ /**
+ * @appliesMixin Gerrit.FireMixin
+ * @appliesMixin Gerrit.KeyboardShortcutMixin
+ */
+ class GrTextarea extends Polymer.mixinBehaviors( [
+ Gerrit.FireBehavior,
+ Gerrit.KeyboardShortcutBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-textarea'; }
/**
* @event bind-value-changed
*/
- properties: {
- autocomplete: Boolean,
- disabled: Boolean,
- rows: Number,
- maxRows: Number,
- placeholder: String,
- text: {
- type: String,
- notify: true,
- observer: '_handleTextChanged',
- },
- hideBorder: {
- type: Boolean,
- value: false,
- },
- /** Text input should be rendered in monspace font. */
- monospace: {
- type: Boolean,
- value: false,
- },
- /** Text input should be rendered in code font, which is smaller than the
+ static get properties() {
+ return {
+ autocomplete: Boolean,
+ disabled: Boolean,
+ rows: Number,
+ maxRows: Number,
+ placeholder: String,
+ text: {
+ type: String,
+ notify: true,
+ observer: '_handleTextChanged',
+ },
+ hideBorder: {
+ type: Boolean,
+ value: false,
+ },
+ /** Text input should be rendered in monspace font. */
+ monospace: {
+ type: Boolean,
+ value: false,
+ },
+ /** Text input should be rendered in code font, which is smaller than the
standard monospace font. */
- code: {
- type: Boolean,
- value: false,
- },
- /** @type(?number) */
- _colonIndex: Number,
- _currentSearchString: {
- type: String,
- observer: '_determineSuggestions',
- },
- _hideAutocomplete: {
- type: Boolean,
- value: true,
- },
- _index: Number,
- _suggestions: Array,
- // Offset makes dropdown appear below text.
- _verticalOffset: {
- type: Number,
- value: 20,
- readOnly: true,
- },
- },
+ code: {
+ type: Boolean,
+ value: false,
+ },
+ /** @type(?number) */
+ _colonIndex: Number,
+ _currentSearchString: {
+ type: String,
+ observer: '_determineSuggestions',
+ },
+ _hideAutocomplete: {
+ type: Boolean,
+ value: true,
+ },
+ _index: Number,
+ _suggestions: Array,
+ // Offset makes dropdown appear below text.
+ _verticalOffset: {
+ type: Number,
+ value: 20,
+ readOnly: true,
+ },
+ };
+ }
- behaviors: [
- Gerrit.FireBehavior,
- Gerrit.KeyboardShortcutBehavior,
- ],
-
- keyBindings: {
- esc: '_handleEscKey',
- tab: '_handleEnterByKey',
- enter: '_handleEnterByKey',
- up: '_handleUpKey',
- down: '_handleDownKey',
- },
+ get keyBindings() {
+ return {
+ esc: '_handleEscKey',
+ tab: '_handleEnterByKey',
+ enter: '_handleEnterByKey',
+ up: '_handleUpKey',
+ down: '_handleDownKey',
+ };
+ }
ready() {
+ super.ready();
if (this.monospace) {
this.classList.add('monospace');
}
@@ -128,15 +136,15 @@
if (this.hideBorder) {
this.$.textarea.classList.add('noBorder');
}
- },
+ }
closeDropdown() {
return this.$.emojiSuggestions.close();
- },
+ }
getNativeTextarea() {
return this.$.textarea.textarea;
- },
+ }
putCursorAtEnd() {
const textarea = this.getNativeTextarea();
@@ -146,14 +154,14 @@
this.async(() => {
textarea.focus();
});
- },
+ }
_handleEscKey(e) {
if (this._hideAutocomplete) { return; }
e.preventDefault();
e.stopPropagation();
this._resetEmojiDropdown();
- },
+ }
_handleUpKey(e) {
if (this._hideAutocomplete) { return; }
@@ -162,7 +170,7 @@
this.$.emojiSuggestions.cursorUp();
this.$.textarea.textarea.focus();
this.disableEnterKeyForSelectingEmoji = false;
- },
+ }
_handleDownKey(e) {
if (this._hideAutocomplete) { return; }
@@ -171,7 +179,7 @@
this.$.emojiSuggestions.cursorDown();
this.$.textarea.textarea.focus();
this.disableEnterKeyForSelectingEmoji = false;
- },
+ }
_handleEnterByKey(e) {
if (this._hideAutocomplete || this.disableEnterKeyForSelectingEmoji) {
@@ -180,11 +188,11 @@
e.preventDefault();
e.stopPropagation();
this._setEmoji(this.$.emojiSuggestions.getCurrentText());
- },
+ }
_handleEmojiSelect(e) {
this._setEmoji(e.detail.selected.dataset.value);
- },
+ }
_setEmoji(text) {
const colonIndex = this._colonIndex;
@@ -193,12 +201,13 @@
this.$.textarea.selectionEnd = colonIndex + 1;
this.$.reporting.reportInteraction('select-emoji');
this._resetEmojiDropdown();
- },
+ }
_getText(value) {
return this.text.substr(0, this._colonIndex || 0) +
value + this.text.substr(this.$.textarea.selectionStart);
- },
+ }
+
/**
* Uses a hidden element with the same width and styling of the textarea and
* the text up until the point of interest. Then caratSpan element is added
@@ -214,17 +223,17 @@
this.$.hiddenText.appendChild(caratSpan);
this.$.emojiSuggestions.positionTarget = caratSpan;
this._openEmojiDropdown();
- },
+ }
_getFontSize() {
const fontSizePx = getComputedStyle(this).fontSize || '12px';
return parseInt(fontSizePx.substr(0, fontSizePx.length - 2),
10);
- },
+ }
_getScrollTop() {
return document.body.scrollTop;
- },
+ }
/**
* _handleKeydown used for key handling in the this.$.textarea AND all child
@@ -271,12 +280,12 @@
this._updateCaratPosition();
}
this.$.textarea.textarea.focus();
- },
+ }
_openEmojiDropdown() {
this.$.emojiSuggestions.open();
this.$.reporting.reportInteraction('open-emoji-dropdown');
- },
+ }
_formatSuggestions(matchedSuggestions) {
const suggestions = [];
@@ -286,7 +295,7 @@
suggestions.push(suggestion);
}
this.set('_suggestions', suggestions);
- },
+ }
_determineSuggestions(emojiText) {
if (!emojiText.length) {
@@ -299,7 +308,7 @@
this._formatSuggestions(matches);
this.disableEnterKeyForSelectingEmoji = false;
}
- },
+ }
_resetEmojiDropdown() {
// hide and reset the autocomplete dropdown.
@@ -309,11 +318,13 @@
this.closeDropdown();
this._colonIndex = null;
this.$.textarea.textarea.focus();
- },
+ }
_handleTextChanged(text) {
this.dispatchEvent(
new CustomEvent('value-changed', {detail: {value: text}}));
- },
- });
+ }
+ }
+
+ customElements.define(GrTextarea.is, GrTextarea);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-tooltip-content/gr-tooltip-content.js b/polygerrit-ui/app/elements/shared/gr-tooltip-content/gr-tooltip-content.js
index c5de8f4..3559949 100644
--- a/polygerrit-ui/app/elements/shared/gr-tooltip-content/gr-tooltip-content.js
+++ b/polygerrit-ui/app/elements/shared/gr-tooltip-content/gr-tooltip-content.js
@@ -17,31 +17,38 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-tooltip-content',
+ /**
+ * @appliesMixin Gerrit.TooltipMixin
+ */
+ class GrTooltipContent extends Polymer.mixinBehaviors( [
+ Gerrit.TooltipBehavior,
+ ], Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element))) {
+ static get is() { return 'gr-tooltip-content'; }
- properties: {
- title: {
- type: String,
- reflectToAttribute: true,
- },
- maxWidth: {
- type: String,
- reflectToAttribute: true,
- },
- positionBelow: {
- type: Boolean,
- valye: false,
- reflectToAttribute: true,
- },
- showIcon: {
- type: Boolean,
- value: false,
- },
- },
+ static get properties() {
+ return {
+ title: {
+ type: String,
+ reflectToAttribute: true,
+ },
+ maxWidth: {
+ type: String,
+ reflectToAttribute: true,
+ },
+ positionBelow: {
+ type: Boolean,
+ valye: false,
+ reflectToAttribute: true,
+ },
+ showIcon: {
+ type: Boolean,
+ value: false,
+ },
+ };
+ }
+ }
- behaviors: [
- Gerrit.TooltipBehavior,
- ],
- });
+ customElements.define(GrTooltipContent.is, GrTooltipContent);
})();
diff --git a/polygerrit-ui/app/elements/shared/gr-tooltip/gr-tooltip.js b/polygerrit-ui/app/elements/shared/gr-tooltip/gr-tooltip.js
index fb87b558..170a442 100644
--- a/polygerrit-ui/app/elements/shared/gr-tooltip/gr-tooltip.js
+++ b/polygerrit-ui/app/elements/shared/gr-tooltip/gr-tooltip.js
@@ -17,23 +17,29 @@
(function() {
'use strict';
- Polymer({
- is: 'gr-tooltip',
+ class GrTooltip extends Polymer.GestureEventListeners(
+ Polymer.LegacyElementMixin(
+ Polymer.Element)) {
+ static get is() { return 'gr-tooltip'; }
- properties: {
- text: String,
- maxWidth: {
- type: String,
- observer: '_updateWidth',
- },
- positionBelow: {
- type: Boolean,
- reflectToAttribute: true,
- },
- },
+ static get properties() {
+ return {
+ text: String,
+ maxWidth: {
+ type: String,
+ observer: '_updateWidth',
+ },
+ positionBelow: {
+ type: Boolean,
+ reflectToAttribute: true,
+ },
+ };
+ }
_updateWidth(maxWidth) {
this.updateStyles({'--tooltip-max-width': maxWidth});
- },
- });
+ }
+ }
+
+ customElements.define(GrTooltip.is, GrTooltip);
})();