Browse Source

Merge pull request #14655 from vvlladd28/bug/cf/edit-page

Fixed edit cf and refactor cf models and service
pull/14659/head
Vladyslav Prykhodko 9 months ago
committed by GitHub
parent
commit
0dd89f8ddd
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 16
      ui-ngx/src/app/core/http/calculated-fields.service.ts
  2. 43
      ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table-config.ts
  3. 50
      ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts
  4. 11
      ui-ngx/src/app/shared/components/entity/entity-subtype-list.component.ts
  5. 2
      ui-ngx/src/app/shared/models/calculated-field.models.ts

16
ui-ngx/src/app/core/http/calculated-fields.service.ts

@ -15,17 +15,13 @@
/// ///
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { import { defaultHttpOptionsFromConfig, defaultHttpOptionsFromParams, RequestConfig } from './http-utils';
createDefaultHttpOptions,
defaultHttpOptionsFromConfig,
defaultHttpOptionsFromParams,
RequestConfig
} from './http-utils';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { PageData } from '@shared/models/page/page-data'; import { PageData } from '@shared/models/page/page-data';
import { import {
CalculatedField, CalculatedField,
CalculatedFieldInfo,
CalculatedFieldsQuery, CalculatedFieldsQuery,
CalculatedFieldTestScriptInputParams, CalculatedFieldTestScriptInputParams,
CalculatedFieldType CalculatedFieldType
@ -56,11 +52,11 @@ export class CalculatedFieldsService {
return this.http.delete<boolean>(`/api/calculatedField/${calculatedFieldId}`, defaultHttpOptionsFromConfig(config)); return this.http.delete<boolean>(`/api/calculatedField/${calculatedFieldId}`, defaultHttpOptionsFromConfig(config));
} }
public getCalculatedFieldsFilter(pageLink: PageLink, query: CalculatedFieldsQuery, config?: RequestConfig): Observable<PageData<CalculatedField>> { public getCalculatedFields(pageLink: PageLink, query: CalculatedFieldsQuery, config?: RequestConfig): Observable<PageData<CalculatedFieldInfo>> {
return this.http.get<PageData<CalculatedField>>(`/api/calculatedFields${pageLink.toQuery()}`, defaultHttpOptionsFromParams(query, config)); return this.http.get<PageData<CalculatedFieldInfo>>(`/api/calculatedFields${pageLink.toQuery()}`, defaultHttpOptionsFromParams(query, config));
} }
public getCalculatedFields({ entityType, id }: EntityId, pageLink: PageLink, type?: CalculatedFieldType, config?: RequestConfig): Observable<PageData<CalculatedField>> { public getCalculatedFieldsByEntityId({ entityType, id }: EntityId, pageLink: PageLink, type?: CalculatedFieldType, config?: RequestConfig): Observable<PageData<CalculatedField>> {
return this.http.get<PageData<CalculatedField>>(`/api/${entityType}/${id}/calculatedFields${pageLink.toQuery()}`, defaultHttpOptionsFromParams({type} , config)); return this.http.get<PageData<CalculatedField>>(`/api/${entityType}/${id}/calculatedFields${pageLink.toQuery()}`, defaultHttpOptionsFromParams({type} , config));
} }
@ -72,7 +68,7 @@ export class CalculatedFieldsService {
return this.http.get<CalculatedFieldEventBody>(`/api/calculatedField/${id}/debug`, defaultHttpOptionsFromConfig(config)); return this.http.get<CalculatedFieldEventBody>(`/api/calculatedField/${id}/debug`, defaultHttpOptionsFromConfig(config));
} }
public getAlarmRuleNames(pageLink: PageLink, type: CalculatedFieldType, config?: RequestConfig): Observable<PageData<string>> { public getCalculatedFieldNames(pageLink: PageLink, type: CalculatedFieldType, config?: RequestConfig): Observable<PageData<string>> {
return this.http.get<PageData<string>>(`/api/calculatedFields/names${pageLink.toQuery()}`, defaultHttpOptionsFromParams({type}, config)); return this.http.get<PageData<string>>(`/api/calculatedFields/names${pageLink.toQuery()}`, defaultHttpOptionsFromParams({type}, config));
} }
} }

43
ui-ngx/src/app/modules/home/components/alarm-rules/alarm-rules-table-config.ts

@ -43,6 +43,7 @@ import {
CalculatedField, CalculatedField,
CalculatedFieldAlarmRule, CalculatedFieldAlarmRule,
CalculatedFieldEventArguments, CalculatedFieldEventArguments,
CalculatedFieldInfo,
CalculatedFieldsQuery, CalculatedFieldsQuery,
CalculatedFieldType, CalculatedFieldType,
getCalculatedFieldArgumentsEditorCompleter, getCalculatedFieldArgumentsEditorCompleter,
@ -67,12 +68,14 @@ import {
CalculatedFieldTestScriptDialogData CalculatedFieldTestScriptDialogData
} from "@home/components/calculated-fields/components/test-dialog/calculated-field-script-test-dialog.component"; } from "@home/components/calculated-fields/components/test-dialog/calculated-field-script-test-dialog.component";
export class AlarmRulesTableConfig extends EntityTableConfig<any> { type AlarmRuleTableEntity = CalculatedField | CalculatedFieldInfo;
export class AlarmRulesTableConfig extends EntityTableConfig<AlarmRuleTableEntity> {
readonly tenantId = getCurrentAuthUser(this.store).tenantId; readonly tenantId = getCurrentAuthUser(this.store).tenantId;
additionalDebugActionConfig = { additionalDebugActionConfig = {
title: this.translate.instant('action.see-debug-events'), title: this.translate.instant('action.see-debug-events'),
action: (calculatedField: CalculatedField) => this.openDebugEventsDialog.call(this, calculatedField), action: (calculatedField: AlarmRuleTableEntity) => this.openDebugEventsDialog.call(this, calculatedField),
}; };
alarmRuleFilterConfig: CalculatedFieldsQuery; alarmRuleFilterConfig: CalculatedFieldsQuery;
@ -81,11 +84,11 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
private translate: TranslateService, private translate: TranslateService,
private dialog: MatDialog, private dialog: MatDialog,
private datePipe: DatePipe, private datePipe: DatePipe,
public entityId: EntityId = null, private entityId: EntityId = null,
private store: Store<AppState>, private store: Store<AppState>,
private destroyRef: DestroyRef, private destroyRef: DestroyRef,
private renderer: Renderer2, private renderer: Renderer2,
public entityName: string, private entityName: string,
private ownerId: EntityId = null, private ownerId: EntityId = null,
private importExportService: ImportExportService, private importExportService: ImportExportService,
private entityDebugSettingsService: EntityDebugSettingsService, private entityDebugSettingsService: EntityDebugSettingsService,
@ -118,7 +121,7 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
this.entitiesFetchFunction = (pageLink: PageLink) => this.fetchCalculatedFields(pageLink); this.entitiesFetchFunction = (pageLink: PageLink) => this.fetchCalculatedFields(pageLink);
this.addEntity = this.getCalculatedAlarmDialog.bind(this); this.addEntity = this.getCalculatedAlarmDialog.bind(this);
this.deleteEntityTitle = (field: CalculatedField) => this.translate.instant('alarm-rule.delete-title', {title: field.name}); this.deleteEntityTitle = (field) => this.translate.instant('alarm-rule.delete-title', {title: field.name});
this.deleteEntityContent = () => this.translate.instant('alarm-rule.delete-text'); this.deleteEntityContent = () => this.translate.instant('alarm-rule.delete-text');
this.deleteEntitiesTitle = count => this.translate.instant('alarm-rule.delete-multiple-title', {count}); this.deleteEntitiesTitle = count => this.translate.instant('alarm-rule.delete-multiple-title', {count});
this.deleteEntitiesContent = () => this.translate.instant('alarm-rule.delete-multiple-text'); this.deleteEntitiesContent = () => this.translate.instant('alarm-rule.delete-multiple-text');
@ -143,10 +146,10 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
this.columns.push(new EntityTableColumn<CalculatedFieldAlarmRule>('name', 'alarm-rule.alarm-type', '33%', this.columns.push(new EntityTableColumn<CalculatedFieldAlarmRule>('name', 'alarm-rule.alarm-type', '33%',
entity => this.utilsService.customTranslation(entity.name, entity.name))); entity => this.utilsService.customTranslation(entity.name, entity.name)));
if (this.pageMode) { if (this.pageMode) {
this.columns.push(new EntityTableColumn<CalculatedFieldAlarmRule>('entityType', 'entity.entity-type', '10%', this.columns.push(new EntityTableColumn<CalculatedFieldInfo>('entityType', 'entity.entity-type', '10%',
entity => this.translate.instant(entityTypeTranslations.get(entity.entityId.entityType).type))); entity => this.translate.instant(entityTypeTranslations.get(entity.entityId.entityType).type)));
this.columns.push(new EntityLinkTableColumn<CalculatedFieldAlarmRule>('entityName', 'entity.entity', '33%', this.columns.push(new EntityLinkTableColumn<CalculatedFieldInfo>('entityName', 'entity.entity', '33%',
entity => this.utilsService.customTranslation(entity['entityName'], entity['entityName']), entity => this.utilsService.customTranslation(entity.entityName, entity.entityName),
entity => getEntityDetailsPageURL(entity.entityId?.id, entity.entityId?.entityType as EntityType), false)); entity => getEntityDetailsPageURL(entity.entityId?.id, entity.entityId?.entityType as EntityType), false));
} }
this.columns.push(new EntityTableColumn<CalculatedFieldAlarmRule>('createRule', 'alarm-rule.severities', this.pageMode ? '23%' : '67%', this.columns.push(new EntityTableColumn<CalculatedFieldAlarmRule>('createRule', 'alarm-rule.severities', this.pageMode ? '23%' : '67%',
@ -193,13 +196,13 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
); );
} }
fetchCalculatedFields(pageLink: PageLink): Observable<PageData<CalculatedField>> { fetchCalculatedFields(pageLink: PageLink): Observable<PageData<AlarmRuleTableEntity>> {
return this.pageMode ? return this.pageMode ?
this.calculatedFieldsService.getCalculatedFieldsFilter(pageLink, {types: [CalculatedFieldType.ALARM], ...this.alarmRuleFilterConfig}) : this.calculatedFieldsService.getCalculatedFields(pageLink, {types: [CalculatedFieldType.ALARM], ...this.alarmRuleFilterConfig}) :
this.calculatedFieldsService.getCalculatedFields(this.entityId, pageLink, CalculatedFieldType.ALARM); this.calculatedFieldsService.getCalculatedFieldsByEntityId(this.entityId, pageLink, CalculatedFieldType.ALARM);
} }
onOpenDebugConfig($event: Event, calculatedField: CalculatedField): void { onOpenDebugConfig($event: Event, calculatedField: AlarmRuleTableEntity): void {
$event?.stopPropagation(); $event?.stopPropagation();
const { debugSettings = {}, id } = calculatedField; const { debugSettings = {}, id } = calculatedField;
const additionalActionConfig = { const additionalActionConfig = {
@ -224,7 +227,7 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
}, $event.target as Element); }, $event.target as Element);
} }
private editCalculatedField($event: Event, calculatedField: CalculatedField, isDirty = false): void { private editCalculatedField($event: Event, calculatedField: AlarmRuleTableEntity, isDirty = false): void {
$event?.stopPropagation(); $event?.stopPropagation();
this.getCalculatedAlarmDialog(calculatedField, 'action.apply', isDirty) this.getCalculatedAlarmDialog(calculatedField, 'action.apply', isDirty)
.subscribe((res) => { .subscribe((res) => {
@ -234,11 +237,12 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
}); });
} }
private copyCalculatedField($event: Event, calculatedField: CalculatedField, isDirty = false): void { private copyCalculatedField($event: Event, calculatedField: AlarmRuleTableEntity, isDirty = false): void {
$event?.stopPropagation(); $event?.stopPropagation();
const copyCalculatedAlarmRule = deepClone(calculatedField); const copyCalculatedAlarmRule = deepClone(calculatedField);
if (this.pageMode) { if (this.pageMode) {
copyCalculatedAlarmRule.entityId = null; copyCalculatedAlarmRule.entityId = null;
delete (copyCalculatedAlarmRule as CalculatedFieldInfo).entityName;
} }
delete copyCalculatedAlarmRule.id; delete copyCalculatedAlarmRule.id;
this.getCalculatedAlarmDialog(copyCalculatedAlarmRule, 'action.apply', isDirty) this.getCalculatedAlarmDialog(copyCalculatedAlarmRule, 'action.apply', isDirty)
@ -249,8 +253,9 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
}); });
} }
private getCalculatedAlarmDialog(value?: CalculatedField, buttonTitle = 'action.add', isDirty = false): Observable<CalculatedField> { private getCalculatedAlarmDialog(value?: AlarmRuleTableEntity, buttonTitle = 'action.add', isDirty = false): Observable<CalculatedField> {
const entityId = this.entityId || value?.entityId; const entityId = this.entityId || value?.entityId;
const entityName = this.entityName || (value as CalculatedFieldInfo)?.entityName;
return this.dialog.open<AlarmRuleDialogComponent, AlarmRuleDialogData, CalculatedField>(AlarmRuleDialogComponent, { return this.dialog.open<AlarmRuleDialogComponent, AlarmRuleDialogData, CalculatedField>(AlarmRuleDialogComponent, {
disableClose: true, disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
@ -258,8 +263,8 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
value, value,
buttonTitle, buttonTitle,
entityId, entityId,
entityName,
tenantId: this.tenantId, tenantId: this.tenantId,
entityName: this.entityName,
ownerId: this.ownerId ?? {entityType: EntityType.TENANT, id: this.tenantId}, ownerId: this.ownerId ?? {entityType: EntityType.TENANT, id: this.tenantId},
additionalDebugActionConfig: this.additionalDebugActionConfig, additionalDebugActionConfig: this.additionalDebugActionConfig,
isDirty, isDirty,
@ -271,7 +276,7 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
.pipe(filter(Boolean)); .pipe(filter(Boolean));
} }
private openDebugEventsDialog($event: Event, calculatedField: CalculatedField): void { private openDebugEventsDialog($event: Event, calculatedField: AlarmRuleTableEntity): void {
$event?.stopPropagation(); $event?.stopPropagation();
this.dialog.open<EventsDialogComponent, EventsDialogData, null>(EventsDialogComponent, { this.dialog.open<EventsDialogComponent, EventsDialogData, null>(EventsDialogComponent, {
disableClose: true, disableClose: true,
@ -290,7 +295,7 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
.subscribe(); .subscribe();
} }
private exportAlarmRule($event: Event, calculatedField: CalculatedField): void { private exportAlarmRule($event: Event, calculatedField: AlarmRuleTableEntity): void {
$event?.stopPropagation(); $event?.stopPropagation();
this.importExportService.exportCalculatedField(calculatedField.id.id); this.importExportService.exportCalculatedField(calculatedField.id.id);
} }
@ -343,7 +348,7 @@ export class AlarmRulesTableConfig extends EntityTableConfig<any> {
).subscribe(() => this.updateData()); ).subscribe(() => this.updateData());
} }
private getTestScriptDialog(calculatedField: CalculatedField, expression: string, argumentsObj?: CalculatedFieldEventArguments, openCalculatedFieldEdit = true): Observable<string> { private getTestScriptDialog(calculatedField: AlarmRuleTableEntity, expression: string, argumentsObj?: CalculatedFieldEventArguments, openCalculatedFieldEdit = true): Observable<string> {
if (calculatedField.type === CalculatedFieldType.ALARM) { if (calculatedField.type === CalculatedFieldType.ALARM) {
const resultArguments = Object.keys(calculatedField.configuration.arguments).reduce((acc, key) => { const resultArguments = Object.keys(calculatedField.configuration.arguments).reduce((acc, key) => {
const type = calculatedField.configuration.arguments[key].refEntityKey.type; const type = calculatedField.configuration.arguments[key].refEntityKey.type;

50
ui-ngx/src/app/modules/home/components/calculated-fields/calculated-fields-table-config.ts

@ -40,8 +40,8 @@ import {
ArgumentEntityType, ArgumentEntityType,
ArgumentType, ArgumentType,
CalculatedField, CalculatedField,
CalculatedFieldAlarmRule,
CalculatedFieldEventArguments, CalculatedFieldEventArguments,
CalculatedFieldInfo,
CalculatedFieldScriptConfiguration, CalculatedFieldScriptConfiguration,
CalculatedFieldsQuery, CalculatedFieldsQuery,
CalculatedFieldType, CalculatedFieldType,
@ -68,12 +68,14 @@ import {
CalculatedFieldsHeaderComponent CalculatedFieldsHeaderComponent
} from '@home/components/calculated-fields/table-header/calculated-fields-header.component'; } from '@home/components/calculated-fields/table-header/calculated-fields-header.component';
export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedField> { type CalculatedFieldsTableEntity = CalculatedField | CalculatedFieldInfo;
export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFieldsTableEntity> {
readonly tenantId = getCurrentAuthUser(this.store).tenantId; readonly tenantId = getCurrentAuthUser(this.store).tenantId;
additionalDebugActionConfig = { additionalDebugActionConfig = {
title: this.translate.instant('action.see-debug-events'), title: this.translate.instant('action.see-debug-events'),
action: (calculatedField: CalculatedField) => this.openDebugEventsDialog.call(this, null, calculatedField), action: (calculatedField: CalculatedFieldsTableEntity) => this.openDebugEventsDialog.call(this, null, calculatedField),
}; };
calculatedFieldFilterConfig: CalculatedFieldsQuery; calculatedFieldFilterConfig: CalculatedFieldsQuery;
@ -82,11 +84,11 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
private translate: TranslateService, private translate: TranslateService,
private dialog: MatDialog, private dialog: MatDialog,
private datePipe: DatePipe, private datePipe: DatePipe,
public entityId: EntityId = null, private entityId: EntityId = null,
private store: Store<AppState>, private store: Store<AppState>,
private destroyRef: DestroyRef, private destroyRef: DestroyRef,
private renderer: Renderer2, private renderer: Renderer2,
public entityName: string, private entityName: string,
private ownerId: EntityId = null, private ownerId: EntityId = null,
private importExportService: ImportExportService, private importExportService: ImportExportService,
private entityDebugSettingsService: EntityDebugSettingsService, private entityDebugSettingsService: EntityDebugSettingsService,
@ -110,7 +112,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
this.entitiesFetchFunction = (pageLink: PageLink) => this.fetchCalculatedFields(pageLink); this.entitiesFetchFunction = (pageLink: PageLink) => this.fetchCalculatedFields(pageLink);
this.addEntity = this.getCalculatedFieldDialog.bind(this); this.addEntity = this.getCalculatedFieldDialog.bind(this);
this.deleteEntityTitle = (field: CalculatedField) => this.translate.instant('calculated-fields.delete-title', {title: field.name}); this.deleteEntityTitle = (field) => this.translate.instant('calculated-fields.delete-title', {title: field.name});
this.deleteEntityContent = () => this.translate.instant('calculated-fields.delete-text'); this.deleteEntityContent = () => this.translate.instant('calculated-fields.delete-text');
this.deleteEntitiesTitle = count => this.translate.instant('calculated-fields.delete-multiple-title', {count}); this.deleteEntitiesTitle = count => this.translate.instant('calculated-fields.delete-multiple-title', {count});
this.deleteEntitiesContent = () => this.translate.instant('calculated-fields.delete-multiple-text'); this.deleteEntitiesContent = () => this.translate.instant('calculated-fields.delete-multiple-text');
@ -136,10 +138,10 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
this.columns.push(new EntityTableColumn<CalculatedField>('name', 'common.name', this.pageMode ? '33%' : '60%', this.columns.push(new EntityTableColumn<CalculatedField>('name', 'common.name', this.pageMode ? '33%' : '60%',
entity => this.utilsService.customTranslation(entity.name, entity.name))); entity => this.utilsService.customTranslation(entity.name, entity.name)));
if (this.pageMode) { if (this.pageMode) {
this.columns.push(new EntityTableColumn<CalculatedFieldAlarmRule>('entityType', 'entity.entity-type', '10%', this.columns.push(new EntityTableColumn<CalculatedFieldInfo>('entityType', 'entity.entity-type', '10%',
entity => this.translate.instant(entityTypeTranslations.get(entity.entityId.entityType).type))); entity => this.translate.instant(entityTypeTranslations.get(entity.entityId.entityType).type)));
this.columns.push(new EntityLinkTableColumn<CalculatedFieldAlarmRule>('entityName', 'entity.entity', '33%', this.columns.push(new EntityLinkTableColumn<CalculatedFieldInfo>('entityName', 'entity.entity', '33%',
entity => this.utilsService.customTranslation(entity['entityName'], entity['entityName']), entity => this.utilsService.customTranslation(entity.entityName, entity.entityName),
entity => getEntityDetailsPageURL(entity.entityId?.id, entity.entityId?.entityType as EntityType), false)); entity => getEntityDetailsPageURL(entity.entityId?.id, entity.entityId?.entityType as EntityType), false));
} }
this.columns.push(new EntityTableColumn<CalculatedField>('type', 'common.type', this.pageMode ? '23%' : '40%', entity => this.translate.instant(CalculatedFieldTypeTranslations.get(entity.type).name), () => ({whiteSpace: 'nowrap' }))); this.columns.push(new EntityTableColumn<CalculatedField>('type', 'common.type', this.pageMode ? '23%' : '40%', entity => this.translate.instant(CalculatedFieldTypeTranslations.get(entity.type).name), () => ({whiteSpace: 'nowrap' })));
@ -180,13 +182,13 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
); );
} }
fetchCalculatedFields(pageLink: PageLink): Observable<PageData<CalculatedField>> { fetchCalculatedFields(pageLink: PageLink): Observable<PageData<CalculatedFieldsTableEntity>> {
return this.pageMode ? return this.pageMode ?
this.calculatedFieldsService.getCalculatedFieldsFilter(pageLink, this.calculatedFieldFilterConfig): this.calculatedFieldsService.getCalculatedFields(pageLink, this.calculatedFieldFilterConfig):
this.calculatedFieldsService.getCalculatedFields(this.entityId, pageLink); this.calculatedFieldsService.getCalculatedFieldsByEntityId(this.entityId, pageLink);
} }
onOpenDebugConfig($event: Event, calculatedField: CalculatedField): void { onOpenDebugConfig($event: Event, calculatedField: CalculatedFieldsTableEntity): void {
$event?.stopPropagation(); $event?.stopPropagation();
const { debugSettings = {}, id } = calculatedField; const { debugSettings = {}, id } = calculatedField;
const additionalActionConfig = { const additionalActionConfig = {
@ -210,7 +212,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
}, $event.target as Element); }, $event.target as Element);
} }
private editCalculatedField($event: Event, calculatedField: CalculatedField, isDirty = false): void { private editCalculatedField($event: Event, calculatedField: CalculatedFieldsTableEntity, isDirty = false): void {
$event?.stopPropagation(); $event?.stopPropagation();
this.getCalculatedFieldDialog(calculatedField, 'action.apply', isDirty) this.getCalculatedFieldDialog(calculatedField, 'action.apply', isDirty)
.subscribe((res) => { .subscribe((res) => {
@ -220,8 +222,9 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
}); });
} }
private getCalculatedFieldDialog(value?: CalculatedField, buttonTitle = 'action.add', isDirty = false): Observable<CalculatedField> { private getCalculatedFieldDialog(value?: CalculatedFieldsTableEntity, buttonTitle = 'action.add', isDirty = false): Observable<CalculatedField> {
const entityId = this.entityId || value?.entityId; const entityId = this.entityId || value?.entityId;
const entityName = this.entityName || (value as CalculatedFieldInfo)?.entityName;
return this.dialog.open<CalculatedFieldDialogComponent, CalculatedFieldDialogData, CalculatedField>(CalculatedFieldDialogComponent, { return this.dialog.open<CalculatedFieldDialogComponent, CalculatedFieldDialogData, CalculatedField>(CalculatedFieldDialogComponent, {
disableClose: true, disableClose: true,
panelClass: ['tb-dialog', 'tb-fullscreen-dialog'], panelClass: ['tb-dialog', 'tb-fullscreen-dialog'],
@ -229,8 +232,8 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
value, value,
buttonTitle, buttonTitle,
entityId, entityId,
entityName,
tenantId: this.tenantId, tenantId: this.tenantId,
entityName: this.entityName,
ownerId: this.ownerId, ownerId: this.ownerId,
additionalDebugActionConfig: this.additionalDebugActionConfig, additionalDebugActionConfig: this.additionalDebugActionConfig,
getTestScriptDialogFn: this.getTestScriptDialog.bind(this), getTestScriptDialogFn: this.getTestScriptDialog.bind(this),
@ -242,7 +245,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
.pipe(filter(Boolean)); .pipe(filter(Boolean));
} }
private openDebugEventsDialog($event: Event, calculatedField: CalculatedField): void { private openDebugEventsDialog($event: Event, calculatedField: CalculatedFieldsTableEntity): void {
$event?.stopPropagation(); $event?.stopPropagation();
const debugActionEnabledFn = (event: DebugEvent) => { const debugActionEnabledFn = (event: DebugEvent) => {
return (calculatedField.type === CalculatedFieldType.SCRIPT || return (calculatedField.type === CalculatedFieldType.SCRIPT ||
@ -274,19 +277,20 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
.subscribe(); .subscribe();
} }
private exportCalculatedField($event: Event, calculatedField: CalculatedField): void { private exportCalculatedField($event: Event, calculatedField: CalculatedFieldsTableEntity): void {
$event?.stopPropagation(); $event?.stopPropagation();
this.importExportService.exportCalculatedField(calculatedField.id.id); this.importExportService.exportCalculatedField(calculatedField.id.id);
} }
private copyCalculatedField($event: Event, calculatedField: CalculatedField): void { private copyCalculatedField($event: Event, calculatedField: CalculatedField): void {
$event?.stopPropagation(); $event?.stopPropagation();
const copyCalculatedAlarmRule = deepClone(calculatedField); const copyCalculatedField = deepClone(calculatedField);
if (this.pageMode) { if (this.pageMode) {
copyCalculatedAlarmRule.entityId = null; copyCalculatedField.entityId = null;
delete (copyCalculatedField as CalculatedFieldInfo).entityName;
} }
delete copyCalculatedAlarmRule.id; delete copyCalculatedField.id;
this.getCalculatedFieldDialog(copyCalculatedAlarmRule, 'action.apply', false) this.getCalculatedFieldDialog(copyCalculatedField, 'action.apply', false)
.subscribe((res) => { .subscribe((res) => {
if (res) { if (res) {
this.updateData(); this.updateData();
@ -350,7 +354,7 @@ export class CalculatedFieldsTableConfig extends EntityTableConfig<CalculatedFie
).subscribe(() => this.updateData()); ).subscribe(() => this.updateData());
} }
private getTestScriptDialog(calculatedField: CalculatedField, argumentsObj?: CalculatedFieldEventArguments, openCalculatedFieldEdit = true, expression?: string): Observable<string> { private getTestScriptDialog(calculatedField: CalculatedFieldsTableEntity, argumentsObj?: CalculatedFieldEventArguments, openCalculatedFieldEdit = true, expression?: string): Observable<string> {
if ( if (
calculatedField.type === CalculatedFieldType.SCRIPT || calculatedField.type === CalculatedFieldType.SCRIPT ||
calculatedField.type === CalculatedFieldType.RELATED_ENTITIES_AGGREGATION || calculatedField.type === CalculatedFieldType.RELATED_ENTITIES_AGGREGATION ||

11
ui-ngx/src/app/shared/components/entity/entity-subtype-list.component.ts

@ -14,7 +14,7 @@
/// limitations under the License. /// limitations under the License.
/// ///
import { AfterViewInit, Component, ElementRef, forwardRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { Component, ElementRef, forwardRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core';
import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms'; import { ControlValueAccessor, FormBuilder, FormGroup, NG_VALUE_ACCESSOR, Validators } from '@angular/forms';
import { Observable, ReplaySubject, Subscription, throwError } from 'rxjs'; import { Observable, ReplaySubject, Subscription, throwError } from 'rxjs';
import { debounceTime, map, mergeMap, share } from 'rxjs/operators'; import { debounceTime, map, mergeMap, share } from 'rxjs/operators';
@ -46,7 +46,7 @@ import { CalculatedFieldsService } from "@core/http/calculated-fields.service";
} }
] ]
}) })
export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit, AfterViewInit, OnDestroy { export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit, OnDestroy {
entitySubtypeListFormGroup: FormGroup; entitySubtypeListFormGroup: FormGroup;
@ -119,7 +119,7 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit,
private dirty = false; private dirty = false;
private propagateChange = (v: any) => { }; private propagateChange = (_v: any) => { };
private hasPageDataEntitySubTypes = new Set<EntityType>([ private hasPageDataEntitySubTypes = new Set<EntityType>([
EntityType.ALARM, EntityType.ALARM,
@ -225,9 +225,6 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit,
); );
} }
ngAfterViewInit(): void {
}
ngOnDestroy(): void { ngOnDestroy(): void {
if (this.broadcastSubscription) { if (this.broadcastSubscription) {
this.broadcastSubscription.unsubscribe(); this.broadcastSubscription.unsubscribe();
@ -335,7 +332,7 @@ export class EntitySubTypeListComponent implements ControlValueAccessor, OnInit,
subTypesPagesObservable = this.alarmService.getAlarmTypes(pageLink, {ignoreLoading: true}); subTypesPagesObservable = this.alarmService.getAlarmTypes(pageLink, {ignoreLoading: true});
break; break;
case EntityType.CALCULATED_FIELD: case EntityType.CALCULATED_FIELD:
subTypesCfPagesObservable = this.calculatedFieldsService.getAlarmRuleNames(pageLink, CalculatedFieldType.ALARM, {ignoreLoading: true}); subTypesCfPagesObservable = this.calculatedFieldsService.getCalculatedFieldNames(pageLink, CalculatedFieldType.ALARM, {ignoreLoading: true});
} }
if (subTypesPagesObservable) { if (subTypesPagesObservable) {
this.entitySubtypes = subTypesPagesObservable.pipe( this.entitySubtypes = subTypesPagesObservable.pipe(

2
ui-ngx/src/app/shared/models/calculated-field.models.ts

@ -79,6 +79,8 @@ export type CalculatedField =
| CalculatedFieldRelatedEntityAggregation | CalculatedFieldRelatedEntityAggregation
| CalculatedFieldAlarmRule; | CalculatedFieldAlarmRule;
export type CalculatedFieldInfo = CalculatedField & {entityName: string};
export enum CalculatedFieldType { export enum CalculatedFieldType {
SIMPLE = 'SIMPLE', SIMPLE = 'SIMPLE',
SCRIPT = 'SCRIPT', SCRIPT = 'SCRIPT',

Loading…
Cancel
Save