MDL-68975 contentbank: add author field to file details view
authorSara Arjona <sara@moodle.com>
Thu, 13 Aug 2020 17:04:51 +0000 (19:04 +0200)
committerAndrew Nicols <andrew@nicols.co.uk>
Thu, 20 Aug 2020 00:42:20 +0000 (08:42 +0800)
12 files changed:
contentbank/amd/build/selectors.min.js
contentbank/amd/build/selectors.min.js.map
contentbank/amd/build/sort.min.js
contentbank/amd/build/sort.min.js.map
contentbank/amd/src/selectors.js
contentbank/amd/src/sort.js
contentbank/classes/output/bankcontent.php
contentbank/templates/bankcontent.mustache
contentbank/tests/behat/sort_content.feature
theme/boost/scss/moodle/contentbank.scss
theme/boost/style/moodle.css
theme/classic/style/moodle.css

index 35b476a..26786ec 100644 (file)
Binary files a/contentbank/amd/build/selectors.min.js and b/contentbank/amd/build/selectors.min.js differ
index 36d959f..2efa6a5 100644 (file)
Binary files a/contentbank/amd/build/selectors.min.js.map and b/contentbank/amd/build/selectors.min.js.map differ
index d8222ca..2fd3317 100644 (file)
Binary files a/contentbank/amd/build/sort.min.js and b/contentbank/amd/build/sort.min.js differ
index dae9e77..a1b8557 100644 (file)
Binary files a/contentbank/amd/build/sort.min.js.map and b/contentbank/amd/build/sort.min.js.map differ
index b8ca6a6..60fe955 100644 (file)
@@ -48,7 +48,8 @@ export default {
         sortname: getDataSelector('action', 'sortname'),
         sortdate: getDataSelector('action', 'sortdate'),
         sortsize: getDataSelector('action', 'sortsize'),
-        sorttype: getDataSelector('action', 'sorttype')
+        sorttype: getDataSelector('action', 'sorttype'),
+        sortauthor: getDataSelector('action', 'sortauthor'),
     },
     elements: {
         listitem: '.cb-listitem',
index 94c1a24..34c282b 100644 (file)
@@ -35,7 +35,7 @@ import Notification from 'core/notification';
  */
 export const init = () => {
     const contentBank = document.querySelector(selectors.regions.contentbank);
-    Prefetch.prefetchStrings('contentbank', ['contentname', 'lastmodified', 'size', 'type']);
+    Prefetch.prefetchStrings('contentbank', ['contentname', 'lastmodified', 'size', 'type', 'author']);
     Prefetch.prefetchStrings('moodle', ['sortbyx', 'sortbyxreverse']);
     registerListenerEvents(contentBank);
 };
@@ -93,12 +93,19 @@ const registerListenerEvents = (contentBank) => {
         updateSortOrder(fileArea, shownItems, 'data-bytes', ascending);
     });
 
-    // Sort by type
+    // Sort by type.
     const sortByType = contentBank.querySelector(selectors.actions.sorttype);
     sortByType.addEventListener('click', () => {
         const ascending = updateSortButtons(contentBank, sortByType);
         updateSortOrder(fileArea, shownItems, 'data-type', ascending);
     });
+
+    // Sort by author.
+    const sortByAuthor = contentBank.querySelector(selectors.actions.sortauthor);
+    sortByAuthor.addEventListener('click', () => {
+        const ascending = updateSortButtons(contentBank, sortByAuthor);
+        updateSortOrder(fileArea, shownItems, 'data-author', ascending);
+    });
 };
 
 
index 5549392..6c799df 100644 (file)
@@ -86,6 +86,7 @@ class bankcontent implements renderable, templatable {
             $contenttypeclass = $content->get_content_type().'\\contenttype';
             $contenttype = new $contenttypeclass($this->context);
             $name = $content->get_name();
+            $author = \core_user::get_user($content->get_content()->usercreated);
             $contentdata[] = array(
                 'name' => $name,
                 'title' => strtolower($name),
@@ -94,7 +95,8 @@ class bankcontent implements renderable, templatable {
                 'timemodified' => $content->get_timemodified(),
                 'bytes' => $filesize,
                 'size' => display_size($filesize),
-                'type' => $mimetype
+                'type' => $mimetype,
+                'author' => fullname($author),
             );
         }
         $data->viewlist = get_user_preferences('core_contentbank_view_list');
index 6819447..a62beff 100644 (file)
@@ -27,6 +27,7 @@
                 "size": "699.3KB",
                 "bytes": 716126,
                 "type": "Archive (H5P)",
+                "author": "Admin user",
                 "link": "http://something/contentbank/contenttype/h5p/view.php?url=http://something/pluginfile.php/1/contentbank/public/accordion.h5p",
                 "icon" : "http://something/theme/image.php/boost/core/1581597850/f/h5p-64"
             },
@@ -37,6 +38,7 @@
                 "size": "699.3KB",
                 "bytes": 716126,
                 "type": "Archive (PDF)",
+                "author": "Admin user",
                 "icon": "http://something/theme/image.php/boost/core/1584597850/f/pdf-64"
             }
         ],
@@ -122,7 +124,7 @@ data-region="contentbank">
                             <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
                         </button>
                     </div>
-                    <div class="cb-type cb-column d-flex last">
+                    <div class="cb-type cb-column d-flex">
                         <div class="title">{{#str}} type, contentbank {{/str}}</div>
                         <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="type" data-action="sorttype"
                         title="{{#str}} sortbyx, core, {{#str}} type, contentbank {{/str}} {{/str}}">
@@ -131,6 +133,15 @@ data-region="contentbank">
                             <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
                         </button>
                     </div>
+                    <div class="cb-author cb-column d-flex last">
+                        <div class="title">{{#str}} author, contentbank {{/str}}</div>
+                        <button class="btn btn-sm cb-btnsort dir-none ml-auto" data-string="author" data-action="sortauthor"
+                        title="{{#str}} sortbyx, core, {{#str}} author, contentbank {{/str}} {{/str}}">
+                            <span class="default">{{#pix}} t/sort, core, {{#str}}sort, core {{/str}} {{/pix}}</span>
+                            <span class="desc">{{#pix}} t/sort_desc, core, {{#str}}desc, core{{/str}} {{/pix}}</span>
+                            <span class="asc">{{#pix}} t/sort_asc, core, {{#str}}asc, core{{/str}} {{/pix}}</span>
+                        </button>
+                    </div>
                 </div>
             {{#contents}}
                 <div class="cb-listitem"
@@ -138,7 +149,8 @@ data-region="contentbank">
                     data-name="{{{ name }}}"
                     data-bytes="{{ bytes }}"
                     data-timemodified="{{ timemodified }}"
-                    data-type="{{{ type }}}">
+                    data-type="{{{ type }}}"
+                    data-author="{{{ author }}}">
                     <div class="cb-file cb-column position-relative">
                         <div class="cb-thumbnail" role="img" aria-label="{{{ name }}}"
                         style="background-image: url('{{{ icon }}}');">
@@ -155,9 +167,12 @@ data-region="contentbank">
                     <div class="cb-size cb-column small">
                         {{ size }}
                     </div>
-                    <div class="cb-type cb-column last small">
+                    <div class="cb-type cb-column small">
                         {{{ type }}}
                     </div>
+                    <div class="cb-type cb-column last small">
+                        {{{ author }}}
+                    </div>
                 </div>
             {{/contents}}
             </div>
index 6abcf95..242c227 100644 (file)
@@ -5,14 +5,20 @@ Feature: Sort content in the content bank
   I need to be able to sort the content bank in various ways
 
   Background:
-    Given the following "contentbank content" exist:
-        | contextlevel | reference | contenttype       | user  | contentname          |
-        | System       |           | contenttype_h5p   | admin | Dragon_santjordi.h5p |
-        | System       |           | contenttype_h5p   | admin | mathsbook.h5p        |
-        | System       |           | contenttype_h5p   | admin | historybook.h5p      |
-        | System       |           | contenttype_h5p   | admin | santjordi.h5p        |
-        | System       |           | contenttype_h5p   | admin | santjordi_rose.h5p   |
-        | System       |           | contenttype_h5p   | admin | SantJordi_book       |
+    Given the following "users" exist:
+      | username    | firstname | lastname | email              |
+      | manager     | Max       | Manager  | man@example.com    |
+    And the following "role assigns" exist:
+      | user        | role      | contextlevel  | reference     |
+      | manager     | manager       | System    |               |
+    And the following "contentbank content" exist:
+        | contextlevel | reference | contenttype       | user    | contentname          |
+        | System       |           | contenttype_h5p   | admin   | Dragon_santjordi.h5p |
+        | System       |           | contenttype_h5p   | admin   | mathsbook.h5p        |
+        | System       |           | contenttype_h5p   | manager | historybook.h5p      |
+        | System       |           | contenttype_h5p   | admin   | santjordi.h5p        |
+        | System       |           | contenttype_h5p   | admin   | santjordi_rose.h5p   |
+        | System       |           | contenttype_h5p   | admin   | SantJordi_book       |
 
   Scenario: Admins can order content in the content bank
     Given I log in as "admin"
@@ -30,3 +36,18 @@ Feature: Sort content in the content bank
     And "historybook.h5p" "text" should appear before "Dragon_santjordi.h5p" "text"
     And "mathsbook.h5p" "text" should appear before "historybook.h5p" "text"
     Then "santjordi_rose.h5p" "text" should appear before "SantJordi_book" "text"
+
+  Scenario: Admins can order content depending on the author
+    Given I log in as "admin"
+    And I am on site homepage
+    And I turn editing mode on
+    And I add the "Navigation" block if not present
+    And I expand "Site pages" node
+    And I click on "Content bank" "link"
+    When I click on "Display content bank with file details" "button"
+    Then I click on "Sort by Author ascending" "button"
+    And "Dragon_santjordi.h5p" "text" should appear before "historybook.h5p" "text"
+    And "santjordi_rose.h5p" "text" should appear before "historybook" "text"
+    And I click on "Sort by Author descending" "button"
+    And "historybook.h5p" "text" should appear before "Dragon_santjordi.h5p" "text"
+    And "historybook.h5p" "text" should appear before "santjordi_rose" "text"
index a7bfc64..8bed4e2 100644 (file)
@@ -47,7 +47,8 @@
         .cb-heading,
         .cb-date,
         .cb-size,
-        .cb-type {
+        .cb-type,
+        .cb-author {
             display: none;
         }
     }
                 z-index: 1;
             }
 
-            .cb-file,
-            .cb-date {
-                flex: 0 0 35%;
-                max-width: 35%;
+            .cb-file {
+                flex: 0 0 40%;
+                max-width: 40%;
             }
+            .cb-date,
             .cb-size,
-            .cb-type {
+            .cb-type,
+            .cb-author {
                 flex: 0 0 15%;
                 max-width: 15%;
             }
index cbdfb38..f760244 100644 (file)
@@ -13048,7 +13048,8 @@ table.calendartable caption {
 .content-bank-container.view-grid .cb-heading,
 .content-bank-container.view-grid .cb-date,
 .content-bank-container.view-grid .cb-size,
-.content-bank-container.view-grid .cb-type {
+.content-bank-container.view-grid .cb-type,
+.content-bank-container.view-grid .cb-author {
   display: none; }
 
 .content-bank-container.view-list .cb-content-wrapper {
@@ -13083,12 +13084,13 @@ table.calendartable caption {
     position: sticky;
     top: 0;
     z-index: 1; }
-  .content-bank-container.view-list .cb-file,
-  .content-bank-container.view-list .cb-date {
-    flex: 0 0 35%;
-    max-width: 35%; }
+  .content-bank-container.view-list .cb-file {
+    flex: 0 0 40%;
+    max-width: 40%; }
+  .content-bank-container.view-list .cb-date,
   .content-bank-container.view-list .cb-size,
-  .content-bank-container.view-list .cb-type {
+  .content-bank-container.view-list .cb-type,
+  .content-bank-container.view-list .cb-author {
     flex: 0 0 15%;
     max-width: 15%; }
   .content-bank-container.view-list .cb-column.last {
index d673dfc..ecdabf3 100644 (file)
@@ -13262,7 +13262,8 @@ table.calendartable caption {
 .content-bank-container.view-grid .cb-heading,
 .content-bank-container.view-grid .cb-date,
 .content-bank-container.view-grid .cb-size,
-.content-bank-container.view-grid .cb-type {
+.content-bank-container.view-grid .cb-type,
+.content-bank-container.view-grid .cb-author {
   display: none; }
 
 .content-bank-container.view-list .cb-content-wrapper {
@@ -13297,12 +13298,13 @@ table.calendartable caption {
     position: sticky;
     top: 0;
     z-index: 1; }
-  .content-bank-container.view-list .cb-file,
-  .content-bank-container.view-list .cb-date {
-    flex: 0 0 35%;
-    max-width: 35%; }
+  .content-bank-container.view-list .cb-file {
+    flex: 0 0 40%;
+    max-width: 40%; }
+  .content-bank-container.view-list .cb-date,
   .content-bank-container.view-list .cb-size,
-  .content-bank-container.view-list .cb-type {
+  .content-bank-container.view-list .cb-type,
+  .content-bank-container.view-list .cb-author {
     flex: 0 0 15%;
     max-width: 15%; }
   .content-bank-container.view-list .cb-column.last {