Merge pull request #13501 from vvlladd28/improved/entity-type/add-reletion
Add allow created/view relation to rule chain
This commit is contained in:
commit
a00ff91540
@ -38,6 +38,7 @@
|
|||||||
'relation.to-entity' : 'relation.from-entity') | translate}}</small>
|
'relation.to-entity' : 'relation.from-entity') | translate}}</small>
|
||||||
<tb-entity-list-select
|
<tb-entity-list-select
|
||||||
formControlName="targetEntityIds"
|
formControlName="targetEntityIds"
|
||||||
|
[additionEntityTypes]="additionEntityTypes"
|
||||||
required="true">
|
required="true">
|
||||||
</tb-entity-list-select>
|
</tb-entity-list-select>
|
||||||
<tb-json-object-edit
|
<tb-json-object-edit
|
||||||
|
|||||||
@ -19,7 +19,7 @@ import { ErrorStateMatcher } from '@angular/material/core';
|
|||||||
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { AppState } from '@core/core.state';
|
import { AppState } from '@core/core.state';
|
||||||
import { UntypedFormBuilder, UntypedFormControl, UntypedFormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms';
|
import { FormBuilder, FormControl, FormGroup, FormGroupDirective, NgForm, Validators } from '@angular/forms';
|
||||||
import {
|
import {
|
||||||
CONTAINS_TYPE,
|
CONTAINS_TYPE,
|
||||||
EntityRelation,
|
EntityRelation,
|
||||||
@ -33,6 +33,9 @@ import { JsonObjectEditComponent } from '@shared/components/json-object-edit.com
|
|||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { DialogComponent } from '@shared/components/dialog.component';
|
import { DialogComponent } from '@shared/components/dialog.component';
|
||||||
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
|
||||||
|
import { getCurrentAuthUser } from '@core/auth/auth.selectors';
|
||||||
|
import { Authority } from '@shared/models/authority.enum';
|
||||||
|
import { EntityType } from '@shared/models/entity-type.models';
|
||||||
|
|
||||||
export interface RelationDialogData {
|
export interface RelationDialogData {
|
||||||
isAdd: boolean;
|
isAdd: boolean;
|
||||||
@ -48,25 +51,29 @@ export interface RelationDialogData {
|
|||||||
})
|
})
|
||||||
export class RelationDialogComponent extends DialogComponent<RelationDialogComponent, boolean> implements OnInit, ErrorStateMatcher {
|
export class RelationDialogComponent extends DialogComponent<RelationDialogComponent, boolean> implements OnInit, ErrorStateMatcher {
|
||||||
|
|
||||||
relationFormGroup: UntypedFormGroup;
|
relationFormGroup: FormGroup;
|
||||||
|
|
||||||
|
additionEntityTypes: {[key in string]: string} = {};
|
||||||
|
|
||||||
isAdd: boolean;
|
isAdd: boolean;
|
||||||
direction: EntitySearchDirection;
|
direction: EntitySearchDirection;
|
||||||
entitySearchDirection = EntitySearchDirection;
|
entitySearchDirection = EntitySearchDirection;
|
||||||
|
|
||||||
additionalInfo: UntypedFormControl;
|
additionalInfo: FormControl;
|
||||||
|
|
||||||
@ViewChild('additionalInfoEdit', {static: true}) additionalInfoEdit: JsonObjectEditComponent;
|
@ViewChild('additionalInfoEdit', {static: true}) additionalInfoEdit: JsonObjectEditComponent;
|
||||||
|
|
||||||
submitted = false;
|
submitted = false;
|
||||||
|
|
||||||
|
private authUser = getCurrentAuthUser(this.store);
|
||||||
|
|
||||||
constructor(protected store: Store<AppState>,
|
constructor(protected store: Store<AppState>,
|
||||||
protected router: Router,
|
protected router: Router,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: RelationDialogData,
|
@Inject(MAT_DIALOG_DATA) public data: RelationDialogData,
|
||||||
private entityRelationService: EntityRelationService,
|
private entityRelationService: EntityRelationService,
|
||||||
@SkipSelf() private errorStateMatcher: ErrorStateMatcher,
|
@SkipSelf() private errorStateMatcher: ErrorStateMatcher,
|
||||||
public dialogRef: MatDialogRef<RelationDialogComponent, boolean>,
|
public dialogRef: MatDialogRef<RelationDialogComponent, boolean>,
|
||||||
public fb: UntypedFormBuilder,
|
public fb: FormBuilder,
|
||||||
private destroyRef: DestroyRef) {
|
private destroyRef: DestroyRef) {
|
||||||
super(store, router, dialogRef);
|
super(store, router, dialogRef);
|
||||||
this.isAdd = data.isAdd;
|
this.isAdd = data.isAdd;
|
||||||
@ -74,13 +81,17 @@ export class RelationDialogComponent extends DialogComponent<RelationDialogCompo
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
if (this.authUser.authority === Authority.TENANT_ADMIN) {
|
||||||
|
this.additionEntityTypes = {[EntityType.RULE_CHAIN]: null};
|
||||||
|
}
|
||||||
|
|
||||||
this.relationFormGroup = this.fb.group({
|
this.relationFormGroup = this.fb.group({
|
||||||
type: [this.isAdd ? CONTAINS_TYPE : this.data.relation.type, [Validators.required]],
|
type: [this.isAdd ? CONTAINS_TYPE : this.data.relation.type, [Validators.required]],
|
||||||
targetEntityIds: [this.isAdd ? null :
|
targetEntityIds: [this.isAdd ? null :
|
||||||
[this.direction === EntitySearchDirection.FROM ? this.data.relation.to : this.data.relation.from],
|
[this.direction === EntitySearchDirection.FROM ? this.data.relation.to : this.data.relation.from],
|
||||||
[Validators.required]]
|
[Validators.required]]
|
||||||
});
|
});
|
||||||
this.additionalInfo = new UntypedFormControl(this.data.relation.additionalInfo ? {...this.data.relation.additionalInfo} : null);
|
this.additionalInfo = new FormControl(this.data.relation.additionalInfo ? {...this.data.relation.additionalInfo} : null);
|
||||||
if (!this.isAdd) {
|
if (!this.isAdd) {
|
||||||
this.relationFormGroup.get('type').disable();
|
this.relationFormGroup.get('type').disable();
|
||||||
this.relationFormGroup.get('targetEntityIds').disable();
|
this.relationFormGroup.get('targetEntityIds').disable();
|
||||||
@ -94,7 +105,7 @@ export class RelationDialogComponent extends DialogComponent<RelationDialogCompo
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
isErrorState(control: UntypedFormControl | null, form: FormGroupDirective | NgForm | null): boolean {
|
isErrorState(control: FormControl | null, form: FormGroupDirective | NgForm | null): boolean {
|
||||||
const originalErrorState = this.errorStateMatcher.isErrorState(control, form);
|
const originalErrorState = this.errorStateMatcher.isErrorState(control, form);
|
||||||
const customErrorState = !!(control && control.invalid && this.submitted);
|
const customErrorState = !!(control && control.invalid && this.submitted);
|
||||||
return originalErrorState || customErrorState;
|
return originalErrorState || customErrorState;
|
||||||
|
|||||||
@ -26,6 +26,7 @@
|
|||||||
[useAliasEntityTypes]="useAliasEntityTypes"
|
[useAliasEntityTypes]="useAliasEntityTypes"
|
||||||
[allowedEntityTypes]="allowedEntityTypes"
|
[allowedEntityTypes]="allowedEntityTypes"
|
||||||
[filterAllowedEntityTypes]="filterAllowedEntityTypes"
|
[filterAllowedEntityTypes]="filterAllowedEntityTypes"
|
||||||
|
[additionEntityTypes]="additionEntityTypes"
|
||||||
formControlName="entityType">
|
formControlName="entityType">
|
||||||
</tb-entity-type-select>
|
</tb-entity-type-select>
|
||||||
<tb-entity-list
|
<tb-entity-list
|
||||||
|
|||||||
@ -65,6 +65,9 @@ export class EntityListSelectComponent implements ControlValueAccessor, OnInit {
|
|||||||
@Input()
|
@Input()
|
||||||
predefinedEntityType: EntityType | AliasEntityType;
|
predefinedEntityType: EntityType | AliasEntityType;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
additionEntityTypes: {[key in string]: string} = {};
|
||||||
|
|
||||||
displayEntityTypeSelect: boolean;
|
displayEntityTypeSelect: boolean;
|
||||||
|
|
||||||
private defaultEntityType: EntityType | AliasEntityType = null;
|
private defaultEntityType: EntityType | AliasEntityType = null;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user