summaryrefslogtreecommitdiffstats
path: root/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js
diff options
context:
space:
mode:
Diffstat (limited to 'polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js')
-rw-r--r--polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js455
1 files changed, 245 insertions, 210 deletions
diff --git a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js
index d6fbfc4e18..73c6721506 100644
--- a/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js
+++ b/polygerrit-ui/app/elements/change/gr-file-list-header/gr-file-list-header.js
@@ -14,41 +14,72 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-(function() {
- 'use strict';
+import '../../../scripts/bundled-polymer.js';
+
+import '../../../styles/shared-styles.js';
+import '../../diff/gr-diff-mode-selector/gr-diff-mode-selector.js';
+import '../../diff/gr-patch-range-select/gr-patch-range-select.js';
+import '../../edit/gr-edit-controls/gr-edit-controls.js';
+import '../../shared/gr-editable-label/gr-editable-label.js';
+import '../../shared/gr-linked-chip/gr-linked-chip.js';
+import '../../shared/gr-rest-api-interface/gr-rest-api-interface.js';
+import '../../shared/gr-select/gr-select.js';
+import '../../shared/gr-button/gr-button.js';
+import '../../shared/gr-icons/gr-icons.js';
+import '../gr-commit-info/gr-commit-info.js';
+import {dom} from '@polymer/polymer/lib/legacy/polymer.dom.js';
+import {mixinBehaviors} from '@polymer/polymer/lib/legacy/class.js';
+import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
+import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
+import {PolymerElement} from '@polymer/polymer/polymer-element.js';
+import {htmlTemplate} from './gr-file-list-header_html.js';
+import {PatchSetBehavior} from '../../../behaviors/gr-patch-set-behavior/gr-patch-set-behavior.js';
+import {KeyboardShortcutBehavior} from '../../../behaviors/keyboard-shortcut-behavior/keyboard-shortcut-behavior.js';
+import {GrFileListConstants} from '../gr-file-list-constants.js';
+import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
+
+// Maximum length for patch set descriptions.
+const PATCH_DESC_MAX_LENGTH = 500;
+const MERGED_STATUS = 'MERGED';
- // Maximum length for patch set descriptions.
- const PATCH_DESC_MAX_LENGTH = 500;
- const MERGED_STATUS = 'MERGED';
-
- Polymer({
- is: 'gr-file-list-header',
-
- /**
- * @event expand-diffs
- */
-
- /**
- * @event collapse-diffs
- */
-
- /**
- * @event open-diff-prefs
- */
-
- /**
- * @event open-included-in-dialog
- */
-
- /**
- * @event open-download-dialog
- */
-
- /**
- * @event open-upload-help-dialog
- */
-
- properties: {
+/**
+ * @extends Polymer.Element
+ */
+class GrFileListHeader extends mixinBehaviors( [
+ PatchSetBehavior,
+ KeyboardShortcutBehavior,
+], GestureEventListeners(
+ LegacyElementMixin(
+ PolymerElement))) {
+ static get template() { return htmlTemplate; }
+
+ static get is() { return 'gr-file-list-header'; }
+ /**
+ * @event expand-diffs
+ */
+
+ /**
+ * @event collapse-diffs
+ */
+
+ /**
+ * @event open-diff-prefs
+ */
+
+ /**
+ * @event open-included-in-dialog
+ */
+
+ /**
+ * @event open-download-dialog
+ */
+
+ /**
+ * @event open-upload-help-dialog
+ */
+
+ static get properties() {
+ return {
account: Object,
allPatchSets: Array,
/** @type {?} */
@@ -81,188 +112,192 @@
type: String,
value: '',
},
- showTitle: {
- type: Boolean,
- value: true,
- },
_descriptionReadOnly: {
type: Boolean,
computed: '_computeDescriptionReadOnly(loggedIn, change, account)',
},
revisionInfo: Object,
- },
+ };
+ }
- behaviors: [
- Gerrit.FireBehavior,
- Gerrit.PatchSetBehavior,
- ],
-
- observers: [
+ static get observers() {
+ return [
'_computePatchSetDescription(change, patchNum)',
- ],
-
- setDiffViewMode(mode) {
- this.$.modeSelect.setMode(mode);
- },
-
- _expandAllDiffs() {
- this._expanded = true;
- this.fire('expand-diffs');
- },
-
- _collapseAllDiffs() {
- this._expanded = false;
- this.fire('collapse-diffs');
- },
-
- _computeExpandedClass(filesExpanded) {
- const classes = [];
- if (filesExpanded === GrFileListConstants.FilesExpandedState.ALL) {
- classes.push('expanded');
- }
- if (filesExpanded === GrFileListConstants.FilesExpandedState.SOME ||
- filesExpanded === GrFileListConstants.FilesExpandedState.ALL) {
- classes.push('openFile');
- }
- return classes.join(' ');
- },
-
- _computeDescriptionPlaceholder(readOnly) {
- return (readOnly ? 'No' : 'Add') + ' patchset description';
- },
-
- _computeDescriptionReadOnly(loggedIn, change, account) {
- // Polymer 2: check for undefined
- if ([loggedIn, change, account].some(arg => arg === undefined)) {
- return undefined;
+ ];
+ }
+
+ setDiffViewMode(mode) {
+ this.$.modeSelect.setMode(mode);
+ }
+
+ _expandAllDiffs() {
+ this._expanded = true;
+ this.dispatchEvent(new CustomEvent('expand-diffs', {
+ composed: true, bubbles: true,
+ }));
+ }
+
+ _collapseAllDiffs() {
+ this._expanded = false;
+ this.dispatchEvent(new CustomEvent('collapse-diffs', {
+ composed: true, bubbles: true,
+ }));
+ }
+
+ _computeExpandedClass(filesExpanded) {
+ const classes = [];
+ if (filesExpanded === GrFileListConstants.FilesExpandedState.ALL) {
+ classes.push('expanded');
+ }
+ if (filesExpanded === GrFileListConstants.FilesExpandedState.SOME ||
+ filesExpanded === GrFileListConstants.FilesExpandedState.ALL) {
+ classes.push('openFile');
+ }
+ return classes.join(' ');
+ }
+
+ _computeDescriptionPlaceholder(readOnly) {
+ return (readOnly ? 'No' : 'Add') + ' patchset description';
+ }
+
+ _computeDescriptionReadOnly(loggedIn, change, account) {
+ // Polymer 2: check for undefined
+ if ([loggedIn, change, account].some(arg => arg === undefined)) {
+ return undefined;
+ }
+
+ return !(loggedIn && (account._account_id === change.owner._account_id));
+ }
+
+ _computePatchSetDescription(change, patchNum) {
+ // Polymer 2: check for undefined
+ if ([change, patchNum].some(arg => arg === undefined)) {
+ return;
+ }
+
+ const rev = this.getRevisionByPatchNum(change.revisions, patchNum);
+ this._patchsetDescription = (rev && rev.description) ?
+ rev.description.substring(0, PATCH_DESC_MAX_LENGTH) : '';
+ }
+
+ _handleDescriptionRemoved(e) {
+ return this._updateDescription('', e);
+ }
+
+ /**
+ * @param {!Object} revisions The revisions object keyed by revision hashes
+ * @param {?Object} patchSet A revision already fetched from {revisions}
+ * @return {string|undefined} the SHA hash corresponding to the revision.
+ */
+ _getPatchsetHash(revisions, patchSet) {
+ for (const rev in revisions) {
+ if (revisions.hasOwnProperty(rev) &&
+ revisions[rev] === patchSet) {
+ return rev;
}
-
- return !(loggedIn && (account._account_id === change.owner._account_id));
- },
-
- _computePatchSetDescription(change, patchNum) {
- // Polymer 2: check for undefined
- if ([change, patchNum].some(arg => arg === undefined)) {
- return;
- }
-
- const rev = this.getRevisionByPatchNum(change.revisions, patchNum);
- this._patchsetDescription = (rev && rev.description) ?
- rev.description.substring(0, PATCH_DESC_MAX_LENGTH) : '';
- },
-
- _handleDescriptionRemoved(e) {
- return this._updateDescription('', e);
- },
-
- /**
- * @param {!Object} revisions The revisions object keyed by revision hashes
- * @param {?Object} patchSet A revision already fetched from {revisions}
- * @return {string|undefined} the SHA hash corresponding to the revision.
- */
- _getPatchsetHash(revisions, patchSet) {
- for (const rev in revisions) {
- if (revisions.hasOwnProperty(rev) &&
- revisions[rev] === patchSet) {
- return rev;
- }
- }
- },
-
- _handleDescriptionChanged(e) {
- const desc = e.detail.trim();
- this._updateDescription(desc, e);
- },
-
- /**
- * Update the patchset description with the rest API.
- *
- * @param {string} desc
- * @param {?(Event|Node)} e
- * @return {!Promise}
- */
- _updateDescription(desc, e) {
- const target = Polymer.dom(e).rootTarget;
- if (target) { target.disabled = true; }
- const rev = this.getRevisionByPatchNum(this.change.revisions,
- this.patchNum);
- const sha = this._getPatchsetHash(this.change.revisions, rev);
- return this.$.restAPI.setDescription(this.changeNum, this.patchNum, desc)
- .then(res => {
- if (res.ok) {
- if (target) { target.disabled = false; }
- this.set(['change', 'revisions', sha, 'description'], desc);
- this._patchsetDescription = desc;
- }
- }).catch(err => {
+ }
+ }
+
+ _handleDescriptionChanged(e) {
+ const desc = e.detail.trim();
+ this._updateDescription(desc, e);
+ }
+
+ /**
+ * Update the patchset description with the rest API.
+ *
+ * @param {string} desc
+ * @param {?(Event|Node)} e
+ * @return {!Promise}
+ */
+ _updateDescription(desc, e) {
+ const target = dom(e).rootTarget;
+ if (target) { target.disabled = true; }
+ const rev = this.getRevisionByPatchNum(this.change.revisions,
+ this.patchNum);
+ const sha = this._getPatchsetHash(this.change.revisions, rev);
+ return this.$.restAPI.setDescription(this.changeNum, this.patchNum, desc)
+ .then(res => {
+ if (res.ok) {
if (target) { target.disabled = false; }
- return;
- });
- },
-
- _computePrefsButtonHidden(prefs, diffPrefsDisabled) {
- return diffPrefsDisabled || !prefs;
- },
-
- _fileListActionsVisible(shownFileCount, maxFilesForBulkActions) {
- return shownFileCount <= maxFilesForBulkActions;
- },
-
- _handlePatchChange(e) {
- const {basePatchNum, patchNum} = e.detail;
- if (this.patchNumEquals(basePatchNum, this.basePatchNum) &&
- this.patchNumEquals(patchNum, this.patchNum)) { return; }
- Gerrit.Nav.navigateToChange(this.change, patchNum, basePatchNum);
- },
-
- _handlePrefsTap(e) {
- e.preventDefault();
- this.fire('open-diff-prefs');
- },
-
- _handleIncludedInTap(e) {
- e.preventDefault();
- this.fire('open-included-in-dialog');
- },
-
- _handleDownloadTap(e) {
- e.preventDefault();
- e.stopPropagation();
- this.dispatchEvent(
- new CustomEvent('open-download-dialog', {bubbles: false}));
- },
-
- _computeEditModeClass(editMode) {
- return editMode ? 'editMode' : '';
- },
-
- _computePatchInfoClass(patchNum, allPatchSets) {
- const latestNum = this.computeLatestPatchNum(allPatchSets);
- if (this.patchNumEquals(patchNum, latestNum)) {
- return '';
- }
- return 'patchInfoOldPatchSet';
- },
-
- _hideIncludedIn(change) {
- return change && change.status === MERGED_STATUS ? '' : 'hide';
- },
-
- _handleUploadTap(e) {
- e.preventDefault();
- e.stopPropagation();
- this.dispatchEvent(
- new CustomEvent('open-upload-help-dialog', {bubbles: false}));
- },
-
- _computeUploadHelpContainerClass(change, account) {
- const changeIsMerged = change && change.status === MERGED_STATUS;
- const ownerId = change && change.owner && change.owner._account_id ?
- change.owner._account_id : null;
- const userId = account && account._account_id;
- const userIsOwner = ownerId && userId && ownerId === userId;
- const hideContainer = !userIsOwner || changeIsMerged;
- return 'uploadContainer desktop' + (hideContainer ? ' hide' : '');
- },
- });
-})();
+ this.set(['change', 'revisions', sha, 'description'], desc);
+ this._patchsetDescription = desc;
+ }
+ })
+ .catch(err => {
+ if (target) { target.disabled = false; }
+ return;
+ });
+ }
+
+ _computePrefsButtonHidden(prefs, diffPrefsDisabled) {
+ return diffPrefsDisabled || !prefs;
+ }
+
+ _fileListActionsVisible(shownFileCount, maxFilesForBulkActions) {
+ return shownFileCount <= maxFilesForBulkActions;
+ }
+
+ _handlePatchChange(e) {
+ const {basePatchNum, patchNum} = e.detail;
+ if (this.patchNumEquals(basePatchNum, this.basePatchNum) &&
+ this.patchNumEquals(patchNum, this.patchNum)) { return; }
+ GerritNav.navigateToChange(this.change, patchNum, basePatchNum);
+ }
+
+ _handlePrefsTap(e) {
+ e.preventDefault();
+ this.dispatchEvent(new CustomEvent('open-diff-prefs', {
+ composed: true, bubbles: true,
+ }));
+ }
+
+ _handleIncludedInTap(e) {
+ e.preventDefault();
+ this.dispatchEvent(new CustomEvent('open-included-in-dialog', {
+ composed: true, bubbles: true,
+ }));
+ }
+
+ _handleDownloadTap(e) {
+ e.preventDefault();
+ e.stopPropagation();
+ this.dispatchEvent(
+ new CustomEvent('open-download-dialog', {bubbles: false}));
+ }
+
+ _computeEditModeClass(editMode) {
+ return editMode ? 'editMode' : '';
+ }
+
+ _computePatchInfoClass(patchNum, allPatchSets) {
+ const latestNum = this.computeLatestPatchNum(allPatchSets);
+ if (this.patchNumEquals(patchNum, latestNum)) {
+ return '';
+ }
+ return 'patchInfoOldPatchSet';
+ }
+
+ _hideIncludedIn(change) {
+ return change && change.status === MERGED_STATUS ? '' : 'hide';
+ }
+
+ _handleUploadTap(e) {
+ e.preventDefault();
+ e.stopPropagation();
+ this.dispatchEvent(
+ new CustomEvent('open-upload-help-dialog', {bubbles: false}));
+ }
+
+ _computeUploadHelpContainerClass(change, account) {
+ const changeIsMerged = change && change.status === MERGED_STATUS;
+ const ownerId = change && change.owner && change.owner._account_id ?
+ change.owner._account_id : null;
+ const userId = account && account._account_id;
+ const userIsOwner = ownerId && userId && ownerId === userId;
+ const hideContainer = !userIsOwner || changeIsMerged;
+ return 'uploadContainer desktop' + (hideContainer ? ' hide' : '');
+ }
+}
+
+customElements.define(GrFileListHeader.is, GrFileListHeader);