From a5f1ae287672feb5247a9142ea46c3d9ae37e14e Mon Sep 17 00:00:00 2001 From: Urs Wolfer Date: Sun, 27 Dec 2015 18:56:00 +0100 Subject: [PATCH] Refactor account-links and avatars code Move code into new elements which can be reused: - gr-account-link: provides a link to changes owned by user including avatar when available - gr-avatar: provides avatars by extending 'img' element (including handling when avatars are not supported by server) Change-Id: Ib8d9d89884425204a5c697f82fe4fa5ca5414b8b --- .../app/elements/gr-account-link.html | 91 +++++++++++++++++++ polygerrit-ui/app/elements/gr-avatar.html | 79 ++++++++++++++++ .../app/elements/gr-change-list-item.html | 43 +-------- .../app/elements/gr-change-view.html | 14 ++- polygerrit-ui/app/elements/gr-message.html | 28 ++---- .../app/elements/gr-reviewer-list.html | 5 +- .../app/test/gr-account-link-test.html | 66 ++++++++++++++ polygerrit-ui/app/test/gr-avatar-test.html | 69 ++++++++++++++ .../app/test/gr-change-list-item-test.html | 15 --- polygerrit-ui/app/test/index.html | 2 + 10 files changed, 324 insertions(+), 88 deletions(-) create mode 100644 polygerrit-ui/app/elements/gr-account-link.html create mode 100644 polygerrit-ui/app/elements/gr-avatar.html create mode 100644 polygerrit-ui/app/test/gr-account-link-test.html create mode 100644 polygerrit-ui/app/test/gr-avatar-test.html diff --git a/polygerrit-ui/app/elements/gr-account-link.html b/polygerrit-ui/app/elements/gr-account-link.html new file mode 100644 index 0000000000..8b682367ea --- /dev/null +++ b/polygerrit-ui/app/elements/gr-account-link.html @@ -0,0 +1,91 @@ + + + + + + + + + diff --git a/polygerrit-ui/app/elements/gr-avatar.html b/polygerrit-ui/app/elements/gr-avatar.html new file mode 100644 index 0000000000..8e808eefd5 --- /dev/null +++ b/polygerrit-ui/app/elements/gr-avatar.html @@ -0,0 +1,79 @@ + + + + + + + + diff --git a/polygerrit-ui/app/elements/gr-change-list-item.html b/polygerrit-ui/app/elements/gr-change-list-item.html index f0ae7f1056..e2241919c7 100644 --- a/polygerrit-ui/app/elements/gr-change-list-item.html +++ b/polygerrit-ui/app/elements/gr-change-list-item.html @@ -16,6 +16,7 @@ limitations under the License. + @@ -45,12 +46,6 @@ limitations under the License. :host([selected]) .positionIndicator { visibility: visible; } - .avatarImage { - border-radius: 50%; - height: 1.3em; - vertical-align: -.3em; - width: 1.3em; - } .u-monospace { font-family: var(--monospace-font-family); } @@ -68,11 +63,7 @@ limitations under the License. [[change.subject]] [[_computeChangeStatusString(change)]] - - [[change.owner.name]] + [[change.project]] [[change.branch]] @@ -102,16 +93,6 @@ limitations under the License. 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) { @@ -177,26 +158,6 @@ limitations under the License. return '' }, - _computeAvatarURL: function(owner) { - if (!owner) { return ''; } - return '/accounts/' + owner._account_id + '/avatar?s=32' - }, - - _computeOwnerLink: function(owner) { - if (!owner) { return ''; } - var ownerID = owner.email || owner._account_id; - return '/q/owner:' + encodeURIComponent(ownerID) + '+status:open'; - }, - - _computeOwnerTitle: function(owner) { - if (!owner || !owner.name) { return ''; } - var result = util.escapeHTML(owner.name); - if (owner.email) { - result += ' <' + util.escapeHTML(owner.email) + '>'; - } - return result; - }, - _computeProjectURL: function(project) { return '/projects/' + project + ',dashboards/default'; }, diff --git a/polygerrit-ui/app/elements/gr-change-view.html b/polygerrit-ui/app/elements/gr-change-view.html index d50f145857..e76c76f16c 100644 --- a/polygerrit-ui/app/elements/gr-change-view.html +++ b/polygerrit-ui/app/elements/gr-change-view.html @@ -16,6 +16,7 @@ limitations under the License. + @@ -177,10 +178,8 @@ limitations under the License. Owner - [[_change.owner.name]] - - ([[_change.owner.email]]) - + @@ -226,8 +225,8 @@ limitations under the License.
[[label.value]] - [[label.accountName]] - ([[label.accountEmail]]) +
@@ -444,8 +443,7 @@ limitations under the License. result.push({ value: labelValPrefix + label.value, className: labelClassName, - accountName: label.name, - accountEmail: label.email, + account: label, }); } }); diff --git a/polygerrit-ui/app/elements/gr-message.html b/polygerrit-ui/app/elements/gr-message.html index 74000b3cea..c1d0e2ef77 100644 --- a/polygerrit-ui/app/elements/gr-message.html +++ b/polygerrit-ui/app/elements/gr-message.html @@ -15,6 +15,7 @@ limitations under the License. --> + @@ -29,15 +30,10 @@ limitations under the License. :host(:not([expanded])) { cursor: pointer; } - .avatar { - border-radius: 50%; + [is="gr-avatar"] { position: absolute; left: var(--default-horizontal-margin); } - :not(.hideAvatar):not(.showAvatar) .avatar, - .hideAvatar .avatar { - display: none; - } .collapsed .contentContainer { color: #777; white-space: nowrap; @@ -57,17 +53,13 @@ limitations under the License. margin-left: 0; padding: 10px 75px 10px 0; } - .collapsed .avatar { + .collapsed [is="gr-avatar"] { top: 8px; - } - .expanded .avatar { - top: 12px; - } - .collapsed .avatar { height: 1.75em; width: 1.75em; } - .expanded .avatar { + .expanded [is="gr-avatar"] { + top: 12px; height: 2.5em; width: 2.5em; } @@ -100,7 +92,7 @@ limitations under the License. }
- +
[[message.author.name]]
@@ -146,7 +138,8 @@ limitations under the License. ready: function() { app.configReady.then(function(cfg) { - this.showAvatar = !!(cfg && cfg.plugin && cfg.plugin.has_avatars); + this.showAvatar = !!(cfg && cfg.plugin && cfg.plugin.has_avatars) && + this.message && this.message.author; }.bind(this)); }, @@ -172,11 +165,6 @@ limitations under the License. return classes.join(' '); }, - _computeAvatarURL: function(author, showAvatar) { - if (!showAvatar || !author) { return '' } - return '/accounts/' + author._account_id + '/avatar?s=100'; - }, - }); })(); diff --git a/polygerrit-ui/app/elements/gr-reviewer-list.html b/polygerrit-ui/app/elements/gr-reviewer-list.html index a799415f3d..cd7d447878 100644 --- a/polygerrit-ui/app/elements/gr-reviewer-list.html +++ b/polygerrit-ui/app/elements/gr-reviewer-list.html @@ -76,10 +76,7 @@ limitations under the License.