• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16import {Component, Input} from '@angular/core';
17import {Chip} from 'viewers/common/chip';
18import {HierarchyTreeNode, Terminal, UiTreeNode} from 'viewers/common/ui_tree_utils';
19import {treeNodeDataViewStyles} from 'viewers/components/styles/tree_node_data_view.styles';
20
21@Component({
22  selector: 'tree-node-data-view',
23  template: `
24    <span class="mat-body-1">
25      <span class="mat-body-2">{{ item.kind }}</span>
26      <ng-container *ngIf="item.kind && item.name">&ngsp;-&ngsp;</ng-container>
27      <span *ngIf="showShortName()" [matTooltip]="itemTooltip()">{{ itemShortName() }}</span>
28      <ng-container *ngIf="!showShortName()">{{ item.name }}</ng-container>
29      <div *ngFor="let chip of chips()" [class]="chipClass(chip)" [matTooltip]="chip.long">
30        {{ chip.short }}
31      </div>
32    </span>
33  `,
34  styles: [treeNodeDataViewStyles],
35})
36export class TreeNodeDataViewComponent {
37  @Input() item!: UiTreeNode;
38
39  chips() {
40    return this.item instanceof HierarchyTreeNode ? this.item.chips : [];
41  }
42
43  itemShortName() {
44    return this.item instanceof HierarchyTreeNode && this.item.shortName
45      ? this.item.shortName
46      : this.item.name;
47  }
48
49  itemTooltip() {
50    if (this.item.name instanceof Terminal) {
51      return '';
52    }
53    return this.item.name ?? '';
54  }
55
56  showShortName() {
57    return (
58      this.item instanceof HierarchyTreeNode &&
59      this.item.simplifyNames &&
60      this.item.shortName &&
61      this.item.shortName !== this.item.name
62    );
63  }
64
65  chipClass(chip: Chip) {
66    return [
67      'tree-view-internal-chip',
68      'tree-view-chip',
69      'tree-view-chip' + '-' + (chip.type.toString() || 'default'),
70    ];
71  }
72}
73