gerrit/polygerrit-ui/app/elements/gr-change-list-item.html
Dave Borowitz 0ef8e2f35a gr-change-list: Replace Code-Review with Code_Review
The former is not a JS identifier, which is not guaranteed to work in
computed properties.

Change-Id: Ia5359bf00beea3800b4a8d64cd59557cd62e0a0d
2015-12-04 15:36:00 -05:00

208 lines
6.1 KiB
HTML

<!--
Copyright (C) 2015 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.
-->
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../styles/gr-change-list-styles.html">
<link rel="import" href="gr-date-formatter.html">
<dom-module id="gr-change-list-item">
<template>
<style>
:host {
display: flex;
}
:host([selected]) {
background-color: #d8EdF9;
}
.cell {
border-bottom: 1px solid #eee;
flex-shrink: 0;
padding: .3em .5em;
}
a {
color: var(--default-text-color);
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
.positionIndicator {
visibility: hidden;
}
:host([selected]) .positionIndicator {
visibility: visible;
}
.avatarImage {
border-radius: 50%;
height: 1.3em;
vertical-align: -.3em;
width: 1.3em;
}
.u-monospace {
font-family: 'Source Code Pro';
}
.u-green {
color: #388E3C;
}
.u-red {
color: #D32F2F;
}
</style>
<style include="gr-change-list-styles"></style>
<span class="cell keyboard">
<span class="positionIndicator">&#x25b6;</span>
</span>
<a class="cell subject" href$="[[changeURL]]">[[change.subject]]</a>
<span class="cell status">[[_computeChangeStatusString(change)]]</span>
<span class="cell owner">
<template is="dom-if" if="[[showAvatar]]">
<img class="avatarImage" src$="[[_computeAvatarURL(change.owner)]]">
</template>
<a href$="[[_computeOwnerLink(change.owner.email)]]"
title$="[[_computeOwnerTitle(change.owner)]]">[[change.owner.name]]</a>
</span>
<a class="cell project" href$="[[_computeProjectURL(change.project)]]">[[change.project]]</a>
<a class="cell branch" href$="[[_computeProjectBranchURL(change.project, change.branch)]]">[[change.branch]]</a>
<gr-date-formatter class="cell updated" date-str="[[change.updated]]"></gr-date-formatter>
<span class="cell size u-monospace">
<span class="u-green"><span>+</span>[[change.insertions]]</span>,
<span class="u-red"><span>-</span>[[change.deletions]]</span>
</span>
<span title="Code-Review"
class$="[[_computeCodeReviewClass(change.labels.Code_Review)]]">[[_computeCodeReviewLabel(change.labels.Code_Review)]]</span>
<span class="cell verified u-green" title="Verified">[[_computeVerifiedLabel(change.labels.Verified)]]</span>
</template>
<script>
(function() {
'use strict';
Polymer({
is: 'gr-change-list-item',
properties: {
selected: {
type: Boolean,
reflectToAttribute: true,
},
change: Object,
changeURL: {
type: String,
computed: '_computeChangeURL(change._number)',
},
showAvatar: {
type: Boolean,
value: false,
},
},
ready: function() {
app.configReady.then(function(cfg) {
this.showAvatar = !!(cfg && cfg.plugin && cfg.plugin.has_avatars);
}.bind(this));
},
_computeChangeURL: function(changeNum) {
if (!changeNum) { return ''; }
return '/c/' + changeNum + '/';
},
_computeChangeStatusString: function(change) {
if (change.mergeable != null && change.mergeable == false) {
return 'Merge Conflict';
}
if (change.status == Changes.Status.MERGED) {
return 'Merged';
}
if (change.status == Changes.Status.DRAFT) {
return 'Draft';
}
if (change.status == Changes.Status.ABANDONED) {
return 'Abandoned';
}
return '';
},
_computeCodeReviewClass: function(codeReview) {
// Mimic a Set.
var classes = {
'cell': true,
'codeReview': true,
};
if (codeReview) {
if (codeReview.approved) {
classes['u-green'] = true;
}
if (codeReview.value == 1) {
classes['u-monospace'] = true;
classes['u-green'] = true;
} else if (codeReview.value == -1) {
classes['u-monospace'] = true;
classes['u-red'] = true;
}
}
return Object.keys(classes).sort().join(' ');
},
_computeCodeReviewLabel: function(codeReview) {
if (!codeReview) { return ''; }
if (codeReview.approved) {
return '✓';
}
if (codeReview.value == 1) {
return '+1';
}
if (codeReview.value == -1) {
return '-1';
}
return '';
},
_computeVerifiedLabel: function(verified) {
if (verified && verified.approved) {
return '✓';
}
return ''
},
_computeAvatarURL: function(owner) {
if (!owner) { return ''; }
return '/accounts/' + owner.email + '/avatar?s=32'
},
_computeOwnerLink: function(email) {
if (!email) { return ''; }
return '/q/owner:' + encodeURIComponent(email) + '+status:open';
},
_computeOwnerTitle: function(owner) {
if (!owner) { return ''; }
// TODO: Is this safe from XSS attacks?
return owner.name + ' <' + owner.email + '>';
},
_computeProjectURL: function(project) {
return '/projects/' + project + ',dashboards/default';
},
_computeProjectBranchURL: function(project, branch) {
return '/q/status:open+project:' + project + '+branch:' + branch;
},
});
})();
</script>
</dom-module>