summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js')
-rw-r--r--polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js196
1 files changed, 117 insertions, 79 deletions
diff --git a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js
index 769ef99d78..61c64ffe26 100644
--- a/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js
+++ b/polygerrit-ui/app/elements/change-list/gr-change-list/gr-change-list.js
@@ -1,20 +1,26 @@
-// Copyright (C) 2016 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+/**
+ * @license
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
(function() {
'use strict';
const NUMBER_FIXED_COLUMNS = 3;
+ const CLOSED_STATUS = ['MERGED', 'ABANDONED'];
+ const LABEL_PREFIX_INVALID_PROLOG = 'Invalid-Prolog-Rules-Label-Name--';
+ const MAX_SHORTCUT_CHARS = 5;
Polymer({
is: 'gr-change-list',
@@ -42,7 +48,7 @@
*/
account: {
type: Object,
- value() { return {}; },
+ value: null,
},
/**
* An array of ChangeInfo objects to render.
@@ -89,6 +95,7 @@
},
changeTableColumns: Array,
visibleChangeTableColumns: Array,
+ preferences: Object,
},
behaviors: [
@@ -99,20 +106,28 @@
Gerrit.URLEncodingBehavior,
],
- keyBindings: {
- 'j': '_handleJKey',
- 'k': '_handleKKey',
- 'n ]': '_handleNKey',
- 'o': '_handleOKey',
- 'p [': '_handlePKey',
- 'shift+r': '_handleRKey',
- 's': '_handleSKey',
- },
-
listeners: {
keydown: '_scopedKeydownHandler',
},
+ observers: [
+ '_sectionsChanged(sections.*)',
+ '_computePreferences(account, preferences)',
+ ],
+
+ keyboardShortcuts() {
+ return {
+ [this.Shortcut.CURSOR_NEXT_CHANGE]: '_nextChange',
+ [this.Shortcut.CURSOR_PREV_CHANGE]: '_prevChange',
+ [this.Shortcut.NEXT_PAGE]: '_nextPage',
+ [this.Shortcut.PREV_PAGE]: '_prevPage',
+ [this.Shortcut.OPEN_CHANGE]: '_openChange',
+ [this.Shortcut.TOGGLE_CHANGE_REVIEWED]: '_toggleChangeReviewed',
+ [this.Shortcut.TOGGLE_CHANGE_STAR]: '_toggleChangeStar',
+ [this.Shortcut.REFRESH_CHANGE_LIST]: '_refreshChangeList',
+ };
+ },
+
/**
* Iron-a11y-keys-behavior catches keyboard events globally. Some keyboard
* events must be scoped to a component level (e.g. `enter`) in order to not
@@ -123,42 +138,27 @@
_scopedKeydownHandler(e) {
if (e.keyCode === 13) {
// Enter.
- this._handleOKey(e);
+ this._openChange(e);
}
},
- attached() {
- this._loadPreferences();
- },
-
_lowerCase(column) {
return column.toLowerCase();
},
- _loadPreferences() {
- return this._getLoggedIn().then(loggedIn => {
- this.changeTableColumns = this.columnNames;
-
- if (!loggedIn) {
- this.showNumber = false;
- this.visibleChangeTableColumns = this.columnNames;
- return;
- }
- return this._getPreferences().then(preferences => {
- this.showNumber = !!(preferences &&
- preferences.legacycid_in_change_table);
- this.visibleChangeTableColumns = preferences.change_table.length > 0 ?
- preferences.change_table : this.columnNames;
- });
- });
- },
-
- _getLoggedIn() {
- return this.$.restAPI.getLoggedIn();
- },
-
- _getPreferences() {
- return this.$.restAPI.getPreferences();
+ _computePreferences(account, preferences) {
+ this.changeTableColumns = this.columnNames;
+
+ if (account) {
+ this.showNumber = !!(preferences &&
+ preferences.legacycid_in_change_table);
+ this.visibleChangeTableColumns = preferences.change_table.length > 0 ?
+ this.getVisibleColumns(preferences.change_table) : this.columnNames;
+ } else {
+ // Not logged in.
+ this.showNumber = false;
+ this.visibleChangeTableColumns = this.columnNames;
+ }
},
_computeColspan(changeTableColumns, labelNames) {
@@ -184,9 +184,15 @@
},
_computeLabelShortcut(labelName) {
- return labelName.split('-').reduce((a, i) => {
- return a + i[0].toUpperCase();
- }, '');
+ if (labelName.startsWith(LABEL_PREFIX_INVALID_PROLOG)) {
+ labelName = labelName.slice(LABEL_PREFIX_INVALID_PROLOG.length);
+ }
+ return labelName.split('-')
+ .reduce((a, i) => {
+ if (!i) { return a; }
+ return a + i[0].toUpperCase();
+ }, '')
+ .slice(0, MAX_SHORTCUT_CHARS);
},
_changesChanged(changes) {
@@ -194,15 +200,15 @@
},
_sectionHref(query) {
- return `${this.getBaseUrl()}/q/${this.encodeURL(query, true)}`;
+ return Gerrit.Nav.getUrlForSearchQuery(query);
},
/**
* Maps an index local to a particular section to the absolute index
* across all the changes on the page.
*
- * @param sectionIndex {number} index of section
- * @param localIndex {number} index of row within section
+ * @param {number} sectionIndex index of section
+ * @param {number} localIndex index of row within section
* @return {number} absolute index of row in the aggregate dashboard
*/
_computeItemAbsoluteIndex(sectionIndex, localIndex) {
@@ -220,36 +226,38 @@
_computeItemNeedsReview(account, change, showReviewedState) {
return showReviewedState && !change.reviewed &&
+ !change.work_in_progress &&
this.changeIsOpen(change.status) &&
- account._account_id != change.owner._account_id;
+ (!account || account._account_id != change.owner._account_id);
},
- _computeItemAssigned(account, change) {
- if (!change.assignee) { return false; }
+ _computeItemHighlight(account, change) {
+ // Do not show the assignee highlight if the change is not open.
+ if (!change.assignee ||
+ !account ||
+ CLOSED_STATUS.indexOf(change.status) !== -1) {
+ return false;
+ }
return account._account_id === change.assignee._account_id;
},
- _handleJKey(e) {
+ _nextChange(e) {
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
- // Compute absolute index of item that would come after final item.
- const len = this._computeItemAbsoluteIndex(this.sections.length, 0);
- if (this.selectedIndex === len - 1) { return; }
- this.selectedIndex += 1;
+ this.$.cursor.next();
},
- _handleKKey(e) {
+ _prevChange(e) {
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
e.preventDefault();
- if (this.selectedIndex === 0) { return; }
- this.selectedIndex -= 1;
+ this.$.cursor.previous();
},
- _handleOKey(e) {
+ _openChange(e) {
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
@@ -257,7 +265,7 @@
Gerrit.Nav.navigateToChange(this._changeForIndex(this.selectedIndex));
},
- _handleNKey(e) {
+ _nextPage(e) {
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e) && !this.isModifierPressed(e, 'shiftKey')) {
return;
@@ -267,7 +275,7 @@
this.fire('next-page');
},
- _handlePKey(e) {
+ _prevPage(e) {
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e) && !this.isModifierPressed(e, 'shiftKey')) {
return;
@@ -277,7 +285,25 @@
this.fire('previous-page');
},
- _handleRKey(e) {
+ _toggleChangeReviewed(e) {
+ if (this.shouldSuppressKeyboardShortcut(e) ||
+ this.modifierPressed(e)) { return; }
+
+ e.preventDefault();
+ this._toggleReviewedForIndex(this.selectedIndex);
+ },
+
+ _toggleReviewedForIndex(index) {
+ const changeEls = this._getListItems();
+ if (index >= changeEls.length || !changeEls[index]) {
+ return;
+ }
+
+ const changeEl = changeEls[index];
+ changeEl.toggleReviewed();
+ },
+
+ _refreshChangeList(e) {
if (this.shouldSuppressKeyboardShortcut(e)) { return; }
e.preventDefault();
@@ -288,7 +314,7 @@
window.location.reload();
},
- _handleSKey(e) {
+ _toggleChangeStar(e) {
if (this.shouldSuppressKeyboardShortcut(e) ||
this.modifierPressed(e)) { return; }
@@ -303,10 +329,7 @@
}
const changeEl = changeEls[index];
- const change = changeEl.change;
- const newVal = !change.starred;
- changeEl.set('change.starred', newVal);
- this.$.restAPI.saveChangeStarred(change._number, newVal);
+ changeEl.$$('gr-change-star').toggleStar();
},
_changeForIndex(index) {
@@ -320,5 +343,20 @@
_getListItems() {
return Polymer.dom(this.root).querySelectorAll('gr-change-list-item');
},
+
+ _sectionsChanged() {
+ // Flush DOM operations so that the list item elements will be loaded.
+ Polymer.dom.flush();
+ this.$.cursor.stops = this._getListItems();
+ this.$.cursor.moveToStart();
+ },
+
+ _isOutgoing(section) {
+ return !!section.isOutgoing;
+ },
+
+ _isEmpty(section) {
+ return !section.results.length;
+ },
});
})();