diff options
Diffstat (limited to 'polygerrit-ui/app/elements/change/gr-message/gr-message.js')
-rw-r--r-- | polygerrit-ui/app/elements/change/gr-message/gr-message.js | 100 |
1 files changed, 59 insertions, 41 deletions
diff --git a/polygerrit-ui/app/elements/change/gr-message/gr-message.js b/polygerrit-ui/app/elements/change/gr-message/gr-message.js index d907f3bcbf..0590c73eb4 100644 --- a/polygerrit-ui/app/elements/change/gr-message/gr-message.js +++ b/polygerrit-ui/app/elements/change/gr-message/gr-message.js @@ -1,22 +1,24 @@ -// 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 CI_LABELS = ['Trybot-Ready', 'Tryjob-Request', 'Commit-Queue']; const PATCH_SET_PREFIX_PATTERN = /^Patch Set \d+: /; - const LABEL_TITLE_SCORE_PATTERN = /([A-Za-z0-9-]+)([+-]\d+)/; + const LABEL_TITLE_SCORE_PATTERN = /^([A-Za-z0-9-]+)([+-]\d+)$/; Polymer({ is: 'gr-message', @@ -79,11 +81,17 @@ type: String, observer: '_projectNameChanged', }, - _commentLinks: Object, + + /** + * A mapping from label names to objects representing the minimum and + * maximum possible values for that label. + */ + labelExtremes: Object, + /** * @type {{ commentlinks: Array }} */ - projectConfig: Object, + _projectConfig: Object, // Computed property needed to trigger Polymer value observing. _expanded: { type: Object, @@ -176,41 +184,42 @@ return event.type === 'REVIEWER_UPDATE'; }, - _isMessagePositive(message) { - if (!message.message) { return null; } + _getScores(message) { + if (!message.message) { return []; } const line = message.message.split('\n', 1)[0]; const patchSetPrefix = PATCH_SET_PREFIX_PATTERN; - if (!line.match(patchSetPrefix)) { return null; } + if (!line.match(patchSetPrefix)) { return []; } const scoresRaw = line.split(patchSetPrefix)[1]; - if (!scoresRaw) { return null; } - const scores = scoresRaw.split(' '); - if (!scores.length) { return null; } - const {min, max} = scores + if (!scoresRaw) { return []; } + return scoresRaw.split(' ') .map(s => s.match(LABEL_TITLE_SCORE_PATTERN)) .filter(ms => ms && ms.length === 3) - .filter(([, label]) => !CI_LABELS.includes(label)) - .map(([, , score]) => score) - .map(s => parseInt(s, 10)) - .reduce(({min, max}, s) => - ({min: (s < min ? s : min), max: (s > max ? s : max)}), - {min: 0, max: 0}); - if (max - min === 0) { - return 0; - } else { - return (max + min) > 0 ? 1 : -1; + .map(ms => ({label: ms[1], value: ms[2]})); + }, + + _computeScoreClass(score, labelExtremes) { + const classes = []; + if (score.value > 0) { + classes.push('positive'); + } else if (score.value < 0) { + classes.push('negative'); } + const extremes = labelExtremes[score.label]; + if (extremes) { + const intScore = parseInt(score.value, 10); + if (intScore === extremes.max) { + classes.push('max'); + } else if (intScore === extremes.min) { + classes.push('min'); + } + } + return classes.join(' '); }, _computeClass(expanded, showAvatar, message) { const classes = []; classes.push(expanded ? 'expanded' : 'collapsed'); classes.push(showAvatar ? 'showAvatar' : 'hideAvatar'); - const scoreQuality = this._isMessagePositive(message); - if (scoreQuality === 1) { - classes.push('positiveVote'); - } else if (scoreQuality === -1) { - classes.push('negativeVote'); - } return classes.join(' '); }, @@ -239,8 +248,17 @@ _projectNameChanged(name) { this.$.restAPI.getProjectConfig(name).then(config => { - this._commentLinks = config.commentlinks; + this._projectConfig = config; }); }, + + _computeExpandToggleIcon(expanded) { + return expanded ? 'gr-icons:expand-less' : 'gr-icons:expand-more'; + }, + + _toggleExpanded(e) { + e.stopPropagation(); + this.set('message.expanded', !this.message.expanded); + }, }); })(); |