Merge pull request #11220 from ArtemDzhereleiko/AD/imp/generator-node

Improvement for generator node
This commit is contained in:
Igor Kulikov 2024-09-03 15:44:00 +03:00 committed by GitHub
commit fed32e72d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 47 additions and 37 deletions

View File

@ -22,12 +22,11 @@
[required]="required" [required]="required"
[useAliasEntityTypes]="useAliasEntityTypes" [useAliasEntityTypes]="useAliasEntityTypes"
[allowedEntityTypes]="allowedEntityTypes" [allowedEntityTypes]="allowedEntityTypes"
[additionEntityTypes]="additionEntityTypes"
formControlName="entityType"> formControlName="entityType">
</tb-entity-type-select> </tb-entity-type-select>
<tb-entity-autocomplete <tb-entity-autocomplete
*ngIf="modelValue.entityType && modelValue.entityType !== AliasEntityType.CURRENT_TENANT *ngIf="modelValue.entityType && !entityTypeNullUUID.has(modelValue.entityType)"
&& modelValue.entityType !== AliasEntityType.CURRENT_USER
&& modelValue.entityType !== AliasEntityType.CURRENT_USER_OWNER"
[required]="required" [required]="required"
[entityType]="modelValue.entityType" [entityType]="modelValue.entityType"
formControlName="entityId"> formControlName="entityId">

View File

@ -15,15 +15,15 @@
/// ///
import { AfterViewInit, Component, forwardRef, Input, OnInit } from '@angular/core'; import { AfterViewInit, Component, forwardRef, Input, OnInit } 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 { 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 } 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 { NULL_UUID } from '@shared/models/id/has-uuid'; import { NULL_UUID } from '@shared/models/id/has-uuid';
import { coerceBoolean } from '@shared/decorators/coercion';
@Component({ @Component({
selector: 'tb-entity-select', selector: 'tb-entity-select',
@ -47,22 +47,24 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
@Input() @Input()
useAliasEntityTypes: boolean; useAliasEntityTypes: boolean;
private requiredValue: boolean;
get required(): boolean {
return this.requiredValue;
}
@Input() @Input()
set required(value: boolean) { @coerceBoolean()
this.requiredValue = coerceBooleanProperty(value); required: boolean;
}
@Input() @Input()
disabled: boolean; disabled: boolean;
@Input()
additionEntityTypes: {[entityType in string]: string} = {};
displayEntityTypeSelect: boolean; displayEntityTypeSelect: boolean;
AliasEntityType = AliasEntityType; AliasEntityType = AliasEntityType;
entityTypeNullUUID: Set<AliasEntityType | EntityType | string> = new Set([
AliasEntityType.CURRENT_TENANT, AliasEntityType.CURRENT_USER, AliasEntityType.CURRENT_USER_OWNER
]);
private readonly defaultEntityType: EntityType | AliasEntityType = null; private readonly defaultEntityType: EntityType | AliasEntityType = null;
private propagateChange = (v: any) => { }; private propagateChange = (v: any) => { };
@ -106,6 +108,10 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
this.updateView(this.modelValue.entityType, id); 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 { ngAfterViewInit(): void {
@ -143,9 +149,7 @@ export class EntitySelectComponent implements ControlValueAccessor, OnInit, Afte
id: this.modelValue.entityType !== entityType ? null : entityId id: this.modelValue.entityType !== entityType ? null : entityId
}; };
if (this.modelValue.entityType === AliasEntityType.CURRENT_TENANT if (this.entityTypeNullUUID.has(this.modelValue.entityType)) {
|| this.modelValue.entityType === AliasEntityType.CURRENT_USER
|| this.modelValue.entityType === AliasEntityType.CURRENT_USER_OWNER) {
this.modelValue.id = NULL_UUID; this.modelValue.id = NULL_UUID;
} else if (this.modelValue.entityType === AliasEntityType.CURRENT_CUSTOMER && !this.modelValue.id) { } else if (this.modelValue.entityType === AliasEntityType.CURRENT_CUSTOMER && !this.modelValue.id) {
this.modelValue.id = NULL_UUID; this.modelValue.id = NULL_UUID;

View File

@ -15,13 +15,13 @@
/// ///
import { AfterViewInit, Component, forwardRef, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core'; 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 { 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';
import { AliasEntityType, EntityType, entityTypeTranslations } from '@app/shared/models/entity-type.models'; import { AliasEntityType, EntityType, entityTypeTranslations } from '@app/shared/models/entity-type.models';
import { EntityService } from '@core/http/entity.service'; import { EntityService } from '@core/http/entity.service';
import { coerceBooleanProperty } from '@angular/cdk/coercion'; import { coerceBoolean } from '@shared/decorators/coercion';
@Component({ @Component({
selector: 'tb-entity-type-select', selector: 'tb-entity-type-select',
@ -48,28 +48,21 @@ export class EntityTypeSelectComponent implements ControlValueAccessor, OnInit,
@Input() @Input()
filterAllowedEntityTypes = true; filterAllowedEntityTypes = true;
private showLabelValue: boolean;
get showLabel(): boolean {
return this.showLabelValue;
}
@Input() @Input()
set showLabel(value: boolean) { @coerceBoolean()
this.showLabelValue = coerceBooleanProperty(value); showLabel: boolean;
}
private requiredValue: boolean;
get required(): boolean {
return this.requiredValue;
}
@Input() @Input()
set required(value: boolean) { @coerceBoolean()
this.requiredValue = coerceBooleanProperty(value); required: boolean;
}
@Input() @Input()
disabled: boolean; disabled: boolean;
entityTypes: Array<EntityType | AliasEntityType>; @Input()
additionEntityTypes: {[key in string]: string} = {};
entityTypes: Array<EntityType | AliasEntityType | string>;
private propagateChange = (v: any) => { }; private propagateChange = (v: any) => { };
@ -93,6 +86,10 @@ export class EntityTypeSelectComponent implements ControlValueAccessor, OnInit,
this.entityTypes = this.filterAllowedEntityTypes this.entityTypes = this.filterAllowedEntityTypes
? this.entityService.prepareAllowedEntityTypesList(this.allowedEntityTypes, this.useAliasEntityTypes) ? this.entityService.prepareAllowedEntityTypesList(this.allowedEntityTypes, this.useAliasEntityTypes)
: this.allowedEntityTypes; : this.allowedEntityTypes;
const additionEntityTypes = Object.keys(this.additionEntityTypes);
if (additionEntityTypes.length > 0) {
this.entityTypes.push(...additionEntityTypes);
}
this.entityTypeFormGroup.get('entityType').valueChanges.subscribe( this.entityTypeFormGroup.get('entityType').valueChanges.subscribe(
(value) => { (value) => {
let modelValue; let modelValue;
@ -113,6 +110,10 @@ export class EntityTypeSelectComponent implements ControlValueAccessor, OnInit,
if (propName === 'allowedEntityTypes') { if (propName === 'allowedEntityTypes') {
this.entityTypes = this.filterAllowedEntityTypes ? this.entityTypes = this.filterAllowedEntityTypes ?
this.entityService.prepareAllowedEntityTypesList(this.allowedEntityTypes, this.useAliasEntityTypes) : this.allowedEntityTypes; 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; const currentEntityType: EntityType | AliasEntityType = this.entityTypeFormGroup.get('entityType').value;
if (currentEntityType && !this.entityTypes.includes(currentEntityType)) { if (currentEntityType && !this.entityTypes.includes(currentEntityType)) {
this.entityTypeFormGroup.get('entityType').patchValue(null, {emitEvent: true}); this.entityTypeFormGroup.get('entityType').patchValue(null, {emitEvent: true});
@ -152,7 +153,9 @@ export class EntityTypeSelectComponent implements ControlValueAccessor, OnInit,
} }
displayEntityTypeFn(entityType?: EntityType | AliasEntityType | null): string | undefined { 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); return this.translate.instant(entityTypeTranslations.get(entityType as EntityType).type);
} else { } else {
return ''; return '';

View File

@ -24,6 +24,7 @@
{{ functionLabel }} {{ functionLabel }}
</label> </label>
<span fxFlex></span> <span fxFlex></span>
<ng-content select="[toolbarPrefixButton]"></ng-content>
<button type='button' *ngIf="!disabled" mat-button class="tidy" (click)="beautifyJs()"> <button type='button' *ngIf="!disabled" mat-button class="tidy" (click)="beautifyJs()">
{{'js-func.tidy' | translate }} {{'js-func.tidy' | translate }}
</button> </button>

View File

@ -17,9 +17,11 @@
--> -->
<div [formGroup]="scriptLangFormGroup" fxLayout="row" fxLayoutAlign="center"> <div [formGroup]="scriptLangFormGroup" fxLayout="row" fxLayoutAlign="center">
<mat-button-toggle-group class="tb-script-lang-toggle-group" <mat-button-toggle-group class="tb-script-lang-toggle-group"
style="width: 320px;" formControlName="scriptLang"
formControlName="scriptLang" aria-label="Script language"> aria-label="Script language">
<mat-button-toggle fxFlex value="{{ scriptLanguage.TBEL }}">{{ 'rulenode.script-lang-tbel' | translate }}</mat-button-toggle> <mat-button-toggle fxFlex value="{{ scriptLanguage.TBEL }}">{{ 'rulenode.script-lang-tbel' | translate }}</mat-button-toggle>
<mat-button-toggle fxFlex value="{{ scriptLanguage.JS }}">{{ 'rulenode.script-lang-java-script' | translate }}</mat-button-toggle> <mat-button-toggle fxFlex value="{{ scriptLanguage.JS }}">
{{ 'rulenode.script-lang-java-script' | translate }}
</mat-button-toggle>
</mat-button-toggle-group> </mat-button-toggle-group>
</div> </div>

View File

@ -14,6 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
.mat-button-toggle-group.tb-script-lang-toggle-group { .mat-button-toggle-group.tb-script-lang-toggle-group {
width: 320px;
&.mat-button-toggle-group-appearance-standard { &.mat-button-toggle-group-appearance-standard {
border: none; border: none;
border-radius: 18px; border-radius: 18px;

View File

@ -15,7 +15,7 @@
/// ///
import { Component, forwardRef, Input, OnInit, ViewEncapsulation } from '@angular/core'; import { Component, forwardRef, Input, OnInit, ViewEncapsulation } from '@angular/core';
import { ControlValueAccessor, UntypedFormBuilder, UntypedFormGroup, NG_VALUE_ACCESSOR } from '@angular/forms'; import { ControlValueAccessor, NG_VALUE_ACCESSOR, UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
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';