Browse Source

Add tenant profile data

pull/3477/head
Igor Kulikov 6 years ago
parent
commit
73a988b541
  1. 8
      common/data/src/main/java/org/thingsboard/server/common/data/TenantProfileData.java
  2. 3
      ui-ngx/src/app/modules/home/components/home-components.module.ts
  3. 24
      ui-ngx/src/app/modules/home/components/profile/tenant-profile-data.component.html
  4. 89
      ui-ngx/src/app/modules/home/components/profile/tenant-profile-data.component.ts
  5. 4
      ui-ngx/src/app/modules/home/components/profile/tenant-profile.component.html
  6. 2
      ui-ngx/src/app/modules/home/components/profile/tenant-profile.component.ts
  7. 1
      ui-ngx/src/assets/locale/locale.constant-en_US.json

8
common/data/src/main/java/org/thingsboard/server/common/data/TenantProfileData.java

@ -17,6 +17,7 @@ package org.thingsboard.server.common.data;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import java.util.HashMap;
@ -25,15 +26,16 @@ import java.util.Map;
@Data
public class TenantProfileData {
private Map<String, String> properties = new HashMap<>();
@JsonIgnore
private Map<String, Object> properties = new HashMap<>();
@JsonAnyGetter
public Map<String, String> properties() {
public Map<String, Object> properties() {
return this.properties;
}
@JsonAnySetter
public void put(String name, String value) {
public void put(String name, Object value) {
this.properties.put(name, value);
}

3
ui-ngx/src/app/modules/home/components/home-components.module.ts

@ -87,6 +87,7 @@ import { FilterPredicateValueComponent } from './filter/filter-predicate-value.c
import { TenantProfileAutocompleteComponent } from './profile/tenant-profile-autocomplete.component';
import { TenantProfileComponent } from './profile/tenant-profile.component';
import { TenantProfileDialogComponent } from './profile/tenant-profile-dialog.component';
import { TenantProfileDataComponent } from './profile/tenant-profile-data.component';
@NgModule({
declarations:
@ -155,6 +156,7 @@ import { TenantProfileDialogComponent } from './profile/tenant-profile-dialog.co
FilterUserInfoDialogComponent,
FilterPredicateValueComponent,
TenantProfileAutocompleteComponent,
TenantProfileDataComponent,
TenantProfileComponent,
TenantProfileDialogComponent
],
@ -214,6 +216,7 @@ import { TenantProfileDialogComponent } from './profile/tenant-profile-dialog.co
FiltersEditComponent,
UserFilterDialogComponent,
TenantProfileAutocompleteComponent,
TenantProfileDataComponent,
TenantProfileComponent,
TenantProfileDialogComponent
],

24
ui-ngx/src/app/modules/home/components/profile/tenant-profile-data.component.html

@ -0,0 +1,24 @@
<!--
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.
-->
<form [formGroup]="tenantProfileDataFormGroup" style="padding-bottom: 16px;">
<tb-json-object-edit
[required]="required"
label="{{ 'tenant-profile.data' | translate }}"
formControlName="tenantProfileData">
</tb-json-object-edit>
</form>

89
ui-ngx/src/app/modules/home/components/profile/tenant-profile-data.component.ts

@ -0,0 +1,89 @@
///
/// 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 { TenantProfileData } from '@shared/models/tenant.model';
@Component({
selector: 'tb-tenant-profile-data',
templateUrl: './tenant-profile-data.component.html',
styleUrls: [],
providers: [{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => TenantProfileDataComponent),
multi: true
}]
})
export class TenantProfileDataComponent implements ControlValueAccessor, OnInit {
tenantProfileDataFormGroup: FormGroup;
modelValue: TenantProfileData | null;
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) {
this.tenantProfileDataFormGroup = this.fb.group({
tenantProfileData: [null, Validators.required]
});
}
registerOnChange(fn: any): void {
this.propagateChange = fn;
}
registerOnTouched(fn: any): void {
}
ngOnInit() {
this.tenantProfileDataFormGroup.get('tenantProfileData').valueChanges.subscribe(
tenantProfileData => {
this.updateView(this.tenantProfileDataFormGroup.valid ? tenantProfileData : null);
}
);
}
setDisabledState(isDisabled: boolean): void {
this.disabled = isDisabled;
}
writeValue(value: TenantProfileData | null): void {
this.modelValue = value;
this.tenantProfileDataFormGroup.get('tenantProfileData').patchValue(value, {emitEvent: false});
}
updateView(value: TenantProfileData | null) {
this.modelValue = value;
this.propagateChange(this.modelValue);
}
}

4
ui-ngx/src/app/modules/home/components/profile/tenant-profile.component.html

@ -59,6 +59,10 @@
<div class="tb-hint">{{'tenant.isolated-tb-rule-engine-details' | translate}}</div>
</mat-checkbox>
</div>
<tb-tenant-profile-data
formControlName="profileData"
required>
</tb-tenant-profile-data>
<mat-form-field class="mat-block">
<mat-label translate>tenant-profile.description</mat-label>
<textarea matInput formControlName="description" rows="2"></textarea>

2
ui-ngx/src/app/modules/home/components/profile/tenant-profile.component.ts

@ -56,6 +56,7 @@ export class TenantProfileComponent extends EntityComponent<TenantProfile> {
name: [entity ? entity.name : '', [Validators.required]],
isolatedTbCore: [entity ? entity.isolatedTbCore : false, []],
isolatedTbRuleEngine: [entity ? entity.isolatedTbRuleEngine : false, []],
profileData: [entity && !this.isAdd ? entity.profileData : {}, []],
description: [entity ? entity.description : '', []],
}
);
@ -65,6 +66,7 @@ export class TenantProfileComponent extends EntityComponent<TenantProfile> {
this.entityForm.patchValue({name: entity.name});
this.entityForm.patchValue({isolatedTbCore: entity.isolatedTbCore});
this.entityForm.patchValue({isolatedTbRuleEngine: entity.isolatedTbRuleEngine});
this.entityForm.patchValue({profileData: entity.profileData});
this.entityForm.patchValue({description: entity.description});
}

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

@ -1693,6 +1693,7 @@
"copyId": "Copy tenant profile Id",
"name": "Name",
"name-required": "Name is required.",
"data": "Profile data",
"description": "Description",
"default": "Default",
"delete-tenant-profile-title": "Are you sure you want to delete the tenant profile '{{tenantProfileName}}'?",

Loading…
Cancel
Save