]> git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/frontend/src/app/shared/directives/milliseconds.directive.ts
import 15.2.0 Octopus source
[ceph.git] / ceph / src / pybind / mgr / dashboard / frontend / src / app / shared / directives / milliseconds.directive.ts
1 import { Directive, EventEmitter, HostListener, Input, OnInit } from '@angular/core';
2 import { NgControl } from '@angular/forms';
3
4 import { FormatterService } from '../services/formatter.service';
5
6 @Directive({
7 selector: '[cdMilliseconds]'
8 })
9 export class MillisecondsDirective implements OnInit {
10 @Input()
11 ngDataReady: EventEmitter<any>;
12
13 constructor(private control: NgControl, private formatter: FormatterService) {}
14
15 setValue(value: string): void {
16 const ms = this.formatter.toMilliseconds(value);
17 this.control.control.setValue(`${ms} ms`);
18 }
19
20 ngOnInit(): void {
21 this.setValue(this.control.value);
22 if (this.ngDataReady) {
23 this.ngDataReady.subscribe(() => this.setValue(this.control.value));
24 }
25 }
26
27 @HostListener('blur', ['$event.target.value'])
28 onUpdate(value: string) {
29 this.setValue(value);
30 }
31 }