diff --git a/ui-ngx/src/app/modules/home/pages/notification-center/notification-center.module.ts b/ui-ngx/src/app/modules/home/pages/notification-center/notification-center.module.ts index c2ef2cb42c..2fa2dbf235 100644 --- a/ui-ngx/src/app/modules/home/pages/notification-center/notification-center.module.ts +++ b/ui-ngx/src/app/modules/home/pages/notification-center/notification-center.module.ts @@ -48,7 +48,6 @@ import { } from '@home/pages/notification-center/rule-table/rule-notification-dialog.component'; import { EscalationsComponent } from '@home/pages/notification-center/rule-table/escalations.component'; import { EscalationFormComponent } from '@home/pages/notification-center/rule-table/escalation-form.component'; -import { AlarmTypeListComponent } from '@home/pages/notification-center/rule-table/alarm-type-list.component'; import { AlarmSeveritiesListComponent } from '@home/pages/notification-center/rule-table/alarm-severities-list.component'; @@ -68,7 +67,6 @@ import { RuleNotificationDialogComponent, EscalationsComponent, EscalationFormComponent, - AlarmTypeListComponent, AlarmSeveritiesListComponent ], imports: [ diff --git a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.html b/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.html index 3d1a68c17e..141822f55c 100644 --- a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/rule-notification-dialog.component.html @@ -91,9 +91,12 @@
notification.filter - - + -
- - alarm.alarm-type-list - - + + {{ label }} + + - {{type}} + (removed)="removeItems(item)"> + {{item}} close - + (matChipInputTokenEnd)="addItem($event)"> + {{ hint }} + {{ requiredText }}
diff --git a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/alarm-type-list.component.ts b/ui-ngx/src/app/shared/components/string-items-list.component.ts similarity index 61% rename from ui-ngx/src/app/modules/home/pages/notification-center/rule-table/alarm-type-list.component.ts rename to ui-ngx/src/app/shared/components/string-items-list.component.ts index 7e3e5056f3..46ee912521 100644 --- a/ui-ngx/src/app/modules/home/pages/notification-center/rule-table/alarm-type-list.component.ts +++ b/ui-ngx/src/app/shared/components/string-items-list.component.ts @@ -19,22 +19,23 @@ import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Valida import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { MatChipInputEvent } from '@angular/material/chips'; import { COMMA, ENTER, SEMICOLON } from '@angular/cdk/keycodes'; +import { FloatLabelType, MatFormFieldAppearance } from '@angular/material/form-field/form-field'; @Component({ - selector: 'tb-alarm-type-list', - templateUrl: './alarm-type-list.component.html', + selector: 'tb-string-items-list', + templateUrl: './string-items-list.component.html', styleUrls: [], providers: [ { provide: NG_VALUE_ACCESSOR, - useExisting: forwardRef(() => AlarmTypeListComponent), + useExisting: forwardRef(() => StringItemsListComponent), multi: true } ] }) -export class AlarmTypeListComponent implements ControlValueAccessor{ +export class StringItemsListComponent implements ControlValueAccessor{ - alarmTypeForm: FormGroup; + stringItemsForm: FormGroup; private modelValue: Array | null; readonly separatorKeysCodes: number[] = [ENTER, COMMA, SEMICOLON]; @@ -55,17 +56,35 @@ export class AlarmTypeListComponent implements ControlValueAccessor{ @Input() 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) => { }; constructor(private fb: FormBuilder) { - this.alarmTypeForm = this.fb.group({ - alarmTypes: [null, this.required ? [Validators.required] : []] + this.stringItemsForm = this.fb.group({ + items: [null, this.required ? [Validators.required] : []] }); } updateValidators() { - this.alarmTypeForm.get('alarmTypes').setValidators(this.required ? [Validators.required] : []); - this.alarmTypeForm.get('alarmTypes').updateValueAndValidity(); + this.stringItemsForm.get('items').setValidators(this.required ? [Validators.required] : []); + this.stringItemsForm.get('items').updateValueAndValidity(); } registerOnChange(fn: any): void { @@ -78,33 +97,33 @@ export class AlarmTypeListComponent implements ControlValueAccessor{ setDisabledState(isDisabled: boolean): void { this.disabled = isDisabled; if (isDisabled) { - this.alarmTypeForm.disable({emitEvent: false}); + this.stringItemsForm.disable({emitEvent: false}); } else { - this.alarmTypeForm.enable({emitEvent: false}); + this.stringItemsForm.enable({emitEvent: false}); } } writeValue(value: Array | null): void { if (value != null && value.length > 0) { this.modelValue = [...value]; - this.alarmTypeForm.get('alarmTypes').setValue(value); + this.stringItemsForm.get('items').setValue(value); } else { - this.alarmTypeForm.get('alarmTypes').setValue(null); + this.stringItemsForm.get('items').setValue(null); this.modelValue = null; } } - addAlarmType(event: MatChipInputEvent): void { - let alarmType = event.value || ''; + addItem(event: MatChipInputEvent): void { + let item = event.value || ''; const input = event.chipInput.inputElement; - alarmType = alarmType.trim(); - if (alarmType) { - if (!this.modelValue || this.modelValue.indexOf(alarmType) === -1) { + item = item.trim(); + if (item) { + if (!this.modelValue || this.modelValue.indexOf(item) === -1) { if (!this.modelValue) { this.modelValue = []; } - this.modelValue.push(alarmType); - this.alarmTypeForm.get('alarmTypes').setValue(this.modelValue); + this.modelValue.push(item); + this.stringItemsForm.get('items').setValue(this.modelValue); } this.propagateChange(this.modelValue); if (input) { @@ -113,20 +132,20 @@ export class AlarmTypeListComponent implements ControlValueAccessor{ } } - removeAlarmType(alarmType: string) { - const index = this.modelValue.indexOf(alarmType); + removeItems(item: string) { + const index = this.modelValue.indexOf(item); if (index >= 0) { this.modelValue.splice(index, 1); if (!this.modelValue.length) { this.modelValue = null; } - this.alarmTypeForm.get('alarmTypes').setValue(this.modelValue); + this.stringItemsForm.get('items').setValue(this.modelValue); this.propagateChange(this.modelValue); } } - get alarmTypeList(): string[] { - return this.alarmTypeForm.get('alarmTypes').value; + get stringItemsList(): string[] { + return this.stringItemsForm.get('items').value; } } diff --git a/ui-ngx/src/app/shared/shared.module.ts b/ui-ngx/src/app/shared/shared.module.ts index 255e0db710..402f6ef324 100644 --- a/ui-ngx/src/app/shared/shared.module.ts +++ b/ui-ngx/src/app/shared/shared.module.ts @@ -95,6 +95,7 @@ import { EntitySelectComponent } from '@shared/components/entity/entity-select.c import { DatetimeComponent } from '@shared/components/time/datetime.component'; import { EntityKeysListComponent } from '@shared/components/entity/entity-keys-list.component'; import { SocialSharePanelComponent } from '@shared/components/socialshare-panel.component'; +import { StringItemsListComponent } from '@shared/components/string-items-list.component'; import { RelationTypeAutocompleteComponent } from '@shared/components/relation/relation-type-autocomplete.component'; import { EntityListSelectComponent } from '@shared/components/entity/entity-list-select.component'; import { JsonObjectEditComponent } from '@shared/components/json-object-edit.component'; @@ -255,6 +256,7 @@ export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService) QueueAutocompleteComponent, RelationTypeAutocompleteComponent, SocialSharePanelComponent, + StringItemsListComponent, JsonObjectEditComponent, JsonObjectViewComponent, JsonContentComponent, @@ -414,6 +416,7 @@ export function MarkedOptionsFactory(markedOptionsService: MarkedOptionsService) QueueAutocompleteComponent, RelationTypeAutocompleteComponent, SocialSharePanelComponent, + StringItemsListComponent, JsonObjectEditComponent, JsonObjectViewComponent, JsonContentComponent,