UI: Minor improvement of excludeVersions in mqtt version select.

This commit is contained in:
deaflynx 2025-06-06 17:37:51 +03:00
parent ef385c4fa9
commit 050fa670af

View File

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component, forwardRef, Input } from '@angular/core'; import { Component, forwardRef, Input, OnChanges, SimpleChanges } from '@angular/core';
import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms'; import { ControlValueAccessor, NG_VALUE_ACCESSOR } from '@angular/forms';
import { coerceBoolean } from '@shared/decorators/coercion'; import { coerceBoolean } from '@shared/decorators/coercion';
import { SubscriptSizing, MatFormFieldAppearance } from '@angular/material/form-field'; import { SubscriptSizing, MatFormFieldAppearance } from '@angular/material/form-field';
@ -30,7 +30,7 @@ import { MqttVersionTranslation, MqttVersion } from '@shared/models/mqtt.models'
multi: true multi: true
}] }]
}) })
export class MqttVersionSelectComponent implements ControlValueAccessor { export class MqttVersionSelectComponent implements ControlValueAccessor, OnChanges {
@Input() @Input()
disabled: boolean; disabled: boolean;
@ -44,10 +44,7 @@ export class MqttVersionSelectComponent implements ControlValueAccessor {
@Input() @Input()
excludeVersions: MqttVersion[]; excludeVersions: MqttVersion[];
get mqttVersions(): MqttVersion[] { mqttVersions = Object.values(MqttVersion);
return Object.values(MqttVersion).filter(v => !this.excludeVersions || !this.excludeVersions.includes(v));
}
mqttVersionTranslation = MqttVersionTranslation; mqttVersionTranslation = MqttVersionTranslation;
modelValue: MqttVersion; modelValue: MqttVersion;
@ -60,6 +57,20 @@ export class MqttVersionSelectComponent implements ControlValueAccessor {
constructor() { constructor() {
} }
ngOnChanges(changes: SimpleChanges): void {
for (const propName of Object.keys(changes)) {
const change = changes[propName];
if (propName === 'excludeVersions' && change.currentValue !== change.previousValue) {
const excludeVersions = change.currentValue;
if (excludeVersions?.length) {
this.mqttVersions = Object.values(MqttVersion).filter(v => !excludeVersions.includes(v));
} else {
this.mqttVersions = Object.values(MqttVersion);
}
}
}
}
registerOnChange(fn: any): void { registerOnChange(fn: any): void {
this.propagateChange = fn; this.propagateChange = fn;
} }