blob: 6942705d4f78df321d13aaced4b16057e2819d3e [file] [log] [blame]
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04001/**
2 * @license
3 * Copyright (C) 2017 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
Wyatt Allen5c3a3cd2017-08-30 13:43:37 -070017(function() {
18 'use strict';
19
20 Polymer({
21 is: 'gr-user-header',
Paladox none44c55c52019-10-14 12:43:51 +000022
Wyatt Allen5c3a3cd2017-08-30 13:43:37 -070023 properties: {
24 /** @type {?String} */
25 userId: {
26 type: String,
27 observer: '_accountChanged',
28 },
29
Wyatt Allen6d4ea582018-01-29 14:30:28 -080030 showDashboardLink: {
31 type: Boolean,
32 value: false,
33 },
34
35 loggedIn: {
36 type: Boolean,
37 value: false,
38 },
39
Wyatt Allen5c3a3cd2017-08-30 13:43:37 -070040 /**
41 * @type {?{name: ?, email: ?, registered_on: ?}}
42 */
43 _accountDetails: {
44 type: Object,
45 value: null,
46 },
47
48 /** @type {?String} */
49 _status: {
50 type: String,
51 value: null,
52 },
53 },
54
55 _accountChanged(userId) {
56 if (!userId) {
57 this._accountDetails = null;
58 this._status = null;
59 return;
60 }
61
62 this.$.restAPI.getAccountDetails(userId).then(details => {
63 this._accountDetails = details;
64 });
65 this.$.restAPI.getAccountStatus(userId).then(status => {
66 this._status = status;
67 });
68 },
69
70 _computeDisplayClass(status) {
71 return status ? ' ' : 'hide';
72 },
73
74 _computeDetail(accountDetails, name) {
75 return accountDetails ? accountDetails[name] : '';
76 },
77
78 _computeStatusClass(accountDetails) {
79 return this._computeDetail(accountDetails, 'status') ? '' : 'hide';
80 },
Wyatt Allen6d4ea582018-01-29 14:30:28 -080081
82 _computeDashboardUrl(accountDetails) {
Sven Selberg0d2b52f2019-08-28 15:46:43 +020083 if (!accountDetails) { return null; }
84 const id = accountDetails._account_id;
85 const email = accountDetails.email;
86 if (!id && !email ) { return null; }
87 return Gerrit.Nav.getUrlForUserDashboard(id ? id : email);
Wyatt Allen6d4ea582018-01-29 14:30:28 -080088 },
89
90 _computeDashboardLinkClass(showDashboardLink, loggedIn) {
91 return showDashboardLink && loggedIn ?
92 'dashboardLink' : 'dashboardLink hide';
93 },
Wyatt Allen5c3a3cd2017-08-30 13:43:37 -070094 });
95})();