Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* This file is part of Anis Client.
*
* @copyright Laboratoire d'Astrophysique de Marseille / CNRS
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { FormControl } from '@angular/forms';
import { rangeValidator } from '../../validators';
import { ConeSearch } from 'src/app/instance/store/models';
@Component({
selector: 'app-radius',
templateUrl: 'radius.component.html',
styleUrls: ['radius.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush
})
/**
* @class
* @classdesc Radius component.
*/
export class RadiusComponent {
/**
* Sets RA, DEC and radius from cone search.
*
* @param {ConeSearch} coneSearch - The cone search.
*/
@Input()
set coneSearch(coneSearch: ConeSearch) {
this.ra = coneSearch.ra;
this.dec = coneSearch.dec;
if (coneSearch.radius) {
this.radiusField.setValue(coneSearch.radius);
this.radiusRange.setValue(coneSearch.radius);
} else {
this.radiusRange.setValue(0);
this.radiusField.setValue(0);
}
}
/**
* Disables radius fields.
*
* @param {boolean} disabled - If the field has to be disabled.
*/
@Input()
set disabled(disabled: boolean) {
if (disabled) {
this.radiusField.disable();
this.radiusRange.disable();
} else {
this.radiusField.enable();
this.radiusRange.enable();
}
}
@Output() updateConeSearch: EventEmitter<ConeSearch> = new EventEmitter();
ra: number;
dec: number;
radiusRange = new FormControl('');
radiusField = new FormControl('', [rangeValidator(0, 150, 'Radius')]);
/**
* Sets radius value form inputs and emits cone search event.
*
* @param {string} value - The value of radius.
*
* @fires EventEmitter<ConeSearch>
*/
radiusChange(value: string): void {
this.radiusField.setValue(+value);
this.radiusRange.setValue(+value);
this.updateConeSearch.emit({ ra: this.ra, dec: this.dec, radius: +value } as ConeSearch);
}
}