diff options
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.js | 161 |
1 files changed, 115 insertions, 46 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 c55e8c47f3..c6e369c0cc 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 @@ -1,25 +1,53 @@ -// Copyright (C) 2017 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) 2017 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'; // 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: { account: Object, allPatchSets: Array, @@ -27,9 +55,9 @@ change: Object, changeNum: String, changeUrl: String, - comments: Object, + changeComments: Object, commitInfo: Object, - editLoaded: Boolean, + editMode: Boolean, loggedIn: Boolean, serverConfig: Object, shownFileCount: Number, @@ -40,7 +68,7 @@ }, patchNum: String, basePatchNum: String, - revisions: Array, + filesExpanded: String, // Caps the number of files that can be shown and have the 'show diffs' / // 'hide diffs' buttons still be functional. _maxFilesForBulkActions: { @@ -48,24 +76,51 @@ readOnly: true, value: 225, }, + _patchsetDescription: { + type: String, + value: '', + }, _descriptionReadOnly: { type: Boolean, computed: '_computeDescriptionReadOnly(loggedIn, change, account)', }, + revisionInfo: Object, }, behaviors: [ Gerrit.PatchSetBehavior, ], + observers: [ + '_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'; }, @@ -76,10 +131,14 @@ _computePatchSetDescription(change, patchNum) { const rev = this.getRevisionByPatchNum(change.revisions, patchNum); - return (rev && rev.description) ? + 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} @@ -96,23 +155,34 @@ _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); - this.$.restAPI.setDescription(this.changeNum, - this.patchNum, desc) + 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 => { + if (target) { target.disabled = false; } + return; }); }, - _computeBasePatchDisabled(patchNum, currentPatchNum) { - return this.findSortedIndex(patchNum, this.revisions) >= - this.findSortedIndex(currentPatchNum, this.revisions); - }, - _computePrefsButtonHidden(prefs, loggedIn) { return !loggedIn || !prefs; }, @@ -122,20 +192,6 @@ return shownFileCount <= maxFilesForBulkActions; }, - /** - * Determines if a patch number should be disabled based on value of the - * basePatchNum from gr-file-list. - * @param {number} patchNum Patch number available in dropdown - * @param {number|string} basePatchNum Base patch number from file list - * @return {boolean} - */ - _computePatchSetDisabled(patchNum, basePatchNum) { - if (basePatchNum === 'PARENT') { return false; } - - return this.findSortedIndex(patchNum, this.revisions) <= - this.findSortedIndex(basePatchNum, this.revisions); - }, - _handlePatchChange(e) { const {basePatchNum, patchNum} = e.detail; if (this.patchNumEquals(basePatchNum, this.basePatchNum) && @@ -155,18 +211,15 @@ _handleDownloadTap(e) { e.preventDefault(); - this.fire('open-download-dialog'); + this.dispatchEvent( + new CustomEvent('open-download-dialog', {bubbles: false})); }, - _computeEditLoadedClass(editLoaded) { - return editLoaded ? 'editLoaded' : ''; + _computeEditModeClass(editMode) { + return editMode ? 'editMode' : ''; }, _computePatchInfoClass(patchNum, allPatchSets) { - if (this.patchNumEquals(patchNum, this.EDIT_NAME)) { - return 'patchInfoEdit'; - } - const latestNum = this.computeLatestPatchNum(allPatchSets); if (this.patchNumEquals(patchNum, latestNum)) { return ''; @@ -175,7 +228,23 @@ }, _hideIncludedIn(change) { - return change && change.status === 'MERGED' ? '' : 'hide'; + return change && change.status === MERGED_STATUS ? '' : 'hide'; + }, + + _handleUploadTap(e) { + e.preventDefault(); + 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' : ''); }, }); })(); |