Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Update field logic #394

Open
wants to merge 2 commits into
base: hotfix
Choose a base branch
from

Conversation

mpuyosa91
Copy link
Contributor

@mpuyosa91 mpuyosa91 commented Nov 15, 2023

This is a feature that consists of being able to modify a field due to certain logic.

Description

  • ESLint fixes on modified files.
  • core/app/core/src/lib/fields/field-logic/actionable-field-logic/actionable-field-logic.action.ts Abstract class ActionableFieldLogicActionHandler that can hold general and reusable functions across field logic actions.
  • core/app/core/src/lib/fields/field-logic/update-field/update-field.action.ts Actual UpdateFieldAction class that holds the logic.
  • core/app/core/src/lib/fields/field-logic/field-logic.manager.ts:[40, 66, 78] Registration of the UpdateFieldAction as Field Logic Action.
  • core/app/core/src/lib/services/logic/active-logic-checker.service.ts: Creation of ActiveLogicChecker class that holds the routine for checking if a logic is active or not.
  • core/app/core/src/lib/core.ts:364 Export created classes

Motivation and Context

This was needed by a client.

How To Test This

  1. Create all files in Test Environment
  2. Rebuild the whole project, Quick Repair & Rebuild, executing database scripts if needed.
  3. Go to any or Create a new Case, but open in Edit Mode
  4. Check the current value of the SUBJECT field
  5. Change the field MODIFY SUBJECT to Custom or Clear.
  6. If you select Custom, Subject field will change to Custom Case Subject.
  7. If you select Clear, Subject field will be cleared.

Test Environment

public/legacy/custom/Extension/modules/Cases/Ext/Vardefs/modify_subject.php

<?php
/**
 * @author SalesAgility <[email protected]>.
 */

$dictionary['Case']['fields']['modify_subject'] = [
    'name' => 'modify_subject',
    'vname' => 'LBL_MODIFY_SUBJECT',
    'type' => 'enum',
    'displayType' => 'dropdown',
    'options' => 'cases_modify_subject_dom',
    'len' => 4,
    'required' => false,
    'audited' => true,
    'reportable' => true,
    'importable' => true,
    'unified_search' => true,
    'inline_edit' => true,
];

public/legacy/custom/Extension/modules/Cases/Ext/Language/en_us.modify_subject.php

<?php
/**
 * @author SalesAgility <[email protected]>.
 */

$mod_strings['LBL_MODIFY_SUBJECT'] = 'Modify Subject';

public/legacy/custom/Extension/application/Ext/Language/en_us.Cases.php

<?php
/**
 * @author SalesAgility <[email protected]>.
 */

$app_list_strings['cases_modify_subject_dom'] = array(
    'none' => '',
    'Custom' => 'Custom',
    'Clear' => 'Clear',
);

public/legacy/custom/modules/Cases/metadata/detailviewdefs.php

<?php
/**
 * @author SalesAgility <[email protected]>.
 */

$viewdefs["Cases"] = [
    "DetailView" => [
        "templateMeta" => [
            "form" => [
                "buttons" => [
                    0 => "EDIT",
                    1 => "DUPLICATE",
                    2 => "DELETE",
                    3 => "FIND_DUPLICATES",
                ],
            ],
            "maxColumns" => "2",
            "widths" => [
                0 => [
                    "label" => "10",
                    "field" => "30",
                ],
                1 => [
                    "label" => "10",
                    "field" => "30",
                ],
            ],
            "useTabs" => true,
            "tabDefs" => [
                "LBL_CASE_INFORMATION" => [
                    "newTab" => true,
                    "panelDefault" => "expanded",
                ],
            ],
        ],
        "topWidget" => [
            "type" => "statistics",
            "options" => [
                "statistics" => [
                    [
                        "labelKey" => "",
                        "type" => "case-days-open",
                        "endLabelKey" => "LBL_STAT_DAYS",
                        "hideValueIfEmpty" => true,
                    ],
                ],
            ],
        ],
        "sidebarWidgets" => [
            [
                "type" => "record-thread",
                "labelKey" => "LBL_CASE_UPDATES",
                "options" => [
                    "recordThread" => [
                        "module" => "case-updates",
                        "class" => "case-updates",
                        "filters" => [
                            "parentFilters" => [
                                "id" => "case_id",
                            ],
                            "orderBy" => "date_entered",
                            "sortOrder" => "DESC",
                        ],
                        "item" => [
                            "itemClass" => "case-updates-item pt-2 pb-2",
                            "collapsible" => true,
                            "dynamicClass" => ["source", "internal"],
                            "layout" => [
                                "header" => ["rows" => []],
                                "body" => [
                                    "rows" => [
                                        [
                                            "align" => "end",
                                            "justify" => "between",
                                            "cols" => [
                                                [
                                                    "field" => "author",
                                                    "labelDisplay" => "none",
                                                    "hideIfEmpty" => true,
                                                    "class" =>
                                                        "font-weight-bold item-title",
                                                ],
                                                [
                                                    "field" => "internal",
                                                    "labelDisplay" => "inline",
                                                    "labelClass" => "m-0",
                                                    "display" => "none",
                                                    "hideIfEmpty" => true,
                                                    "class" =>
                                                        "small ml-auto font-weight-light",
                                                ],
                                            ],
                                        ],
                                        [
                                            "align" => "start",
                                            "justify" => "start",
                                            "class" =>
                                                "flex-grow-1 item-content",
                                            "cols" => [
                                                [
                                                    "field" => [
                                                        "name" => "description",
                                                        "type" => "html",
                                                    ],
                                                    "labelDisplay" => "none",
                                                ],
                                            ],
                                        ],
                                        [
                                            "justify" => "left",
                                            "class" =>
                                                "flex-grow-1 item-content-extra",
                                            "cols" => [
                                                [
                                                    "field" => [
                                                        "name" => "notes",
                                                        "type" => "line-items",
                                                        "lineItems" => [
                                                            "labelOnFirstLine" => true,
                                                            "definition" => [
                                                                "name" =>
                                                                    "notes_fields",
                                                                "vname" =>
                                                                    "LBL_FILENAME",
                                                                "type" =>
                                                                    "composite",
                                                                "layout" => [
                                                                    "filename",
                                                                ],
                                                                "display" =>
                                                                    "inline",
                                                                "attributeFields" => [
                                                                    "filename" => [
                                                                        "name" =>
                                                                            "filename",
                                                                        "type" =>
                                                                            "file",
                                                                        "vname" =>
                                                                            "LBL_FILENAME",
                                                                        "labelKey" =>
                                                                            "LBL_FILENAME",
                                                                        "required" => true,
                                                                        "valueParent" =>
                                                                            "record",
                                                                        "showLabel" => [
                                                                            "*",
                                                                        ],
                                                                    ],
                                                                ],
                                                            ],
                                                        ],
                                                    ],
                                                    "labelDisplay" => "none",
                                                    "hideIfEmpty" => false,
                                                    "class" =>
                                                        "small ml-auto font-weight-light",
                                                ],
                                            ],
                                        ],
                                        [
                                            "justify" => "end",
                                            "class" => "flex-grow-1",
                                            "cols" => [
                                                [
                                                    "field" => "date_entered",
                                                    "labelDisplay" => "none",
                                                    "hideIfEmpty" => true,
                                                    "class" =>
                                                        "small ml-auto font-weight-light",
                                                ],
                                            ],
                                        ],
                                    ],
                                ],
                            ],
                        ],
                        "create" => [
                            "presetFields" => [
                                "parentValues" => [
                                    "id" => "case_id",
                                ],
                            ],
                            "layout" => [
                                "header" => ["rows" => []],
                                "body" => [
                                    "rows" => [
                                        [
                                            "justify" => "start",
                                            "class" => "flex-grow-1",
                                            "cols" => [
                                                [
                                                    "field" => [
                                                        "name" => "description",
                                                        "metadata" => [
                                                            "rows" => 3,
                                                        ],
                                                    ],
                                                    "labelDisplay" => "top",
                                                    "class" => "flex-grow-1",
                                                ],
                                            ],
                                        ],
                                        [
                                            "align" => "end",
                                            "justify" => "start",
                                            "class" => "flex-grow-1",
                                            "cols" => [
                                                [
                                                    "field" => "internal",
                                                    "labelDisplay" => "inline",
                                                ],
                                            ],
                                        ],
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
                "acls" => [
                    "Cases" => ["view", "list"],
                ],
            ],
            [
                "type" => "statistics",
                "labelKey" => "LBL_NUMBER_OF_CASES_PER_ACCOUNT",
                "options" => [
                    "sidebarStatistic" => [
                        "rows" => [
                            [
                                "align" => "start",
                                "cols" => [
                                    [
                                        "labelKey" =>
                                            "LBL_TOTAL_CASES_FOR_THIS_ACCOUNT",
                                        "size" => "medium",
                                    ],
                                ],
                            ],
                            [
                                "align" => "start",
                                "cols" => [
                                    [
                                        "statistic" => "cases-per-account",
                                        "size" => "xx-large",
                                        "bold" => true,
                                        "color" => "green",
                                    ],
                                ],
                            ],
                            [
                                "align" => "start",
                                "cols" => [
                                    [
                                        "labelKey" => "LBL_SINCE",
                                        "size" => "regular",
                                    ],
                                    [
                                        "statistic" =>
                                            "get-account-date-entered",
                                        "size" => "regular",
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
                "acls" => [
                    "Cases" => ["view", "list"],
                    "Accounts" => ["view", "list"],
                ],
            ],
        ],
        "panels" => [
            "lbl_case_information" => [
                0 => [
                    0 => [
                        "name" => "case_number",
                        "label" => "LBL_CASE_NUMBER",
                    ],
                    1 => "priority",
                ],
                1 => [
                    0 => [
                        "name" => "state",
                        "comment" => "The state of the case (i.e. open/closed)",
                        "label" => "LBL_STATE",
                    ],
                    1 => "status",
                ],
                2 => [
                    0 => "type",
                    1 => "modify_subject",
                ],
                3 => [
                    0 => [
                        "name" => "name",
                        "label" => "LBL_SUBJECT",
                    ],
                ],
                4 => [
                    0 => "description",
                ],
                5 => [
                    0 => "resolution",
                ],
                6 => [
                    0 => [
                        "name" => "assigned_user_name",
                        "label" => "LBL_ASSIGNED_TO",
                    ],
                ],
                7 => [
                    0 => [
                        "name" => "date_entered",
                        "customCode" =>
                            '{$fields.date_entered.value} {$APP.LBL_BY} {$fields.created_by_name.value}',
                    ],
                    1 => [
                        "name" => "date_modified",
                        "label" => "LBL_DATE_MODIFIED",
                        "customCode" =>
                            '{$fields.date_modified.value} {$APP.LBL_BY} {$fields.modified_by_name.value}',
                    ],
                ],
            ],
        ],
    ],
];

public/legacy/custom/modules/Cases/metadata/editviewdefs.php

<?php
/**
 * @author SalesAgility <[email protected]>.
 */

$viewdefs["Cases"] = [
    "EditView" => [
        "templateMeta" => [
            "maxColumns" => "2",
            "widths" => [
                0 => [
                    "label" => "10",
                    "field" => "30",
                ],
                1 => [
                    "label" => "10",
                    "field" => "30",
                ],
            ],
            "includes" => [
                0 => [
                    "file" => "include/javascript/bindWithDelay.js",
                ],
                1 => [
                    "file" =>
                        "modules/AOK_KnowledgeBase/AOK_KnowledgeBase_SuggestionBox.js",
                ],
                2 => [
                    "file" => "include/javascript/qtip/jquery.qtip.min.js",
                ],
            ],
            "useTabs" => false,
            "tabDefs" => [
                "LBL_CASE_INFORMATION" => [
                    "newTab" => false,
                    "panelDefault" => "expanded",
                ],
            ],
            "form" => [
                "enctype" => "multipart/form-data",
            ],
        ],
        "panels" => [
            "lbl_case_information" => [
                0 => [
                    0 => [
                        "name" => "case_number",
                        "type" => "readonly",
                    ],
                    1 => "priority",
                ],
                1 => [
                    0 => [
                        "name" => "state",
                        "comment" => "The state of the case (i.e. open/closed)",
                        "label" => "LBL_STATE",
                    ],
                    1 => "status",
                ],
                2 => [
                    0 => "type",
                    1 => "modify_subject",
                ],
                3 => [
                    0 => [
                        "name" => "name",
                        "displayParams" => [
                            //'size' => 75,
                        ],
                    ],
                    1 => [
                        "name" => "suggestion_box",
                        //'studio' => 'visible',
                        "label" => "LBL_SUGGESTION_BOX",
                    ],
                ],
                4 => [
                    0 => [
                        "name" => "description",
                    ],
                ],
                5 => [
                    0 => [
                        "name" => "resolution",
                        "nl2br" => true,
                    ],
                ],
                6 => [
                    0 => [
                        "name" => "update_text",
                        "studio" => "visible",
                        "label" => "LBL_UPDATE_TEXT",
                    ],
                ],
                7 => [
                    0 => [
                        "name" => "internal",
                        "studio" => "visible",
                        "label" => "LBL_INTERNAL",
                    ],
                ],
                8 => [
                    0 => [
                        "name" => "case_update_form",
                        "studio" => "visible",
                    ],
                ],
                9 => [
                    0 => "assigned_user_name",
                ],
            ],
        ],
    ],
];

public/legacy/custom/Extension/modules/Cases/Ext/Vardefs/_override_name.php

<?php
/**
 * @author SalesAgility <[email protected]>.
 */

$dictionary['Case']['fields']['name']['logic'] = [
    'updateField1' => [
        'key' => 'updateValue',
        'modes' => ['edit', 'create'],
        'params' => [
            'fieldDependencies' => [
                'modify_subject',
            ],
            'activeOnFields' => [
                'modify_subject' => [
                    'operator' => 'is-equal',
                    'values' => ['Custom']
                ],
            ],
            'activeValue' => 'Custom Case Subject',
        ]
    ],
    'updateField2' => [
        'key' => 'updateValue',
        'modes' => ['edit', 'create'],
        'params' => [
            'fieldDependencies' => [
                'modify_subject',
            ],
            'activeOnFields' => [
                'modify_subject' => [
                    'operator' => 'is-equal',
                    'values' => ['Clear']
                ],
            ],
            'activeValue' => '',
        ]
    ],
];

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Final checklist

  • My code follows the code style of this project found here.
  • My change requires a change to the documentation.
  • I have read the How to Contribute guidelines.

@clemente-raposo
Copy link
Contributor

Hi @mpuyosa91 could you add the PR or the issue number to the PR please?

@clemente-raposo
Copy link
Contributor

Hi @mpuyosa91, as we spoke this code should be replacing the updateValue logic

@clemente-raposo clemente-raposo added Status:Requires Updates Issues & PRs which requires input or update from the author Status: Requires Code Review labels Dec 6, 2023
@mpuyosa91 mpuyosa91 added Status: Fix Proposed A issue that has a PR related to it that provides a possible resolution and removed Status:Requires Updates Issues & PRs which requires input or update from the author labels Dec 6, 2023
@mpuyosa91 mpuyosa91 changed the title Feature Update field logic Closes #394 Feature Update field logic Dec 6, 2023
mpuyosa91 added a commit to mpuyosa91/SuiteCRM-Core that referenced this pull request Dec 6, 2023
mpuyosa91 added a commit to mpuyosa91/SuiteCRM-Core that referenced this pull request Dec 6, 2023
@mpuyosa91 mpuyosa91 changed the title Closes #394 Feature Update field logic Feature Update field logic Dec 6, 2023
@clemente-raposo clemente-raposo added Status:Requires Updates Issues & PRs which requires input or update from the author and removed Status: Fix Proposed A issue that has a PR related to it that provides a possible resolution labels Dec 7, 2023
mpuyosa91 added a commit to mpuyosa91/SuiteCRM-Core that referenced this pull request Dec 8, 2023
mpuyosa91 added a commit to mpuyosa91/SuiteCRM-Core that referenced this pull request Dec 8, 2023
@mpuyosa91 mpuyosa91 added Status: Fix Proposed A issue that has a PR related to it that provides a possible resolution and removed Status:Requires Updates Issues & PRs which requires input or update from the author labels Dec 8, 2023
@clemente-raposo clemente-raposo added Status:Requires Updates Issues & PRs which requires input or update from the author and removed Status: Fix Proposed A issue that has a PR related to it that provides a possible resolution labels Dec 14, 2023
@mpuyosa91 mpuyosa91 added Status: Fix Proposed A issue that has a PR related to it that provides a possible resolution and removed Status:Requires Updates Issues & PRs which requires input or update from the author labels Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Fix Proposed A issue that has a PR related to it that provides a possible resolution Status: Requires Code Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants