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 Conditional Options Logic #392

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 depends on #382. It consists of being able to add and remove options due to certain logic.

Caution

DO NOT MERGE BEFORE #382

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/conditional-options/conditional-options.action.ts Actual ConditionalOptionsAction class that holds the logic.
  • core/app/core/src/lib/fields/field-logic/field-logic.manager.ts:[40, 66, 78] Registration of the Conditional Options Action 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 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 SHOW CONDITIONAL OPTION field; if is not 'Yes' you should see on the TYPE field 3 options, 4 instead.

Test Environment

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

<?php
/**
 * @author SalesAgility <info@salesagility.com>.
 */

$dictionary['Case']['fields']['show_conditional_option'] = [
    'name' => 'show_conditional_option',
    'vname' => 'LBL_SHOW_CONDITIONAL_OPTION',
    'type' => 'enum',
    'displayType' => 'dropdown',
    'options' => 'cases_show_conditional_option_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.show_conditional_option.php

<?php
/**
 * @author SalesAgility <info@salesagility.com>.
 */

$mod_strings['LBL_SHOW_CONDITIONAL_OPTION'] = 'Show Conditional Option';

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

<?php
/**
 * @author SalesAgility <info@salesagility.com>.
 */

$app_list_strings['cases_show_conditional_option_dom'] = array(
    'none' => '',
    'Yes' => 'Yes',
    'No' => 'No',
);

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

<?php
/**
 * @author SalesAgility <info@salesagility.com>.
 */

$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 => "show_conditional_option",
                ],
                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 <info@salesagility.com>.
 */

$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 => "show_conditional_option",
                ],
                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_type.php

<?php
/**
 * @author SalesAgility <info@salesagility.com>.
 */

$dictionary['Case']['fields']['type']['logic'] = [
    'conditional-options-logic' => [
        'key' => 'conditional-options',
        'modes' => ['detail', 'edit', 'create'],
        'params' => [
            'fieldDependencies' => [
                'show_conditional_option',
            ],
            'conditionalOptions' => [
                [
                    'value' => 'ConditionalOption',
                    'labelKey' => 'LBL_CONDITIONAL_OPTION',
                    'params' => [
                        'activeOnFields' => [
                            'show_conditional_option' => [
                                'operator' => 'is-equal',
                                'values' => [
                                    'Yes',
                                ],
                            ]
                        ],
                    ],
                ],
            ]
        ],
    ],
];

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

<?php
/**
 * @author SalesAgility <info@salesagility.com>.
 */

$mod_strings['LBL_CONDITIONAL_OPTION'] = 'Conditional Option';

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.

@mpuyosa91 mpuyosa91 force-pushed the feature/conditional_options_logic branch from 041d9a2 to 948a22f Compare November 16, 2023 13:53
@mpuyosa91 mpuyosa91 changed the title Feature Conditional Options Logic Closes #392 Feature Conditional Options Logic Dec 6, 2023
@mpuyosa91 mpuyosa91 changed the title Closes #392 Feature Conditional Options Logic Closes #392 - Feature Conditional Options Logic Dec 6, 2023
@mpuyosa91 mpuyosa91 force-pushed the feature/conditional_options_logic branch from 948a22f to 301e772 Compare December 6, 2023 13:09
mpuyosa91 added a commit to mpuyosa91/SuiteCRM-Core that referenced this pull request Dec 6, 2023
@mpuyosa91 mpuyosa91 changed the title Closes #392 - Feature Conditional Options Logic Feature Conditional Options Logic Dec 6, 2023
@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 added a commit to mpuyosa91/SuiteCRM-Core that referenced this pull request Dec 7, 2023
@mpuyosa91 mpuyosa91 force-pushed the feature/conditional_options_logic branch from 301e772 to 49a7208 Compare December 7, 2023 11:30
@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 7, 2023
value: this.field.value,
valueList: this.field.valueList,
valueObject: this.field.valueObject,
forceNotEqual: 'forceNotEqual',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mpuyosa91, where do we use the forceNotEqual?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @clemente-raposo is just a way to make it different and force a true in line 120. It also could be accomplished with an undefined due to line 47 but I was anticipating any use of that first state of this.previousValue

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mpuyosa91, can we use an alternative solution for this, please.

@clemente-raposo clemente-raposo added the Status:Requires Updates Issues & PRs which requires input or update from the author label Dec 7, 2023
@clemente-raposo clemente-raposo removed the Status: Fix Proposed A issue that has a PR related to it that provides a possible resolution label Dec 14, 2023
@mpuyosa91 mpuyosa91 force-pushed the feature/conditional_options_logic branch from 49a7208 to bb07323 Compare December 27, 2023 15:17
@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 27, 2023
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.

3 participants