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

Core: Improve display_size function

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 4.0
    • Fix Version/s: 4.0
    • Component/s: Libraries
    • Labels:
    • Affected Branches:
      MOODLE_400_STABLE
    • Fixed Branches:
      MOODLE_400_STABLE
    • Pull Master Branch:
      MDL-72643-master
    • Testing Instructions:
      Hide
      1. Go to a course and turn editing on.
      2. Add three files of different sizes: one tiny file between 0 and 1023 bytes in size, one small file between 2 KB and 500 KB, and one that is more than 1 MB, using this procedure:
        1. Click 'Add an activity or resource'
        2. Choose 'File' from the popup.
        3. Drag your file into the 'Select files' area, or otherwise upload it.
        4. Expand the 'Appearance' fieldset, and ensure the 'Show size' tickbox is ticked.
        5. Save changes.
      3. On the course page, check the size displayed for the files.
        • The files should show sizes like '43 bytes', '13.0 KB', and '1.4 MB'.
        • Specifically, the small file shown in bytes should have no decimal place. The other two files should have one decimal place.
        • All sizes should have a visible space between the number and the unit.
      Show
      Go to a course and turn editing on. Add three files of different sizes: one tiny file between 0 and 1023 bytes in size, one small file between 2 KB and 500 KB, and one that is more than 1 MB, using this procedure: Click 'Add an activity or resource' Choose 'File' from the popup. Drag your file into the 'Select files' area, or otherwise upload it. Expand the 'Appearance' fieldset, and ensure the 'Show size' tickbox is ticked. Save changes. On the course page, check the size displayed for the files. The files should show sizes like '43 bytes', '13.0 KB', and '1.4 MB'. Specifically, the small file shown in bytes should have no decimal place. The other two files should have one decimal place. All sizes should have a visible space between the number and the unit.

      Description

      The display_size function has several limitations:

      • It is not possible to fix a unit; for example, when displaying several values together it might be useful to force them all to show in MB so that we can easily see that 0.4MB is less than 1.8MB (currently 439.9KB looks bigger visually).
      • Current behaviour uses either 1 or 0 decimal places; if the number rounded to 1 decimal place happens to end in a zero (4.0 KB) it displays with no decimal places (4 KB), whereas if it ends in any other digit it will display wth one place (4.1 KB). This is weird and unhelpful.
      • There should be a space between the value and the unit to make it easier to read, e.g. 65.0 KB. (This should be a non-breaking space, to avoid unhelpful display if it wraps at the end of a line or in a narrow table cell.) At the moment there is a space when the unit is 'bytes' but not for the other units.

      These were identified while working on MDL-72596 but rather than hack around it I thought it was better to fix the actual library function.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              quen Sam Marshall
              Reporter:
              quen Sam Marshall
              Peer reviewer:
              Brendan Heywood Brendan Heywood
              Integrator:
              Ilya Tregubov Ilya Tregubov
              Tester:
              Angelia Dela Cruz Angelia Dela Cruz
              Participants:
              Component watchers:
              Amaia Anabitarte, Carlos Escobedo, Ferran Recio, Ilya Tregubov, Sara Arjona (@sarjona)
              Votes:
              1 Vote for this issue
              Watchers:
              6 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0 minutes
                  0m
                  Logged:
                  Time Spent - 15 minutes
                  15m