UI: Added additionEntityTypes in entity-select.component and delete CURRENT_RULE_NODE
This commit is contained in:
parent
bec4e811eb
commit
ff01f77f9e
@ -414,8 +414,6 @@ export class EntityAutocompleteComponent implements ControlValueAccessor, OnInit
|
||||
} else {
|
||||
return EntityType.CUSTOMER;
|
||||
}
|
||||
} else if (entityType === AliasEntityType.CURRENT_RULE_NODE) {
|
||||
return EntityType.RULE_NODE;
|
||||
}
|
||||
return entityType;
|
||||
}
|
||||
|
||||
@ -22,10 +22,11 @@
|
||||
[required]="required"
|
||||
[useAliasEntityTypes]="useAliasEntityTypes"
|
||||
[allowedEntityTypes]="allowedEntityTypes"
|
||||
[additionEntityTypes]="additionEntityTypes"
|
||||
formControlName="entityType">
|
||||
</tb-entity-type-select>
|
||||
<tb-entity-autocomplete
|
||||
*ngIf="modelValue.entityType && !entityTypeNullUid.has(modelValue.entityType)"
|
||||
*ngIf="modelValue.entityType && !entityTypeNullUUID.has(modelValue.entityType)"
|
||||
[required]="required"
|
||||
[entityType]="modelValue.entityType"
|
||||
formControlName="entityId">
|
||||
|
||||
@ -22,8 +22,8 @@ import { TranslateService } from '@ngx-translate/core';
|
||||
import { AliasEntityType, EntityType } from '@shared/models/entity-type.models';
|
||||
import { EntityService } from '@core/http/entity.service';
|
||||
import { EntityId } from '@shared/models/id/entity-id';
|
||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||
import { NULL_UUID } from '@shared/models/id/has-uuid';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-entity-select',
|
||||
@ -47,24 +47,22 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
|
||||
@Input()
|
||||
useAliasEntityTypes: boolean;
|
||||
|
||||
private requiredValue: boolean;
|
||||
get required(): boolean {
|
||||
return this.requiredValue;
|
||||
}
|
||||
@Input()
|
||||
set required(value: boolean) {
|
||||
this.requiredValue = coerceBooleanProperty(value);
|
||||
}
|
||||
@coerceBoolean()
|
||||
required: boolean;
|
||||
|
||||
@Input()
|
||||
disabled: boolean;
|
||||
|
||||
@Input()
|
||||
additionEntityTypes: {[entityType in string]: string} = {};
|
||||
|
||||
displayEntityTypeSelect: boolean;
|
||||
|
||||
AliasEntityType = AliasEntityType;
|
||||
|
||||
entityTypeNullUid: Set<AliasEntityType | EntityType> = new Set([
|
||||
AliasEntityType.CURRENT_TENANT, AliasEntityType.CURRENT_USER, AliasEntityType.CURRENT_USER_OWNER, AliasEntityType.CURRENT_RULE_NODE
|
||||
entityTypeNullUUID: Set<AliasEntityType | EntityType | string> = new Set([
|
||||
AliasEntityType.CURRENT_TENANT, AliasEntityType.CURRENT_USER, AliasEntityType.CURRENT_USER_OWNER
|
||||
]);
|
||||
|
||||
private readonly defaultEntityType: EntityType | AliasEntityType = null;
|
||||
@ -110,6 +108,10 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
|
||||
this.updateView(this.modelValue.entityType, id);
|
||||
}
|
||||
);
|
||||
const additionNullUIIDEntityTypes = Object.keys(this.additionEntityTypes) as string[];
|
||||
if (additionNullUIIDEntityTypes.length > 0) {
|
||||
additionNullUIIDEntityTypes.forEach((entityType) => this.entityTypeNullUUID.add(entityType));
|
||||
}
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
@ -147,7 +149,7 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
|
||||
id: this.modelValue.entityType !== entityType ? null : entityId
|
||||
};
|
||||
|
||||
if (this.entityTypeNullUid.has(this.modelValue.entityType)) {
|
||||
if (this.entityTypeNullUUID.has(this.modelValue.entityType)) {
|
||||
this.modelValue.id = NULL_UUID;
|
||||
} else if (this.modelValue.entityType === AliasEntityType.CURRENT_CUSTOMER && !this.modelValue.id) {
|
||||
this.modelValue.id = NULL_UUID;
|
||||
|
||||
@ -15,13 +15,13 @@
|
||||
///
|
||||
|
||||
import { AfterViewInit, Component, forwardRef, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
|
||||
import { ControlValueAccessor, UntypedFormBuilder, UntypedFormGroup, NG_VALUE_ACCESSOR } from '@angular/forms';
|
||||
import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { AppState } from '@app/core/core.state';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { AliasEntityType, EntityType, entityTypeTranslations } from '@app/shared/models/entity-type.models';
|
||||
import { EntityService } from '@core/http/entity.service';
|
||||
import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
||||
import { coerceBoolean } from '@shared/decorators/coercion';
|
||||
|
||||
@Component({
|
||||
selector: 'tb-entity-type-select',
|
||||
@ -48,28 +48,21 @@ export class EntityTypeSelectComponent implements ControlValueAccessor, OnInit,
|
||||
@Input()
|
||||
filterAllowedEntityTypes = true;
|
||||
|
||||
private showLabelValue: boolean;
|
||||
get showLabel(): boolean {
|
||||
return this.showLabelValue;
|
||||
}
|
||||
@Input()
|
||||
set showLabel(value: boolean) {
|
||||
this.showLabelValue = coerceBooleanProperty(value);
|
||||
}
|
||||
@coerceBoolean()
|
||||
showLabel: boolean;
|
||||
|
||||
private requiredValue: boolean;
|
||||
get required(): boolean {
|
||||
return this.requiredValue;
|
||||
}
|
||||
@Input()
|
||||
set required(value: boolean) {
|
||||
this.requiredValue = coerceBooleanProperty(value);
|
||||
}
|
||||
@coerceBoolean()
|
||||
required: boolean;
|
||||
|
||||
@Input()
|
||||
disabled: boolean;
|
||||
|
||||
entityTypes: Array<EntityType | AliasEntityType>;
|
||||
@Input()
|
||||
additionEntityTypes: {[key in string]: string} = {};
|
||||
|
||||
entityTypes: Array<EntityType | AliasEntityType | string>;
|
||||
|
||||
private propagateChange = (v: any) => { };
|
||||
|
||||
@ -93,8 +86,9 @@ export class EntityTypeSelectComponent implements ControlValueAccessor, OnInit,
|
||||
this.entityTypes = this.filterAllowedEntityTypes
|
||||
? this.entityService.prepareAllowedEntityTypesList(this.allowedEntityTypes, this.useAliasEntityTypes)
|
||||
: this.allowedEntityTypes;
|
||||
if (this.allowedEntityTypes?.length && this.allowedEntityTypes.includes(AliasEntityType.CURRENT_RULE_NODE)) {
|
||||
this.entityTypes.push(AliasEntityType.CURRENT_RULE_NODE);
|
||||
const additionEntityTypes = Object.keys(this.additionEntityTypes);
|
||||
if (additionEntityTypes.length > 0) {
|
||||
this.entityTypes.push(...additionEntityTypes);
|
||||
}
|
||||
this.entityTypeFormGroup.get('entityType').valueChanges.subscribe(
|
||||
(value) => {
|
||||
@ -116,6 +110,10 @@ export class EntityTypeSelectComponent implements ControlValueAccessor, OnInit,
|
||||
if (propName === 'allowedEntityTypes') {
|
||||
this.entityTypes = this.filterAllowedEntityTypes ?
|
||||
this.entityService.prepareAllowedEntityTypesList(this.allowedEntityTypes, this.useAliasEntityTypes) : this.allowedEntityTypes;
|
||||
const additionEntityTypes = Object.keys(this.additionEntityTypes);
|
||||
if (additionEntityTypes.length > 0) {
|
||||
this.entityTypes.push(...additionEntityTypes);
|
||||
}
|
||||
const currentEntityType: EntityType | AliasEntityType = this.entityTypeFormGroup.get('entityType').value;
|
||||
if (currentEntityType && !this.entityTypes.includes(currentEntityType)) {
|
||||
this.entityTypeFormGroup.get('entityType').patchValue(null, {emitEvent: true});
|
||||
@ -155,7 +153,9 @@ export class EntityTypeSelectComponent implements ControlValueAccessor, OnInit,
|
||||
}
|
||||
|
||||
displayEntityTypeFn(entityType?: EntityType | AliasEntityType | null): string | undefined {
|
||||
if (entityType) {
|
||||
if (this.additionEntityTypes[entityType]) {
|
||||
return this.additionEntityTypes[entityType];
|
||||
} else if (entityType) {
|
||||
return this.translate.instant(entityTypeTranslations.get(entityType as EntityType).type);
|
||||
} else {
|
||||
return '';
|
||||
|
||||
@ -54,8 +54,7 @@ export enum AliasEntityType {
|
||||
CURRENT_CUSTOMER = 'CURRENT_CUSTOMER',
|
||||
CURRENT_TENANT = 'CURRENT_TENANT',
|
||||
CURRENT_USER = 'CURRENT_USER',
|
||||
CURRENT_USER_OWNER = 'CURRENT_USER_OWNER',
|
||||
CURRENT_RULE_NODE = 'CURRENT_RULE_NODE'
|
||||
CURRENT_USER_OWNER = 'CURRENT_USER_OWNER'
|
||||
}
|
||||
|
||||
export interface EntityTypeTranslation {
|
||||
@ -327,13 +326,6 @@ export const entityTypeTranslations = new Map<EntityType | AliasEntityType, Enti
|
||||
list: 'entity.type-current-user-owner'
|
||||
}
|
||||
],
|
||||
[
|
||||
AliasEntityType.CURRENT_RULE_NODE,
|
||||
{
|
||||
type: 'entity.type-current-rule-node',
|
||||
list: 'entity.type-current-rule-node'
|
||||
}
|
||||
],
|
||||
[
|
||||
EntityType.TB_RESOURCE,
|
||||
{
|
||||
|
||||
@ -2315,7 +2315,6 @@
|
||||
"type-current-tenant": "Current Tenant",
|
||||
"type-current-user": "Current User",
|
||||
"type-current-user-owner": "Current User Owner",
|
||||
"type-current-rule-node": "Current Rule Node",
|
||||
"type-widgets-bundle": "Widgets bundle",
|
||||
"type-widgets-bundles": "Widgets bundles",
|
||||
"list-of-widgets-bundles": "{ count, plural, =1 {One widgets bundle} other {List of # widget bundles} }",
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user