blob: 1cc1369c47ccd50bda13207cf8815c282a85116c [file] [log] [blame]
Dave Borowitz8cdc76b2018-03-26 10:04:27 -04001/**
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 Filippovdaf0ec92020-03-17 11:27:28 +010017import '../../../scripts/bundled-polymer.js';
Wyatt Allen64056502016-06-16 14:53:01 -070018
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010019import '../../../styles/shared-styles.js';
20import '../../../styles/gr-form-styles.js';
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010021import '../../shared/gr-rest-api-interface/gr-rest-api-interface.js';
22import {GestureEventListeners} from '@polymer/polymer/lib/mixins/gesture-event-listeners.js';
23import {LegacyElementMixin} from '@polymer/polymer/lib/legacy/legacy-element-mixin.js';
24import {PolymerElement} from '@polymer/polymer/polymer-element.js';
25import {htmlTemplate} from './gr-group-list_html.js';
Dmitrii Filippoveb8b2692020-04-06 18:02:35 +020026import {GerritNav} from '../../core/gr-navigation/gr-navigation.js';
Wyatt Allen64056502016-06-16 14:53:01 -070027
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010028/** @extends Polymer.Element */
29class GrGroupList extends GestureEventListeners(
30 LegacyElementMixin(
31 PolymerElement)) {
32 static get template() { return htmlTemplate; }
Wyatt Allen64056502016-06-16 14:53:01 -070033
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010034 static get is() { return 'gr-group-list'; }
Wyatt Allen64056502016-06-16 14:53:01 -070035
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010036 static get properties() {
37 return {
38 _groups: Array,
39 };
Dmitrii Filippov3fd2b102019-11-15 16:16:46 +010040 }
41
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010042 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 Filippoveb8b2692020-04-06 18:02:35 +020057 return GerritNav.getUrlForGroup(decodeURIComponent(group.id));
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010058 }
59}
60
61customElements.define(GrGroupList.is, GrGroupList);