Showing
7 changed files
with
128 additions
and
3 deletions
... | ... | @@ -17,6 +17,7 @@ package org.thingsboard.server.common.data; |
17 | 17 | |
18 | 18 | import com.fasterxml.jackson.annotation.JsonAnyGetter; |
19 | 19 | import com.fasterxml.jackson.annotation.JsonAnySetter; |
20 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
20 | 21 | import lombok.Data; |
21 | 22 | |
22 | 23 | import java.util.HashMap; |
... | ... | @@ -25,15 +26,16 @@ import java.util.Map; |
25 | 26 | @Data |
26 | 27 | public class TenantProfileData { |
27 | 28 | |
28 | - private Map<String, String> properties = new HashMap<>(); | |
29 | + @JsonIgnore | |
30 | + private Map<String, Object> properties = new HashMap<>(); | |
29 | 31 | |
30 | 32 | @JsonAnyGetter |
31 | - public Map<String, String> properties() { | |
33 | + public Map<String, Object> properties() { | |
32 | 34 | return this.properties; |
33 | 35 | } |
34 | 36 | |
35 | 37 | @JsonAnySetter |
36 | - public void put(String name, String value) { | |
38 | + public void put(String name, Object value) { | |
37 | 39 | this.properties.put(name, value); |
38 | 40 | } |
39 | 41 | ... | ... |
... | ... | @@ -87,6 +87,7 @@ import { FilterPredicateValueComponent } from './filter/filter-predicate-value.c |
87 | 87 | import { TenantProfileAutocompleteComponent } from './profile/tenant-profile-autocomplete.component'; |
88 | 88 | import { TenantProfileComponent } from './profile/tenant-profile.component'; |
89 | 89 | import { TenantProfileDialogComponent } from './profile/tenant-profile-dialog.component'; |
90 | +import { TenantProfileDataComponent } from './profile/tenant-profile-data.component'; | |
90 | 91 | |
91 | 92 | @NgModule({ |
92 | 93 | declarations: |
... | ... | @@ -155,6 +156,7 @@ import { TenantProfileDialogComponent } from './profile/tenant-profile-dialog.co |
155 | 156 | FilterUserInfoDialogComponent, |
156 | 157 | FilterPredicateValueComponent, |
157 | 158 | TenantProfileAutocompleteComponent, |
159 | + TenantProfileDataComponent, | |
158 | 160 | TenantProfileComponent, |
159 | 161 | TenantProfileDialogComponent |
160 | 162 | ], |
... | ... | @@ -214,6 +216,7 @@ import { TenantProfileDialogComponent } from './profile/tenant-profile-dialog.co |
214 | 216 | FiltersEditComponent, |
215 | 217 | UserFilterDialogComponent, |
216 | 218 | TenantProfileAutocompleteComponent, |
219 | + TenantProfileDataComponent, | |
217 | 220 | TenantProfileComponent, |
218 | 221 | TenantProfileDialogComponent |
219 | 222 | ], | ... | ... |
1 | +<!-- | |
2 | + | |
3 | + Copyright © 2016-2020 The Thingsboard Authors | |
4 | + | |
5 | + Licensed under the Apache License, Version 2.0 (the "License"); | |
6 | + you may not use this file except in compliance with the License. | |
7 | + You may obtain a copy of the License at | |
8 | + | |
9 | + http://www.apache.org/licenses/LICENSE-2.0 | |
10 | + | |
11 | + Unless required by applicable law or agreed to in writing, software | |
12 | + distributed under the License is distributed on an "AS IS" BASIS, | |
13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | + See the License for the specific language governing permissions and | |
15 | + limitations under the License. | |
16 | + | |
17 | +--> | |
18 | +<form [formGroup]="tenantProfileDataFormGroup" style="padding-bottom: 16px;"> | |
19 | + <tb-json-object-edit | |
20 | + [required]="required" | |
21 | + label="{{ 'tenant-profile.data' | translate }}" | |
22 | + formControlName="tenantProfileData"> | |
23 | + </tb-json-object-edit> | |
24 | +</form> | ... | ... |
1 | +/// | |
2 | +/// Copyright © 2016-2020 The Thingsboard Authors | |
3 | +/// | |
4 | +/// Licensed under the Apache License, Version 2.0 (the "License"); | |
5 | +/// you may not use this file except in compliance with the License. | |
6 | +/// You may obtain a copy of the License at | |
7 | +/// | |
8 | +/// http://www.apache.org/licenses/LICENSE-2.0 | |
9 | +/// | |
10 | +/// Unless required by applicable law or agreed to in writing, software | |
11 | +/// distributed under the License is distributed on an "AS IS" BASIS, | |
12 | +/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | +/// See the License for the specific language governing permissions and | |
14 | +/// limitations under the License. | |
15 | +/// | |
16 | + | |
17 | +import { Component, forwardRef, Input, OnInit } from '@angular/core'; | |
18 | +import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; | |
19 | +import { Store } from '@ngrx/store'; | |
20 | +import { AppState } from '@app/core/core.state'; | |
21 | +import { coerceBooleanProperty } from '@angular/cdk/coercion'; | |
22 | +import { TenantProfileData } from '@shared/models/tenant.model'; | |
23 | + | |
24 | +@Component({ | |
25 | + selector: 'tb-tenant-profile-data', | |
26 | + templateUrl: './tenant-profile-data.component.html', | |
27 | + styleUrls: [], | |
28 | + providers: [{ | |
29 | + provide: NG_VALUE_ACCESSOR, | |
30 | + useExisting: forwardRef(() => TenantProfileDataComponent), | |
31 | + multi: true | |
32 | + }] | |
33 | +}) | |
34 | +export class TenantProfileDataComponent implements ControlValueAccessor, OnInit { | |
35 | + | |
36 | + tenantProfileDataFormGroup: FormGroup; | |
37 | + | |
38 | + modelValue: TenantProfileData | null; | |
39 | + | |
40 | + private requiredValue: boolean; | |
41 | + get required(): boolean { | |
42 | + return this.requiredValue; | |
43 | + } | |
44 | + @Input() | |
45 | + set required(value: boolean) { | |
46 | + this.requiredValue = coerceBooleanProperty(value); | |
47 | + } | |
48 | + | |
49 | + @Input() | |
50 | + disabled: boolean; | |
51 | + | |
52 | + private propagateChange = (v: any) => { }; | |
53 | + | |
54 | + constructor(private store: Store<AppState>, | |
55 | + private fb: FormBuilder) { | |
56 | + this.tenantProfileDataFormGroup = this.fb.group({ | |
57 | + tenantProfileData: [null, Validators.required] | |
58 | + }); | |
59 | + } | |
60 | + | |
61 | + registerOnChange(fn: any): void { | |
62 | + this.propagateChange = fn; | |
63 | + } | |
64 | + | |
65 | + registerOnTouched(fn: any): void { | |
66 | + } | |
67 | + | |
68 | + ngOnInit() { | |
69 | + this.tenantProfileDataFormGroup.get('tenantProfileData').valueChanges.subscribe( | |
70 | + tenantProfileData => { | |
71 | + this.updateView(this.tenantProfileDataFormGroup.valid ? tenantProfileData : null); | |
72 | + } | |
73 | + ); | |
74 | + } | |
75 | + | |
76 | + setDisabledState(isDisabled: boolean): void { | |
77 | + this.disabled = isDisabled; | |
78 | + } | |
79 | + | |
80 | + writeValue(value: TenantProfileData | null): void { | |
81 | + this.modelValue = value; | |
82 | + this.tenantProfileDataFormGroup.get('tenantProfileData').patchValue(value, {emitEvent: false}); | |
83 | + } | |
84 | + | |
85 | + updateView(value: TenantProfileData | null) { | |
86 | + this.modelValue = value; | |
87 | + this.propagateChange(this.modelValue); | |
88 | + } | |
89 | +} | ... | ... |
... | ... | @@ -59,6 +59,10 @@ |
59 | 59 | <div class="tb-hint">{{'tenant.isolated-tb-rule-engine-details' | translate}}</div> |
60 | 60 | </mat-checkbox> |
61 | 61 | </div> |
62 | + <tb-tenant-profile-data | |
63 | + formControlName="profileData" | |
64 | + required> | |
65 | + </tb-tenant-profile-data> | |
62 | 66 | <mat-form-field class="mat-block"> |
63 | 67 | <mat-label translate>tenant-profile.description</mat-label> |
64 | 68 | <textarea matInput formControlName="description" rows="2"></textarea> | ... | ... |
... | ... | @@ -56,6 +56,7 @@ export class TenantProfileComponent extends EntityComponent<TenantProfile> { |
56 | 56 | name: [entity ? entity.name : '', [Validators.required]], |
57 | 57 | isolatedTbCore: [entity ? entity.isolatedTbCore : false, []], |
58 | 58 | isolatedTbRuleEngine: [entity ? entity.isolatedTbRuleEngine : false, []], |
59 | + profileData: [entity && !this.isAdd ? entity.profileData : {}, []], | |
59 | 60 | description: [entity ? entity.description : '', []], |
60 | 61 | } |
61 | 62 | ); |
... | ... | @@ -65,6 +66,7 @@ export class TenantProfileComponent extends EntityComponent<TenantProfile> { |
65 | 66 | this.entityForm.patchValue({name: entity.name}); |
66 | 67 | this.entityForm.patchValue({isolatedTbCore: entity.isolatedTbCore}); |
67 | 68 | this.entityForm.patchValue({isolatedTbRuleEngine: entity.isolatedTbRuleEngine}); |
69 | + this.entityForm.patchValue({profileData: entity.profileData}); | |
68 | 70 | this.entityForm.patchValue({description: entity.description}); |
69 | 71 | } |
70 | 72 | ... | ... |
... | ... | @@ -1693,6 +1693,7 @@ |
1693 | 1693 | "copyId": "Copy tenant profile Id", |
1694 | 1694 | "name": "Name", |
1695 | 1695 | "name-required": "Name is required.", |
1696 | + "data": "Profile data", | |
1696 | 1697 | "description": "Description", |
1697 | 1698 | "default": "Default", |
1698 | 1699 | "delete-tenant-profile-title": "Are you sure you want to delete the tenant profile '{{tenantProfileName}}'?", | ... | ... |