From 48e5aed0b628f98b009fc625d42869da08b02512 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Wed, 6 Jul 2022 14:33:18 +0300 Subject: [PATCH 01/18] Rate limits implementation --- .../home/components/home-components.module.ts | 16 +- ...enant-profile-configuration.component.html | 118 +++++-------- ...-tenant-profile-configuration.component.ts | 3 + .../rate-limits-details-dialog.component.html | 52 ++++++ .../rate-limits-details-dialog.component.ts | 83 +++++++++ .../rate-limits-list.component.html | 61 +++++++ .../rate-limits-list.component.scss | 47 +++++ .../rate-limits/rate-limits-list.component.ts | 161 ++++++++++++++++++ .../rate-limits-text.component.html | 19 +++ .../rate-limits-text.component.scss | 49 ++++++ .../rate-limits/rate-limits-text.component.ts | 98 +++++++++++ .../rate-limits/rate-limits.component.html | 34 ++++ .../rate-limits/rate-limits.component.scss | 31 ++++ .../rate-limits/rate-limits.component.ts | 153 +++++++++++++++++ .../app/shared/models/rate-limits.models.ts | 137 +++++++++++++++ .../assets/locale/locale.constant-en_US.json | 36 +++- 16 files changed, 1018 insertions(+), 80 deletions(-) create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.scss create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.scss create mode 100644 ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts create mode 100644 ui-ngx/src/app/shared/models/rate-limits.models.ts diff --git a/ui-ngx/src/app/modules/home/components/home-components.module.ts b/ui-ngx/src/app/modules/home/components/home-components.module.ts index d195137509..9468289df8 100644 --- a/ui-ngx/src/app/modules/home/components/home-components.module.ts +++ b/ui-ngx/src/app/modules/home/components/home-components.module.ts @@ -166,6 +166,10 @@ import { EntityTypesVersionLoadComponent } from '@home/components/vc/entity-type import { ComplexVersionLoadComponent } from '@home/components/vc/complex-version-load.component'; import { RemoveOtherEntitiesConfirmComponent } from '@home/components/vc/remove-other-entities-confirm.component'; import { AutoCommitSettingsComponent } from '@home/components/vc/auto-commit-settings.component'; +import { RateLimitsListComponent } from '@home/components/profile/tenant/rate-limits/rate-limits-list.component'; +import { RateLimitsComponent } from '@home/components/profile/tenant/rate-limits/rate-limits.component'; +import { RateLimitsTextComponent } from '@home/components/profile/tenant/rate-limits/rate-limits-text.component'; +import { RateLimitsDetailsDialogComponent } from '@home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component'; @NgModule({ declarations: @@ -302,7 +306,11 @@ import { AutoCommitSettingsComponent } from '@home/components/vc/auto-commit-set EntityTypesVersionLoadComponent, ComplexVersionLoadComponent, RemoveOtherEntitiesConfirmComponent, - AutoCommitSettingsComponent + AutoCommitSettingsComponent, + RateLimitsListComponent, + RateLimitsComponent, + RateLimitsTextComponent, + RateLimitsDetailsDialogComponent ], imports: [ CommonModule, @@ -432,7 +440,11 @@ import { AutoCommitSettingsComponent } from '@home/components/vc/auto-commit-set EntityTypesVersionLoadComponent, ComplexVersionLoadComponent, RemoveOtherEntitiesConfirmComponent, - AutoCommitSettingsComponent + AutoCommitSettingsComponent, + RateLimitsListComponent, + RateLimitsComponent, + RateLimitsTextComponent, + RateLimitsDetailsDialogComponent ], providers: [ WidgetComponentService, diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html index 0e1553806a..5484aaed28 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html @@ -418,38 +418,24 @@
- Rate limits + + {{ 'tenant-profile.rate-limits.rate-limits' | translate }} +
- - tenant-profile.transport-tenant-msg-rate-limit - - - {{ 'tenant-profile.incorrect-pattern-for-rate-limits' | translate}} - - - - tenant-profile.transport-device-msg-rate-limit - - - {{ 'tenant-profile.incorrect-pattern-for-rate-limits' | translate}} - - + + + +
- - tenant-profile.transport-tenant-telemetry-msg-rate-limit - - - {{ 'tenant-profile.incorrect-pattern-for-rate-limits' | translate}} - - - - tenant-profile.transport-device-telemetry-msg-rate-limit - - - {{ 'tenant-profile.incorrect-pattern-for-rate-limits' | translate}} - - + + + +
@@ -459,40 +445,28 @@
- - tenant-profile.transport-tenant-telemetry-data-points-rate-limit - - - {{ 'tenant-profile.incorrect-pattern-for-rate-limits' | translate}} - - - - tenant-profile.transport-device-telemetry-data-points-rate-limit - - - {{ 'tenant-profile.incorrect-pattern-for-rate-limits' | translate}} - - + + + +
- - tenant-profile.tenant-rest-limits - - - {{ 'tenant-profile.incorrect-pattern-for-rate-limits' | translate}} - - - - tenant-profile.customer-rest-limits - - - {{ 'tenant-profile.incorrect-pattern-for-rate-limits' | translate}} - - + + + + +
+
+ + + +
@@ -503,22 +477,12 @@ tenant-profile.tenant-entity-import-rate-limit -
-
- - tenant-profile.ws-limit-updates-per-session - - - {{ 'tenant-profile.incorrect-pattern-for-rate-limits' | translate}} - - - - tenant-profile.cassandra-tenant-limits-configuration - - - {{ 'tenant-profile.incorrect-pattern-for-rate-limits' | translate}} - - +
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts index 65f030a3a6..ac2702ca43 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts @@ -21,6 +21,7 @@ import { AppState } from '@app/core/core.state'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { DefaultTenantProfileConfiguration, TenantProfileConfiguration } from '@shared/models/tenant.model'; import { isDefinedAndNotNull } from '@core/utils'; +import { RateLimitsType } from '@shared/models/rate-limits.models'; @Component({ selector: 'tb-default-tenant-profile-configuration', @@ -49,6 +50,8 @@ export class DefaultTenantProfileConfigurationComponent implements ControlValueA @Input() disabled: boolean; + rateLimitsType = RateLimitsType; + private propagateChange = (v: any) => { }; constructor(private store: Store, diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html new file mode 100644 index 0000000000..911b44ecd8 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html @@ -0,0 +1,52 @@ + +
+ +

{{ title }}

+ + +
+ + +
+
+
+ + +
+
+
+
+ + +
+
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts new file mode 100644 index 0000000000..69bf5cda4f --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts @@ -0,0 +1,83 @@ +/// +/// Copyright © 2016-2022 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, Inject, OnInit, SkipSelf } from '@angular/core'; +import { ErrorStateMatcher } from '@angular/material/core'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; +import { Store } from '@ngrx/store'; +import { AppState } from '@core/core.state'; +import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm } from '@angular/forms'; +import { Router } from '@angular/router'; +import { DialogComponent } from '@app/shared/components/dialog.component'; +import { TranslateService } from '@ngx-translate/core'; + +export interface RateLimitsDetailsDialogData { + rateLimits: string; + title: string; + readonly: boolean; +} + +@Component({ + templateUrl: './rate-limits-details-dialog.component.html', + providers: [{provide: ErrorStateMatcher, useExisting: RateLimitsDetailsDialogComponent}] +}) +export class RateLimitsDetailsDialogComponent extends DialogComponent + implements OnInit, ErrorStateMatcher { + + editDetailsFormGroup: FormGroup; + + submitted: boolean = false; + + rateLimits: string = this.data.rateLimits; + + title: string = this.data.title; + + constructor(protected store: Store, + protected router: Router, + @Inject(MAT_DIALOG_DATA) public data: RateLimitsDetailsDialogData, + @SkipSelf() private errorStateMatcher: ErrorStateMatcher, + public dialogRef: MatDialogRef, + private fb: FormBuilder, + public translate: TranslateService) { + super(store, router, dialogRef); + + this.editDetailsFormGroup = this.fb.group({ + rateLimits: [this.rateLimits, []] + }); + if (this.data.readonly) { + this.editDetailsFormGroup.disable(); + } + } + + ngOnInit(): void { + } + + isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean { + const originalErrorState = this.errorStateMatcher.isErrorState(control, form); + const customErrorState = !!(control && control.invalid && this.submitted); + return originalErrorState || customErrorState; + } + + cancel(): void { + this.dialogRef.close(null); + } + + save(): void { + this.submitted = true; + this.dialogRef.close(this.editDetailsFormGroup.get('rateLimits').value); + } + +} diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html new file mode 100644 index 0000000000..c0923927d8 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html @@ -0,0 +1,61 @@ + +
+
+
+ tenant-profile.rate-limits.but-less-than +
+
+ + tenant-profile.rate-limits.number-of-messages + + + {{ 'tenant-profile.rate-limits.number-of-messages-required' | translate }} + + + + tenant-profile.rate-limits.per-seconds + + + {{ 'tenant-profile.rate-limits.per-seconds-required' | translate }} + + + +
+
+
+ +
+
+ tenant-profile.rate-limits.preview +
+ +
+
+
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.scss b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.scss new file mode 100644 index 0000000000..0db3694166 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.scss @@ -0,0 +1,47 @@ +/** + * Copyright © 2016-2022 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. + */ +:host { + button { + min-width: 40px; + mat-icon { + margin-top: 0.6em; + } + } + .tb-rate-limits-preview { + margin-top: 1.5em; + span { + padding-left: 1em; + } + div { + border: 1px groove rgba(0, 0, 0, .25); + border-radius: 4px; + padding: 1em; + } + } + .tb-rate-limits-operation { + font-size: 12px; + color: rgba(0,0,0,.54); + margin-bottom: 16px; + } +} + +:host ::ng-deep { + mat-form-field { + .mat-form-field-wrapper { + padding-bottom: 1em; + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts new file mode 100644 index 0000000000..eb7a37cfde --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts @@ -0,0 +1,161 @@ +/// +/// Copyright © 2016-2022 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 { + ControlValueAccessor, + FormArray, + FormBuilder, + FormControl, + FormGroup, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + ValidationErrors, + Validator, + Validators +} from '@angular/forms'; +import { Subscription } from 'rxjs'; +import { + RateLimits, + rateLimitsArrayToString, + stringToRateLimitsArray +} from '@shared/models/rate-limits.models'; +import { isDefinedAndNotNull } from '@core/utils'; + +@Component({ + selector: 'tb-rate-limits-list', + templateUrl: './rate-limits-list.component.html', + styleUrls: ['./rate-limits-list.component.scss'], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => RateLimitsListComponent), + multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => RateLimitsListComponent), + multi: true + } + ] +}) +export class RateLimitsListComponent implements ControlValueAccessor, Validator, OnInit { + + @Input() disabled: boolean; + + rateLimitsListFormGroup: FormGroup; + + rateLimitsControl: FormControl; + + private propagateChange = (v: any) => { }; + + private valueChangeSubscription: Subscription = null; + + constructor(private fb: FormBuilder) { + } + + ngOnInit(): void { + this.rateLimitsListFormGroup = this.fb.group({}); + this.rateLimitsListFormGroup.addControl('rateLimits', + this.fb.array([])); + this.rateLimitsControl = this.fb.control(null); + this.rateLimitsListFormGroup.valueChanges.subscribe((value) => { + this.updateView(value?.rateLimits); + } + ); + } + + rateLimitsFormArray(): FormArray { + return this.rateLimitsListFormGroup.get('rateLimits') as FormArray; + } + + registerOnChange(fn: any): void { + this.propagateChange = fn; + } + + registerOnTouched(fn: any): void { + } + + setDisabledState?(isDisabled: boolean): void { + this.disabled = isDisabled; + if (this.disabled) { + this.rateLimitsListFormGroup.disable({emitEvent: false}); + this.rateLimitsControl.disable({emitEvent: false}); + } else { + this.rateLimitsListFormGroup.enable({emitEvent: false}); + this.rateLimitsControl.enable({emitEvent: false}); + } + } + + validate(): ValidationErrors | null { + return this.rateLimitsListFormGroup.valid && this.rateLimitsControl.valid ? null : { + rateLimitsList: {valid: false} + }; + } + + writeValue(value: string) { + if (this.valueChangeSubscription) { + this.valueChangeSubscription.unsubscribe(); + } + const rateLimitsControls: Array = []; + if (value) { + let rateLimitsArray = value.split(','); + for (let i = 0; i < rateLimitsArray.length; i++) { + let valueTime = rateLimitsArray[i].split(':'); + let value = valueTime[0]; + let time = valueTime[1]; + const rateLimitsControl = this.fb.group({ + value: [value, [Validators.required]], + time: [time, [Validators.required]] + }); + if (this.disabled) { + rateLimitsControl.disable(); + } + rateLimitsControls.push(rateLimitsControl); + } + } + this.rateLimitsListFormGroup.setControl('rateLimits', this.fb.array(rateLimitsControls)); + this.rateLimitsControl.patchValue(stringToRateLimitsArray(value), {emitEvent: false}); + this.valueChangeSubscription = this.rateLimitsListFormGroup.valueChanges.subscribe((value) => { + this.updateView(value?.rateLimits); + }); + } + + public removeRateLimits(index: number) { + (this.rateLimitsListFormGroup.get('rateLimits') as FormArray).removeAt(index); + } + + public addRateLimits() { + const rateLimitsArray = this.rateLimitsListFormGroup.get('rateLimits') as FormArray; + rateLimitsArray.push(this.fb.group({ + value: [null, [Validators.required]], + time: [null, [Validators.required]] + })); + this.rateLimitsListFormGroup.updateValueAndValidity(); + } + + updateView(rateLimitsArray: Array) { + if (rateLimitsArray.length > 0) { + const notNullRateLimits = rateLimitsArray.filter(rateLimits => isDefinedAndNotNull(rateLimits.value) && isDefinedAndNotNull(rateLimits.time)); + const rateLimitsString = rateLimitsArrayToString(notNullRateLimits); + this.propagateChange(rateLimitsString); + this.rateLimitsControl.patchValue(stringToRateLimitsArray(rateLimitsString), {emitEvent: false}); + } else { + this.propagateChange(null); + this.rateLimitsControl.patchValue(null, {emitEvent: false}); + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html new file mode 100644 index 0000000000..98a30b055e --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html @@ -0,0 +1,19 @@ + +
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss new file mode 100644 index 0000000000..a8f8f8553f --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss @@ -0,0 +1,49 @@ +/** + * Copyright © 2016-2022 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. + */ +:host { + .tb-rate-limits-text { + overflow: hidden; + + &.disabled { + opacity: 0.7; + } + &.required { + color: #f44336; + padding: 0 4px; + } + &.nowrap { + white-space: nowrap; + overflow: hidden; + } + } +} + +:host ::ng-deep { + .tb-rate-limits-text { + span { + font-size: 14px; + line-height: 1.8em; + } + .tb-rate-limits-value { + font-weight: bold; + border: 1px groove rgba(0, 0, 0, .25); + border-radius: 4px; + padding-left: 4px; + padding-right: 4px; + color: #305680; + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts new file mode 100644 index 0000000000..9ab7e9b56b --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts @@ -0,0 +1,98 @@ +/// +/// Copyright © 2016-2022 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 { ControlValueAccessor, FormBuilder, NG_VALUE_ACCESSOR } from '@angular/forms'; +import { MatDialog } from '@angular/material/dialog'; +import { TranslateService } from '@ngx-translate/core'; +import { coerceBooleanProperty } from '@angular/cdk/coercion'; +import { RateLimits, rateLimitsArrayToHtml } from '@shared/models/rate-limits.models'; + +@Component({ + selector: 'tb-rate-limits-text', + templateUrl: './rate-limits-text.component.html', + styleUrls: ['./rate-limits-text.component.scss'], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => RateLimitsTextComponent), + multi: true + } + ] +}) +export class RateLimitsTextComponent implements ControlValueAccessor, OnInit { + + private requiredValue: boolean; + get required(): boolean { + return this.requiredValue; + } + @Input() + set required(value: boolean) { + this.requiredValue = coerceBooleanProperty(value); + } + + @Input() + disabled: boolean; + + @Input() + noRateLimitsText = this.translate.instant('tenant-profile.rate-limits.not-set'); + + @Input() + nowrap = false; + + requiredClass = false; + + public rateLimitsText: string; + + private propagateChange = (v: any) => { }; + + constructor(private dialog: MatDialog, + private fb: FormBuilder, + private translate: TranslateService) { + } + + registerOnChange(fn: any): void { + this.propagateChange = fn; + } + + registerOnTouched(fn: any): void { + } + + ngOnInit() { + } + + setDisabledState(isDisabled: boolean): void { + this.disabled = isDisabled; + } + + writeValue(value: Array): void { + this.updateText(value); + } + + private updateText(value: Array) { + this.requiredClass = false; + if (value && value.length) { + this.rateLimitsText = rateLimitsArrayToHtml(this.translate, value); + } else { + if (this.required && !this.disabled) { + this.requiredClass = true; + } else { + this.rateLimitsText = this.noRateLimitsText; + } + } + } + +} diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html new file mode 100644 index 0000000000..3f1b698553 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html @@ -0,0 +1,34 @@ + +
+
+ {{ label | translate }} +
+ +
+
+
+ +
+
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.scss b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.scss new file mode 100644 index 0000000000..6d45b33b73 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.scss @@ -0,0 +1,31 @@ +/** + * Copyright © 2016-2022 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. + */ +:host { + padding: 12px 0 12px 0; + + .fieldset-element { + cursor: pointer; + padding: 0.5em; + border: 1px groove rgba(0, 0, 0, 0.25); + border-radius: 4px; + width: 100%; + + .legend-element { + color: rgba(0, 0, 0, 0.54); + font-size: 12px; + } + } +} diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts new file mode 100644 index 0000000000..34cbadb755 --- /dev/null +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts @@ -0,0 +1,153 @@ +/// +/// Copyright © 2016-2022 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 { + ControlValueAccessor, + FormBuilder, + FormControl, + FormGroup, + NG_VALIDATORS, + NG_VALUE_ACCESSOR, + Validator +} from '@angular/forms'; +import { MatDialog } from '@angular/material/dialog'; +import { + RateLimitsDetailsDialogComponent, + RateLimitsDetailsDialogData +} from '@home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component'; +import { + addRateLimitTranslationMap, + editRateLimitTranslationMap, + rateLimitLabelTranslationMap, + RateLimitsType, + stringToRateLimitsArray +} from '@shared/models/rate-limits.models'; + +@Component({ + selector: 'tb-rate-limits', + templateUrl: './rate-limits.component.html', + styleUrls: ['./rate-limits.component.scss'], + providers: [ + { + provide: NG_VALUE_ACCESSOR, + useExisting: forwardRef(() => RateLimitsComponent), + multi: true + }, + { + provide: NG_VALIDATORS, + useExisting: forwardRef(() => RateLimitsComponent), + multi: true, + } + ] +}) +export class RateLimitsComponent implements ControlValueAccessor, OnInit, Validator { + + @Input() + disabled: boolean; + + @Input() + type: RateLimitsType; + + label: string; + + rateLimitsFormGroup: FormGroup; + + private modelValue: string; + + private propagateChange = null; + + constructor(private dialog: MatDialog, + private fb: FormBuilder) { + } + + registerOnChange(fn: any): void { + this.propagateChange = fn; + } + + registerOnTouched(fn: any): void { + } + + ngOnInit() { + this.label = rateLimitLabelTranslationMap.get(this.type); + this.rateLimitsFormGroup = this.fb.group({ + rateLimits: [null, []] + }); + } + + setDisabledState(isDisabled: boolean) { + this.disabled = isDisabled; + if (this.disabled) { + this.rateLimitsFormGroup.disable({emitEvent: false}); + } else { + this.rateLimitsFormGroup.enable({emitEvent: false}); + } + } + + writeValue(value: string) { + this.modelValue = value; + this.updateRateLimitsInfo(); + } + + public validate(c: FormControl) { + return null; + } + + public onClick($event: Event, action: string) { + if ($event) { + $event.stopPropagation(); + } + const title = this.setTitle(action); + this.dialog.open(RateLimitsDetailsDialogComponent, { + disableClose: true, + panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], + data: { + rateLimits: this.modelValue, + title, + readonly: this.disabled + } + }).afterClosed().subscribe((result) => { + if (result) { + this.modelValue = result; + this.updateModel(); + } + }); + } + + private setTitle(action: string): string { + switch (action) { + case 'add': + return addRateLimitTranslationMap.get(this.type); + case 'edit': + return editRateLimitTranslationMap.get(this.type); + } + } + + private updateRateLimitsInfo() { + this.rateLimitsFormGroup.patchValue( + { + rateLimits: stringToRateLimitsArray(this.modelValue) + } + ); + } + + private updateModel() { + this.updateRateLimitsInfo(); + this.propagateChange(this.modelValue); + } + +} diff --git a/ui-ngx/src/app/shared/models/rate-limits.models.ts b/ui-ngx/src/app/shared/models/rate-limits.models.ts new file mode 100644 index 0000000000..8b8eae794a --- /dev/null +++ b/ui-ngx/src/app/shared/models/rate-limits.models.ts @@ -0,0 +1,137 @@ +/// +/// Copyright © 2016-2022 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 { TranslateService } from '@ngx-translate/core'; + +export interface RateLimits { + value: string; + time: string; +} + +export enum RateLimitsType { + DEVICE_MESSAGES = 'DEVICE_MESSAGES', + DEVICE_TELEMETRY_MESSAGES = 'DEVICE_TELEMETRY_MESSAGES', + DEVICE_TELEMETRY_DATA_POINTS = 'DEVICE_TELEMETRY_DATA_POINTS', + TENANT_MESSAGES = 'TENANT_MESSAGES', + TENANT_TELEMETRY_MESSAGES = 'TENANT_TELEMETRY_MESSAGES', + TENANT_TELEMETRY_DATA_POINTS = 'TENANT_TELEMETRY_DATA_POINTS', + TENANT_SERVER_REST_LIMITS_CONFIGURATION = 'TENANT_SERVER_REST_LIMITS_CONFIGURATION', + CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION = 'CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION', + WS_UPDATE_PER_SESSION_RATE_LIMIT = 'WS_UPDATE_PER_SESSION_RATE_LIMIT', + CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION = 'CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION', +} + +export const rateLimitLabelTranslationMap = new Map( + [ + [RateLimitsType.TENANT_MESSAGES, 'tenant-profile.rate-limits.transport-tenant-msg'], + [RateLimitsType.TENANT_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.transport-tenant-telemetry-msg'], + [RateLimitsType.TENANT_TELEMETRY_DATA_POINTS, 'tenant-profile.rate-limits.transport-tenant-telemetry-data-points'], + [RateLimitsType.DEVICE_MESSAGES, 'tenant-profile.rate-limits.transport-device-msg'], + [RateLimitsType.DEVICE_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.transport-device-telemetry-msg'], + [RateLimitsType.DEVICE_TELEMETRY_DATA_POINTS, 'tenant-profile.rate-limits.transport-device-telemetry-data-points'], + [RateLimitsType.TENANT_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.transport-tenant-msg-rate-limit'], + [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.customer-rest-limits'], + [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.ws-limit-updates-per-session'], + [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.cassandra-tenant-limits-configuration'], + ] +); + +export const editRateLimitTranslationMap = new Map( + [ + [RateLimitsType.TENANT_MESSAGES, 'tenant-profile.rate-limits.edit-transport-tenant-msg-title'], + [RateLimitsType.TENANT_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.edit-transport-tenant-telemetry-msg-title'], + [RateLimitsType.TENANT_TELEMETRY_DATA_POINTS, 'tenant-profile.rate-limits.edit-transport-tenant-telemetry-data-points-title'], + [RateLimitsType.DEVICE_MESSAGES, 'tenant-profile.rate-limits.edit-transport-device-msg-title'], + [RateLimitsType.DEVICE_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.edit-transport-device-telemetry-msg-title'], + [RateLimitsType.DEVICE_TELEMETRY_DATA_POINTS, 'tenant-profile.rate-limits.edit-transport-device-telemetry-data-points-title'], + [RateLimitsType.TENANT_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-transport-device-telemetry-data-points-title'], + [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-transport-device-telemetry-data-points-title'], + [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.rate-limits.edit-transport-device-telemetry-data-points-title'], + [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-transport-device-telemetry-data-points-title'], + ] +); + +export const addRateLimitTranslationMap = new Map( + [ + [RateLimitsType.TENANT_MESSAGES, 'tenant-profile.rate-limits.add-transport-tenant-msg-title'], + [RateLimitsType.TENANT_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.add-transport-tenant-telemetry-msg-title'], + [RateLimitsType.TENANT_TELEMETRY_DATA_POINTS, 'tenant-profile.rate-limits.add-transport-tenant-telemetry-data-points-title'], + [RateLimitsType.DEVICE_MESSAGES, 'tenant-profile.rate-limits.add-transport-device-msg-title'], + [RateLimitsType.DEVICE_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.add-transport-device-telemetry-msg-title'], + [RateLimitsType.DEVICE_TELEMETRY_DATA_POINTS, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], + [RateLimitsType.TENANT_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], + [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], + [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], + [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], + ] +); + +export function stringToRateLimitsArray(rateLimits: string): Array { + const result: Array = []; + if (rateLimits?.length > 0) { + let rateLimitsArrays = rateLimits.split(','); + for (let i = 0; i < rateLimitsArrays.length; i++) { + let valueTime = rateLimitsArrays[i].split(':'); + let value = valueTime[0]; + let time = valueTime[1]; + const rateLimitControl = { + value, + time + } + result.push(rateLimitControl); + } + } + return result; +} + +export function rateLimitsArrayToString(rateLimits: Array): string { + let result = ''; + for (let i = 0; i < rateLimits.length; i++) { + result = result.concat(rateLimits[i].value, ':', rateLimits[i].time); + if ((rateLimits.length > 1) && (i !== rateLimits.length - 1)) { + result = result.concat(','); + } + } + return result; +} + +export function rateLimitsArrayToHtml(translate: TranslateService, rateLimitsArray: Array): string { + const rateLimitsHtml = rateLimitsArray.map((rateLimits, index) => { + const isLast: boolean = index === rateLimitsArray.length-1; + return rateLimitsToHtml(translate, rateLimits, isLast); + }); + let result: string; + if (rateLimitsHtml.length > 1) { + const butLessThanText = translate.instant('tenant-profile.rate-limits.but-less-than'); + result = rateLimitsHtml.join(' ' + butLessThanText + ' '); + } else { + result = rateLimitsHtml[0]; + } + return result; +} + +function rateLimitsToHtml(translate: TranslateService, rateLimit: RateLimits, isLast: boolean): string { + const value = rateLimit.value; + const time = rateLimit.time; + const operation = translate.instant('tenant-profile.rate-limits.messages-per'); + const seconds = translate.instant('tenant-profile.rate-limits.sec'); + const comma = isLast ? '' : ','; + const result = `${value} + ${operation} + ${time} + ${seconds}${comma}
`; + return result; +} diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 6e76448847..4e83984480 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3187,7 +3187,41 @@ "ws-limit-max-subscriptions-per-customer": "Subscriptions per customer maximum number", "ws-limit-max-subscriptions-per-regular-user": "Subscriptions per regular user maximum number", "ws-limit-max-subscriptions-per-public-user": "Subscriptions per public user maximum number", - "ws-limit-updates-per-session": "WS updates per session" + "ws-limit-updates-per-session": "WS updates per session", + "rate-limits": { + "add-limit": "Add limit", + "add-transport-tenant-msg-title": "Add transport tenant messages rate limit", + "add-transport-tenant-telemetry-msg-title": "Add transport tenant telemetry messages rate limit", + "add-transport-tenant-telemetry-data-points-title": "Add transport tenant telemetry data points rate limit", + "add-transport-device-msg-title": "Add transport device messages rate limit", + "add-transport-device-telemetry-msg-title": "Add transport device telemetry messages rate limit", + "add-transport-device-telemetry-data-points-title": "Add transport device telemetry data points rate limit", + "advanced-settings": "Advanced settings", + "edit-limit": "Edit limit", + "but-less-than": "but less than", + "edit-transport-tenant-msg-title": "Edit transport tenant messages rate limit", + "edit-transport-tenant-telemetry-msg-title": "Edit transport tenant telemetry messages rate limit", + "edit-transport-tenant-telemetry-data-points-title": "Edit transport tenant telemetry data points rate limit", + "edit-transport-device-msg-title": "Edit transport device messages rate limit", + "edit-transport-device-telemetry-msg-title": "Edit transport device telemetry messages rate limit", + "edit-transport-device-telemetry-data-points-title": "Edit transport device telemetry data points rate limit", + "messages-per": "messages per", + "not-set": "Not set", + "number-of-messages": "Number of messages", + "number-of-messages-required": "Number of messages is required.", + "preview": "Preview", + "per-seconds": "Per seconds", + "per-seconds-required": "Time rate is required.", + "rate-limits": "Rate limits", + "remove-limit": "Remove rate limit", + "transport-tenant-msg": "Transport tenant messages", + "transport-tenant-telemetry-msg": "Transport tenant telemetry messages", + "transport-tenant-telemetry-data-points": "Transport tenant telemetry data points", + "transport-device-msg": "Transport device messages", + "transport-device-telemetry-msg": "Transport device telemetry messages", + "transport-device-telemetry-data-points": "Transport device telemetry data points", + "sec": "sec" + } }, "timeinterval": { "seconds-interval": "{ seconds, plural, 1 {1 second} other {# seconds} }", From 97e46e18cbd1b14c315981e2d01ca353c21838a1 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Wed, 6 Jul 2022 14:47:31 +0300 Subject: [PATCH 02/18] Rate limits translations updated --- .../app/shared/models/rate-limits.models.ts | 16 ++++----- .../assets/locale/locale.constant-en_US.json | 34 ++++++++++++------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/ui-ngx/src/app/shared/models/rate-limits.models.ts b/ui-ngx/src/app/shared/models/rate-limits.models.ts index 8b8eae794a..e6b4218773 100644 --- a/ui-ngx/src/app/shared/models/rate-limits.models.ts +++ b/ui-ngx/src/app/shared/models/rate-limits.models.ts @@ -57,10 +57,10 @@ export const editRateLimitTranslationMap = new Map( [RateLimitsType.DEVICE_MESSAGES, 'tenant-profile.rate-limits.edit-transport-device-msg-title'], [RateLimitsType.DEVICE_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.edit-transport-device-telemetry-msg-title'], [RateLimitsType.DEVICE_TELEMETRY_DATA_POINTS, 'tenant-profile.rate-limits.edit-transport-device-telemetry-data-points-title'], - [RateLimitsType.TENANT_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-transport-device-telemetry-data-points-title'], - [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-transport-device-telemetry-data-points-title'], - [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.rate-limits.edit-transport-device-telemetry-data-points-title'], - [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-transport-device-telemetry-data-points-title'], + [RateLimitsType.TENANT_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-transport-tenant-msg-rate-limit-title'], + [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-customer-rest-limits-title'], + [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.rate-limits.edit-ws-limit-updates-per-session-title'], + [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-cassandra-tenant-limits-configuration-title'], ] ); @@ -72,10 +72,10 @@ export const addRateLimitTranslationMap = new Map( [RateLimitsType.DEVICE_MESSAGES, 'tenant-profile.rate-limits.add-transport-device-msg-title'], [RateLimitsType.DEVICE_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.add-transport-device-telemetry-msg-title'], [RateLimitsType.DEVICE_TELEMETRY_DATA_POINTS, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], - [RateLimitsType.TENANT_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], - [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], - [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], - [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], + [RateLimitsType.TENANT_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-transport-tenant-msg-rate-limit-title'], + [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-customer-rest-limits-title'], + [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.rate-limits.add-ws-limit-updates-per-session-title'], + [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-cassandra-tenant-limits-configuration-title'], ] ); diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 4e83984480..8cd65a139e 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3190,21 +3190,29 @@ "ws-limit-updates-per-session": "WS updates per session", "rate-limits": { "add-limit": "Add limit", - "add-transport-tenant-msg-title": "Add transport tenant messages rate limit", - "add-transport-tenant-telemetry-msg-title": "Add transport tenant telemetry messages rate limit", - "add-transport-tenant-telemetry-data-points-title": "Add transport tenant telemetry data points rate limit", - "add-transport-device-msg-title": "Add transport device messages rate limit", - "add-transport-device-telemetry-msg-title": "Add transport device telemetry messages rate limit", - "add-transport-device-telemetry-data-points-title": "Add transport device telemetry data points rate limit", + "add-transport-tenant-msg-title": "Add transport tenant messages rate limits", + "add-transport-tenant-telemetry-msg-title": "Add transport tenant telemetry messages rate limits", + "add-transport-tenant-telemetry-data-points-title": "Add transport tenant telemetry data points rate limits", + "add-transport-device-msg-title": "Add transport device messages rate limits", + "add-transport-device-telemetry-msg-title": "Add transport device telemetry messages rate limits", + "add-transport-device-telemetry-data-points-title": "Add transport device telemetry data points rate limits", + "add-transport-tenant-msg-rate-limit-title": "Add transport tenant messages rate limits", + "add-customer-rest-limits-title": "Add REST requests for customer rate limits", + "add-ws-limit-updates-per-session-title": "Add WS updates per session rate limits", + "add-cassandra-tenant-limits-configuration-title": "Add Cassandra query for tenant rate limits", "advanced-settings": "Advanced settings", "edit-limit": "Edit limit", "but-less-than": "but less than", - "edit-transport-tenant-msg-title": "Edit transport tenant messages rate limit", - "edit-transport-tenant-telemetry-msg-title": "Edit transport tenant telemetry messages rate limit", - "edit-transport-tenant-telemetry-data-points-title": "Edit transport tenant telemetry data points rate limit", - "edit-transport-device-msg-title": "Edit transport device messages rate limit", - "edit-transport-device-telemetry-msg-title": "Edit transport device telemetry messages rate limit", - "edit-transport-device-telemetry-data-points-title": "Edit transport device telemetry data points rate limit", + "edit-transport-tenant-msg-title": "Edit transport tenant messages rate limits", + "edit-transport-tenant-telemetry-msg-title": "Edit transport tenant telemetry messages rate limits", + "edit-transport-tenant-telemetry-data-points-title": "Edit transport tenant telemetry data points rate limits", + "edit-transport-device-msg-title": "Edit transport device messages rate limits", + "edit-transport-device-telemetry-msg-title": "Edit transport device telemetry messages rate limits", + "edit-transport-device-telemetry-data-points-title": "Edit transport device telemetry data points rate limits", + "edit-transport-tenant-msg-rate-limit-title": "Edit transport tenant messages rate limits", + "edit-customer-rest-limits-title": "Edit REST requests for customer rate limits", + "edit-ws-limit-updates-per-session-title": "Edit WS updates per session rate limits", + "edit-cassandra-tenant-limits-configuration-title": "Edit Cassandra query for tenant rate limits", "messages-per": "messages per", "not-set": "Not set", "number-of-messages": "Number of messages", @@ -3213,7 +3221,7 @@ "per-seconds": "Per seconds", "per-seconds-required": "Time rate is required.", "rate-limits": "Rate limits", - "remove-limit": "Remove rate limit", + "remove-limit": "Remove limit", "transport-tenant-msg": "Transport tenant messages", "transport-tenant-telemetry-msg": "Transport tenant telemetry messages", "transport-tenant-telemetry-data-points": "Transport tenant telemetry data points", From a5d67401f84176974d403b058233ecce8d439a87 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 21 Jul 2022 13:07:15 +0300 Subject: [PATCH 03/18] Rate limits added tenant entity version/load --- ...enant-profile-configuration.component.html | 20 ++++++------------- ...-tenant-profile-configuration.component.ts | 4 ++-- .../rate-limits-details-dialog.component.html | 4 ++-- .../rate-limits-list.component.html | 7 +++++++ .../rate-limits-list.component.scss | 12 +++++------ .../rate-limits/rate-limits.component.html | 13 ++++++------ .../rate-limits/rate-limits.component.scss | 4 ++++ .../app/shared/models/rate-limits.models.ts | 8 ++++++++ .../assets/locale/locale.constant-en_US.json | 6 ++++++ 9 files changed, 47 insertions(+), 31 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html index 5484aaed28..34015f71ad 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html @@ -469,20 +469,12 @@
- - tenant-profile.tenant-entity-export-rate-limit - - - - tenant-profile.tenant-entity-import-rate-limit - - - + + + +
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts index ac2702ca43..5652f7dd71 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts @@ -71,8 +71,8 @@ export class DefaultTenantProfileConfigurationComponent implements ControlValueA transportDeviceMsgRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], transportDeviceTelemetryMsgRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], transportDeviceTelemetryDataPointsRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], - tenantEntityExportRateLimit: [null, []], - tenantEntityImportRateLimit: [null, []], + tenantEntityExportRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], + tenantEntityImportRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], maxTransportMessages: [null, [Validators.required, Validators.min(0)]], maxTransportDataPoints: [null, [Validators.required, Validators.min(0)]], maxREExecutions: [null, [Validators.required, Validators.min(0)]], diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html index 911b44ecd8..751ffe0e2c 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html @@ -15,9 +15,9 @@ limitations under the License. --> -
+ -

{{ title }}

+

{{ title | translate }}

-
- -
+ diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.scss b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.scss index 6d45b33b73..1d7e817839 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.scss +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.scss @@ -28,4 +28,8 @@ font-size: 12px; } } + + .tb-rate-limits-button { + margin-top: 0.5em; + } } diff --git a/ui-ngx/src/app/shared/models/rate-limits.models.ts b/ui-ngx/src/app/shared/models/rate-limits.models.ts index e6b4218773..ffde8a3c87 100644 --- a/ui-ngx/src/app/shared/models/rate-limits.models.ts +++ b/ui-ngx/src/app/shared/models/rate-limits.models.ts @@ -32,6 +32,8 @@ export enum RateLimitsType { CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION = 'CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION', WS_UPDATE_PER_SESSION_RATE_LIMIT = 'WS_UPDATE_PER_SESSION_RATE_LIMIT', CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION = 'CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION', + TENANT_ENTITY_EXPORT_RATE_LIMIT = 'TENANT_ENTITY_EXPORT_RATE_LIMIT', + TENANT_ENTITY_IMPORT_RATE_LIMIT = 'TENANT_ENTITY_IMPORT_RATE_LIMIT' } export const rateLimitLabelTranslationMap = new Map( @@ -46,6 +48,8 @@ export const rateLimitLabelTranslationMap = new Map( [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.customer-rest-limits'], [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.ws-limit-updates-per-session'], [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.cassandra-tenant-limits-configuration'], + [RateLimitsType.TENANT_ENTITY_EXPORT_RATE_LIMIT, 'tenant-profile.tenant-entity-export-rate-limit'], + [RateLimitsType.TENANT_ENTITY_IMPORT_RATE_LIMIT, 'tenant-profile.tenant-entity-import-rate-limit'], ] ); @@ -61,6 +65,8 @@ export const editRateLimitTranslationMap = new Map( [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-customer-rest-limits-title'], [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.rate-limits.edit-ws-limit-updates-per-session-title'], [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.edit-cassandra-tenant-limits-configuration-title'], + [RateLimitsType.TENANT_ENTITY_EXPORT_RATE_LIMIT, 'tenant-profile.rate-limits.edit-tenant-entity-export-rate-limit-title'], + [RateLimitsType.TENANT_ENTITY_IMPORT_RATE_LIMIT, 'tenant-profile.rate-limits.edit-tenant-entity-import-rate-limit-title'], ] ); @@ -76,6 +82,8 @@ export const addRateLimitTranslationMap = new Map( [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-customer-rest-limits-title'], [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.rate-limits.add-ws-limit-updates-per-session-title'], [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-cassandra-tenant-limits-configuration-title'], + [RateLimitsType.TENANT_ENTITY_EXPORT_RATE_LIMIT, 'tenant-profile.rate-limits.add-tenant-entity-export-rate-limit-title'], + [RateLimitsType.TENANT_ENTITY_IMPORT_RATE_LIMIT, 'tenant-profile.rate-limits.add-tenant-entity-import-rate-limit-title'], ] ); diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 8cd65a139e..371ade779c 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3200,6 +3200,8 @@ "add-customer-rest-limits-title": "Add REST requests for customer rate limits", "add-ws-limit-updates-per-session-title": "Add WS updates per session rate limits", "add-cassandra-tenant-limits-configuration-title": "Add Cassandra query for tenant rate limits", + "add-tenant-entity-export-rate-limit-title": "Add entity version creation rate limits", + "add-tenant-entity-import-rate-limit-title": "Add entity version load rate limits", "advanced-settings": "Advanced settings", "edit-limit": "Edit limit", "but-less-than": "but less than", @@ -3213,13 +3215,17 @@ "edit-customer-rest-limits-title": "Edit REST requests for customer rate limits", "edit-ws-limit-updates-per-session-title": "Edit WS updates per session rate limits", "edit-cassandra-tenant-limits-configuration-title": "Edit Cassandra query for tenant rate limits", + "edit-tenant-entity-export-rate-limit-title": "Edit entity version creation rate limits", + "edit-tenant-entity-import-rate-limit-title": "Edit entity version load rate limits", "messages-per": "messages per", "not-set": "Not set", "number-of-messages": "Number of messages", "number-of-messages-required": "Number of messages is required.", + "number-of-messages-min": "Minimum value is 1.", "preview": "Preview", "per-seconds": "Per seconds", "per-seconds-required": "Time rate is required.", + "per-seconds-min": "Minimum value is 1.", "rate-limits": "Rate limits", "remove-limit": "Remove limit", "transport-tenant-msg": "Transport tenant messages", From e74eeed6a8b3c6a3f5e05a1e9acd4f8f5d061a8e Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 21 Jul 2022 13:09:55 +0300 Subject: [PATCH 04/18] Removed Add rate limit titles --- .../rate-limits/rate-limits.component.html | 4 ++-- .../tenant/rate-limits/rate-limits.component.ts | 14 ++------------ .../src/app/shared/models/rate-limits.models.ts | 17 ----------------- .../assets/locale/locale.constant-en_US.json | 12 ------------ 4 files changed, 4 insertions(+), 43 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html index 2c4b82e4ab..3a6591790f 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html @@ -19,14 +19,14 @@
{{ label | translate }}
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts index 34cbadb755..75318c41cb 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts @@ -30,7 +30,6 @@ import { RateLimitsDetailsDialogData } from '@home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component'; import { - addRateLimitTranslationMap, editRateLimitTranslationMap, rateLimitLabelTranslationMap, RateLimitsType, @@ -106,11 +105,11 @@ export class RateLimitsComponent implements ControlValueAccessor, OnInit, Valida return null; } - public onClick($event: Event, action: string) { + public onClick($event: Event) { if ($event) { $event.stopPropagation(); } - const title = this.setTitle(action); + const title = editRateLimitTranslationMap.get(this.type); this.dialog.open(RateLimitsDetailsDialogComponent, { disableClose: true, @@ -128,15 +127,6 @@ export class RateLimitsComponent implements ControlValueAccessor, OnInit, Valida }); } - private setTitle(action: string): string { - switch (action) { - case 'add': - return addRateLimitTranslationMap.get(this.type); - case 'edit': - return editRateLimitTranslationMap.get(this.type); - } - } - private updateRateLimitsInfo() { this.rateLimitsFormGroup.patchValue( { diff --git a/ui-ngx/src/app/shared/models/rate-limits.models.ts b/ui-ngx/src/app/shared/models/rate-limits.models.ts index ffde8a3c87..f035d9f67c 100644 --- a/ui-ngx/src/app/shared/models/rate-limits.models.ts +++ b/ui-ngx/src/app/shared/models/rate-limits.models.ts @@ -70,23 +70,6 @@ export const editRateLimitTranslationMap = new Map( ] ); -export const addRateLimitTranslationMap = new Map( - [ - [RateLimitsType.TENANT_MESSAGES, 'tenant-profile.rate-limits.add-transport-tenant-msg-title'], - [RateLimitsType.TENANT_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.add-transport-tenant-telemetry-msg-title'], - [RateLimitsType.TENANT_TELEMETRY_DATA_POINTS, 'tenant-profile.rate-limits.add-transport-tenant-telemetry-data-points-title'], - [RateLimitsType.DEVICE_MESSAGES, 'tenant-profile.rate-limits.add-transport-device-msg-title'], - [RateLimitsType.DEVICE_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.add-transport-device-telemetry-msg-title'], - [RateLimitsType.DEVICE_TELEMETRY_DATA_POINTS, 'tenant-profile.rate-limits.add-transport-device-telemetry-data-points-title'], - [RateLimitsType.TENANT_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-transport-tenant-msg-rate-limit-title'], - [RateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-customer-rest-limits-title'], - [RateLimitsType.WS_UPDATE_PER_SESSION_RATE_LIMIT, 'tenant-profile.rate-limits.add-ws-limit-updates-per-session-title'], - [RateLimitsType.CASSANDRA_QUERY_TENANT_RATE_LIMITS_CONFIGURATION, 'tenant-profile.rate-limits.add-cassandra-tenant-limits-configuration-title'], - [RateLimitsType.TENANT_ENTITY_EXPORT_RATE_LIMIT, 'tenant-profile.rate-limits.add-tenant-entity-export-rate-limit-title'], - [RateLimitsType.TENANT_ENTITY_IMPORT_RATE_LIMIT, 'tenant-profile.rate-limits.add-tenant-entity-import-rate-limit-title'], - ] -); - export function stringToRateLimitsArray(rateLimits: string): Array { const result: Array = []; if (rateLimits?.length > 0) { diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 371ade779c..612823b803 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -3190,18 +3190,6 @@ "ws-limit-updates-per-session": "WS updates per session", "rate-limits": { "add-limit": "Add limit", - "add-transport-tenant-msg-title": "Add transport tenant messages rate limits", - "add-transport-tenant-telemetry-msg-title": "Add transport tenant telemetry messages rate limits", - "add-transport-tenant-telemetry-data-points-title": "Add transport tenant telemetry data points rate limits", - "add-transport-device-msg-title": "Add transport device messages rate limits", - "add-transport-device-telemetry-msg-title": "Add transport device telemetry messages rate limits", - "add-transport-device-telemetry-data-points-title": "Add transport device telemetry data points rate limits", - "add-transport-tenant-msg-rate-limit-title": "Add transport tenant messages rate limits", - "add-customer-rest-limits-title": "Add REST requests for customer rate limits", - "add-ws-limit-updates-per-session-title": "Add WS updates per session rate limits", - "add-cassandra-tenant-limits-configuration-title": "Add Cassandra query for tenant rate limits", - "add-tenant-entity-export-rate-limit-title": "Add entity version creation rate limits", - "add-tenant-entity-import-rate-limit-title": "Add entity version load rate limits", "advanced-settings": "Advanced settings", "edit-limit": "Edit limit", "but-less-than": "but less than", From 9ada3562d56788298036317460cd88a53dd3659c Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 21 Jul 2022 13:11:40 +0300 Subject: [PATCH 05/18] Rate limit dialog minor title refactor --- .../profile/tenant/rate-limits/rate-limits.component.ts | 4 ++-- ui-ngx/src/app/shared/models/rate-limits.models.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts index 75318c41cb..2c320bcbe2 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts @@ -30,7 +30,7 @@ import { RateLimitsDetailsDialogData } from '@home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component'; import { - editRateLimitTranslationMap, + rateLimitDialogTitleTranslationMap, rateLimitLabelTranslationMap, RateLimitsType, stringToRateLimitsArray @@ -109,7 +109,7 @@ export class RateLimitsComponent implements ControlValueAccessor, OnInit, Valida if ($event) { $event.stopPropagation(); } - const title = editRateLimitTranslationMap.get(this.type); + const title = rateLimitDialogTitleTranslationMap.get(this.type); this.dialog.open(RateLimitsDetailsDialogComponent, { disableClose: true, diff --git a/ui-ngx/src/app/shared/models/rate-limits.models.ts b/ui-ngx/src/app/shared/models/rate-limits.models.ts index f035d9f67c..272728c647 100644 --- a/ui-ngx/src/app/shared/models/rate-limits.models.ts +++ b/ui-ngx/src/app/shared/models/rate-limits.models.ts @@ -53,7 +53,7 @@ export const rateLimitLabelTranslationMap = new Map( ] ); -export const editRateLimitTranslationMap = new Map( +export const rateLimitDialogTitleTranslationMap = new Map( [ [RateLimitsType.TENANT_MESSAGES, 'tenant-profile.rate-limits.edit-transport-tenant-msg-title'], [RateLimitsType.TENANT_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.edit-transport-tenant-telemetry-msg-title'], From acadd0f8278a19eef4b5053ee5fbbcc54891885e Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 21 Jul 2022 13:31:00 +0300 Subject: [PATCH 06/18] Rate limits fix close null bug --- .../rate-limits-details-dialog.component.ts | 2 +- .../tenant/rate-limits/rate-limits.component.ts | 11 ++++++----- ui-ngx/src/app/shared/models/rate-limits.models.ts | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts index 69bf5cda4f..790ca57838 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts @@ -72,7 +72,7 @@ export class RateLimitsDetailsDialogComponent extends DialogComponent(RateLimitsDetailsDialogComponent, { disableClose: true, @@ -120,7 +121,7 @@ export class RateLimitsComponent implements ControlValueAccessor, OnInit, Valida readonly: this.disabled } }).afterClosed().subscribe((result) => { - if (result) { + if (result || result === null) { this.modelValue = result; this.updateModel(); } diff --git a/ui-ngx/src/app/shared/models/rate-limits.models.ts b/ui-ngx/src/app/shared/models/rate-limits.models.ts index 272728c647..7185dbdd44 100644 --- a/ui-ngx/src/app/shared/models/rate-limits.models.ts +++ b/ui-ngx/src/app/shared/models/rate-limits.models.ts @@ -36,7 +36,7 @@ export enum RateLimitsType { TENANT_ENTITY_IMPORT_RATE_LIMIT = 'TENANT_ENTITY_IMPORT_RATE_LIMIT' } -export const rateLimitLabelTranslationMap = new Map( +export const rateLimitsLabelTranslationMap = new Map( [ [RateLimitsType.TENANT_MESSAGES, 'tenant-profile.rate-limits.transport-tenant-msg'], [RateLimitsType.TENANT_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.transport-tenant-telemetry-msg'], @@ -53,7 +53,7 @@ export const rateLimitLabelTranslationMap = new Map( ] ); -export const rateLimitDialogTitleTranslationMap = new Map( +export const rateLimitsDialogTitleTranslationMap = new Map( [ [RateLimitsType.TENANT_MESSAGES, 'tenant-profile.rate-limits.edit-transport-tenant-msg-title'], [RateLimitsType.TENANT_TELEMETRY_MESSAGES, 'tenant-profile.rate-limits.edit-transport-tenant-telemetry-msg-title'], From b331bbbb2491373a52096590cf02f331c2dcb955 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 21 Jul 2022 13:50:17 +0300 Subject: [PATCH 07/18] Rate limits: changed order --- ...t-tenant-profile-configuration.component.html | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html index 34015f71ad..847aae7bf1 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html @@ -460,14 +460,6 @@ [type]="rateLimitsType.CUSTOMER_SERVER_REST_LIMITS_CONFIGURATION"> -
- - - - -
@@ -476,6 +468,14 @@ [type]="rateLimitsType.TENANT_ENTITY_IMPORT_RATE_LIMIT">
+
+ + + + +
From 913db7a0d329f132218beaecdc55a2b0098c8d5b Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 21 Jul 2022 15:45:00 +0300 Subject: [PATCH 08/18] - Fixed diabled button in the edit rate limits; - Removed validation by the pattern for the rate limits --- ...-tenant-profile-configuration.component.ts | 25 +++++++++---------- .../rate-limits-list.component.html | 2 ++ 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts index 5652f7dd71..d44715cc63 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts @@ -36,7 +36,6 @@ import { RateLimitsType } from '@shared/models/rate-limits.models'; export class DefaultTenantProfileConfigurationComponent implements ControlValueAccessor, OnInit { defaultTenantProfileConfigurationFormGroup: FormGroup; - rateLimitsPattern = '([1-9]\\d*:[1-9]\\d*)(,[1-9]\\d*:[1-9]\\d*)*'; private requiredValue: boolean; get required(): boolean { @@ -65,14 +64,14 @@ export class DefaultTenantProfileConfigurationComponent implements ControlValueA maxRuleChains: [null, [Validators.required, Validators.min(0)]], maxResourcesInBytes: [null, [Validators.required, Validators.min(0)]], maxOtaPackagesInBytes: [null, [Validators.required, Validators.min(0)]], - transportTenantMsgRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], - transportTenantTelemetryMsgRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], - transportTenantTelemetryDataPointsRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], - transportDeviceMsgRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], - transportDeviceTelemetryMsgRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], - transportDeviceTelemetryDataPointsRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], - tenantEntityExportRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], - tenantEntityImportRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], + transportTenantMsgRateLimit: [null, []], + transportTenantTelemetryMsgRateLimit: [null, []], + transportTenantTelemetryDataPointsRateLimit: [null, []], + transportDeviceMsgRateLimit: [null, []], + transportDeviceTelemetryMsgRateLimit: [null, []], + transportDeviceTelemetryDataPointsRateLimit: [null, []], + tenantEntityExportRateLimit: [null, []], + tenantEntityImportRateLimit: [null, []], maxTransportMessages: [null, [Validators.required, Validators.min(0)]], maxTransportDataPoints: [null, [Validators.required, Validators.min(0)]], maxREExecutions: [null, [Validators.required, Validators.min(0)]], @@ -85,8 +84,8 @@ export class DefaultTenantProfileConfigurationComponent implements ControlValueA defaultStorageTtlDays: [null, [Validators.required, Validators.min(0)]], alarmsTtlDays: [null, [Validators.required, Validators.min(0)]], rpcTtlDays: [null, [Validators.required, Validators.min(0)]], - tenantServerRestLimitsConfiguration: [null, [Validators.pattern(this.rateLimitsPattern)]], - customerServerRestLimitsConfiguration: [null, [Validators.pattern(this.rateLimitsPattern)]], + tenantServerRestLimitsConfiguration: [null, []], + customerServerRestLimitsConfiguration: [null, []], maxWsSessionsPerTenant: [null, [Validators.min(0)]], maxWsSessionsPerCustomer: [null, [Validators.min(0)]], maxWsSessionsPerRegularUser: [null, [Validators.min(0)]], @@ -96,8 +95,8 @@ export class DefaultTenantProfileConfigurationComponent implements ControlValueA maxWsSubscriptionsPerCustomer: [null, [Validators.min(0)]], maxWsSubscriptionsPerRegularUser: [null, [Validators.min(0)]], maxWsSubscriptionsPerPublicUser: [null, [Validators.min(0)]], - wsUpdatesPerSessionRateLimit: [null, [Validators.pattern(this.rateLimitsPattern)]], - cassandraQueryTenantRateLimitsConfiguration: [null, [Validators.pattern(this.rateLimitsPattern)]] + wsUpdatesPerSessionRateLimit: [null, []], + cassandraQueryTenantRateLimitsConfiguration: [null, []] }); this.defaultTenantProfileConfigurationFormGroup.valueChanges.subscribe(() => { this.updateModel(); diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html index 7d1f3e4561..768b351070 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html @@ -47,6 +47,7 @@ class="tb-rate-limits-button" *ngIf="!rateLimitsFormArray().disabled" (click)="removeRateLimits($index)" + [disabled]="disabled" [matTooltip]="'tenant-profile.rate-limits.remove-limit' | translate" matTooltipPosition="above"> remove_circle_outline @@ -55,6 +56,7 @@
From a0fd18221de1c4a0cc43f3dd35f554e473ec8b74 Mon Sep 17 00:00:00 2001 From: Artem Babak Date: Thu, 21 Jul 2022 16:29:40 +0300 Subject: [PATCH 09/18] Remove redundant import --- .../profile/tenant/rate-limits/rate-limits.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts index 9029d36a9f..753ef133a9 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts @@ -35,7 +35,6 @@ import { RateLimitsType, stringToRateLimitsArray } from '@shared/models/rate-limits.models'; -import { isNull } from 'util'; @Component({ selector: 'tb-rate-limits', From b3fdc881f48a8b985acd6ab15e24cca6ddb71de7 Mon Sep 17 00:00:00 2001 From: deaflynx Date: Mon, 25 Jul 2022 17:19:07 +0300 Subject: [PATCH 10/18] Fixed bugs, removed redundant code --- ...enant-profile-configuration.component.html | 24 +++++++------- ...-tenant-profile-configuration.component.ts | 2 +- .../rate-limits-details-dialog.component.html | 10 ++---- .../rate-limits-details-dialog.component.ts | 21 +++--------- .../rate-limits-list.component.html | 22 ++++++------- .../rate-limits/rate-limits-list.component.ts | 32 +++++++------------ .../rate-limits-text.component.html | 2 +- .../rate-limits-text.component.scss | 8 ----- .../rate-limits/rate-limits-text.component.ts | 25 ++------------- .../rate-limits/rate-limits.component.ts | 2 +- .../tenant/rate-limits}/rate-limits.models.ts | 0 11 files changed, 47 insertions(+), 101 deletions(-) rename ui-ngx/src/app/{shared/models => modules/home/components/profile/tenant/rate-limits}/rate-limits.models.ts (100%) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html index 847aae7bf1..a3f285bece 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.html @@ -422,18 +422,18 @@ {{ 'tenant-profile.rate-limits.rate-limits' | translate }}
- -
- -
@@ -445,34 +445,34 @@
- -
- -
- -
- -
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts index d44715cc63..9649966bd1 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/default-tenant-profile-configuration.component.ts @@ -21,7 +21,7 @@ import { AppState } from '@app/core/core.state'; import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { DefaultTenantProfileConfiguration, TenantProfileConfiguration } from '@shared/models/tenant.model'; import { isDefinedAndNotNull } from '@core/utils'; -import { RateLimitsType } from '@shared/models/rate-limits.models'; +import { RateLimitsType } from './rate-limits/rate-limits.models'; @Component({ selector: 'tb-default-tenant-profile-configuration', diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html index 751ffe0e2c..6cbe5472c2 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html @@ -25,14 +25,11 @@ close - -
-
+
+ formControlName="rateLimits">
@@ -40,12 +37,11 @@
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts index 790ca57838..80b9e1ba34 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts @@ -19,7 +19,7 @@ import { ErrorStateMatcher } from '@angular/material/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; -import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm } from '@angular/forms'; +import { FormBuilder, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { DialogComponent } from '@app/shared/components/dialog.component'; import { TranslateService } from '@ngx-translate/core'; @@ -31,16 +31,12 @@ export interface RateLimitsDetailsDialogData { } @Component({ - templateUrl: './rate-limits-details-dialog.component.html', - providers: [{provide: ErrorStateMatcher, useExisting: RateLimitsDetailsDialogComponent}] + templateUrl: './rate-limits-details-dialog.component.html' }) -export class RateLimitsDetailsDialogComponent extends DialogComponent - implements OnInit, ErrorStateMatcher { +export class RateLimitsDetailsDialogComponent extends DialogComponent implements OnInit { editDetailsFormGroup: FormGroup; - submitted: boolean = false; - rateLimits: string = this.data.rateLimits; title: string = this.data.title; @@ -49,7 +45,7 @@ export class RateLimitsDetailsDialogComponent extends DialogComponent, + public dialogRef: MatDialogRef, private fb: FormBuilder, public translate: TranslateService) { super(store, router, dialogRef); @@ -65,18 +61,11 @@ export class RateLimitsDetailsDialogComponent extends DialogComponent -
-
-
+
+
+
tenant-profile.rate-limits.but-less-than
@@ -45,7 +45,7 @@
-
- -
+
tenant-profile.rate-limits.preview
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts index eb7a37cfde..dd5f52dbc2 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts @@ -32,7 +32,7 @@ import { RateLimits, rateLimitsArrayToString, stringToRateLimitsArray -} from '@shared/models/rate-limits.models'; +} from './rate-limits.models'; import { isDefinedAndNotNull } from '@core/utils'; @Component({ @@ -68,17 +68,17 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, } ngOnInit(): void { - this.rateLimitsListFormGroup = this.fb.group({}); - this.rateLimitsListFormGroup.addControl('rateLimits', - this.fb.array([])); + this.rateLimitsListFormGroup = this.fb.group({ + rateLimits: this.fb.array([]) + }); this.rateLimitsControl = this.fb.control(null); - this.rateLimitsListFormGroup.valueChanges.subscribe((value) => { + this.valueChangeSubscription = this.rateLimitsListFormGroup.valueChanges.subscribe((value) => { this.updateView(value?.rateLimits); } ); } - rateLimitsFormArray(): FormArray { + get rateLimitsFormArray(): FormArray { return this.rateLimitsListFormGroup.get('rateLimits') as FormArray; } @@ -107,16 +107,11 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, } writeValue(value: string) { - if (this.valueChangeSubscription) { - this.valueChangeSubscription.unsubscribe(); - } const rateLimitsControls: Array = []; if (value) { let rateLimitsArray = value.split(','); for (let i = 0; i < rateLimitsArray.length; i++) { - let valueTime = rateLimitsArray[i].split(':'); - let value = valueTime[0]; - let time = valueTime[1]; + const [value, time] = rateLimitsArray[i].split(':'); const rateLimitsControl = this.fb.group({ value: [value, [Validators.required]], time: [time, [Validators.required]] @@ -127,11 +122,8 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, rateLimitsControls.push(rateLimitsControl); } } - this.rateLimitsListFormGroup.setControl('rateLimits', this.fb.array(rateLimitsControls)); + this.rateLimitsListFormGroup.setControl('rateLimits', this.fb.array(rateLimitsControls), {emitEvent: false}); this.rateLimitsControl.patchValue(stringToRateLimitsArray(value), {emitEvent: false}); - this.valueChangeSubscription = this.rateLimitsListFormGroup.valueChanges.subscribe((value) => { - this.updateView(value?.rateLimits); - }); } public removeRateLimits(index: number) { @@ -139,17 +131,17 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, } public addRateLimits() { - const rateLimitsArray = this.rateLimitsListFormGroup.get('rateLimits') as FormArray; - rateLimitsArray.push(this.fb.group({ + this.rateLimitsFormArray.push(this.fb.group({ value: [null, [Validators.required]], time: [null, [Validators.required]] })); - this.rateLimitsListFormGroup.updateValueAndValidity(); } updateView(rateLimitsArray: Array) { if (rateLimitsArray.length > 0) { - const notNullRateLimits = rateLimitsArray.filter(rateLimits => isDefinedAndNotNull(rateLimits.value) && isDefinedAndNotNull(rateLimits.time)); + const notNullRateLimits = rateLimitsArray.filter(rateLimits => + isDefinedAndNotNull(rateLimits.value) && isDefinedAndNotNull(rateLimits.time) + ); const rateLimitsString = rateLimitsArrayToString(notNullRateLimits); this.propagateChange(rateLimitsString); this.rateLimitsControl.patchValue(stringToRateLimitsArray(rateLimitsString), {emitEvent: false}); diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html index 98a30b055e..077ede2e0b 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html @@ -15,5 +15,5 @@ limitations under the License. --> -
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss index a8f8f8553f..b78f1033bd 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.scss @@ -20,14 +20,6 @@ &.disabled { opacity: 0.7; } - &.required { - color: #f44336; - padding: 0 4px; - } - &.nowrap { - white-space: nowrap; - overflow: hidden; - } } } diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts index 9ab7e9b56b..604318d6fd 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts @@ -18,8 +18,7 @@ import { Component, forwardRef, Input, OnInit } from '@angular/core'; import { ControlValueAccessor, FormBuilder, NG_VALUE_ACCESSOR } from '@angular/forms'; import { MatDialog } from '@angular/material/dialog'; import { TranslateService } from '@ngx-translate/core'; -import { coerceBooleanProperty } from '@angular/cdk/coercion'; -import { RateLimits, rateLimitsArrayToHtml } from '@shared/models/rate-limits.models'; +import { RateLimits, rateLimitsArrayToHtml } from './rate-limits.models'; @Component({ selector: 'tb-rate-limits-text', @@ -35,26 +34,11 @@ import { RateLimits, rateLimitsArrayToHtml } from '@shared/models/rate-limits.mo }) export class RateLimitsTextComponent implements ControlValueAccessor, OnInit { - private requiredValue: boolean; - get required(): boolean { - return this.requiredValue; - } - @Input() - set required(value: boolean) { - this.requiredValue = coerceBooleanProperty(value); - } - @Input() disabled: boolean; - @Input() noRateLimitsText = this.translate.instant('tenant-profile.rate-limits.not-set'); - @Input() - nowrap = false; - - requiredClass = false; - public rateLimitsText: string; private propagateChange = (v: any) => { }; @@ -83,15 +67,10 @@ export class RateLimitsTextComponent implements ControlValueAccessor, OnInit { } private updateText(value: Array) { - this.requiredClass = false; if (value && value.length) { this.rateLimitsText = rateLimitsArrayToHtml(this.translate, value); } else { - if (this.required && !this.disabled) { - this.requiredClass = true; - } else { - this.rateLimitsText = this.noRateLimitsText; - } + this.rateLimitsText = this.noRateLimitsText; } } diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts index 753ef133a9..dcf0403a22 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.ts @@ -34,7 +34,7 @@ import { rateLimitsLabelTranslationMap, RateLimitsType, stringToRateLimitsArray -} from '@shared/models/rate-limits.models'; +} from './rate-limits.models'; @Component({ selector: 'tb-rate-limits', diff --git a/ui-ngx/src/app/shared/models/rate-limits.models.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.models.ts similarity index 100% rename from ui-ngx/src/app/shared/models/rate-limits.models.ts rename to ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.models.ts From 88599262daa26a19e365acadd2375d44666c9d0b Mon Sep 17 00:00:00 2001 From: deaflynx Date: Mon, 25 Jul 2022 17:55:15 +0300 Subject: [PATCH 11/18] Rate limits update styles --- .../rate-limits-details-dialog.component.html | 5 +++-- .../rate-limits-details-dialog.component.ts | 13 ++----------- .../rate-limits/rate-limits-list.component.scss | 4 ++++ .../tenant/rate-limits/rate-limits.component.ts | 3 ++- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html index 6cbe5472c2..e69b95a3e2 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.html @@ -20,7 +20,7 @@

{{ title | translate }}

@@ -37,7 +37,8 @@
-
-
- - -
-
+
tenant-profile.rate-limits.preview -
- -
+
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.scss b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.scss index 64f9c7afe2..2a53096c17 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.scss +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.scss @@ -27,7 +27,7 @@ span { padding-left: 1em; } - div { + tb-rate-limits-text { border: 1px groove rgba(0, 0, 0, .25); border-radius: 4px; padding: 1em; diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html index 077ede2e0b..e154a7ce54 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.html @@ -15,5 +15,4 @@ limitations under the License. --> -
+
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts index 604318d6fd..0b65e97d5d 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts @@ -14,64 +14,41 @@ /// limitations under the License. /// -import { Component, forwardRef, Input, OnInit } from '@angular/core'; -import { ControlValueAccessor, FormBuilder, NG_VALUE_ACCESSOR } from '@angular/forms'; -import { MatDialog } from '@angular/material/dialog'; +import { Component, Input, OnChanges, SimpleChanges } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; import { RateLimits, rateLimitsArrayToHtml } from './rate-limits.models'; @Component({ selector: 'tb-rate-limits-text', templateUrl: './rate-limits-text.component.html', - styleUrls: ['./rate-limits-text.component.scss'], - providers: [ - { - provide: NG_VALUE_ACCESSOR, - useExisting: forwardRef(() => RateLimitsTextComponent), - multi: true - } - ] + styleUrls: ['./rate-limits-text.component.scss'] }) -export class RateLimitsTextComponent implements ControlValueAccessor, OnInit { +export class RateLimitsTextComponent implements OnChanges { @Input() - disabled: boolean; - - noRateLimitsText = this.translate.instant('tenant-profile.rate-limits.not-set'); - - public rateLimitsText: string; - - private propagateChange = (v: any) => { }; - - constructor(private dialog: MatDialog, - private fb: FormBuilder, - private translate: TranslateService) { - } - - registerOnChange(fn: any): void { - this.propagateChange = fn; - } + rateLimitsArray: Array; - registerOnTouched(fn: any): void { - } + @Input() + disabled: boolean; - ngOnInit() { - } + rateLimitsText: string; - setDisabledState(isDisabled: boolean): void { - this.disabled = isDisabled; - } + constructor(private translate: TranslateService) {} - writeValue(value: Array): void { - this.updateText(value); + ngOnChanges(changes: SimpleChanges): void { + for (const propName of Object.keys(changes)) { + if (propName === 'rateLimitsArray') { + const change = changes[propName]; + this.updateView(change.currentValue); + } + } } - private updateText(value: Array) { - if (value && value.length) { + private updateView(value: Array): void { + if (value?.length) { this.rateLimitsText = rateLimitsArrayToHtml(this.translate, value); } else { - this.rateLimitsText = this.noRateLimitsText; + this.rateLimitsText = this.translate.instant('tenant-profile.rate-limits.not-set'); } } - } diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html index 3a6591790f..ac341c8b69 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html @@ -21,7 +21,7 @@
- +
tenant-profile.rate-limits.preview - +
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts index 0d8abf6657..0c135d0d9a 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts @@ -95,6 +95,10 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, return this.rateLimitsListFormGroup.get('rateLimits') as FormArray; } + get rateLimitsArray(): Array { + return this.rateLimitsControl.value; + } + registerOnChange(fn: any): void { this.propagateChange = fn; } From c2f0d4725531da8bd307769defd24912d3f68567 Mon Sep 17 00:00:00 2001 From: deaflynx Date: Tue, 26 Jul 2022 15:44:51 +0300 Subject: [PATCH 16/18] Code cleanup --- .../rate-limits/rate-limits-details-dialog.component.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts index 9d01ddcd5b..46a50bf484 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts @@ -15,14 +15,12 @@ /// import { Component, Inject, SkipSelf } from '@angular/core'; -import { ErrorStateMatcher } from '@angular/material/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; import { FormBuilder, FormGroup } from '@angular/forms'; import { Router } from '@angular/router'; import { DialogComponent } from '@app/shared/components/dialog.component'; -import { TranslateService } from '@ngx-translate/core'; export interface RateLimitsDetailsDialogData { rateLimits: string; @@ -44,10 +42,8 @@ export class RateLimitsDetailsDialogComponent extends DialogComponent, protected router: Router, @Inject(MAT_DIALOG_DATA) public data: RateLimitsDetailsDialogData, - @SkipSelf() private errorStateMatcher: ErrorStateMatcher, public dialogRef: MatDialogRef, - private fb: FormBuilder, - public translate: TranslateService) { + private fb: FormBuilder) { super(store, router, dialogRef); this.editDetailsFormGroup = this.fb.group({ rateLimits: [this.rateLimits, []] From 4811a3d56cbe44d2c5a6576748273554ef15855e Mon Sep 17 00:00:00 2001 From: deaflynx Date: Tue, 26 Jul 2022 16:04:55 +0300 Subject: [PATCH 17/18] Code cleanup --- .../tenant/rate-limits/rate-limits-details-dialog.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts index 46a50bf484..4818304491 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-details-dialog.component.ts @@ -14,7 +14,7 @@ /// limitations under the License. /// -import { Component, Inject, SkipSelf } from '@angular/core'; +import { Component, Inject } from '@angular/core'; import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { Store } from '@ngrx/store'; import { AppState } from '@core/core.state'; From 43b847b9d85ed89bd7a4b6e1a077e2548d79a6f3 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Tue, 26 Jul 2022 16:39:56 +0300 Subject: [PATCH 18/18] UI: Refactoring code --- .../rate-limits-list.component.html | 2 +- .../rate-limits/rate-limits-list.component.ts | 32 ++++++------------- .../rate-limits/rate-limits-text.component.ts | 3 +- .../rate-limits/rate-limits.component.html | 2 +- .../tenant/rate-limits/rate-limits.models.ts | 19 +++++------ 5 files changed, 22 insertions(+), 36 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html index ec25c80683..ba51cbc358 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.html @@ -61,6 +61,6 @@
tenant-profile.rate-limits.preview - +
diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts index 0c135d0d9a..e6ad1c5b20 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-list.component.ts @@ -19,7 +19,6 @@ import { ControlValueAccessor, FormArray, FormBuilder, - FormControl, FormGroup, NG_VALIDATORS, NG_VALUE_ACCESSOR, @@ -28,11 +27,7 @@ import { Validators } from '@angular/forms'; import { Subject, Subscription } from 'rxjs'; -import { - RateLimits, - rateLimitsArrayToString, - stringToRateLimitsArray -} from './rate-limits.models'; +import { RateLimits, rateLimitsArrayToString, stringToRateLimitsArray } from './rate-limits.models'; import { isDefinedAndNotNull } from '@core/utils'; import { takeUntil } from 'rxjs/operators'; @@ -59,11 +54,11 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, rateLimitsListFormGroup: FormGroup; - rateLimitsControl: FormControl; + rateLimitsArray: Array; - private propagateChange = (v: any) => { }; private valueChangeSubscription: Subscription = null; private destroy$ = new Subject(); + private propagateChange = (v: any) => { }; constructor(private fb: FormBuilder) {} @@ -71,7 +66,6 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, this.rateLimitsListFormGroup = this.fb.group({ rateLimits: this.fb.array([]) }); - this.rateLimitsControl = this.fb.control(null); this.valueChangeSubscription = this.rateLimitsListFormGroup.valueChanges .pipe(takeUntil(this.destroy$)) .subscribe((value) => { @@ -95,10 +89,6 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, return this.rateLimitsListFormGroup.get('rateLimits') as FormArray; } - get rateLimitsArray(): Array { - return this.rateLimitsControl.value; - } - registerOnChange(fn: any): void { this.propagateChange = fn; } @@ -110,23 +100,21 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, this.disabled = isDisabled; if (this.disabled) { this.rateLimitsListFormGroup.disable({emitEvent: false}); - this.rateLimitsControl.disable({emitEvent: false}); } else { this.rateLimitsListFormGroup.enable({emitEvent: false}); - this.rateLimitsControl.enable({emitEvent: false}); } } validate(): ValidationErrors | null { - return this.rateLimitsListFormGroup.valid && this.rateLimitsControl.valid ? null : { + return this.rateLimitsListFormGroup.valid ? null : { rateLimitsList: {valid: false} }; } - writeValue(value: string) { + writeValue(rateLimits: string) { const rateLimitsControls: Array = []; - if (value) { - let rateLimitsArray = value.split(','); + if (rateLimits) { + const rateLimitsArray = rateLimits.split(','); for (let i = 0; i < rateLimitsArray.length; i++) { const [value, time] = rateLimitsArray[i].split(':'); const rateLimitsControl = this.fb.group({ @@ -140,7 +128,7 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, } } this.rateLimitsListFormGroup.setControl('rateLimits', this.fb.array(rateLimitsControls), {emitEvent: false}); - this.rateLimitsControl.patchValue(stringToRateLimitsArray(value), {emitEvent: false}); + this.rateLimitsArray = stringToRateLimitsArray(rateLimits); } updateView(rateLimitsArray: Array) { @@ -150,10 +138,10 @@ export class RateLimitsListComponent implements ControlValueAccessor, Validator, ); const rateLimitsString = rateLimitsArrayToString(notNullRateLimits); this.propagateChange(rateLimitsString); - this.rateLimitsControl.patchValue(stringToRateLimitsArray(rateLimitsString), {emitEvent: false}); + this.rateLimitsArray = stringToRateLimitsArray(rateLimitsString); } else { this.propagateChange(null); - this.rateLimitsControl.patchValue(null, {emitEvent: false}); + this.rateLimitsArray = null; } } diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts index 0b65e97d5d..9081acc208 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits-text.component.ts @@ -33,7 +33,8 @@ export class RateLimitsTextComponent implements OnChanges { rateLimitsText: string; - constructor(private translate: TranslateService) {} + constructor(private translate: TranslateService) { + } ngOnChanges(changes: SimpleChanges): void { for (const propName of Object.keys(changes)) { diff --git a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html index ac341c8b69..0ab20fc533 100644 --- a/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/tenant/rate-limits/rate-limits.component.html @@ -21,7 +21,7 @@
- +