|
1 |
| -import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core'; |
| 1 | +import { Component, OnInit, Input, Output, EventEmitter, Renderer2 } from '@angular/core'; |
2 | 2 | import { trigger, state, style, animate, transition } from '@angular/animations';
|
| 3 | +import { from } from 'rxjs'; |
3 | 4 |
|
4 | 5 | import { SortOption } from './server-and-agent-list-container.component';
|
5 | 6 |
|
| 7 | +const enum ListStyle { |
| 8 | + LEFT_PADDING = 17, |
| 9 | + ICON_WIDTH = 17 |
| 10 | +} |
| 11 | + |
6 | 12 | @Component({
|
7 | 13 | selector: 'pp-server-and-agent-list',
|
8 | 14 | templateUrl: './server-and-agent-list.component.html',
|
@@ -57,7 +63,9 @@ export class ServerAndAgentListComponent implements OnInit {
|
57 | 63 | private _serverKeyList: string[];
|
58 | 64 | isCollapsed: { [key: string]: boolean };
|
59 | 65 |
|
60 |
| - constructor() {} |
| 66 | + constructor( |
| 67 | + private renderer: Renderer2 |
| 68 | + ) {} |
61 | 69 | ngOnInit() {}
|
62 | 70 | getIconPath(iconState: number) {
|
63 | 71 | let iconName = '';
|
@@ -106,4 +114,33 @@ export class ServerAndAgentListComponent implements OnInit {
|
106 | 114 | return agentName ? agentName : `N/A (${agentId})`;
|
107 | 115 | }
|
108 | 116 | }
|
| 117 | + |
| 118 | + getLeftPosition(labelWrapperElement: HTMLElement, labelElement: HTMLElement): string { |
| 119 | + const labelWrapperWidth = labelWrapperElement.offsetWidth; |
| 120 | + const labelWidth = labelElement.offsetWidth; |
| 121 | + |
| 122 | + return labelWidth + ListStyle.ICON_WIDTH >= labelWrapperWidth |
| 123 | + ? `${ListStyle.LEFT_PADDING + labelWrapperWidth - 25}px` |
| 124 | + : `${ListStyle.LEFT_PADDING + ListStyle.ICON_WIDTH + labelElement.offsetWidth - 4}px`; |
| 125 | + } |
| 126 | + |
| 127 | + onClickCopy(event: Event, agentLabel: string): void { |
| 128 | + event.stopPropagation(); |
| 129 | + from(navigator.clipboard.writeText(agentLabel)).subscribe(() => { |
| 130 | + const copyBtnElement = event.target as HTMLElement; |
| 131 | + const wrapperElement = copyBtnElement.parentElement; |
| 132 | + const pElement = this.renderer.createElement('p'); |
| 133 | + const copiedTextElement = this.renderer.createText('Copied'); |
| 134 | + |
| 135 | + this.renderer.setStyle(copyBtnElement, 'display', 'none'); |
| 136 | + this.renderer.setStyle(pElement, 'font-size', '10px'); |
| 137 | + this.renderer.appendChild(pElement, copiedTextElement); |
| 138 | + this.renderer.appendChild(wrapperElement, pElement); |
| 139 | + |
| 140 | + setTimeout(() => { |
| 141 | + this.renderer.removeChild(wrapperElement, pElement); |
| 142 | + this.renderer.setStyle(copyBtnElement, 'display', 'inline-block'); |
| 143 | + }, 1500); |
| 144 | + }); |
| 145 | + } |
109 | 146 | }
|
0 commit comments