UI: Improved disabled rulenode config

This commit is contained in:
Vladyslav_Prykhodko 2023-08-25 16:29:51 +03:00
parent 186614a18d
commit b493f1a1b7
5 changed files with 52 additions and 69 deletions

View File

@ -29,16 +29,12 @@
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async"> <mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async">
</mat-progress-bar> </mat-progress-bar>
<div mat-dialog-content> <div mat-dialog-content>
<fieldset [disabled]="isLoading$ | async"> <tb-rule-node #tbRuleNode
<tb-rule-node #tbRuleNode [ruleNode]="ruleNode"
[ruleNode]="ruleNode" [ruleChainId]="ruleChainId"
[ruleChainId]="ruleChainId" [ruleChainType]="ruleChainType"
[ruleChainType]="ruleChainType" isAdd>
[isEdit]="true" </tb-rule-node>
[isAdd]="true"
[isReadOnly]="false">
</tb-rule-node>
</fieldset>
</div> </div>
<div mat-dialog-actions fxLayoutAlign="end center"> <div mat-dialog-actions fxLayoutAlign="end center">
<button mat-button color="primary" <button mat-button color="primary"

View File

@ -15,7 +15,7 @@
*/ */
:host { :host {
display: block; display: block;
margin-bottom: 16px;
tb-json-object-edit.tb-rule-node-configuration-json { tb-json-object-edit.tb-rule-node-configuration-json {
display: block; display: block;
height: 300px; height: 300px;

View File

@ -22,44 +22,40 @@
</button> </button>
</div> </div>
<form [formGroup]="ruleNodeFormGroup" class="mat-padding"> <form [formGroup]="ruleNodeFormGroup" class="mat-padding">
<fieldset [disabled]="(isLoading$ | async)"> <section class="title-row">
<section> <mat-form-field fxFlex class="mat-block">
<section class="title-row"> <mat-label translate>rulenode.name</mat-label>
<mat-form-field fxFlex class="mat-block"> <input matInput formControlName="name" required>
<mat-label translate>rulenode.name</mat-label> <mat-error *ngIf="ruleNodeFormGroup.get('name').hasError('required')
<input matInput formControlName="name" required>
<mat-error *ngIf="ruleNodeFormGroup.get('name').hasError('required')
|| ruleNodeFormGroup.get('name').hasError('pattern')"> || ruleNodeFormGroup.get('name').hasError('pattern')">
{{ 'rulenode.name-required' | translate }} {{ 'rulenode.name-required' | translate }}
</mat-error> </mat-error>
<mat-error *ngIf="ruleNodeFormGroup.get('name').hasError('maxlength')"> <mat-error *ngIf="ruleNodeFormGroup.get('name').hasError('maxlength')">
{{ 'rulenode.name-max-length' | translate }} {{ 'rulenode.name-max-length' | translate }}
</mat-error> </mat-error>
</mat-form-field> </mat-form-field>
<section class="node-setting"> <section class="node-setting">
<mat-slide-toggle formControlName="debugMode"> <mat-slide-toggle formControlName="debugMode">
{{ 'rulenode.debug-mode' | translate }} {{ 'rulenode.debug-mode' | translate }}
</mat-slide-toggle> </mat-slide-toggle>
<mat-slide-toggle *ngIf="isSingletonEditAllowed()" formControlName="singletonMode"> <mat-slide-toggle *ngIf="isSingletonEditAllowed()" formControlName="singletonMode">
{{ 'rulenode.singleton-mode' | translate }} {{ 'rulenode.singleton-mode' | translate }}
</mat-slide-toggle > </mat-slide-toggle>
</section>
</section>
<tb-rule-node-config #ruleNodeConfigComponent
formControlName="configuration"
[ruleNodeId]="ruleNode.ruleNodeId?.id"
[ruleChainId]="ruleChainId"
[ruleChainType]="ruleChainType"
[nodeDefinition]="ruleNode.component.configurationDescriptor.nodeDefinition"
(initRuleNode)="initRuleNode.emit($event)"
(changeScript)="changeScript.emit($event)">
</tb-rule-node-config>
<div formGroupName="additionalInfo" fxLayout="column" class="description-block">
<mat-form-field class="mat-block">
<mat-label translate>rulenode.rule-node-description</mat-label>
<textarea matInput formControlName="description" rows="1"></textarea>
</mat-form-field>
</div>
</section> </section>
</fieldset> </section>
<tb-rule-node-config #ruleNodeConfigComponent
formControlName="configuration"
[ruleNodeId]="ruleNode.ruleNodeId?.id"
[ruleChainId]="ruleChainId"
[ruleChainType]="ruleChainType"
[nodeDefinition]="ruleNode.component.configurationDescriptor.nodeDefinition"
(initRuleNode)="initRuleNode.emit($event)"
(changeScript)="changeScript.emit($event)">
</tb-rule-node-config>
<div formGroupName="additionalInfo" fxLayout="column" class="description-block">
<mat-form-field class="mat-block">
<mat-label translate>rulenode.rule-node-description</mat-label>
<textarea matInput formControlName="description" rows="1"></textarea>
</mat-form-field>
</div>
</form> </form>

View File

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChange, SimpleChanges, ViewChild } from '@angular/core'; import { Component, EventEmitter, Input, OnChanges, OnInit, Output, SimpleChanges, ViewChild } from '@angular/core';
import { PageComponent } from '@shared/components/page.component'; import { PageComponent } from '@shared/components/page.component';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { AppState } from '@core/core.state'; import { AppState } from '@core/core.state';
@ -22,11 +22,11 @@ import { UntypedFormBuilder, UntypedFormGroup, Validators } from '@angular/forms
import { FcRuleNode, RuleNodeType } from '@shared/models/rule-node.models'; import { FcRuleNode, RuleNodeType } from '@shared/models/rule-node.models';
import { EntityType } from '@shared/models/entity-type.models'; import { EntityType } from '@shared/models/entity-type.models';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { RuleChainService } from '@core/http/rule-chain.service';
import { RuleNodeConfigComponent } from './rule-node-config.component'; import { RuleNodeConfigComponent } from './rule-node-config.component';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { RuleChainType } from '@app/shared/models/rule-chain.models'; import { RuleChainType } from '@app/shared/models/rule-chain.models';
import { ComponentClusteringMode } from '@shared/models/component-descriptor.models'; import { ComponentClusteringMode } from '@shared/models/component-descriptor.models';
import { coerceBoolean } from '@shared/decorators/coercion';
@Component({ @Component({
selector: 'tb-rule-node', selector: 'tb-rule-node',
@ -47,12 +47,11 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O
ruleChainType: RuleChainType; ruleChainType: RuleChainType;
@Input() @Input()
isEdit: boolean; @coerceBoolean()
disabled = false;
@Input()
isReadOnly: boolean;
@Input() @Input()
@coerceBoolean()
isAdd = false; isAdd = false;
@Output() @Output()
@ -70,7 +69,6 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O
constructor(protected store: Store<AppState>, constructor(protected store: Store<AppState>,
private fb: UntypedFormBuilder, private fb: UntypedFormBuilder,
private ruleChainService: RuleChainService,
private router: Router) { private router: Router) {
super(store); super(store);
this.ruleNodeFormGroup = this.fb.group({}); this.ruleNodeFormGroup = this.fb.group({});
@ -99,6 +97,9 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O
} else { } else {
this.ruleNodeFormGroup = this.fb.group({}); this.ruleNodeFormGroup = this.fb.group({});
} }
if (this.disabled) {
this.ruleNodeFormGroup.disable({emitEvent: false});
}
} }
private updateRuleNode() { private updateRuleNode() {
@ -108,6 +109,9 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O
} }
ngOnInit(): void { ngOnInit(): void {
if (this.disabled) {
this.ruleNodeFormGroup.disable({emitEvent: false});
}
} }
ngOnChanges(changes: SimpleChanges): void { ngOnChanges(changes: SimpleChanges): void {
@ -119,17 +123,6 @@ export class RuleNodeDetailsComponent extends PageComponent implements OnInit, O
} }
} }
} }
this.disableControl(changes.isEdit, changes.isReadOnly);
}
private disableControl(isEdit: SimpleChange, isReadOnly: SimpleChange) {
if (isEdit.currentValue !== isEdit.previousValue || isReadOnly.currentValue !== isReadOnly.previousValue) {
if (!isEdit.currentValue || isReadOnly.currentValue) {
this.ruleNodeFormGroup.disable({emitEvent: false});
} else {
this.ruleNodeFormGroup.enable({emitEvent: false});
}
}
} }
validate() { validate() {

View File

@ -110,8 +110,6 @@
[ruleNode]="editingRuleNode" [ruleNode]="editingRuleNode"
[ruleChainId]="ruleChain.id?.id" [ruleChainId]="ruleChain.id?.id"
[ruleChainType]="ruleChainType" [ruleChainType]="ruleChainType"
[isEdit]="true"
[isReadOnly]="false"
(initRuleNode)="onRuleNodeInit()" (initRuleNode)="onRuleNodeInit()"
(changeScript)="switchToFirstTab()"> (changeScript)="switchToFirstTab()">
</tb-rule-node> </tb-rule-node>