From 56565e593b7b5f76d0a1f476e8db76c3df2b42a4 Mon Sep 17 00:00:00 2001 From: "Moises E. Puyosa" Date: Wed, 6 Dec 2023 07:07:18 -0500 Subject: [PATCH] Replace UpdateValueAction with UpdateFieldAction --- .../fields/field-logic/field-logic.manager.ts | 7 +- .../update-field/update-field.action.ts | 12 ++- .../update-value/update-value.action.ts | 91 ------------------- 3 files changed, 11 insertions(+), 99 deletions(-) delete mode 100644 core/app/core/src/lib/fields/field-logic/update-value/update-value.action.ts diff --git a/core/app/core/src/lib/fields/field-logic/field-logic.manager.ts b/core/app/core/src/lib/fields/field-logic/field-logic.manager.ts index 22cfda37e9..54a54784b4 100644 --- a/core/app/core/src/lib/fields/field-logic/field-logic.manager.ts +++ b/core/app/core/src/lib/fields/field-logic/field-logic.manager.ts @@ -34,10 +34,9 @@ import {RequiredAction} from './required/required.action'; import {UpdateBaseCurrencyAction} from './currency-conversion/update-base-currency.action'; import {UpdateCurrencyAction} from './currency-conversion/update-currency.action'; import {UpdateFlexRelateModuleAction} from './update-flex-relate-module/update-flex-relate-module.action'; -import {UpdateValueAction} from './update-value/update-value.action'; +import {UpdateFieldAction} from './update-field/update-field.action'; import {UpdateValueBackendAction} from './update-value-backend/update-value-backend.action'; import {DisplayTypeBackendAction} from './display-type-backend/display-type-backend.action'; -import {UpdateFieldAction} from './update-field/update-field.action'; @Injectable({ providedIn: 'root' @@ -59,11 +58,10 @@ export class FieldLogicManager extends BaseActionManager { required: RequiredAction, updateBaseCurrency: UpdateBaseCurrencyAction, updateCurrency: UpdateCurrencyAction, - updateValue: UpdateValueAction, + updateValue: UpdateFieldAction, updateFlexRelateModule: UpdateFlexRelateModuleAction, updateValueBackend: UpdateValueBackendAction, dislayTypeBackend: DisplayTypeBackendAction, - updateFieldAction: UpdateFieldAction, ) { super(); displayType.modes.forEach(mode => this.actions[mode][displayType.key] = displayType); @@ -75,7 +73,6 @@ export class FieldLogicManager extends BaseActionManager { updateValue.modes.forEach(mode => this.actions[mode][updateValue.key] = updateValue); updateValueBackend.modes.forEach(mode => this.actions[mode][updateValueBackend.key] = updateValueBackend); dislayTypeBackend.modes.forEach(mode => this.actions[mode][dislayTypeBackend.key] = dislayTypeBackend); - updateFieldAction.modes.forEach(mode => this.actions[mode][updateFieldAction.key] = updateFieldAction); } /** diff --git a/core/app/core/src/lib/fields/field-logic/update-field/update-field.action.ts b/core/app/core/src/lib/fields/field-logic/update-field/update-field.action.ts index 32168d9c13..9f3f4263b6 100644 --- a/core/app/core/src/lib/fields/field-logic/update-field/update-field.action.ts +++ b/core/app/core/src/lib/fields/field-logic/update-field/update-field.action.ts @@ -2,8 +2,9 @@ * @author SalesAgility . */ +import {isEmpty} from 'lodash-es'; import {Injectable} from '@angular/core'; -import {EDITABLE_VIEW_MODES, Field, Record} from 'common'; +import {ALL_VIEW_MODES, Field, Record} from 'common'; import {ActionableFieldLogicActionHandler} from '../actionable-field-logic/actionable-field-logic.action'; import {ActiveLogicChecker} from '../../../services/logic/active-logic-checker.service'; @@ -12,6 +13,7 @@ type UpdateFieldParamType = string | string[]; interface UpdateFieldParams { nonActiveValue?: UpdateFieldParamType; activeValue?: UpdateFieldParamType; + targetValue?: UpdateFieldParamType; } @Injectable({ @@ -19,8 +21,8 @@ interface UpdateFieldParams { }) export class UpdateFieldAction extends ActionableFieldLogicActionHandler { - key = 'updateField'; - modes = EDITABLE_VIEW_MODES; + key = 'updateValue'; + modes = ALL_VIEW_MODES; constructor( protected activeLogicChecker: ActiveLogicChecker, @@ -39,6 +41,10 @@ export class UpdateFieldAction extends ActionableFieldLogicActionHandler { } private getToUpdateValue(logicIsActive: boolean, params: UpdateFieldParams): UpdateFieldParamType | null { + if (!isEmpty(params.targetValue)){ + params.activeValue = params.targetValue; + } + const valueAccordingToLogicState = logicIsActive ? params.activeValue : params.nonActiveValue; diff --git a/core/app/core/src/lib/fields/field-logic/update-value/update-value.action.ts b/core/app/core/src/lib/fields/field-logic/update-value/update-value.action.ts deleted file mode 100644 index cb67506279..0000000000 --- a/core/app/core/src/lib/fields/field-logic/update-value/update-value.action.ts +++ /dev/null @@ -1,91 +0,0 @@ -/** - * SuiteCRM is a customer relationship management program developed by SalesAgility Ltd. - * Copyright (C) 2023 SalesAgility Ltd. - * - * This program is free software; you can redistribute it and/or modify it under - * the terms of the GNU Affero General Public License version 3 as published by the - * Free Software Foundation with the addition of the following permission added - * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK - * IN WHICH THE COPYRIGHT IS OWNED BY SALESAGILITY, SALESAGILITY DISCLAIMS THE - * WARRANTY OF NON INFRINGEMENT OF THIRD PARTY RIGHTS. - * - * This program is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS - * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more - * details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - * In accordance with Section 7(b) of the GNU Affero General Public License - * version 3, these Appropriate Legal Notices must retain the display of the - * "Supercharged by SuiteCRM" logo. If the display of the logos is not reasonably - * feasible for technical reasons, the Appropriate Legal Notices must display - * the words "Supercharged by SuiteCRM". - */ - -import {Injectable} from '@angular/core'; -import {FieldLogicActionData, FieldLogicActionHandler} from '../field-logic.action'; -import {Action, Field, Record, StringArrayMap, StringArrayMatrix, ViewMode} from 'common'; -import {ActiveFieldsChecker} from "../../../services/condition-operators/active-fields-checker.service"; - -@Injectable({ - providedIn: 'root' -}) -export class UpdateValueAction extends FieldLogicActionHandler { - - key = 'updateValue'; - modes = ['edit', 'detail', 'list', 'create', 'massupdate', 'filter'] as ViewMode[]; - - constructor(protected activeFieldsChecker: ActiveFieldsChecker) { - super(); - } - - run(data: FieldLogicActionData, action: Action): void { - const record = data.record; - const field = data.field; - - if (!record || !field) { - return; - } - - const activeOnFields: StringArrayMap = (action.params && action.params.activeOnFields) || {} as StringArrayMap; - const relatedFields: string[] = Object.keys(activeOnFields); - - const activeOnAttributes: StringArrayMatrix = (action.params && action.params.activeOnAttributes) || {} as StringArrayMatrix; - const relatedAttributesFields: string[] = Object.keys(activeOnAttributes); - - if (!relatedFields.length && !relatedAttributesFields.length) { - return; - } - - const targetValue = action.params && action.params.targetValue; - - if (!targetValue) { - return; - } - - const isActive = this.activeFieldsChecker.isActive(relatedFields, record, activeOnFields, relatedAttributesFields, activeOnAttributes); - - let value = data.field?.value; - - if (isActive) { - value = targetValue; - } - - this.updateValue(field, value.toString(), record); - - } - - /** - * Update the new value - * @param {object} field - * @param {object} record - */ - protected updateValue(field: Field, value: string, record: Record): void { - field.value = value.toString(); - field.formControl.setValue(value); - // re-validate the parent form-control after value update - record.formGroup.updateValueAndValidity({onlySelf: true, emitEvent: true}); - } -}