Files
gerrit/polygerrit-ui/app/elements/change/gr-message/gr-message.js
Becky Siegel eb47127aca Fix cursor pointer on all gr-messages
Previously, the css rule was set for non-expanded messages to get cursor
pointer styling. There were two issues. The expanded attribute was not
on the host, and it was checking for 'expanded' rather than '_expanded'

This change adds a class to the host so that (updated) css styles can
be appropriately applied.

Bug: Issue 5808
Change-Id: Icb6fe2ac57e06e049d3222e855906b7f3419087f
2017-03-21 10:50:54 -07:00

185 lines
5.0 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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';
Polymer({
is: 'gr-message',
/**
* Fired when this message's permalink is tapped.
*
* @event scroll-to
*/
/**
* Fired when this message's reply link is tapped.
*
* @event reply
*/
listeners: {
'tap': '_handleTap',
},
properties: {
changeNum: Number,
message: Object,
author: {
type: Object,
computed: '_computeAuthor(message)',
},
comments: {
type: Object,
observer: '_commentsChanged',
},
config: Object,
hideAutomated: {
type: Boolean,
value: false,
},
hidden: {
type: Boolean,
computed: '_computeIsHidden(hideAutomated, isAutomated)',
reflectToAttribute: true,
},
isAutomated: {
type: Boolean,
computed: '_computeIsAutomated(message)',
},
showAvatar: {
type: Boolean,
computed: '_computeShowAvatar(author, config)',
},
showReplyButton: {
type: Boolean,
computed: '_computeShowReplyButton(message, _loggedIn)',
},
projectConfig: Object,
// Computed property needed to trigger Polymer value observing.
_expanded: {
type: Object,
computed: '_computeExpanded(message.expanded)',
},
_loggedIn: {
type: Boolean,
value: false,
},
},
observers: [
'_updateExpandedClass(message.expanded)',
],
ready: function() {
this.$.restAPI.getConfig().then(function(config) {
this.config = config;
}.bind(this));
this.$.restAPI.getLoggedIn().then(function(loggedIn) {
this._loggedIn = loggedIn;
}.bind(this));
},
_updateExpandedClass: function(expanded) {
if (expanded) {
this.classList.add('expanded');
} else {
this.classList.remove('expanded');
}
},
_computeAuthor: function(message) {
return message.author || message.updated_by;
},
_computeShowAvatar: function(author, config) {
return !!(author && config && config.plugin && config.plugin.has_avatars);
},
_computeShowReplyButton: function(message, loggedIn) {
return !!message.message && loggedIn;
},
_computeExpanded: function(expanded) {
return expanded;
},
/**
* If there is no value set on the message object as to whether _expanded
* should be true or not, then _expanded is set to true if there are
* inline comments (otherwise false).
*/
_commentsChanged: function(value) {
if (this.message && this.message.expanded === undefined) {
this.set('message.expanded', Object.keys(value || {}).length > 0);
}
},
_handleTap: function(e) {
if (this.message.expanded) { return; }
e.stopPropagation();
this.set('message.expanded', true);
},
_handleNameTap: function(e) {
if (!this.message.expanded) { return; }
e.stopPropagation();
this.set('message.expanded', false);
},
_computeIsAutomated: function(message) {
return !!(message.reviewer ||
(message.tag && message.tag.indexOf('autogenerated') === 0));
},
_computeIsHidden: function(hideAutomated, isAutomated) {
return hideAutomated && isAutomated;
},
_computeIsReviewerUpdate: function(event) {
return event.type === 'REVIEWER_UPDATE';
},
_computeClass: function(expanded, showAvatar) {
var classes = [];
classes.push(expanded ? 'expanded' : 'collapsed');
classes.push(showAvatar ? 'showAvatar' : 'hideAvatar');
return classes.join(' ');
},
_computeMessageHash: function(message) {
return '#message-' + message.id;
},
_handleLinkTap: function(e) {
e.preventDefault();
this.fire('scroll-to', {message: this.message}, {bubbles: false});
var hash = this._computeMessageHash(this.message);
// Don't add the hash to the window history if it's already there.
// Otherwise you mess up expected back button behavior.
if (window.location.hash == hash) { return; }
// Change the URL but dont trigger a nav event. Otherwise it will
// reload the page.
page.show(window.location.pathname + hash, null, false);
},
_handleReplyTap: function(e) {
e.preventDefault();
this.fire('reply', {message: this.message});
},
});
})();