Browse Source

Added component for query params

pull/14540/head
Maksym Tsymbarov 9 months ago
parent
commit
1bd9b8d287
  1. 7
      ui-ngx/src/app/modules/home/components/rule-node/common/common-rule-node-config.module.ts
  2. 89
      ui-ngx/src/app/modules/home/components/rule-node/common/kv-list-config.component.ts
  3. 6
      ui-ngx/src/app/modules/home/components/rule-node/common/kv-map-config-old.component.ts
  4. 9
      ui-ngx/src/app/modules/home/components/rule-node/external/rest-api-call-config.component.html
  5. 1
      ui-ngx/src/assets/locale/locale.constant-en_US.json

7
ui-ngx/src/app/modules/home/components/rule-node/common/common-rule-node-config.module.ts

@ -34,6 +34,7 @@ import { SelectAttributesComponent } from './select-attributes.component';
import { AlarmStatusSelectComponent } from './alarm-status-select.component'; import { AlarmStatusSelectComponent } from './alarm-status-select.component';
import { ExampleHintComponent } from './example-hint.component'; import { ExampleHintComponent } from './example-hint.component';
import { TimeUnitInputComponent } from './time-unit-input.component'; import { TimeUnitInputComponent } from './time-unit-input.component';
import { KvListConfigComponent } from '@home/components/rule-node/common/kv-list-config.component';
@NgModule({ @NgModule({
declarations: [ declarations: [
@ -52,7 +53,8 @@ import { TimeUnitInputComponent } from './time-unit-input.component';
SelectAttributesComponent, SelectAttributesComponent,
AlarmStatusSelectComponent, AlarmStatusSelectComponent,
ExampleHintComponent, ExampleHintComponent,
TimeUnitInputComponent TimeUnitInputComponent,
KvListConfigComponent
], ],
imports: [ imports: [
CommonModule, CommonModule,
@ -75,7 +77,8 @@ import { TimeUnitInputComponent } from './time-unit-input.component';
SelectAttributesComponent, SelectAttributesComponent,
AlarmStatusSelectComponent, AlarmStatusSelectComponent,
ExampleHintComponent, ExampleHintComponent,
TimeUnitInputComponent TimeUnitInputComponent,
KvListConfigComponent
] ]
}) })

89
ui-ngx/src/app/modules/home/components/rule-node/common/kv-list-config.component.ts

@ -0,0 +1,89 @@
///
/// Copyright © 2016-2025 The Thingsboard Authors
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///
import { Component, forwardRef, Input, OnInit } from '@angular/core';
import {
AbstractControl,
ControlValueAccessor,
NG_VALIDATORS,
NG_VALUE_ACCESSOR,
Validator,
Validators
} from '@angular/forms';
import { KvMapConfigOldComponent } from '@home/components/rule-node/common/kv-map-config-old.component';
@Component({
selector: 'tb-kv-list-config',
templateUrl: './kv-map-config-old.component.html',
styleUrls: ['./kv-map-config-old.component.scss'],
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => KvListConfigComponent),
multi: true
},
{
provide: NG_VALIDATORS,
useExisting: forwardRef(() => KvListConfigComponent),
multi: true,
}
]
})
export class KvListConfigComponent extends KvMapConfigOldComponent implements ControlValueAccessor, OnInit, Validator{
@Input() keyProperty: string = 'key';
override writeValue(kvList: any): void {
const keyValsControls: Array<AbstractControl> = [];
if (Array.isArray(kvList) && kvList.length > 0) {
for (const property of kvList) {
keyValsControls.push(this.fb.group({
key: [property[this.keyProperty], [Validators.required]],
value: [property.value, [Validators.required]]
}))
}
}
this.kvListFormGroup.setControl('keyVals', this.fb.array(keyValsControls), {emitEvent: false});
}
public override validate() {
const kvList: { key: string; value: string }[] = this.kvListFormGroup.get('keyVals').value;
if (!kvList.length && this.required) {
return {
kvMapRequired: true
};
}
if (!this.kvListFormGroup.valid) {
return {
kvFieldsRequired: true
};
}
return null;
}
protected override updateModel() {
const kvList: { key: string; value: string }[] = this.kvListFormGroup.get('keyVals').value;
if (this.required && !kvList.length || !this.kvListFormGroup.valid) {
this.propagateChange(null);
} else {
const result = kvList.map(entry => ({
[this.keyProperty]: entry.key,
value: entry.value
}));
this.propagateChange(result);
}
}
}

6
ui-ngx/src/app/modules/home/components/rule-node/common/kv-map-config-old.component.ts

@ -86,11 +86,11 @@ export class KvMapConfigOldComponent extends PageComponent implements ControlVal
ngControl: NgControl; ngControl: NgControl;
private propagateChange = null; public propagateChange = null;
constructor(public translate: TranslateService, constructor(public translate: TranslateService,
private injector: Injector, private injector: Injector,
private fb: FormBuilder, protected fb: FormBuilder,
private destroyRef: DestroyRef) { private destroyRef: DestroyRef) {
super(); super();
} }
@ -182,7 +182,7 @@ export class KvMapConfigOldComponent extends PageComponent implements ControlVal
return null; return null;
} }
private updateModel() { protected updateModel() {
const kvList: { key: string; value: string }[] = this.kvListFormGroup.get('keyVals').value; const kvList: { key: string; value: string }[] = this.kvListFormGroup.get('keyVals').value;
if (this.required && !kvList.length || !this.kvListFormGroup.valid) { if (this.required && !kvList.length || !this.kvListFormGroup.valid) {
this.propagateChange(null); this.propagateChange(null);

9
ui-ngx/src/app/modules/home/components/rule-node/external/rest-api-call-config.component.html

@ -19,7 +19,7 @@
<div class="tb-form-panel stroked"> <div class="tb-form-panel stroked">
<div class="tb-form-panel-title">Request URL</div> <div class="tb-form-panel-title">Request URL</div>
<mat-form-field class="mat-block" subscriptSizing="dynamic"> <mat-form-field class="mat-block" subscriptSizing="dynamic">
<mat-label translate>rule-node-config.endpoint-url-pattern</mat-label> <mat-label translate>rule-node-config.url</mat-label>
<input required matInput formControlName="restEndpointUrlPattern"> <input required matInput formControlName="restEndpointUrlPattern">
<mat-error *ngIf="restApiCallConfigForm.get('restEndpointUrlPattern').hasError('required')"> <mat-error *ngIf="restApiCallConfigForm.get('restEndpointUrlPattern').hasError('required')">
{{ 'rule-node-config.endpoint-url-pattern-required' | translate }} {{ 'rule-node-config.endpoint-url-pattern-required' | translate }}
@ -32,14 +32,15 @@
<div [tb-hint-tooltip-icon]="'rule-node-config.query-params-hint' | translate" tooltipPosition="above"></div> <div [tb-hint-tooltip-icon]="'rule-node-config.query-params-hint' | translate" tooltipPosition="above"></div>
</mat-expansion-panel-header> </mat-expansion-panel-header>
<ng-template matExpansionPanelContent> <ng-template matExpansionPanelContent>
<tb-kv-map-config-old <tb-kv-list-config
formControlName="queryParams" formControlName="queryParams"
keyText="rule-node-config.query-params-name" keyText="rule-node-config.query-params-name"
keyRequiredText="rule-node-config.query-params-name-required" keyRequiredText="rule-node-config.query-params-name-required"
valText="rule-node-config.query-params-value" valText="rule-node-config.query-params-value"
valRequiredText="rule-node-config.query-params-value-required" valRequiredText="rule-node-config.query-params-value-required"
emptyText="rule-node-config.query-params-empty">> emptyText="rule-node-config.query-params-empty"
</tb-kv-map-config-old> keyProperty="name">
</tb-kv-list-config>
</ng-template> </ng-template>
</mat-expansion-panel> </mat-expansion-panel>
</div> </div>

1
ui-ngx/src/assets/locale/locale.constant-en_US.json

@ -5411,6 +5411,7 @@
"query-params-name-required": "Name is required", "query-params-name-required": "Name is required",
"query-params-value-required": "Value is required", "query-params-value-required": "Value is required",
"headers-empty": "No headers configured", "headers-empty": "No headers configured",
"url": "URL",
"save-time-series": { "save-time-series": {
"processing-settings": "Processing settings", "processing-settings": "Processing settings",
"processing-settings-hint": "Define how incoming messages are processed. Basic processing settings allow you to select preconfigured strategies, while Advanced settings allow you to select individual processing strategies for each action.", "processing-settings-hint": "Define how incoming messages are processed. Basic processing settings allow you to select preconfigured strategies, while Advanced settings allow you to select individual processing strategies for each action.",

Loading…
Cancel
Save