diff options
Diffstat (limited to 'polygerrit-ui/app/behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html')
-rw-r--r-- | polygerrit-ui/app/behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html | 59 |
1 files changed, 41 insertions, 18 deletions
diff --git a/polygerrit-ui/app/behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html b/polygerrit-ui/app/behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html index 13c232e373..d4e83d9870 100644 --- a/polygerrit-ui/app/behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html +++ b/polygerrit-ui/app/behaviors/gr-patch-set-behavior/gr-patch-set-behavior.html @@ -1,4 +1,5 @@ <!-- +@license Copyright (C) 2016 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); @@ -33,6 +34,7 @@ limitations under the License. /** @polymerBehavior this */ Gerrit.PatchSetBehavior = { EDIT_NAME: 'edit', + PARENT_NAME: 'PARENT', /** * As patchNum can be either a string (e.g. 'edit', 'PARENT') OR a number, @@ -104,11 +106,13 @@ limitations under the License. }, /** - * Sort given revisions array according to the patch set number. The sort - * algorithm is change edit aware. Change edit has patch set number equals - * 0, but must appear after the patch set it was based on. Example: change - * edit is based on patch set 2, and another patch set was uploaded after - * change edit creation, the sorted order should be: 1, 2, (0|edit), 3. + * Sort given revisions array according to the patch set number, in + * descending order. + * The sort algorithm is change edit aware. Change edit has patch set number + * equals 'edit', but must appear after the patch set it was based on. + * Example: change edit is based on patch set 2, and another patch set was + * uploaded after change edit creation, the sorted order should be: + * 3, edit, 2, 1. * * @param {!Array<!Object>} revisions The revisions array * @return {!Array<!Object>} The sorted {revisions} array @@ -122,7 +126,7 @@ limitations under the License. const num = r => r._number === Gerrit.PatchSetBehavior.EDIT_NAME ? 2 * editParent : 2 * (r._number - 1) + 1; - return revisions.sort((a, b) => num(a) - num(b)); + return revisions.sort((a, b) => num(b) - num(a)); }, /** @@ -143,8 +147,7 @@ limitations under the License. computeAllPatchSets(change) { if (!change) { return []; } let patchNums = []; - if (change.revisions && - Object.keys(change.revisions).length) { + if (change.revisions && Object.keys(change.revisions).length) { patchNums = Gerrit.PatchSetBehavior.sortRevisions(Object.values(change.revisions)) .map(e => { @@ -195,29 +198,35 @@ limitations under the License. /** @return {number|undefined} */ computeLatestPatchNum(allPatchSets) { if (!allPatchSets || !allPatchSets.length) { return undefined; } - if (allPatchSets[allPatchSets.length - 1].num === - Gerrit.PatchSetBehavior.EDIT_NAME) { - return allPatchSets[allPatchSets.length - 2].num; + if (allPatchSets[0].num === Gerrit.PatchSetBehavior.EDIT_NAME) { + return allPatchSets[1].num; } - return allPatchSets[allPatchSets.length - 1].num; + return allPatchSets[0].num; }, /** @return {Boolean} */ hasEditBasedOnCurrentPatchSet(allPatchSets) { - if (!allPatchSets || !allPatchSets.length) { return false; } - return allPatchSets[allPatchSets.length - 1].num === - Gerrit.PatchSetBehavior.EDIT_NAME; + if (!allPatchSets || allPatchSets.length < 2) { return false; } + return allPatchSets[0].num === Gerrit.PatchSetBehavior.EDIT_NAME; + }, + + /** @return {Boolean} */ + hasEditPatchsetLoaded(patchRangeRecord) { + const patchRange = patchRangeRecord.base; + if (!patchRange) { return false; } + return patchRange.patchNum === Gerrit.PatchSetBehavior.EDIT_NAME || + patchRange.basePatchNum === Gerrit.PatchSetBehavior.EDIT_NAME; }, /** * Check whether there is no newer patch than the latest patch that was * available when this change was loaded. * - * @return {Promise<boolean>} A promise that yields true if the latest patch + * @return {Promise<!Object>} A promise that yields true if the latest patch * has been loaded, and false if a newer patch has been uploaded in the * meantime. The promise is rejected on network error. */ - fetchIsLatestKnown(change, restAPI) { + fetchChangeUpdates(change, restAPI) { const knownLatest = Gerrit.PatchSetBehavior.computeLatestPatchNum( Gerrit.PatchSetBehavior.computeAllPatchSets(change)); return restAPI.getChangeDetail(change._number) @@ -227,7 +236,11 @@ limitations under the License. } const actualLatest = Gerrit.PatchSetBehavior.computeLatestPatchNum( Gerrit.PatchSetBehavior.computeAllPatchSets(detail)); - return actualLatest <= knownLatest; + return { + isLatest: actualLatest <= knownLatest, + newStatus: change.status !== detail.status ? detail.status : null, + newMessages: change.messages.length < detail.messages.length, + }; }); }, @@ -242,6 +255,16 @@ limitations under the License. const findNum = rev => rev._number + '' === patchNum + ''; return revisions.findIndex(findNum); }, + + /** + * Convert parent indexes from patch range expressions to numbers. + * For example, in a patch range expression `"-3"` becomes `3`. + * @param {number|string} rangeBase + * @return {number} + */ + getParentIndex(rangeBase) { + return -parseInt(rangeBase + '', 10); + }, }; })(window); </script> |