Moodle
  1. Moodle
  2. MDL-31121

File resource: Option to display file size, type

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 2.3
    • Fix Version/s: 2.3
    • Component/s: Resource
    • Labels:
    • Testing Instructions:
      Hide

      NOTE: The precise display of sizes (101.4KB) and types (PDF document) is not a part of this change. These strings are generated by existing standard Moodle code which has not been changed and is already used elsewhere in Moodle. For instance, if during testing you decide the size format is not really appropriate (it should have a space, or use KiB, or something), that is not a bug with this system.

      1. Add a new File item. Type a name and upload a PDF file. Type some basic text for the intro. Leave other options at default; save and display.
      + On the resulting page, the PDF displays (embedded) just as it always did.
      + The intro box should show the text you typed as usual.
      2. Return to the course page.
      + The link to the PDF should also be unchanged.
      3. Edit the File item. Turn on the 'Show size' and 'Show type' options; save and display.
      + Below your text in the intro box there should be a paragraph of small grey text such as '114.2KB PDF document'
      4. Visit the course page.
      + Next to the link to the PDF, the same information '114.2KB PDF document' should display.
      5. Edit the File item. Turn off 'Show type' so that it only shows the size. Save it; look at the PDF page and the course page again.
      + In both places, the text should now read only '114.2KB'.
      6. Edit it again; turn 'Show type' on, and 'Show size' off. Check both pages.
      + In both pages, the text should now read only 'PDF document'.
      7. Site administration / Plugins / Activity modules / File.
      + Page should now include options for 'Show size' and 'Show type'.
      8. Turn on all four checkboxes next to 'Show size' and 'Show type', and save changes.
      9. Go back to a course page and choose Add a resources... / File.
      + Toggle the 'Show/Hide advanced' button and check that the 'Show size' and 'Show type' options now appear/disappear.
      + Verify that both options are now ticked by default.
      10. Add 3 files of different types to the new resource. Set one of the files as the main file. Save and return to course.
      + Check that the size displayed by the file is equal to the sum total of the size of all 3 files.
      + Check that the type displayed by the file is the correct type for the main file.
      11. On your computer, create an .xqq file (made-up extension) and a .flv file (real extension that has MIME type but no description).
      12. Create a new File item for each file. In both cases leave the 'show size' and 'show type' enabled.
      + Verify that both files display on the course with size only (not type) even though the type option was checked, because there is no type description available.

      Show
      NOTE: The precise display of sizes (101.4KB) and types (PDF document) is not a part of this change. These strings are generated by existing standard Moodle code which has not been changed and is already used elsewhere in Moodle. For instance, if during testing you decide the size format is not really appropriate (it should have a space, or use KiB, or something), that is not a bug with this system. 1. Add a new File item. Type a name and upload a PDF file. Type some basic text for the intro. Leave other options at default; save and display. + On the resulting page, the PDF displays (embedded) just as it always did. + The intro box should show the text you typed as usual. 2. Return to the course page. + The link to the PDF should also be unchanged. 3. Edit the File item. Turn on the 'Show size' and 'Show type' options; save and display. + Below your text in the intro box there should be a paragraph of small grey text such as '114.2KB PDF document' 4. Visit the course page. + Next to the link to the PDF, the same information '114.2KB PDF document' should display. 5. Edit the File item. Turn off 'Show type' so that it only shows the size. Save it; look at the PDF page and the course page again. + In both places, the text should now read only '114.2KB'. 6. Edit it again; turn 'Show type' on, and 'Show size' off. Check both pages. + In both pages, the text should now read only 'PDF document'. 7. Site administration / Plugins / Activity modules / File. + Page should now include options for 'Show size' and 'Show type'. 8. Turn on all four checkboxes next to 'Show size' and 'Show type', and save changes. 9. Go back to a course page and choose Add a resources... / File. + Toggle the 'Show/Hide advanced' button and check that the 'Show size' and 'Show type' options now appear/disappear. + Verify that both options are now ticked by default. 10. Add 3 files of different types to the new resource. Set one of the files as the main file. Save and return to course. + Check that the size displayed by the file is equal to the sum total of the size of all 3 files. + Check that the type displayed by the file is the correct type for the main file. 11. On your computer, create an .xqq file (made-up extension) and a .flv file (real extension that has MIME type but no description). 12. Create a new File item for each file. In both cases leave the 'show size' and 'show type' enabled. + Verify that both files display on the course with size only (not type) even though the type option was checked, because there is no type description available.
    • Affected Branches:
      MOODLE_23_STABLE
    • Fixed Branches:
      MOODLE_23_STABLE
    • Pull Master Branch:
      MDL-31121-master
    • Rank:
      37551

      Description

      The file resource should have an option to display the file size and/or type. For example, a link might currently display as:

      Book 1

      We would like options so that it can display as:

      Book 1 (4.7MB)

      or

      Book 1 (4.7MB PDF document)

      The reason for this feature are as follows.

      File size: Students have a better user experience if they can see how large a file is before they start to download it (especially when using slow broadband connections or even, in certain rural areas, old-fashioned dialup; or when files are very large). For example, if they can see that the file is moderately large, they might decide not to download it until after an existing large download completes.

      Type: It is also a better user experience if you know what program is used to open the file. For example, if a file is an Excel spreadsheet and you are currently using a netbook which does not have MS Office installed, you might decide to switch to your main desktop computer and download the file there instead. (You can guess the file type from the icon, but spelling it out in visible text helps. And it's more efficient and more consistent if we have an automated way to display this information rather than expecting teachers to type it in as part of the name of the file.)

      I have coded this feature, and will submit it for review shortly.

        Issue Links

          Activity

          Hide
          Sam Marshall added a comment -

          Screenshots attached. The file is in the middle of the course main page (display) screenshot, titled 'Test script'.

          Show
          Sam Marshall added a comment - Screenshots attached. The file is in the middle of the course main page (display) screenshot, titled 'Test script'.
          Hide
          Sam Marshall added a comment -

          Performance notes:

          • This change should have no significant impact on performance when the new options are turned off (default).
          • There should be no significant impact on performance of the main course page even if the new options are used.
          • When both options are turned on, this adds 2 simple database queries to a view of the file that displays the intro box.
          • This adds 2 simple database queries (per file that has the options turned on) to the effort taken to rebuild modinfo.
          Show
          Sam Marshall added a comment - Performance notes: This change should have no significant impact on performance when the new options are turned off (default). There should be no significant impact on performance of the main course page even if the new options are used. When both options are turned on, this adds 2 simple database queries to a view of the file that displays the intro box. This adds 2 simple database queries (per file that has the options turned on) to the effort taken to rebuild modinfo.
          Hide
          Michael de Raadt added a comment -

          I like this.

          Show
          Michael de Raadt added a comment - I like this.
          Hide
          Sam Hemelryk added a comment -

          Hi Sam,

          I've just been looking at this now. Certainly a nice improvement and appears to work perfectly.
          Gets a +1 for integration from me.

          Two things I did note neither of which are conditional to it going up for integration:

          1. I can't help but feel that the get_field_sql within resource_get_optional_details should not be using sortorder=1 and instead ordering by sort order and then using IGNORE_MULTIPLE. Just in case for any reason there is not a sortorder=1.
          2. I'm not 100% sure about the display if the mimetype end up being document/unknown. If just show type is enabled then you get 'file' which seems slightly redundant. With both showtype and showsize enabled you get something like '3.5mb file' which is marginally better.

          Cheers
          Sam

          Show
          Sam Hemelryk added a comment - Hi Sam, I've just been looking at this now. Certainly a nice improvement and appears to work perfectly. Gets a +1 for integration from me. Two things I did note neither of which are conditional to it going up for integration: I can't help but feel that the get_field_sql within resource_get_optional_details should not be using sortorder=1 and instead ordering by sort order and then using IGNORE_MULTIPLE. Just in case for any reason there is not a sortorder=1. I'm not 100% sure about the display if the mimetype end up being document/unknown. If just show type is enabled then you get 'file' which seems slightly redundant. With both showtype and showsize enabled you get something like '3.5mb file' which is marginally better. Cheers Sam
          Hide
          Sam Marshall added a comment -

          Thanks for the review! I agree with your comments and made two changes:

          1) I changed it to use ORDER BY and also added a comment explaining why it is doing that because that field is super confusing. (A 'sort order' in which all the items are 0 except one main entry which is 1...)

          2) I changed it so if EITHER the mimetype is document/unknown, OR the result of the description is the same string as document/unknown, it treats it the same as if type is not displayed (so it will just show '3.4MB' not '3.4MB file'). Also added a line to the popup help text for the Type box to document this behaviour.

          Show
          Sam Marshall added a comment - Thanks for the review! I agree with your comments and made two changes: 1) I changed it to use ORDER BY and also added a comment explaining why it is doing that because that field is super confusing. (A 'sort order' in which all the items are 0 except one main entry which is 1...) 2) I changed it so if EITHER the mimetype is document/unknown, OR the result of the description is the same string as document/unknown, it treats it the same as if type is not displayed (so it will just show '3.4MB' not '3.4MB file'). Also added a line to the popup help text for the Type box to document this behaviour.
          Hide
          Sam Hemelryk added a comment -

          Cool thanks Sam

          Show
          Sam Hemelryk added a comment - Cool thanks Sam
          Hide
          Eloy Lafuente (stronk7) added a comment -

          The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week.

          TIA and ciao

          Show
          Eloy Lafuente (stronk7) added a comment - The main moodle.git repository has just been updated with latest weekly modifications. You may wish to rebase your PULL branches to simplify history and avoid any possible merge conflicts. This would also make integrator's life easier next week. TIA and ciao
          Hide
          Sam Marshall added a comment -

          rebased

          Show
          Sam Marshall added a comment - rebased
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Nice one, integrated, thanks!

          Show
          Eloy Lafuente (stronk7) added a comment - Nice one, integrated, thanks!
          Hide
          Rossiani Wijaya added a comment -

          This is working great.

          Thanks

          Test passed.

          Show
          Rossiani Wijaya added a comment - This is working great. Thanks Test passed.
          Hide
          Eloy Lafuente (stronk7) added a comment -

          Your nice code represents only 1/46 of the issues that have been sent upstream this week, so thanks, but not many.

          Nah, joking, many thanks! Closing this a fixed, ciao

          Show
          Eloy Lafuente (stronk7) added a comment - Your nice code represents only 1/46 of the issues that have been sent upstream this week, so thanks, but not many. Nah, joking, many thanks! Closing this a fixed, ciao
          Hide
          Mary Cooch added a comment -

          I know this is closed but I can't find a reference anywhere else although I have searched - I can't get docx or xlsx files to display their type on the QA Moodle. Is this a known issue?

          Show
          Mary Cooch added a comment - I know this is closed but I can't find a reference anywhere else although I have searched - I can't get docx or xlsx files to display their type on the QA Moodle. Is this a known issue?
          Hide
          Michael Woods added a comment -

          Agree with Mary. There's a problem with .docx and .xlsx files not being able to display their type.

          Show
          Michael Woods added a comment - Agree with Mary. There's a problem with .docx and .xlsx files not being able to display their type.
          Hide
          Helen Foster added a comment -

          Mary and Michael, thanks for your feedback / bug finding. As this issue is now closed, please feel free to create a new issue about docx and xlsx files and then link it to this issue (or just add a comment here mentioning the new issue number).

          Show
          Helen Foster added a comment - Mary and Michael, thanks for your feedback / bug finding. As this issue is now closed, please feel free to create a new issue about docx and xlsx files and then link it to this issue (or just add a comment here mentioning the new issue number).
          Hide
          Mary Cooch added a comment - - edited

          Ok I just made a new tracker issue and it is here MDL-32831

          Show
          Mary Cooch added a comment - - edited Ok I just made a new tracker issue and it is here MDL-32831
          Hide
          Tim Barker added a comment -

          Added tests MDLQA-1553 and MDLQA-1554.

          Show
          Tim Barker added a comment - Added tests MDLQA-1553 and MDLQA-1554.
          Hide
          Helen Foster added a comment -

          Documentation on this improvement available here: http://docs.moodle.org/23/en/File_module_settings

          Show
          Helen Foster added a comment - Documentation on this improvement available here: http://docs.moodle.org/23/en/File_module_settings

            People

            • Votes:
              7 Vote for this issue
              Watchers:
              7 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: