committed by
Andrew Shvayka
25 changed files with 628 additions and 32 deletions
@ -0,0 +1,20 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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. |
|||
*/ |
|||
package org.thingsboard.server.common.data; |
|||
|
|||
public enum TenantProfileType { |
|||
DEFAULT |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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. |
|||
*/ |
|||
package org.thingsboard.server.common.data.tenant.profile; |
|||
|
|||
import lombok.Data; |
|||
import org.thingsboard.server.common.data.TenantProfileType; |
|||
|
|||
@Data |
|||
public class DefaultTenantProfileConfiguration implements TenantProfileConfiguration { |
|||
|
|||
private long maxDevices; |
|||
private long maxAssets; |
|||
|
|||
private String transportTenantMsgRateLimit; |
|||
private String transportTenantTelemetryMsgRateLimit; |
|||
private String transportTenantTelemetryDataPointsRateLimit; |
|||
private String transportDeviceMsgRateLimit; |
|||
private String transportDeviceTelemetryMsgRateLimit; |
|||
private String transportDeviceTelemetryDataPointsRateLimit; |
|||
|
|||
private long maxTransportMessages; |
|||
private long maxTransportDataPoints; |
|||
private long maxREExecutions; |
|||
private long maxJSExecutions; |
|||
private long maxDPStorageDays; |
|||
private int maxRuleNodeExecutionsPerMessage; |
|||
|
|||
@Override |
|||
public TenantProfileType getType() { |
|||
return TenantProfileType.DEFAULT; |
|||
} |
|||
} |
|||
@ -0,0 +1,36 @@ |
|||
/** |
|||
* Copyright © 2016-2020 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. |
|||
*/ |
|||
package org.thingsboard.server.common.data.tenant.profile; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonIgnore; |
|||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
|||
import com.fasterxml.jackson.annotation.JsonSubTypes; |
|||
import com.fasterxml.jackson.annotation.JsonTypeInfo; |
|||
import org.thingsboard.server.common.data.TenantProfileType; |
|||
|
|||
@JsonIgnoreProperties(ignoreUnknown = true) |
|||
@JsonTypeInfo( |
|||
use = JsonTypeInfo.Id.NAME, |
|||
include = JsonTypeInfo.As.PROPERTY, |
|||
property = "type") |
|||
@JsonSubTypes({ |
|||
@JsonSubTypes.Type(value = DefaultTenantProfileConfiguration.class, name = "DEFAULT")}) |
|||
public interface TenantProfileConfiguration { |
|||
|
|||
@JsonIgnore |
|||
TenantProfileType getType(); |
|||
|
|||
} |
|||
@ -0,0 +1,141 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2020 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. |
|||
|
|||
--> |
|||
<section [formGroup]="defaultTenantProfileConfigurationFormGroup"> |
|||
<section formGroupName="configuration" fxLayout="column"> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.maximum-devices</mat-label> |
|||
<input matInput required min="0" step="1" |
|||
formControlName="maxDevices" |
|||
type="number"> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxDevices').hasError('required')"> |
|||
{{ 'tenant-profile.maximum-devices-required' | translate}} |
|||
</mat-error> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxDevices').hasError('min')"> |
|||
{{ 'tenant-profile.maximum-devices-range' | translate}} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.maximum-assets</mat-label> |
|||
<input matInput required min="0" step="1" |
|||
formControlName="maxAssets" |
|||
type="number"> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxAssets').hasError('required')"> |
|||
{{ 'tenant-profile.maximum-assets-required' | translate}} |
|||
</mat-error> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxAssets').hasError('min')"> |
|||
{{ 'tenant-profile.maximum-assets-range' | translate}} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.max-transport-messages</mat-label> |
|||
<input matInput required min="0" step="1" |
|||
formControlName="maxTransportMessages" |
|||
type="number"> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxTransportMessages').hasError('required')"> |
|||
{{ 'tenant-profile.max-transport-messages-range' | translate}} |
|||
</mat-error> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxTransportMessages').hasError('min')"> |
|||
{{ 'tenant-profile.max-transport-messages-required' | translate}} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.max-transport-data-points</mat-label> |
|||
<input matInput required min="0" step="1" |
|||
formControlName="maxTransportDataPoints" |
|||
type="number"> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxTransportDataPoints').hasError('required')"> |
|||
{{ 'tenant-profile.max-transport-data-points-required' | translate}} |
|||
</mat-error> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxTransportDataPoints').hasError('min')"> |
|||
{{ 'tenant-profile.max-transport-data-points-range' | translate}} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.max-r-e-executions</mat-label> |
|||
<input matInput required min="0" step="1" |
|||
formControlName="maxREExecutions" |
|||
type="number"> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxREExecutions').hasError('required')"> |
|||
{{ 'tenant-profile.max-r-e-executions-required' | translate}} |
|||
</mat-error> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxREExecutions').hasError('min')"> |
|||
{{ 'tenant-profile.max-r-e-executions-range' | translate}} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.max-j-s-executions</mat-label> |
|||
<input matInput required min="0" step="1" |
|||
formControlName="maxJSExecutions" |
|||
type="number"> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxJSExecutions').hasError('required')"> |
|||
{{ 'tenant-profile.max-j-s-executions-required' | translate}} |
|||
</mat-error> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxJSExecutions').hasError('min')"> |
|||
{{ 'tenant-profile.max-j-s-executions-range' | translate}} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.max-d-p-storage-days</mat-label> |
|||
<input matInput required min="0" step="1" |
|||
formControlName="maxDPStorageDays" |
|||
type="number"> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxDPStorageDays').hasError('required')"> |
|||
{{ 'tenant-profile.max-d-p-storage-days-required' | translate}} |
|||
</mat-error> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxDPStorageDays').hasError('min')"> |
|||
{{ 'tenant-profile.max-d-p-storage-days-range' | translate}} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.max-rule-node-executions-per-message</mat-label> |
|||
<input matInput required min="0" step="1" |
|||
formControlName="maxRuleNodeExecutionsPerMessage" |
|||
type="number"> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxRuleNodeExecutionsPerMessage').hasError('required')"> |
|||
{{ 'tenant-profile.max-rule-node-executions-per-message-required' | translate}} |
|||
</mat-error> |
|||
<mat-error *ngIf="defaultTenantProfileConfigurationFormGroup.get('configuration.maxRuleNodeExecutionsPerMessage').hasError('min')"> |
|||
{{ 'tenant-profile.max-rule-node-executions-per-message-range' | translate}} |
|||
</mat-error> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.transport-tenant-msg-rate-limit</mat-label> |
|||
<input matInput formControlName="transportTenantMsgRateLimit"> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.transport-tenant-telemetry-msg-rate-limit</mat-label> |
|||
<input matInput formControlName="transportTenantTelemetryMsgRateLimit"> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.transport-tenant-telemetry-data-points-rate-limit</mat-label> |
|||
<input matInput formControlName="transportTenantTelemetryDataPointsRateLimit"> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.transport-device-msg-rate-limit</mat-label> |
|||
<input matInput formControlName="transportDeviceMsgRateLimit"> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.transport-device-telemetry-msg-rate-limit</mat-label> |
|||
<input matInput formControlName="transportDeviceTelemetryMsgRateLimit"> |
|||
</mat-form-field> |
|||
<mat-form-field class="mat-block"> |
|||
<mat-label translate>tenant-profile.transport-device-telemetry-data-points-rate-limit</mat-label> |
|||
<input matInput formControlName="transportDeviceTelemetryDataPointsRateLimit"> |
|||
</mat-form-field> |
|||
</section> |
|||
</section> |
|||
@ -0,0 +1,115 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@app/core/core.state'; |
|||
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
|||
import { |
|||
DefaultTenantProfileConfiguration, |
|||
TenantProfileConfiguration, |
|||
TenantProfileType |
|||
} from '@shared/models/tenant.model'; |
|||
import { isDefinedAndNotNull } from '@core/utils'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-default-tenant-profile-configuration', |
|||
templateUrl: './default-tenant-profile-configuration.component.html', |
|||
styleUrls: [], |
|||
providers: [{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => DefaultTenantProfileConfigurationComponent), |
|||
multi: true |
|||
}] |
|||
}) |
|||
export class DefaultTenantProfileConfigurationComponent implements ControlValueAccessor, OnInit { |
|||
|
|||
defaultTenantProfileConfigurationFormGroup: FormGroup; |
|||
|
|||
private requiredValue: boolean; |
|||
get required(): boolean { |
|||
return this.requiredValue; |
|||
} |
|||
@Input() |
|||
set required(value: boolean) { |
|||
this.requiredValue = coerceBooleanProperty(value); |
|||
} |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
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.defaultTenantProfileConfigurationFormGroup = this.fb.group({ |
|||
configuration: this.fb.group({ |
|||
maxDevices: [null, [Validators.required, Validators.min(0)]], |
|||
maxAssets: [null, [Validators.required, Validators.min(0)]], |
|||
transportTenantMsgRateLimit: [null, []], |
|||
transportTenantTelemetryMsgRateLimit: [null, []], |
|||
transportTenantTelemetryDataPointsRateLimit: [null, []], |
|||
transportDeviceMsgRateLimit: [null, []], |
|||
transportDeviceTelemetryMsgRateLimit: [null, []], |
|||
transportDeviceTelemetryDataPointsRateLimit: [null, []], |
|||
maxTransportMessages: [null, [Validators.required, Validators.min(0)]], |
|||
maxTransportDataPoints: [null, [Validators.required, Validators.min(0)]], |
|||
maxREExecutions: [null, [Validators.required, Validators.min(0)]], |
|||
maxJSExecutions: [null, [Validators.required, Validators.min(0)]], |
|||
maxDPStorageDays: [null, [Validators.required, Validators.min(0)]], |
|||
maxRuleNodeExecutionsPerMessage: [null, [Validators.required, Validators.min(0)]] |
|||
}) |
|||
}); |
|||
this.defaultTenantProfileConfigurationFormGroup.valueChanges.subscribe(() => { |
|||
this.updateModel(); |
|||
}); |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
if (this.disabled) { |
|||
this.defaultTenantProfileConfigurationFormGroup.disable({emitEvent: false}); |
|||
} else { |
|||
this.defaultTenantProfileConfigurationFormGroup.enable({emitEvent: false}); |
|||
} |
|||
} |
|||
|
|||
writeValue(value: DefaultTenantProfileConfiguration | null): void { |
|||
if (isDefinedAndNotNull(value)) { |
|||
this.defaultTenantProfileConfigurationFormGroup.patchValue({configuration: value}, {emitEvent: false}); |
|||
} |
|||
} |
|||
|
|||
private updateModel() { |
|||
let configuration: TenantProfileConfiguration = null; |
|||
if (this.defaultTenantProfileConfigurationFormGroup.valid) { |
|||
configuration = this.defaultTenantProfileConfigurationFormGroup.getRawValue().configuration; |
|||
configuration.type = TenantProfileType.DEFAULT; |
|||
} |
|||
this.propagateChange(configuration); |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2020 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 [formGroup]="tenantProfileConfigurationFormGroup"> |
|||
<div [ngSwitch]="type"> |
|||
<ng-template [ngSwitchCase]="tenantProfileType.DEFAULT"> |
|||
<tb-default-tenant-profile-configuration |
|||
[required]="required" |
|||
formControlName="configuration"> |
|||
</tb-default-tenant-profile-configuration> |
|||
</ng-template> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,103 @@ |
|||
///
|
|||
/// Copyright © 2016-2020 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, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@app/core/core.state'; |
|||
import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
|||
import { deepClone } from '@core/utils'; |
|||
import { TenantProfileConfiguration, TenantProfileType } from '@shared/models/tenant.model'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-tenant-profile-configuration', |
|||
templateUrl: './tenant-profile-configuration.component.html', |
|||
styleUrls: [], |
|||
providers: [{ |
|||
provide: NG_VALUE_ACCESSOR, |
|||
useExisting: forwardRef(() => TenantProfileConfigurationComponent), |
|||
multi: true |
|||
}] |
|||
}) |
|||
export class TenantProfileConfigurationComponent implements ControlValueAccessor, OnInit { |
|||
|
|||
tenantProfileType = TenantProfileType; |
|||
|
|||
tenantProfileConfigurationFormGroup: FormGroup; |
|||
|
|||
private requiredValue: boolean; |
|||
get required(): boolean { |
|||
return this.requiredValue; |
|||
} |
|||
@Input() |
|||
set required(value: boolean) { |
|||
this.requiredValue = coerceBooleanProperty(value); |
|||
} |
|||
|
|||
@Input() |
|||
disabled: boolean; |
|||
|
|||
type: TenantProfileType; |
|||
|
|||
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.tenantProfileConfigurationFormGroup = this.fb.group({ |
|||
configuration: [null, Validators.required] |
|||
}); |
|||
this.tenantProfileConfigurationFormGroup.valueChanges.subscribe(() => { |
|||
this.updateModel(); |
|||
}); |
|||
} |
|||
|
|||
setDisabledState(isDisabled: boolean): void { |
|||
this.disabled = isDisabled; |
|||
if (this.disabled) { |
|||
this.tenantProfileConfigurationFormGroup.disable({emitEvent: false}); |
|||
} else { |
|||
this.tenantProfileConfigurationFormGroup.enable({emitEvent: false}); |
|||
} |
|||
} |
|||
|
|||
writeValue(value: TenantProfileConfiguration | null): void { |
|||
this.type = value?.type; |
|||
const configuration = deepClone(value); |
|||
if (configuration) { |
|||
delete configuration.type; |
|||
} |
|||
this.tenantProfileConfigurationFormGroup.patchValue({configuration}, {emitEvent: false}); |
|||
} |
|||
|
|||
private updateModel() { |
|||
let configuration: TenantProfileConfiguration = null; |
|||
if (this.tenantProfileConfigurationFormGroup.valid) { |
|||
configuration = this.tenantProfileConfigurationFormGroup.getRawValue().configuration; |
|||
configuration.type = this.type; |
|||
} |
|||
this.propagateChange(configuration); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue