20 changed files with 878 additions and 201 deletions
@ -0,0 +1,194 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
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. |
||||
|
|
||||
|
--> |
||||
|
<mat-expansion-panel fxFlex [formGroup]="queueFormGroup" [(expanded)]="expanded"> |
||||
|
<mat-expansion-panel-header> |
||||
|
<div fxFlex fxLayout="row" fxLayoutAlign="start center"> |
||||
|
<mat-panel-title> |
||||
|
<div fxLayout="row" fxFlex fxLayoutAlign="start center"> |
||||
|
{{ queueTitle }} |
||||
|
</div> |
||||
|
</mat-panel-title> |
||||
|
<span fxFlex></span> |
||||
|
<button *ngIf="!mainQueue && !disabled" mat-icon-button style="min-width: 40px;" |
||||
|
type="button" |
||||
|
(click)="removeQueue.emit()" |
||||
|
matTooltip="{{ 'action.remove' | translate }}" |
||||
|
matTooltipPosition="above"> |
||||
|
<mat-icon>delete</mat-icon> |
||||
|
</button> |
||||
|
</div> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<div fxLayout="column" fxLayoutGap="0.5em"> |
||||
|
<mat-divider></mat-divider> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>admin.queue-name</mat-label> |
||||
|
<input matInput formControlName="name" required> |
||||
|
<mat-error *ngIf="queueFormGroup.get('name').hasError('required')"> |
||||
|
{{ 'queue.name-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>queue.poll-interval</mat-label> |
||||
|
<input type="number" matInput formControlName="pollInterval" required> |
||||
|
<mat-error *ngIf="queueFormGroup.get('pollInterval').hasError('required')"> |
||||
|
{{ 'queue.poll-interval-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error *ngIf="queueFormGroup.get('pollInterval').hasError('min') && |
||||
|
!queueFormGroup.get('pollInterval').hasError('required')"> |
||||
|
{{ 'queue.poll-interval-min-value' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>queue.partitions</mat-label> |
||||
|
<input type="number" matInput formControlName="partitions" required> |
||||
|
<mat-error *ngIf="queueFormGroup.get('partitions').hasError('required')"> |
||||
|
{{ 'queue.partitions-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error *ngIf="queueFormGroup.get('partitions').hasError('min') && |
||||
|
!queueFormGroup.get('partitions').hasError('required')"> |
||||
|
{{ 'queue.partitions-min-value' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
|
||||
|
<mat-checkbox class="hinted-checkbox" formControlName="consumerPerPartition"> |
||||
|
<div>{{ 'queue.consumer-per-partition' | translate }}</div> |
||||
|
<div class="tb-hint">{{'queue.consumer-per-partition-hint' | translate}}</div> |
||||
|
</mat-checkbox> |
||||
|
|
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>queue.processing-timeout</mat-label> |
||||
|
<input type="number" matInput formControlName="packProcessingTimeout" required> |
||||
|
<mat-error *ngIf="queueFormGroup.get('packProcessingTimeout').hasError('required')"> |
||||
|
{{ 'queue.pack-processing-timeout-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error *ngIf="queueFormGroup.get('packProcessingTimeout').hasError('min') && |
||||
|
!queueFormGroup.get('packProcessingTimeout').hasError('required')"> |
||||
|
{{ 'queue.pack-processing-timeout-min-value' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-accordion class="queue-strategy" [multi]="true"> |
||||
|
<mat-expansion-panel> |
||||
|
<mat-expansion-panel-header> |
||||
|
<mat-panel-title translate> |
||||
|
queue.submit-strategy |
||||
|
</mat-panel-title> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<div formGroupName="submitStrategy"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>queue.submit-strategy</mat-label> |
||||
|
<mat-select formControlName="type" required> |
||||
|
<mat-option *ngFor="let strategy of submitStrategies" [value]="strategy"> |
||||
|
{{ strategy }} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
<mat-error *ngIf="queueFormGroup.get('submitStrategy.type').hasError('required')"> |
||||
|
{{ 'queue.submit-strategy-type-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block" *ngIf="hideBatchSize"> |
||||
|
<mat-label translate>queue.batch-size</mat-label> |
||||
|
<input type="number" matInput formControlName="batchSize" required> |
||||
|
<mat-error *ngIf="queueFormGroup.get('submitStrategy.batchSize').hasError('required')"> |
||||
|
{{ 'queue.batch-size-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error *ngIf="queueFormGroup.get('submitStrategy.batchSize').hasError('min') && |
||||
|
!queueFormGroup.get('submitStrategy.batchSize').hasError('required')"> |
||||
|
{{ 'queue.batch-size-min-value' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
<mat-expansion-panel> |
||||
|
<mat-expansion-panel-header> |
||||
|
<mat-panel-title translate> |
||||
|
queue.processing-strategy |
||||
|
</mat-panel-title> |
||||
|
</mat-expansion-panel-header> |
||||
|
<ng-template matExpansionPanelContent> |
||||
|
<div formGroupName="processingStrategy"> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>queue.processing-strategy</mat-label> |
||||
|
<mat-select formControlName="type" required> |
||||
|
<mat-option *ngFor="let strategy of processingStrategies" [value]="strategy"> |
||||
|
{{ strategy }} |
||||
|
</mat-option> |
||||
|
</mat-select> |
||||
|
<mat-error *ngIf="queueFormGroup.get('processingStrategy.type').hasError('required')"> |
||||
|
{{ 'queue.processing-strategy-type-required' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>queue.retries</mat-label> |
||||
|
<input type="number" matInput formControlName="retries" required> |
||||
|
<mat-error *ngIf="queueFormGroup.get('processingStrategy.retries').hasError('required')"> |
||||
|
{{ 'queue.retries-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error *ngIf="queueFormGroup.get('processingStrategy.retries').hasError('min') && |
||||
|
!queueFormGroup.get('processingStrategy.retries').hasError('required')"> |
||||
|
{{ 'queue.retries-min-value' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>queue.failure-percentage</mat-label> |
||||
|
<input type="number" matInput formControlName="failurePercentage" required> |
||||
|
<mat-error *ngIf="queueFormGroup.get('processingStrategy.failurePercentage').hasError('required')"> |
||||
|
{{ 'queue.failure-percentage-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error *ngIf="queueFormGroup.get('processingStrategy.failurePercentage').hasError('min') && |
||||
|
!queueFormGroup.get('processingStrategy.failurePercentage').hasError('required') && |
||||
|
!queueFormGroup.get('processingStrategy.failurePercentage').hasError('max')"> |
||||
|
{{ 'queue.failure-percentage-min-value' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error *ngIf="queueFormGroup.get('processingStrategy.failurePercentage').hasError('max') && |
||||
|
!queueFormGroup.get('processingStrategy.failurePercentage').hasError('required') && |
||||
|
!queueFormGroup.get('processingStrategy.failurePercentage').hasError('min')"> |
||||
|
{{ 'queue.failure-percentage-max-value' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>queue.pause-between-retries</mat-label> |
||||
|
<input type="number" matInput formControlName="pauseBetweenRetries" required> |
||||
|
<mat-error *ngIf="queueFormGroup.get('processingStrategy.pauseBetweenRetries').hasError('required')"> |
||||
|
{{ 'queue.pause-between-retries-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error *ngIf="queueFormGroup.get('processingStrategy.pauseBetweenRetries').hasError('min') && |
||||
|
!queueFormGroup.get('processingStrategy.pauseBetweenRetries').hasError('required')"> |
||||
|
{{ 'queue.pause-between-retries-min-value' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
<mat-form-field class="mat-block"> |
||||
|
<mat-label translate>queue.max-pause-between-retries</mat-label> |
||||
|
<input type="number" matInput formControlName="maxPauseBetweenRetries" required> |
||||
|
<mat-error *ngIf="queueFormGroup.get('processingStrategy.maxPauseBetweenRetries').hasError('required')"> |
||||
|
{{ 'queue.max-pause-between-retries-required' | translate }} |
||||
|
</mat-error> |
||||
|
<mat-error *ngIf="queueFormGroup.get('processingStrategy.maxPauseBetweenRetries').hasError('min') && |
||||
|
!queueFormGroup.get('processingStrategy.maxPauseBetweenRetries').hasError('required')"> |
||||
|
{{ 'queue.max-pause-between-retries-min-value' | translate }} |
||||
|
</mat-error> |
||||
|
</mat-form-field> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
|
</mat-accordion> |
||||
|
</div> |
||||
|
</ng-template> |
||||
|
</mat-expansion-panel> |
||||
@ -0,0 +1,22 @@ |
|||||
|
/** |
||||
|
* 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 ::ng-deep { |
||||
|
.queue-strategy { |
||||
|
.mat-expansion-panel-body { |
||||
|
padding-bottom: 0 !important; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,206 @@ |
|||||
|
///
|
||||
|
/// 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, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core'; |
||||
|
import { |
||||
|
ControlValueAccessor, |
||||
|
FormBuilder, |
||||
|
FormControl, |
||||
|
FormGroup, |
||||
|
NG_VALIDATORS, |
||||
|
NG_VALUE_ACCESSOR, |
||||
|
Validator, |
||||
|
Validators |
||||
|
} from '@angular/forms'; |
||||
|
import { DeviceProfileAlarm } from '@shared/models/device.models'; |
||||
|
import { MatDialog } from '@angular/material/dialog'; |
||||
|
import { UtilsService } from '@core/services/utils.service'; |
||||
|
import { QueueProcessingStrategyTypes, QueueSubmitStrategyTypes } from '@shared/models/queue.models'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-tenant-profile-queue', |
||||
|
templateUrl: './tenant-profile-queue.component.html', |
||||
|
styleUrls: ['./tenant-profile-queue.component.scss'], |
||||
|
providers: [ |
||||
|
{ |
||||
|
provide: NG_VALUE_ACCESSOR, |
||||
|
useExisting: forwardRef(() => TenantProfileQueueComponent), |
||||
|
multi: true |
||||
|
}, |
||||
|
{ |
||||
|
provide: NG_VALIDATORS, |
||||
|
useExisting: forwardRef(() => TenantProfileQueueComponent), |
||||
|
multi: true, |
||||
|
} |
||||
|
] |
||||
|
}) |
||||
|
export class TenantProfileQueueComponent implements ControlValueAccessor, OnInit, Validator { |
||||
|
|
||||
|
@Input() |
||||
|
disabled: boolean; |
||||
|
|
||||
|
@Output() |
||||
|
removeQueue = new EventEmitter(); |
||||
|
|
||||
|
@Input() |
||||
|
expanded = false; |
||||
|
|
||||
|
@Input() |
||||
|
mainQueue = false; |
||||
|
|
||||
|
@Input() |
||||
|
newQueue = false; |
||||
|
|
||||
|
private modelValue: DeviceProfileAlarm; |
||||
|
|
||||
|
queueFormGroup: FormGroup; |
||||
|
|
||||
|
submitStrategies: string[] = []; |
||||
|
processingStrategies: string[] = []; |
||||
|
|
||||
|
hideBatchSize = false; |
||||
|
|
||||
|
private propagateChange = null; |
||||
|
private propagateChangePending = false; |
||||
|
|
||||
|
constructor(private dialog: MatDialog, |
||||
|
private utils: UtilsService, |
||||
|
private fb: FormBuilder) { |
||||
|
} |
||||
|
|
||||
|
registerOnChange(fn: any): void { |
||||
|
this.propagateChange = fn; |
||||
|
if (this.propagateChangePending) { |
||||
|
this.propagateChangePending = false; |
||||
|
setTimeout(() => { |
||||
|
this.propagateChange(this.modelValue); |
||||
|
}, 0); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
registerOnTouched(fn: any): void { |
||||
|
} |
||||
|
|
||||
|
ngOnInit() { |
||||
|
this.submitStrategies = Object.values(QueueSubmitStrategyTypes); |
||||
|
this.processingStrategies = Object.values(QueueProcessingStrategyTypes); |
||||
|
this.queueFormGroup = this.fb.group( |
||||
|
{ |
||||
|
name: ['', [Validators.required]], |
||||
|
pollInterval: [25, [Validators.min(1), Validators.required]], |
||||
|
partitions: [10, [Validators.min(1), Validators.required]], |
||||
|
consumerPerPartition: [false, []], |
||||
|
packProcessingTimeout: [2000, [Validators.min(1), Validators.required]], |
||||
|
submitStrategy: this.fb.group({ |
||||
|
type: [null, [Validators.required]], |
||||
|
batchSize: [0, [Validators.min(1), Validators.required]], |
||||
|
}), |
||||
|
processingStrategy: this.fb.group({ |
||||
|
type: [null, [Validators.required]], |
||||
|
retries: [3, [Validators.min(0), Validators.required]], |
||||
|
failurePercentage: [ 0, [Validators.min(0), Validators.required, Validators.max(100)]], |
||||
|
pauseBetweenRetries: [3, [Validators.min(1), Validators.required]], |
||||
|
maxPauseBetweenRetries: [3, [Validators.min(1), Validators.required]], |
||||
|
}), |
||||
|
topic: [''] |
||||
|
}); |
||||
|
this.queueFormGroup.valueChanges.subscribe(() => { |
||||
|
this.updateModel(); |
||||
|
}); |
||||
|
this.queueFormGroup.get('name').valueChanges.subscribe((value) => this.queueFormGroup.patchValue({topic: `tb_rule_engine.${value}`})); |
||||
|
this.queueFormGroup.get('submitStrategy').get('type').valueChanges.subscribe(() => { |
||||
|
this.submitStrategyTypeChanged(); |
||||
|
}); |
||||
|
if (this.newQueue) { |
||||
|
this.queueFormGroup.get('name').enable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.queueFormGroup.get('name').disable({emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
setDisabledState(isDisabled: boolean): void { |
||||
|
this.disabled = isDisabled; |
||||
|
if (this.disabled) { |
||||
|
this.queueFormGroup.disable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.queueFormGroup.enable({emitEvent: false}); |
||||
|
this.queueFormGroup.get('name').disable({emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
writeValue(value: DeviceProfileAlarm): void { |
||||
|
this.propagateChangePending = false; |
||||
|
this.modelValue = value; |
||||
|
if (!this.modelValue.alarmType) { |
||||
|
this.expanded = true; |
||||
|
} |
||||
|
this.queueFormGroup.reset(this.modelValue || undefined, {emitEvent: false}); |
||||
|
if (!this.disabled && !this.queueFormGroup.valid) { |
||||
|
this.updateModel(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public validate(c: FormControl) { |
||||
|
if (c.parent) { |
||||
|
const queueName = c.value.name; |
||||
|
const profileQueues = []; |
||||
|
c.parent.getRawValue().forEach((queue) => { |
||||
|
profileQueues.push(queue.name); |
||||
|
} |
||||
|
); |
||||
|
if (profileQueues.filter(profileQueue => profileQueue === queueName).length > 1) { |
||||
|
this.queueFormGroup.get('name').setErrors({ |
||||
|
unique: true |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
return (this.queueFormGroup.valid) ? null : { |
||||
|
queue: { |
||||
|
valid: false, |
||||
|
}, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
get queueTitle(): string { |
||||
|
const queueName = this.queueFormGroup.get('name').value; |
||||
|
return this.utils.customTranslation(queueName, queueName); |
||||
|
} |
||||
|
|
||||
|
private updateModel() { |
||||
|
const value = this.queueFormGroup.value; |
||||
|
this.modelValue = {...this.modelValue, ...value}; |
||||
|
if (this.propagateChange) { |
||||
|
this.propagateChange(this.modelValue); |
||||
|
} else { |
||||
|
this.propagateChangePending = true; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
submitStrategyTypeChanged() { |
||||
|
const form = this.queueFormGroup.get('submitStrategy') as FormGroup; |
||||
|
const type: QueueSubmitStrategyTypes = form.get('type').value; |
||||
|
const batchSizeField = form.get('batchSize'); |
||||
|
if (type === QueueSubmitStrategyTypes.BATCH) { |
||||
|
batchSizeField.enable(); |
||||
|
batchSizeField.patchValue(1000); |
||||
|
this.hideBatchSize = true; |
||||
|
} else { |
||||
|
batchSizeField.patchValue(null); |
||||
|
batchSizeField.disable(); |
||||
|
this.hideBatchSize = false; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
<!-- |
||||
|
|
||||
|
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. |
||||
|
|
||||
|
--> |
||||
|
<div fxLayout="column"> |
||||
|
<div class="tb-tenant-profile-queues"> |
||||
|
<mat-accordion [multi]="true"> |
||||
|
<div *ngFor="let queuesControl of queuesFormArray().controls; trackBy: trackByQueue; |
||||
|
let $index = index; last as isLast;" fxLayout="column"> |
||||
|
<tb-tenant-profile-queue [formControl]="queuesControl" |
||||
|
[mainQueue]="$index === 0" |
||||
|
[newQueue]="newQueue" |
||||
|
(removeQueue)="removeQueue($index)"> |
||||
|
</tb-tenant-profile-queue> |
||||
|
</div> |
||||
|
</mat-accordion> |
||||
|
</div> |
||||
|
<div *ngIf="!queuesFormArray().controls.length"> |
||||
|
<span translate fxLayoutAlign="center center" |
||||
|
class="tb-prompt">tenant-profile.no-queue</span> |
||||
|
</div> |
||||
|
<div *ngIf="!disabled" style="padding-top: 16px;"> |
||||
|
<button mat-raised-button color="primary" |
||||
|
type="button" |
||||
|
(click)="addQueue()"> |
||||
|
<span translate>tenant-profile.add-queue</span> |
||||
|
</button> |
||||
|
</div> |
||||
|
</div> |
||||
@ -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. |
||||
|
*/ |
||||
|
@import '../../../../../../scss/constants'; |
||||
|
|
||||
|
:host { |
||||
|
.tb-tenant-profile-queues { |
||||
|
&.mat-padding { |
||||
|
padding: 8px; |
||||
|
@media #{$mat-gt-sm} { |
||||
|
padding: 16px; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
.tb-prompt{ |
||||
|
margin: 30px 0; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,178 @@ |
|||||
|
///
|
||||
|
/// 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 { |
||||
|
AbstractControl, |
||||
|
ControlValueAccessor, |
||||
|
FormArray, |
||||
|
FormBuilder, |
||||
|
FormControl, |
||||
|
FormGroup, |
||||
|
NG_VALIDATORS, |
||||
|
NG_VALUE_ACCESSOR, |
||||
|
Validator, |
||||
|
Validators |
||||
|
} from '@angular/forms'; |
||||
|
import { Store } from '@ngrx/store'; |
||||
|
import { AppState } from '@app/core/core.state'; |
||||
|
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
||||
|
import { Subscription } from 'rxjs'; |
||||
|
import { QueueInfo } from '@shared/models/queue.models'; |
||||
|
|
||||
|
@Component({ |
||||
|
selector: 'tb-tenant-profile-queues', |
||||
|
templateUrl: './tenant-profile-queues.component.html', |
||||
|
styleUrls: ['./tenant-profile-queues.component.scss'], |
||||
|
providers: [ |
||||
|
{ |
||||
|
provide: NG_VALUE_ACCESSOR, |
||||
|
useExisting: forwardRef(() => TenantProfileQueuesComponent), |
||||
|
multi: true |
||||
|
}, |
||||
|
{ |
||||
|
provide: NG_VALIDATORS, |
||||
|
useExisting: forwardRef(() => TenantProfileQueuesComponent), |
||||
|
multi: true, |
||||
|
} |
||||
|
] |
||||
|
}) |
||||
|
export class TenantProfileQueuesComponent implements ControlValueAccessor, OnInit, Validator { |
||||
|
|
||||
|
tenantProfileQueuesFormGroup: FormGroup; |
||||
|
newQueue = false; |
||||
|
|
||||
|
private requiredValue: boolean; |
||||
|
get required(): boolean { |
||||
|
return this.requiredValue; |
||||
|
} |
||||
|
@Input() |
||||
|
set required(value: boolean) { |
||||
|
this.requiredValue = coerceBooleanProperty(value); |
||||
|
} |
||||
|
|
||||
|
@Input() |
||||
|
disabled: boolean; |
||||
|
|
||||
|
private valueChangeSubscription: Subscription = null; |
||||
|
|
||||
|
private propagateChange = (v: any) => { }; |
||||
|
|
||||
|
constructor(private store: Store<AppState>, |
||||
|
private fb: FormBuilder) { |
||||
|
} |
||||
|
|
||||
|
registerOnChange(fn: any): void { |
||||
|
this.propagateChange = fn; |
||||
|
} |
||||
|
|
||||
|
registerOnTouched(fn: any): void { |
||||
|
} |
||||
|
|
||||
|
ngOnInit() { |
||||
|
this.tenantProfileQueuesFormGroup = this.fb.group({ |
||||
|
queues: this.fb.array([]) |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
queuesFormArray(): FormArray { |
||||
|
return this.tenantProfileQueuesFormGroup.get('queues') as FormArray; |
||||
|
} |
||||
|
|
||||
|
setDisabledState(isDisabled: boolean): void { |
||||
|
this.disabled = isDisabled; |
||||
|
if (this.disabled) { |
||||
|
this.tenantProfileQueuesFormGroup.disable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.tenantProfileQueuesFormGroup.enable({emitEvent: false}); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
writeValue(queues: Array<QueueInfo> | null): void { |
||||
|
if (this.valueChangeSubscription) { |
||||
|
this.valueChangeSubscription.unsubscribe(); |
||||
|
} |
||||
|
const queuesControls: Array<AbstractControl> = []; |
||||
|
if (queues) { |
||||
|
queues.forEach((queue) => { |
||||
|
queuesControls.push(this.fb.control(queue, [Validators.required])); |
||||
|
}); |
||||
|
} |
||||
|
this.tenantProfileQueuesFormGroup.setControl('queues', this.fb.array(queuesControls)); |
||||
|
if (this.disabled) { |
||||
|
this.tenantProfileQueuesFormGroup.disable({emitEvent: false}); |
||||
|
} else { |
||||
|
this.tenantProfileQueuesFormGroup.enable({emitEvent: false}); |
||||
|
} |
||||
|
this.valueChangeSubscription = this.tenantProfileQueuesFormGroup.valueChanges.subscribe(() => { |
||||
|
this.updateModel(); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
public trackByQueue(index: number, queueControl: AbstractControl): string { |
||||
|
if (queueControl) { |
||||
|
return queueControl.value.id; |
||||
|
} else { |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public removeQueue(index: number) { |
||||
|
(this.tenantProfileQueuesFormGroup.get('queues') as FormArray).removeAt(index); |
||||
|
} |
||||
|
|
||||
|
public addQueue() { |
||||
|
const queue = { |
||||
|
consumerPerPartition: false, |
||||
|
name: '', |
||||
|
packProcessingTimeout: 2000, |
||||
|
partitions: 10, |
||||
|
pollInterval: 25, |
||||
|
processingStrategy: { |
||||
|
failurePercentage: 0, |
||||
|
maxPauseBetweenRetries: 3, |
||||
|
pauseBetweenRetries: 3, |
||||
|
retries: 3, |
||||
|
type: '' |
||||
|
}, |
||||
|
submitStrategy: { |
||||
|
batchSize: 0, |
||||
|
type: '' |
||||
|
}, |
||||
|
topic: '' |
||||
|
}; |
||||
|
this.newQueue = true; |
||||
|
const queuesArray = this.tenantProfileQueuesFormGroup.get('queues') as FormArray; |
||||
|
queuesArray.push(this.fb.control(queue, [])); |
||||
|
this.tenantProfileQueuesFormGroup.updateValueAndValidity(); |
||||
|
if (!this.tenantProfileQueuesFormGroup.valid) { |
||||
|
this.updateModel(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public validate(c: FormControl) { |
||||
|
return (this.tenantProfileQueuesFormGroup.valid) ? null : { |
||||
|
queues: { |
||||
|
valid: false, |
||||
|
}, |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
private updateModel() { |
||||
|
const queues: Array<QueueInfo> = this.tenantProfileQueuesFormGroup.get('queues').value; |
||||
|
this.propagateChange(queues); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue