|
|
@ -19,22 +19,23 @@ import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Valida |
|
|
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
|
|
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
|
|
import { MatChipInputEvent } from '@angular/material/chips'; |
|
|
import { MatChipInputEvent } from '@angular/material/chips'; |
|
|
import { COMMA, ENTER, SEMICOLON } from '@angular/cdk/keycodes'; |
|
|
import { COMMA, ENTER, SEMICOLON } from '@angular/cdk/keycodes'; |
|
|
|
|
|
import { FloatLabelType, MatFormFieldAppearance } from '@angular/material/form-field/form-field'; |
|
|
|
|
|
|
|
|
@Component({ |
|
|
@Component({ |
|
|
selector: 'tb-alarm-type-list', |
|
|
selector: 'tb-string-items-list', |
|
|
templateUrl: './alarm-type-list.component.html', |
|
|
templateUrl: './string-items-list.component.html', |
|
|
styleUrls: [], |
|
|
styleUrls: [], |
|
|
providers: [ |
|
|
providers: [ |
|
|
{ |
|
|
{ |
|
|
provide: NG_VALUE_ACCESSOR, |
|
|
provide: NG_VALUE_ACCESSOR, |
|
|
useExisting: forwardRef(() => AlarmTypeListComponent), |
|
|
useExisting: forwardRef(() => StringItemsListComponent), |
|
|
multi: true |
|
|
multi: true |
|
|
} |
|
|
} |
|
|
] |
|
|
] |
|
|
}) |
|
|
}) |
|
|
export class AlarmTypeListComponent implements ControlValueAccessor{ |
|
|
export class StringItemsListComponent implements ControlValueAccessor{ |
|
|
|
|
|
|
|
|
alarmTypeForm: FormGroup; |
|
|
stringItemsForm: FormGroup; |
|
|
private modelValue: Array<string> | null; |
|
|
private modelValue: Array<string> | null; |
|
|
|
|
|
|
|
|
readonly separatorKeysCodes: number[] = [ENTER, COMMA, SEMICOLON]; |
|
|
readonly separatorKeysCodes: number[] = [ENTER, COMMA, SEMICOLON]; |
|
|
@ -55,17 +56,35 @@ export class AlarmTypeListComponent implements ControlValueAccessor{ |
|
|
@Input() |
|
|
@Input() |
|
|
disabled: boolean; |
|
|
disabled: boolean; |
|
|
|
|
|
|
|
|
|
|
|
@Input() |
|
|
|
|
|
label: string; |
|
|
|
|
|
|
|
|
|
|
|
@Input() |
|
|
|
|
|
placeholder: string; |
|
|
|
|
|
|
|
|
|
|
|
@Input() |
|
|
|
|
|
hint: string; |
|
|
|
|
|
|
|
|
|
|
|
@Input() |
|
|
|
|
|
requiredText: string; |
|
|
|
|
|
|
|
|
|
|
|
@Input() |
|
|
|
|
|
floatLabel: FloatLabelType = 'auto'; |
|
|
|
|
|
|
|
|
|
|
|
@Input() |
|
|
|
|
|
appearance: MatFormFieldAppearance = 'standard'; |
|
|
|
|
|
|
|
|
private propagateChange = (v: any) => { }; |
|
|
private propagateChange = (v: any) => { }; |
|
|
|
|
|
|
|
|
constructor(private fb: FormBuilder) { |
|
|
constructor(private fb: FormBuilder) { |
|
|
this.alarmTypeForm = this.fb.group({ |
|
|
this.stringItemsForm = this.fb.group({ |
|
|
alarmTypes: [null, this.required ? [Validators.required] : []] |
|
|
items: [null, this.required ? [Validators.required] : []] |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
updateValidators() { |
|
|
updateValidators() { |
|
|
this.alarmTypeForm.get('alarmTypes').setValidators(this.required ? [Validators.required] : []); |
|
|
this.stringItemsForm.get('items').setValidators(this.required ? [Validators.required] : []); |
|
|
this.alarmTypeForm.get('alarmTypes').updateValueAndValidity(); |
|
|
this.stringItemsForm.get('items').updateValueAndValidity(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
registerOnChange(fn: any): void { |
|
|
registerOnChange(fn: any): void { |
|
|
@ -78,33 +97,33 @@ export class AlarmTypeListComponent implements ControlValueAccessor{ |
|
|
setDisabledState(isDisabled: boolean): void { |
|
|
setDisabledState(isDisabled: boolean): void { |
|
|
this.disabled = isDisabled; |
|
|
this.disabled = isDisabled; |
|
|
if (isDisabled) { |
|
|
if (isDisabled) { |
|
|
this.alarmTypeForm.disable({emitEvent: false}); |
|
|
this.stringItemsForm.disable({emitEvent: false}); |
|
|
} else { |
|
|
} else { |
|
|
this.alarmTypeForm.enable({emitEvent: false}); |
|
|
this.stringItemsForm.enable({emitEvent: false}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
writeValue(value: Array<string> | null): void { |
|
|
writeValue(value: Array<string> | null): void { |
|
|
if (value != null && value.length > 0) { |
|
|
if (value != null && value.length > 0) { |
|
|
this.modelValue = [...value]; |
|
|
this.modelValue = [...value]; |
|
|
this.alarmTypeForm.get('alarmTypes').setValue(value); |
|
|
this.stringItemsForm.get('items').setValue(value); |
|
|
} else { |
|
|
} else { |
|
|
this.alarmTypeForm.get('alarmTypes').setValue(null); |
|
|
this.stringItemsForm.get('items').setValue(null); |
|
|
this.modelValue = null; |
|
|
this.modelValue = null; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
addAlarmType(event: MatChipInputEvent): void { |
|
|
addItem(event: MatChipInputEvent): void { |
|
|
let alarmType = event.value || ''; |
|
|
let item = event.value || ''; |
|
|
const input = event.chipInput.inputElement; |
|
|
const input = event.chipInput.inputElement; |
|
|
alarmType = alarmType.trim(); |
|
|
item = item.trim(); |
|
|
if (alarmType) { |
|
|
if (item) { |
|
|
if (!this.modelValue || this.modelValue.indexOf(alarmType) === -1) { |
|
|
if (!this.modelValue || this.modelValue.indexOf(item) === -1) { |
|
|
if (!this.modelValue) { |
|
|
if (!this.modelValue) { |
|
|
this.modelValue = []; |
|
|
this.modelValue = []; |
|
|
} |
|
|
} |
|
|
this.modelValue.push(alarmType); |
|
|
this.modelValue.push(item); |
|
|
this.alarmTypeForm.get('alarmTypes').setValue(this.modelValue); |
|
|
this.stringItemsForm.get('items').setValue(this.modelValue); |
|
|
} |
|
|
} |
|
|
this.propagateChange(this.modelValue); |
|
|
this.propagateChange(this.modelValue); |
|
|
if (input) { |
|
|
if (input) { |
|
|
@ -113,20 +132,20 @@ export class AlarmTypeListComponent implements ControlValueAccessor{ |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
removeAlarmType(alarmType: string) { |
|
|
removeItems(item: string) { |
|
|
const index = this.modelValue.indexOf(alarmType); |
|
|
const index = this.modelValue.indexOf(item); |
|
|
if (index >= 0) { |
|
|
if (index >= 0) { |
|
|
this.modelValue.splice(index, 1); |
|
|
this.modelValue.splice(index, 1); |
|
|
if (!this.modelValue.length) { |
|
|
if (!this.modelValue.length) { |
|
|
this.modelValue = null; |
|
|
this.modelValue = null; |
|
|
} |
|
|
} |
|
|
this.alarmTypeForm.get('alarmTypes').setValue(this.modelValue); |
|
|
this.stringItemsForm.get('items').setValue(this.modelValue); |
|
|
this.propagateChange(this.modelValue); |
|
|
this.propagateChange(this.modelValue); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
get alarmTypeList(): string[] { |
|
|
get stringItemsList(): string[] { |
|
|
return this.alarmTypeForm.get('alarmTypes').value; |
|
|
return this.stringItemsForm.get('items').value; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |