blob: a972db37fc70eb222bbe1f858c3552a151445bd5 [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 */
Paladox none5b3746d2017-06-21 15:30:03 +000017
Milutin Kristofic79dc3ec2020-08-19 21:56:21 +020018import {getBaseUrl} from '../../../utils/url-util';
Milutin Kristofic79dc3ec2020-08-19 21:56:21 +020019import {ContributorAgreementInfo} from '../../../types/common';
Ben Rohlfs43935a42020-12-01 19:14:09 +010020import {appContext} from '../../../services/app-context';
Paladox nonecc167472021-08-10 23:20:12 +000021import {formStyles} from '../../../styles/gr-form-styles';
22import {sharedStyles} from '../../../styles/shared-styles';
Ben Rohlfse2b2f592021-09-07 08:47:53 +000023import {css, html, LitElement} from 'lit';
24import {customElement, property} from 'lit/decorators';
Paladox none5b3746d2017-06-21 15:30:03 +000025
Milutin Kristofic79dc3ec2020-08-19 21:56:21 +020026@customElement('gr-agreements-list')
Paladox nonecc167472021-08-10 23:20:12 +000027export class GrAgreementsList extends LitElement {
Milutin Kristofic79dc3ec2020-08-19 21:56:21 +020028 @property({type: Array})
29 _agreements?: ContributorAgreementInfo[];
30
Ben Rohlfs43935a42020-12-01 19:14:09 +010031 private readonly restApiService = appContext.restApiService;
32
Chris Poucet59dad572021-08-20 15:25:36 +000033 override connectedCallback() {
Ben Rohlfs5f520da2021-03-10 14:58:43 +010034 super.connectedCallback();
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010035 this.loadData();
36 }
37
38 loadData() {
Ben Rohlfs43935a42020-12-01 19:14:09 +010039 return this.restApiService.getAccountAgreements().then(agreements => {
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010040 this._agreements = agreements;
41 });
42 }
43
Gerrit Code Reviewd3f24192021-09-28 10:30:30 +020044 static override get styles() {
Paladox nonecc167472021-08-10 23:20:12 +000045 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 Reviewd3f24192021-09-28 10:30:30 +020074 override render() {
Paladox nonecc167472021-08-10 23:20:12 +000075 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 Filippovdaf0ec92020-03-17 11:27:28 +010093 getUrl() {
Milutin Kristofic79dc3ec2020-08-19 21:56:21 +020094 return `${getBaseUrl()}/settings/new-agreement`;
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010095 }
96
Milutin Kristofic79dc3ec2020-08-19 21:56:21 +020097 getUrlBase(item: string) {
98 return `${getBaseUrl()}/${item}`;
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010099 }
100}
101
Milutin Kristofic79dc3ec2020-08-19 21:56:21 +0200102declare global {
103 interface HTMLElementTagNameMap {
104 'gr-agreements-list': GrAgreementsList;
105 }
106}