Add new alias Current Tenant (#2604)
This commit is contained in:
parent
352b073062
commit
2a1fa76c2f
@ -480,6 +480,7 @@ export class EntityService {
|
|||||||
entityTypes.push(EntityType.DASHBOARD);
|
entityTypes.push(EntityType.DASHBOARD);
|
||||||
if (useAliasEntityTypes) {
|
if (useAliasEntityTypes) {
|
||||||
entityTypes.push(AliasEntityType.CURRENT_CUSTOMER);
|
entityTypes.push(AliasEntityType.CURRENT_CUSTOMER);
|
||||||
|
entityTypes.push(AliasEntityType.CURRENT_TENANT);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Authority.CUSTOMER_USER:
|
case Authority.CUSTOMER_USER:
|
||||||
@ -1065,6 +1066,10 @@ export class EntityService {
|
|||||||
if (authUser.authority === Authority.CUSTOMER_USER) {
|
if (authUser.authority === Authority.CUSTOMER_USER) {
|
||||||
entityId.id = authUser.customerId;
|
entityId.id = authUser.customerId;
|
||||||
}
|
}
|
||||||
|
} else if (entityType === AliasEntityType.CURRENT_TENANT){
|
||||||
|
const authUser = getCurrentAuthUser(this.store);
|
||||||
|
entityId.entityType = EntityType.TENANT;
|
||||||
|
entityId.id = authUser.tenantId;
|
||||||
}
|
}
|
||||||
return entityId;
|
return entityId;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,11 +14,8 @@
|
|||||||
/// limitations under the License.
|
/// limitations under the License.
|
||||||
///
|
///
|
||||||
|
|
||||||
import { Component, Inject, InjectionToken, OnInit } from '@angular/core';
|
import { Component, Inject, InjectionToken } from '@angular/core';
|
||||||
import { Timewindow } from '@shared/models/time/time.models';
|
|
||||||
import { AliasInfo, IAliasController } from '@core/api/widget-api.models';
|
import { AliasInfo, IAliasController } from '@core/api/widget-api.models';
|
||||||
import { PageComponent } from '@shared/components/page.component';
|
|
||||||
import { TIMEWINDOW_PANEL_DATA, TimewindowPanelData } from '@shared/components/time/timewindow-panel.component';
|
|
||||||
import { deepClone } from '@core/utils';
|
import { deepClone } from '@core/utils';
|
||||||
|
|
||||||
export const ALIASES_ENTITY_SELECT_PANEL_DATA = new InjectionToken<any>('AliasesEntitySelectPanelData');
|
export const ALIASES_ENTITY_SELECT_PANEL_DATA = new InjectionToken<any>('AliasesEntitySelectPanelData');
|
||||||
|
|||||||
@ -15,8 +15,8 @@
|
|||||||
limitations under the License.
|
limitations under the License.
|
||||||
|
|
||||||
-->
|
-->
|
||||||
<form #entityAliasForm="ngForm" [formGroup]="entityAliasFormGroup" (ngSubmit)="save()" style="width: 600px;">
|
<form #entityAliasForm="ngForm" [formGroup]="entityAliasFormGroup" (ngSubmit)="save()" style="min-width: 550px;">
|
||||||
<mat-toolbar fxLayout="row" color="primary">
|
<mat-toolbar color="primary">
|
||||||
<h2>{{ (isAdd ? 'alias.add' : 'alias.edit') | translate }}</h2>
|
<h2>{{ (isAdd ? 'alias.add' : 'alias.edit') | translate }}</h2>
|
||||||
<span fxFlex></span>
|
<span fxFlex></span>
|
||||||
<button mat-button mat-icon-button
|
<button mat-button mat-icon-button
|
||||||
|
|||||||
@ -18,7 +18,7 @@
|
|||||||
<div fxLayout="column" [formGroup]="entityFilterFormGroup" class="tb-entity-filter">
|
<div fxLayout="column" [formGroup]="entityFilterFormGroup" class="tb-entity-filter">
|
||||||
<mat-form-field class="mat-block">
|
<mat-form-field class="mat-block">
|
||||||
<mat-label translate>alias.filter-type</mat-label>
|
<mat-label translate>alias.filter-type</mat-label>
|
||||||
<mat-select required matInput formControlName="type">
|
<mat-select required formControlName="type">
|
||||||
<mat-option *ngFor="let type of aliasFilterTypes" [value]="type">
|
<mat-option *ngFor="let type of aliasFilterTypes" [value]="type">
|
||||||
{{aliasFilterTypeTranslations.get(type) | translate}}
|
{{aliasFilterTypeTranslations.get(type) | translate}}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
|
|||||||
@ -15,14 +15,7 @@
|
|||||||
///
|
///
|
||||||
|
|
||||||
import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core';
|
import { Component, EventEmitter, forwardRef, Input, OnInit, Output } from '@angular/core';
|
||||||
import {
|
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
|
||||||
ControlValueAccessor,
|
|
||||||
FormBuilder, FormControl,
|
|
||||||
FormGroup,
|
|
||||||
NG_VALUE_ACCESSOR,
|
|
||||||
ValidatorFn,
|
|
||||||
Validators
|
|
||||||
} from '@angular/forms';
|
|
||||||
import { AliasFilterType, aliasFilterTypeTranslationMap, EntityAliasFilter } from '@shared/models/alias.models';
|
import { AliasFilterType, aliasFilterTypeTranslationMap, EntityAliasFilter } from '@shared/models/alias.models';
|
||||||
import { AliasEntityType, EntityType } from '@shared/models/entity-type.models';
|
import { AliasEntityType, EntityType } from '@shared/models/entity-type.models';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
|
|||||||
@ -17,7 +17,7 @@
|
|||||||
import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnInit, ViewChild } from '@angular/core';
|
import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnInit, ViewChild } from '@angular/core';
|
||||||
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
|
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import {map, mergeMap, startWith, tap, share} from 'rxjs/operators';
|
import { map, mergeMap, share, tap } from 'rxjs/operators';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { AppState } from '@app/core/core.state';
|
import { AppState } from '@app/core/core.state';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
@ -164,6 +164,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
|
|||||||
this.entityRequiredText = 'rulechain.rulechain-required';
|
this.entityRequiredText = 'rulechain.rulechain-required';
|
||||||
break;
|
break;
|
||||||
case EntityType.TENANT:
|
case EntityType.TENANT:
|
||||||
|
case AliasEntityType.CURRENT_TENANT:
|
||||||
this.entityText = 'tenant.tenant';
|
this.entityText = 'tenant.tenant';
|
||||||
this.noEntitiesMatchingText = 'tenant.no-tenants-matching';
|
this.noEntitiesMatchingText = 'tenant.no-tenants-matching';
|
||||||
this.entityRequiredText = 'tenant.tenant-required';
|
this.entityRequiredText = 'tenant.tenant-required';
|
||||||
@ -226,10 +227,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
|
|||||||
this.searchText = '';
|
this.searchText = '';
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if (typeof value === 'string') {
|
if (typeof value === 'string') {
|
||||||
let targetEntityType = this.entityTypeValue;
|
const targetEntityType = this.checkEntityType(this.entityTypeValue);
|
||||||
if (targetEntityType === AliasEntityType.CURRENT_CUSTOMER) {
|
|
||||||
targetEntityType = EntityType.CUSTOMER;
|
|
||||||
}
|
|
||||||
this.entityService.getEntity(targetEntityType, value, {ignoreLoading: true}).subscribe(
|
this.entityService.getEntity(targetEntityType, value, {ignoreLoading: true}).subscribe(
|
||||||
(entity) => {
|
(entity) => {
|
||||||
this.modelValue = entity.id.id;
|
this.modelValue = entity.id.id;
|
||||||
@ -237,7 +235,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const targetEntityType = value.entityType as EntityType;
|
const targetEntityType = this.checkEntityType(value.entityType);
|
||||||
this.entityService.getEntity(targetEntityType, value.id, {ignoreLoading: true}).subscribe(
|
this.entityService.getEntity(targetEntityType, value.id, {ignoreLoading: true}).subscribe(
|
||||||
(entity) => {
|
(entity) => {
|
||||||
this.modelValue = entity.id.id;
|
this.modelValue = entity.id.id;
|
||||||
@ -276,10 +274,7 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
|
|||||||
|
|
||||||
fetchEntities(searchText?: string): Observable<Array<BaseData<EntityId>>> {
|
fetchEntities(searchText?: string): Observable<Array<BaseData<EntityId>>> {
|
||||||
this.searchText = searchText;
|
this.searchText = searchText;
|
||||||
let targetEntityType = this.entityTypeValue;
|
const targetEntityType = this.checkEntityType(this.entityTypeValue);
|
||||||
if (targetEntityType === AliasEntityType.CURRENT_CUSTOMER) {
|
|
||||||
targetEntityType = EntityType.CUSTOMER;
|
|
||||||
}
|
|
||||||
return this.entityService.getEntitiesByNameFilter(targetEntityType, searchText,
|
return this.entityService.getEntitiesByNameFilter(targetEntityType, searchText,
|
||||||
50, this.entitySubtypeValue, {ignoreLoading: true}).pipe(
|
50, this.entitySubtypeValue, {ignoreLoading: true}).pipe(
|
||||||
map((data) => {
|
map((data) => {
|
||||||
@ -310,4 +305,12 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
|
|||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
checkEntityType(entityType: EntityType | AliasEntityType): EntityType {
|
||||||
|
if (entityType === AliasEntityType.CURRENT_CUSTOMER) {
|
||||||
|
return EntityType.CUSTOMER;
|
||||||
|
} else if (entityType === AliasEntityType.CURRENT_TENANT) {
|
||||||
|
return EntityType.TENANT;
|
||||||
|
}
|
||||||
|
return entityType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,7 +27,7 @@
|
|||||||
</tb-entity-type-select>
|
</tb-entity-type-select>
|
||||||
<tb-entity-autocomplete
|
<tb-entity-autocomplete
|
||||||
fxFlex
|
fxFlex
|
||||||
*ngIf="modelValue.entityType"
|
*ngIf="modelValue.entityType && modelValue.entityType !== AliasEntityType.CURRENT_TENANT"
|
||||||
[required]="required"
|
[required]="required"
|
||||||
[entityType]="modelValue.entityType"
|
[entityType]="modelValue.entityType"
|
||||||
formControlName="entityId">
|
formControlName="entityId">
|
||||||
|
|||||||
@ -19,10 +19,11 @@ import {ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR} from '@
|
|||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { AppState } from '@core/core.state';
|
import { AppState } from '@core/core.state';
|
||||||
import { TranslateService } from '@ngx-translate/core';
|
import { TranslateService } from '@ngx-translate/core';
|
||||||
import {AliasEntityType, EntityType, entityTypeTranslations} from '@shared/models/entity-type.models';
|
import { AliasEntityType, EntityType } from '@shared/models/entity-type.models';
|
||||||
import { EntityService } from '@core/http/entity.service';
|
import { EntityService } from '@core/http/entity.service';
|
||||||
import { EntityId } from '@shared/models/id/entity-id';
|
import { EntityId } from '@shared/models/id/entity-id';
|
||||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||||
|
import { NULL_UUID } from '@shared/models/id/has-uuid';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'tb-entity-select',
|
selector: 'tb-entity-select',
|
||||||
@ -60,6 +61,8 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
|
|||||||
|
|
||||||
displayEntityTypeSelect: boolean;
|
displayEntityTypeSelect: boolean;
|
||||||
|
|
||||||
|
AliasEntityType = AliasEntityType;
|
||||||
|
|
||||||
private readonly defaultEntityType: EntityType | AliasEntityType = null;
|
private readonly defaultEntityType: EntityType | AliasEntityType = null;
|
||||||
|
|
||||||
private propagateChange = (v: any) => { };
|
private propagateChange = (v: any) => { };
|
||||||
@ -94,6 +97,9 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
|
|||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.entitySelectFormGroup.get('entityType').valueChanges.subscribe(
|
this.entitySelectFormGroup.get('entityType').valueChanges.subscribe(
|
||||||
(value) => {
|
(value) => {
|
||||||
|
if(value === AliasEntityType.CURRENT_TENANT){
|
||||||
|
this.modelValue.id = NULL_UUID;
|
||||||
|
}
|
||||||
this.updateView(value, this.modelValue.id);
|
this.updateView(value, this.modelValue.id);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -139,7 +145,7 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
|
|||||||
entityType,
|
entityType,
|
||||||
id: this.modelValue.entityType !== entityType ? null : entityId
|
id: this.modelValue.entityType !== entityType ? null : entityId
|
||||||
};
|
};
|
||||||
if (this.modelValue.entityType && this.modelValue.id) {
|
if (this.modelValue.entityType && (this.modelValue.id || this.modelValue.entityType === AliasEntityType.CURRENT_TENANT)) {
|
||||||
this.propagateChange(this.modelValue);
|
this.propagateChange(this.modelValue);
|
||||||
} else {
|
} else {
|
||||||
this.propagateChange(null);
|
this.propagateChange(null);
|
||||||
|
|||||||
@ -49,7 +49,8 @@ export enum EntityType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export enum AliasEntityType {
|
export enum AliasEntityType {
|
||||||
CURRENT_CUSTOMER = 'CURRENT_CUSTOMER'
|
CURRENT_CUSTOMER = 'CURRENT_CUSTOMER',
|
||||||
|
CURRENT_TENANT = 'CURRENT_TENANT'
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EntityTypeTranslation {
|
export interface EntityTypeTranslation {
|
||||||
@ -218,9 +219,16 @@ export const entityTypeTranslations = new Map<EntityType | AliasEntityType, Enti
|
|||||||
[
|
[
|
||||||
AliasEntityType.CURRENT_CUSTOMER,
|
AliasEntityType.CURRENT_CUSTOMER,
|
||||||
{
|
{
|
||||||
type: 'entity.type-entity-view',
|
type: 'entity.type-current-customer',
|
||||||
list: 'entity.type-current-customer'
|
list: 'entity.type-current-customer'
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
[
|
||||||
|
AliasEntityType.CURRENT_TENANT,
|
||||||
|
{
|
||||||
|
type: 'entity.type-current-tenant',
|
||||||
|
list: 'entity.type-current-tenant'
|
||||||
|
}
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|||||||
@ -771,6 +771,7 @@
|
|||||||
"list-of-rulenodes": "{ count, plural, 1 {Jeden uzel pravidla} other {Seznam # uzlů pravidel} }",
|
"list-of-rulenodes": "{ count, plural, 1 {Jeden uzel pravidla} other {Seznam # uzlů pravidel} }",
|
||||||
"rulenode-name-starts-with": "Uzly pravidel, jejichž název začíná '{{prefix}}'",
|
"rulenode-name-starts-with": "Uzly pravidel, jejichž název začíná '{{prefix}}'",
|
||||||
"type-current-customer": "Stávající zákazník",
|
"type-current-customer": "Stávající zákazník",
|
||||||
|
"type-current-tenant": "Stávající tenant",
|
||||||
"search": "Vyhledat entity",
|
"search": "Vyhledat entity",
|
||||||
"selected-entities": "{ count, plural, 1 {1 entita} other {# entit} } zvoleno",
|
"selected-entities": "{ count, plural, 1 {1 entita} other {# entit} } zvoleno",
|
||||||
"entity-name": "Název entity",
|
"entity-name": "Název entity",
|
||||||
|
|||||||
@ -830,6 +830,7 @@
|
|||||||
"list-of-rulenodes": "{ count, plural, 1 {One rule node} other {List of # rule nodes} }",
|
"list-of-rulenodes": "{ count, plural, 1 {One rule node} other {List of # rule nodes} }",
|
||||||
"rulenode-name-starts-with": "Rule nodes whose names start with '{{prefix}}'",
|
"rulenode-name-starts-with": "Rule nodes whose names start with '{{prefix}}'",
|
||||||
"type-current-customer": "Current Customer",
|
"type-current-customer": "Current Customer",
|
||||||
|
"type-current-tenant": "Current Tenant",
|
||||||
"search": "Search entities",
|
"search": "Search entities",
|
||||||
"selected-entities": "{ count, plural, 1 {1 entity} other {# entities} } selected",
|
"selected-entities": "{ count, plural, 1 {1 entity} other {# entities} } selected",
|
||||||
"entity-name": "Entity name",
|
"entity-name": "Entity name",
|
||||||
|
|||||||
@ -810,6 +810,7 @@
|
|||||||
"list-of-rulenodes": "{ count, plural, 1 {Одно правило} other {Список из # правил} }",
|
"list-of-rulenodes": "{ count, plural, 1 {Одно правило} other {Список из # правил} }",
|
||||||
"rulenode-name-starts-with": "Правила, чьи названия начинаются с '{{prefix}}'",
|
"rulenode-name-starts-with": "Правила, чьи названия начинаются с '{{prefix}}'",
|
||||||
"type-current-customer": "Текущий клиент",
|
"type-current-customer": "Текущий клиент",
|
||||||
|
"type-current-tenant": "Текущий владелец",
|
||||||
"search": "Поиск объектов",
|
"search": "Поиск объектов",
|
||||||
"selected-entities": "Выбран(ы) { count, plural, 1 {1 объект} few {# объекта} other {# объектов} }",
|
"selected-entities": "Выбран(ы) { count, plural, 1 {1 объект} few {# объекта} other {# объектов} }",
|
||||||
"entity-name": "Название объекта",
|
"entity-name": "Название объекта",
|
||||||
|
|||||||
@ -943,6 +943,7 @@
|
|||||||
"list-of-rulenodes": "{ count, plural, 1 {Одне правило} other {Список # правил} }",
|
"list-of-rulenodes": "{ count, plural, 1 {Одне правило} other {Список # правил} }",
|
||||||
"rulenode-name-starts-with": "Список правил, імена яких починаються '{{prefix}}'",
|
"rulenode-name-starts-with": "Список правил, імена яких починаються '{{prefix}}'",
|
||||||
"type-current-customer": "Поточний клієнт",
|
"type-current-customer": "Поточний клієнт",
|
||||||
|
"type-current-tenant": "Поточний власник",
|
||||||
"search": "Пошук сутностей",
|
"search": "Пошук сутностей",
|
||||||
"selected-entities": "{ count, plural, 1 {1 сутність} other {# сутності} } вибрано",
|
"selected-entities": "{ count, plural, 1 {1 сутність} other {# сутності} } вибрано",
|
||||||
"entity-name": "Ім'я сутності",
|
"entity-name": "Ім'я сутності",
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user