Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-82571

Add display format for the number-type custom field

XMLWordPrintable

    • MOODLE_405_STABLE
    • MOODLE_405_STABLE
    • Hide

      Automated tests

      1. Covered by automated tests (Behat/PHPUnit)

      Manual setup

      1. Log in as admin
      2. Install Spanish additional language packs in your site via Site administration ► Language ► Language packs
        • Search for Spanish (international) and install it
      3. Navigate to Courses ► Default settings ► Course custom fields in site administration
      4. Press Add a new category (if none already exists)
      5. Press Add a new custom field ► Number and fill the following:
        • Name: Price
        • Shortname: price
        • Under Number field settings:
          • Default value: 10
          • Decimal places: 2
        • Under Display format settings:
          • Display template: {value}
          • Display when zero: Free
        • Save the field

      General test

      1. Navigate to Courses ► Add a new course in site administration
      2. Enter course fullname/shortname
      3. Expand custom field category in form (usually Other fields)
      4. Confirm Price field default value is 10
      5. Set Price field to 15 and save
      6. Manually navigate to <WWWROOT>/course/index.php
      7. Confirm the course summary shows the following:
        • Price: 15.00
      8. Edit the course settings
      9. Change the value of the Price field to 0 and save
      10. Manually navigate to <WWWROOT>/course/index.php
      11. Confirm the course summary shows the following:
        • Price: Free
      12. Navigate to Courses ► Default settings ► Course custom fields in site administration
      13. Press Edit over "Price" custom field ► Number and edit the following:
        • Under Display format settings:
          • Display template: $ {value}
        • Save the field
      14. Edit the course settings
      15. Change the value of the Price field to 15 and save
      16. Manually navigate to <WWWROOT>/course/index.php
      17. Confirm the course summary shows the following:
        • Price: $ 15.00
      18. Navigate to Site admin ► Reports ► Custom reports
      19. Create a new report with data source "Course categories" without the default setup
      20. Edit the custom report and add the columns "Course > Course full name" & "Course > Price"
      21. Confirm the report shown the following ('.' as decimal separator):
        • Price: $ 15.00
      1. Close the custom report
      2. In User Menu ► Language ► change the language to "Español - Internacional (es)"
      3. Edit the report content
      4. Confirm the report shown the following (',' as decimal separator):
        • Price: $ 15,00

      Multilang test

      1. Navigate to Courses ► Default settings ► Course custom fields in site administration
      2. Press Edit over "Price" custom field ► Number and edit the following:
        • Under Display format settings:
          • Display template: <span lang="en" class="multilang">$ {value}</span><span lang="es" class="multilang">€ {value}</span>
          • Display when zero: <span lang="en" class="multilang">Free</span><span lang="es" class="multilang">Gratis</span>
        • Save the field
      3. Navigate to Courses > Add a new course in site administration
      4. Enter course fullname/shortname
      5. Expand custom field category in form (usually Other fields)
      6. Set Price field to 150 and save
      7. Manually navigate to <WWWROOT>/course/index.php
      8. Confirm the course summary shows the following:
        • Price: $ 150.00
      9. Edit the course settings
      10. Change the value of the Price field to 0 and save
      11. Manually navigate to <WWWROOT>/course/index.php
      12. Confirm the course summary shows the following:
        • Price: Free
      13. In User Menu ► Language ► change the language to "Español - Internacional (es)"
      14. Confirm the course summary shows the following:
        • Price: Gratis
      15. Edit the course settings
      16. Change the value of the Price field to 100 and save
      17. Manually navigate to <WWWROOT>/course/index.php
      18. Confirm the course summary shows the following:
        • Price: ·€ 100.00
      Show
      Automated tests Covered by automated tests (Behat/PHPUnit) Manual setup Log in as admin Install Spanish additional language packs in your site via Site administration ► Language ► Language packs Search for Spanish (international) and install it Navigate to Courses ► Default settings ► Course custom fields in site administration Press Add a new category (if none already exists) Press Add a new custom field ► Number and fill the following: Name: Price Shortname: price Under Number field settings : Default value: 10 Decimal places: 2 Under Display format settings: Display template: {value} Display when zero: Free Save the field General test Navigate to Courses ► Add a new course in site administration Enter course fullname/shortname Expand custom field category in form (usually Other fields ) Confirm Price field default value is 10 Set Price field to 15 and save Manually navigate to <WWWROOT>/course/index.php Confirm the course summary shows the following: Price: 15.00 Edit the course settings Change the value of the Price field to 0 and save Manually navigate to <WWWROOT>/course/index.php Confirm the course summary shows the following: Price: Free Navigate to Courses ► Default settings ► Course custom fields in site administration Press Edit over "Price" custom field ► Number and edit the following: Under Display format settings: Display template: $ {value} Save the field Edit the course settings Change the value of the Price field to 15 and save Manually navigate to <WWWROOT>/course/index.php Confirm the course summary shows the following: Price: $ 15.00 Navigate to  Site admin ► Reports ► Custom reports Create a new report with data source "Course categories" without the default setup Edit the custom report and add the columns "Course > Course full name" & "Course > Price" Confirm the report shown the following ('.' as decimal separator): Price: $ 15.00 Close the custom report In User Menu ► Language ► change the language to "Español - Internacional (es)" Edit the report content Confirm the report shown the following (',' as decimal separator): Price: $ 15,00 Multilang test Navigate to Courses ► Default settings ► Course custom fields in site administration Press Edit over "Price" custom field ► Number and edit the following: Under Display format settings: Display template: <span lang="en" class="multilang">$ {value}</span><span lang="es" class="multilang">€ {value}</span> Display when zero: <span lang="en" class="multilang">Free</span><span lang="es" class="multilang">Gratis</span> Save the field Navigate to Courses > Add a new course in site administration Enter course fullname/shortname Expand custom field category in form (usually Other fields ) Set Price field to 150 and save Manually navigate to <WWWROOT>/course/index.php Confirm the course summary shows the following: Price: $ 150.00 Edit the course settings Change the value of the Price field to 0 and save Manually navigate to <WWWROOT>/course/index.php Confirm the course summary shows the following: Price: Free In User Menu ► Language ► change the language to "Español - Internacional (es)" Confirm the course summary shows the following: Price: Gratis Edit the course settings Change the value of the Price field to 100 and save Manually navigate to <WWWROOT>/course/index.php Confirm the course summary shows the following: Price: ·€ 100.00
    • 3
    • WP Sprint 2024-I3.1 (Clones), WP Sprint 2024-I3.2 (Clones)

      Following on from MDL-80858, there are additional requirements for Workplace in this custom field type:

      1. Add "Display format" setting for the field, describing how it should be displayed. Very often we want to display a particular suffix or prefix, maybe display the fixed number of digits after decimal point. When the value is 15.5, for example, "Price" field will be displayed as "$ 15.50" but the "Duration" field will be displayed as "15.5 hours" and so on. Default value is "%g"
      2. Add a separate setting "Display when zero". Again, in the example above, for the "Price" it will be the word "Free" but for the "Duration" it would mean that the duration is unknown and the field should be left empty (which means it won't be displayed at all). Default value is "0"
      3. And finally a separate setting "Display when empty". In the majority of cases it will be empty value, which means do not display but in some cases somebody may want to show "unknown", for example. Default value is empty
      4. Add tests ensuring that the custom field is displayed using this format in the course listing (i.e. "Avaiable courses" on the front page) and WS core_course_get_courses_by_field returns the field correctly

      Requirements:

      • The "Display format" should use a placeholder for the value. I would recommend to use the same placeholders the function sprintf takes because they serve most of the use cases. Only admin can change the setting for the custom field so we assume that it is not a problem that it's a little "nerdy".
      • Add validation that makes sure that a placeholder is used in the value of the setting "Display format".
      • Make sure these settings work with multilang filter, including the case when people enter placeholder several times (one for each language).
      • Keep in mind that in MDL-82715 we will need to make all of the settings fields hidden if the "Automatically populated" field type is selected. It is not possible to use a header in "hideIf()" function, therefore the "Input format" and "Display format" are not headers but are actually static fields. For the same reason it may not be possible to display a "required" exclamation mark next to the "Display template" field even though the field is actually required. It is ok to deviate from mockups in such cases
      • Create a separate method prepare_field_for_display() in the field_controller class that applies the "Display format" and call it from data_controller::export_value. This function will be needed for the follow up tasks MDL-82715 and WP-4863 - we need to be able to hook into into and also call it independently to format bounds of the ranges.

      Mockups for all the setting fields:

        1. After.png
          After.png
          23 kB
        2. Before.png
          Before.png
          23 kB
        3. Course index.png
          Course index.png
          17 kB
        4. MDL-82571 - 1.png
          MDL-82571 - 1.png
          671 kB
        5. MDL-82571 - 2.png
          MDL-82571 - 2.png
          397 kB
        6. numberfieldsettings.png
          numberfieldsettings.png
          29 kB

            carlos.castillo@moodle.com Carlos Castillo
            marina Marina Glancy
            Pedro Jordao Pedro Jordao
            Paul Holden Paul Holden
            Ron Carl Alfon Yu Ron Carl Alfon Yu
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - 0 minutes
                0m
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 1 week, 3 days, 27 minutes
                1w 3d 27m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.