Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 1 | /** |
| 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 Allen | 5c3a3cd | 2017-08-30 13:43:37 -0700 | [diff] [blame] | 17 | (function() { |
| 18 | 'use strict'; |
| 19 | |
| 20 | Polymer({ |
| 21 | is: 'gr-user-header', |
Paladox none | 44c55c5 | 2019-10-14 12:43:51 +0000 | [diff] [blame^] | 22 | |
Wyatt Allen | 5c3a3cd | 2017-08-30 13:43:37 -0700 | [diff] [blame] | 23 | properties: { |
| 24 | /** @type {?String} */ |
| 25 | userId: { |
| 26 | type: String, |
| 27 | observer: '_accountChanged', |
| 28 | }, |
| 29 | |
Wyatt Allen | 6d4ea58 | 2018-01-29 14:30:28 -0800 | [diff] [blame] | 30 | showDashboardLink: { |
| 31 | type: Boolean, |
| 32 | value: false, |
| 33 | }, |
| 34 | |
| 35 | loggedIn: { |
| 36 | type: Boolean, |
| 37 | value: false, |
| 38 | }, |
| 39 | |
Wyatt Allen | 5c3a3cd | 2017-08-30 13:43:37 -0700 | [diff] [blame] | 40 | /** |
| 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 Allen | 6d4ea58 | 2018-01-29 14:30:28 -0800 | [diff] [blame] | 81 | |
| 82 | _computeDashboardUrl(accountDetails) { |
Sven Selberg | 0d2b52f | 2019-08-28 15:46:43 +0200 | [diff] [blame] | 83 | 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 Allen | 6d4ea58 | 2018-01-29 14:30:28 -0800 | [diff] [blame] | 88 | }, |
| 89 | |
| 90 | _computeDashboardLinkClass(showDashboardLink, loggedIn) { |
| 91 | return showDashboardLink && loggedIn ? |
| 92 | 'dashboardLink' : 'dashboardLink hide'; |
| 93 | }, |
Wyatt Allen | 5c3a3cd | 2017-08-30 13:43:37 -0700 | [diff] [blame] | 94 | }); |
| 95 | })(); |