2022-03-21 21:21:21 +01:00
|
|
|
import { Clipboard } from '@angular/cdk/clipboard';
|
2022-02-28 23:18:07 +01:00
|
|
|
import { Component, Input } from '@angular/core';
|
2022-03-28 17:26:50 +02:00
|
|
|
import { SnackBarType } from "src/app/models/dto/snack-bar-type.dto";
|
2022-03-01 21:51:21 +01:00
|
|
|
import { UtilService } from 'src/app/util/util.service';
|
2022-02-28 23:18:07 +01:00
|
|
|
|
|
|
|
|
@Component({
|
2022-03-03 22:48:03 +01:00
|
|
|
selector: 'copyfield',
|
|
|
|
|
templateUrl: './copyfield.component.html',
|
|
|
|
|
styleUrls: ['./copyfield.component.scss'],
|
2022-02-28 23:18:07 +01:00
|
|
|
})
|
|
|
|
|
export class CopyFieldComponent {
|
2022-03-28 16:47:07 +02:00
|
|
|
// Two parameters: name, value
|
2022-03-01 20:41:55 +01:00
|
|
|
@Input() label: string = 'Loading...';
|
|
|
|
|
@Input() value: string = 'Loading...';
|
|
|
|
|
|
2022-03-21 21:21:21 +01:00
|
|
|
constructor(private utilService: UtilService, private clipboard: Clipboard) {}
|
2022-02-28 23:18:07 +01:00
|
|
|
|
|
|
|
|
public copy() {
|
2022-03-21 21:21:21 +01:00
|
|
|
if (this.clipboard.copy(this.value)) {
|
|
|
|
|
this.utilService.showSnackBar(`Copied ${this.label}!`, SnackBarType.Info);
|
|
|
|
|
return;
|
2022-03-01 21:51:21 +01:00
|
|
|
}
|
2022-02-28 23:18:07 +01:00
|
|
|
|
2022-03-21 21:21:21 +01:00
|
|
|
return this.utilService.showSnackBar(
|
|
|
|
|
'Copying to clipboard failed',
|
|
|
|
|
SnackBarType.Error
|
|
|
|
|
);
|
2022-02-28 23:18:07 +01:00
|
|
|
}
|
|
|
|
|
}
|