|
|
@ -1,17 +1,25 @@ |
|
|
import { getLocale } from '@ghostfolio/common/helper'; |
|
|
import { getLocale } from '@ghostfolio/common/helper'; |
|
|
|
|
|
|
|
|
|
|
|
import { Clipboard } from '@angular/cdk/clipboard'; |
|
|
import { CommonModule } from '@angular/common'; |
|
|
import { CommonModule } from '@angular/common'; |
|
|
import { |
|
|
import { |
|
|
CUSTOM_ELEMENTS_SCHEMA, |
|
|
AfterViewInit, |
|
|
ChangeDetectionStrategy, |
|
|
ChangeDetectionStrategy, |
|
|
Component, |
|
|
Component, |
|
|
|
|
|
computed, |
|
|
|
|
|
CUSTOM_ELEMENTS_SCHEMA, |
|
|
|
|
|
ElementRef, |
|
|
|
|
|
input, |
|
|
Input, |
|
|
Input, |
|
|
OnChanges, |
|
|
OnChanges, |
|
|
computed, |
|
|
ViewChild |
|
|
input |
|
|
|
|
|
} from '@angular/core'; |
|
|
} from '@angular/core'; |
|
|
|
|
|
import { MatSnackBar } from '@angular/material/snack-bar'; |
|
|
import { IonIcon } from '@ionic/angular/standalone'; |
|
|
import { IonIcon } from '@ionic/angular/standalone'; |
|
|
|
|
|
import { addIcons } from 'ionicons'; |
|
|
|
|
|
import { copyOutline } from 'ionicons/icons'; |
|
|
import { isNumber } from 'lodash'; |
|
|
import { isNumber } from 'lodash'; |
|
|
|
|
|
import ms from 'ms'; |
|
|
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; |
|
|
import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
@ -22,9 +30,10 @@ import { NgxSkeletonLoaderModule } from 'ngx-skeleton-loader'; |
|
|
styleUrls: ['./value.component.scss'], |
|
|
styleUrls: ['./value.component.scss'], |
|
|
templateUrl: './value.component.html' |
|
|
templateUrl: './value.component.html' |
|
|
}) |
|
|
}) |
|
|
export class GfValueComponent implements OnChanges { |
|
|
export class GfValueComponent implements AfterViewInit, OnChanges { |
|
|
@Input() colorizeSign = false; |
|
|
@Input() colorizeSign = false; |
|
|
@Input() deviceType: string; |
|
|
@Input() deviceType: string; |
|
|
|
|
|
@Input() enableCopyToClipboardButton = false; |
|
|
@Input() icon = ''; |
|
|
@Input() icon = ''; |
|
|
@Input() isAbsolute = false; |
|
|
@Input() isAbsolute = false; |
|
|
@Input() isCurrency = false; |
|
|
@Input() isCurrency = false; |
|
|
@ -37,12 +46,24 @@ export class GfValueComponent implements OnChanges { |
|
|
@Input() unit = ''; |
|
|
@Input() unit = ''; |
|
|
@Input() value: number | string = ''; |
|
|
@Input() value: number | string = ''; |
|
|
|
|
|
|
|
|
|
|
|
@ViewChild('labelContent', { static: false }) labelContent!: ElementRef; |
|
|
|
|
|
|
|
|
public absoluteValue = 0; |
|
|
public absoluteValue = 0; |
|
|
public formattedValue = ''; |
|
|
public formattedValue = ''; |
|
|
|
|
|
public hasLabel = false; |
|
|
public isNumber = false; |
|
|
public isNumber = false; |
|
|
public isString = false; |
|
|
public isString = false; |
|
|
public useAbsoluteValue = false; |
|
|
public useAbsoluteValue = false; |
|
|
|
|
|
|
|
|
|
|
|
public constructor( |
|
|
|
|
|
private clipboard: Clipboard, |
|
|
|
|
|
private snackBar: MatSnackBar |
|
|
|
|
|
) { |
|
|
|
|
|
addIcons({ |
|
|
|
|
|
copyOutline |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public readonly precision = input<number>(); |
|
|
public readonly precision = input<number>(); |
|
|
|
|
|
|
|
|
private readonly formatOptions = computed<Intl.NumberFormatOptions>(() => { |
|
|
private readonly formatOptions = computed<Intl.NumberFormatOptions>(() => { |
|
|
@ -59,6 +80,20 @@ export class GfValueComponent implements OnChanges { |
|
|
return precision !== undefined && precision >= 0; |
|
|
return precision !== undefined && precision >= 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private initializeVariables() { |
|
|
|
|
|
this.absoluteValue = 0; |
|
|
|
|
|
this.formattedValue = ''; |
|
|
|
|
|
this.isNumber = false; |
|
|
|
|
|
this.isString = false; |
|
|
|
|
|
this.locale = this.locale || getLocale(); |
|
|
|
|
|
this.useAbsoluteValue = false; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public ngAfterViewInit() { |
|
|
|
|
|
const el = this.labelContent.nativeElement; |
|
|
|
|
|
this.hasLabel = el.textContent.trim().length > 0 || el.children.length > 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public ngOnChanges() { |
|
|
public ngOnChanges() { |
|
|
this.initializeVariables(); |
|
|
this.initializeVariables(); |
|
|
|
|
|
|
|
|
@ -137,12 +172,20 @@ export class GfValueComponent implements OnChanges { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private initializeVariables() { |
|
|
public onCopyValueToClipboard() { |
|
|
this.absoluteValue = 0; |
|
|
if (this.value || this.value === 0) { |
|
|
this.formattedValue = ''; |
|
|
this.clipboard.copy(this.formattedValue); |
|
|
this.isNumber = false; |
|
|
this.snackBar.open( |
|
|
this.isString = false; |
|
|
'✅ ' + $localize`Value has been copied to the clipboard`, |
|
|
this.locale = this.locale || getLocale(); |
|
|
undefined, |
|
|
this.useAbsoluteValue = false; |
|
|
{ |
|
|
|
|
|
duration: ms('3 seconds') |
|
|
|
|
|
} |
|
|
|
|
|
); |
|
|
|
|
|
} else { |
|
|
|
|
|
this.snackBar.open($localize`Value is empty`, undefined, { |
|
|
|
|
|
duration: ms('3 seconds') |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|