Dave Borowitz | 8cdc76b | 2018-03-26 10:04:27 -0400 | [diff] [blame] | 1 | /** |
| 2 | * @license |
| 3 | * Copyright (C) 2016 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 | */ |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 17 | import '../../../scripts/bundled-polymer.js'; |
Wyatt Allen | 6405650 | 2016-06-16 14:53:01 -0700 | [diff] [blame] | 18 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 19 | import '../../../styles/shared-styles.js'; |
| 20 | import '../../../styles/gr-form-styles.js'; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 21 | import '../../shared/gr-rest-api-interface/gr-rest-api-interface.js'; |
| 22 | import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js'; |
| 23 | import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js'; |
| 24 | import {PolymerElement} from '@polymer/polymer/polymer-element.js'; |
| 25 | import {htmlTemplate} from './gr-group-list_html.js'; |
Dmitrii Filippov | eb8b269 | 2020-04-06 18:02:35 +0200 | [diff] [blame] | 26 | import {GerritNav} from '../../core/gr-navigation/gr-navigation.js'; |
Wyatt Allen | 6405650 | 2016-06-16 14:53:01 -0700 | [diff] [blame] | 27 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 28 | /** @extends Polymer.Element */ |
| 29 | class GrGroupList extends GestureEventListeners( |
| 30 | LegacyElementMixin( |
| 31 | PolymerElement)) { |
| 32 | static get template() { return htmlTemplate; } |
Wyatt Allen | 6405650 | 2016-06-16 14:53:01 -0700 | [diff] [blame] | 33 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 34 | static get is() { return 'gr-group-list'; } |
Wyatt Allen | 6405650 | 2016-06-16 14:53:01 -0700 | [diff] [blame] | 35 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 36 | static get properties() { |
| 37 | return { |
| 38 | _groups: Array, |
| 39 | }; |
Dmitrii Filippov | 3fd2b10 | 2019-11-15 16:16:46 +0100 | [diff] [blame] | 40 | } |
| 41 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 42 | loadData() { |
| 43 | return this.$.restAPI.getAccountGroups().then(groups => { |
| 44 | this._groups = groups.sort((a, b) => a.name.localeCompare(b.name)); |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | _computeVisibleToAll(group) { |
| 49 | return group.options.visible_to_all ? 'Yes' : 'No'; |
| 50 | } |
| 51 | |
| 52 | _computeGroupPath(group) { |
| 53 | if (!group || !group.id) { return; } |
| 54 | |
| 55 | // Group ID is already encoded from the API |
| 56 | // Decode it here to match with our router encoding behavior |
Dmitrii Filippov | eb8b269 | 2020-04-06 18:02:35 +0200 | [diff] [blame] | 57 | return GerritNav.getUrlForGroup(decodeURIComponent(group.id)); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
| 61 | customElements.define(GrGroupList.is, GrGroupList); |