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 | */ |
Paladox none | 5b3746d | 2017-06-21 15:30:03 +0000 | [diff] [blame] | 17 | |
Milutin Kristofic | 79dc3ec | 2020-08-19 21:56:21 +0200 | [diff] [blame] | 18 | import {getBaseUrl} from '../../../utils/url-util'; |
Milutin Kristofic | 79dc3ec | 2020-08-19 21:56:21 +0200 | [diff] [blame] | 19 | import {ContributorAgreementInfo} from '../../../types/common'; |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 20 | import {appContext} from '../../../services/app-context'; |
Paladox none | cc16747 | 2021-08-10 23:20:12 +0000 | [diff] [blame] | 21 | import {formStyles} from '../../../styles/gr-form-styles'; |
| 22 | import {sharedStyles} from '../../../styles/shared-styles'; |
Ben Rohlfs | e2b2f59 | 2021-09-07 08:47:53 +0000 | [diff] [blame] | 23 | import {css, html, LitElement} from 'lit'; |
| 24 | import {customElement, property} from 'lit/decorators'; |
Paladox none | 5b3746d | 2017-06-21 15:30:03 +0000 | [diff] [blame] | 25 | |
Milutin Kristofic | 79dc3ec | 2020-08-19 21:56:21 +0200 | [diff] [blame] | 26 | @customElement('gr-agreements-list') |
Paladox none | cc16747 | 2021-08-10 23:20:12 +0000 | [diff] [blame] | 27 | export class GrAgreementsList extends LitElement { |
Milutin Kristofic | 79dc3ec | 2020-08-19 21:56:21 +0200 | [diff] [blame] | 28 | @property({type: Array}) |
| 29 | _agreements?: ContributorAgreementInfo[]; |
| 30 | |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 31 | private readonly restApiService = appContext.restApiService; |
| 32 | |
Chris Poucet | 59dad57 | 2021-08-20 15:25:36 +0000 | [diff] [blame] | 33 | override connectedCallback() { |
Ben Rohlfs | 5f520da | 2021-03-10 14:58:43 +0100 | [diff] [blame] | 34 | super.connectedCallback(); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 35 | this.loadData(); |
| 36 | } |
| 37 | |
| 38 | loadData() { |
Ben Rohlfs | 43935a4 | 2020-12-01 19:14:09 +0100 | [diff] [blame] | 39 | return this.restApiService.getAccountAgreements().then(agreements => { |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 40 | this._agreements = agreements; |
| 41 | }); |
| 42 | } |
| 43 | |
Gerrit Code Review | d3f2419 | 2021-09-28 10:30:30 +0200 | [diff] [blame] | 44 | static override get styles() { |
Paladox none | cc16747 | 2021-08-10 23:20:12 +0000 | [diff] [blame] | 45 | return [ |
| 46 | sharedStyles, |
| 47 | css` |
| 48 | #agreements .nameColumn { |
| 49 | min-width: 15em; |
| 50 | width: auto; |
| 51 | } |
| 52 | #agreements .descriptionColumn { |
| 53 | width: auto; |
| 54 | } |
| 55 | `, |
| 56 | formStyles, |
| 57 | ]; |
| 58 | } |
| 59 | |
| 60 | renderAgreement(agreement: ContributorAgreementInfo) { |
| 61 | if (!agreement) return; |
| 62 | return html` |
| 63 | <tr> |
| 64 | <td class="nameColumn"> |
| 65 | <a href="${this.getUrlBase(agreement.url)}" rel="external"> |
| 66 | ${agreement.name} |
| 67 | </a> |
| 68 | </td> |
| 69 | <td class="descriptionColumn">${agreement.description}</td> |
| 70 | </tr> |
| 71 | `; |
| 72 | } |
| 73 | |
Gerrit Code Review | d3f2419 | 2021-09-28 10:30:30 +0200 | [diff] [blame] | 74 | override render() { |
Paladox none | cc16747 | 2021-08-10 23:20:12 +0000 | [diff] [blame] | 75 | return html` <div class="gr-form-styles"> |
| 76 | <table id="agreements"> |
| 77 | <thead> |
| 78 | <tr> |
| 79 | <th class="nameColumn">Name</th> |
| 80 | <th class="descriptionColumn">Description</th> |
| 81 | </tr> |
| 82 | </thead> |
| 83 | <tbody> |
| 84 | ${(this._agreements ?? []).map(agreement => |
| 85 | this.renderAgreement(agreement) |
| 86 | )} |
| 87 | </tbody> |
| 88 | </table> |
| 89 | <a href="${this.getUrl()}">New Contributor Agreement</a> |
| 90 | </div>`; |
| 91 | } |
| 92 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 93 | getUrl() { |
Milutin Kristofic | 79dc3ec | 2020-08-19 21:56:21 +0200 | [diff] [blame] | 94 | return `${getBaseUrl()}/settings/new-agreement`; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 95 | } |
| 96 | |
Milutin Kristofic | 79dc3ec | 2020-08-19 21:56:21 +0200 | [diff] [blame] | 97 | getUrlBase(item: string) { |
| 98 | return `${getBaseUrl()}/${item}`; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | |
Milutin Kristofic | 79dc3ec | 2020-08-19 21:56:21 +0200 | [diff] [blame] | 102 | declare global { |
| 103 | interface HTMLElementTagNameMap { |
| 104 | 'gr-agreements-list': GrAgreementsList; |
| 105 | } |
| 106 | } |