Merge branch 'MDL-73900-master' of https://github.com/vmdef/moodle

This commit is contained in:
Jun Pataleta 2022-03-30 11:08:05 +08:00
commit bf13032bf7
11 changed files with 121 additions and 26 deletions

View File

@ -5,6 +5,6 @@
* @copyright 2018 Victor Deniz <victor@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define("block_recentlyaccesseditems/main",["jquery","block_recentlyaccesseditems/repository","core/templates","core/notification"],(function($,Repository,Templates,Notification){var SELECTORS_CARDDECK_CONTAINER='[data-region="recentlyaccesseditems-view"]',SELECTORS_CARDDECK='[data-region="recentlyaccesseditems-view-content"]';return{init:function(root){var limit,itemsContainer=(root=$(root)).find(SELECTORS_CARDDECK_CONTAINER),itemsContent=root.find(SELECTORS_CARDDECK),itemsPromise=(limit=9,Repository.getRecentItems(limit));itemsPromise.then((function(items){var pageContentPromise=function(root,items){if(items.length>0)return Templates.render("block_recentlyaccesseditems/view-cards",{items:items});var noitemsimgurl=root.attr("data-noitemsimgurl");return Templates.render("block_recentlyaccesseditems/no-items",{noitemsimgurl:noitemsimgurl})}(itemsContainer,items);return pageContentPromise.then((function(html,js){return Templates.replaceNodeContents(itemsContent,html,js)})).catch(Notification.exception),itemsPromise})).catch(Notification.exception)}}}));
define("block_recentlyaccesseditems/main",["jquery","block_recentlyaccesseditems/repository","core/templates","core/notification"],(function($,Repository,Templates,Notification){var SELECTORS_CARDDECK_CONTAINER='[data-region="recentlyaccesseditems-view"]',SELECTORS_CARDDECK='[data-region="recentlyaccesseditems-view-content"]',SELECTORS_SHOWMORE_LINK='[data-region="recentlyaccesseditems-view"] [data-action="more-items"]';return{init:function(root){var limit,itemsContainer=(root=$(root)).find(SELECTORS_CARDDECK_CONTAINER),itemsContent=root.find(SELECTORS_CARDDECK);(limit=9,Repository.getRecentItems(limit)).then((function(items){var pageContentPromise=function(root,items){if(items.length>0){let hasmoreitems=!1;return items.length>3&&(hasmoreitems=!0),Templates.render("block_recentlyaccesseditems/view-cards",{items:items,hasmoreitems:hasmoreitems})}var noitemsimgurl=root.attr("data-noitemsimgurl");return Templates.render("block_recentlyaccesseditems/no-items",{noitemsimgurl:noitemsimgurl})}(itemsContainer,items);pageContentPromise.then((function(html,js){return Templates.replaceNodeContents(itemsContent,html,js),items.length>3&&(()=>{const showmoreLink=document.querySelector(SELECTORS_SHOWMORE_LINK);showmoreLink.addEventListener("click",(()=>{showmoreLink.classList.add("d-none"),document.querySelector('[data-region="items-list"]').children.forEach((function(hiddenItem){hiddenItem.style="display: block"}))}))})(),null})).catch(Notification.exception)})).catch(Notification.exception)}}}));
//# sourceMappingURL=main.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -37,10 +37,30 @@ define(
) {
var NUM_ITEMS = 9;
// Maximum number of elements to display in the block initially.
var NUM_ITEMS_INIT = 3;
var SELECTORS = {
CARDDECK_CONTAINER: '[data-region="recentlyaccesseditems-view"]',
CARDDECK: '[data-region="recentlyaccesseditems-view-content"]',
SHOWMORE_LINK: '[data-region="recentlyaccesseditems-view"] [data-action="more-items"]',
};
/**
* Register event listeners.
*/
const registerEventListeners = () => {
const showmoreLink = document.querySelector(SELECTORS.SHOWMORE_LINK);
// Hide "Show more" link and show additional items.
showmoreLink.addEventListener('click', () => {
showmoreLink.classList.add('d-none');
const hiddenItems = document.querySelector('[data-region="items-list"]').children;
hiddenItems.forEach(function(hiddenItem) {
hiddenItem.style = "display: block";
});
});
};
/**
@ -64,8 +84,13 @@ define(
*/
var renderItems = function(root, items) {
if (items.length > 0) {
let hasmoreitems = false;
if (items.length > NUM_ITEMS_INIT) {
hasmoreitems = true;
}
return Templates.render('block_recentlyaccesseditems/view-cards', {
items: items
items: items,
hasmoreitems: hasmoreitems
});
} else {
var noitemsimgurl = root.attr('data-noitemsimgurl');
@ -92,9 +117,12 @@ define(
var pageContentPromise = renderItems(itemsContainer, items);
pageContentPromise.then(function(html, js) {
return Templates.replaceNodeContents(itemsContent, html, js);
Templates.replaceNodeContents(itemsContent, html, js);
if (items.length > 3) {
registerEventListeners();
}
return null;
}).catch(Notification.exception);
return itemsPromise;
}).catch(Notification.exception);
};

View File

@ -20,6 +20,7 @@
* @copyright 2018 Victor Deniz <victor@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['moreitems'] = 'Show more items';
$string['noitems'] = 'No recent items';
$string['pluginname'] = 'Recently accessed items';
$string['privacy:metadata:cmid'] = 'The ID of the activity or resource';

View File

@ -24,11 +24,12 @@
"noitemsimgurl": "https://moodlesite/theme/image.php/boost/block_recentlyaccesseditems/1535727318/items"
}
}}
<div class="text-center" data-region="empty-message">
<img class="empty-placeholder-image-lg"
<div class="text-xs-center text-center mt-4" data-region="empty-message">
<img
src="{{noitemsimgurl}}"
alt="{{#str}} noitems, block_recentlyaccesseditems {{/str}}"
role="presentation"
style="height: 70px; width: 70px;"
>
<p class="text-muted mt-3 mb-0">{{#str}} noitems, block_recentlyaccesseditems {{/str}}</p>
</div>

View File

@ -22,12 +22,14 @@
Example context (json):
{}
}}
<div class="card dashboard-card border-0 mb-0">
<div class="d-flex flex-row align-items-center" style="height: 6rem">
<div class="bg-pulse-grey rounded-circle" style="height: 2rem; width: 2rem;"></div>
<div class="w-100 line-height-3 ml-1">
<div class="card dashboard-card mb-1">
<div class="card-body p-2 m-1">
<div class="d-flex flex-row mw-100 align-items-center">
<div class="bg-pulse-grey rounded-circle" style="height: 40px; width: 40px;"></div>
<div class="pl-2" style="flex: 1;">
<div class="bg-pulse-grey w-100" style="height: 1rem;"></div>
<div class="bg-pulse-grey w-75 mt-1" style="height: 0.8rem;"></div>
</div>
</div>
</div>
</div>

View File

@ -40,10 +40,10 @@
}
}}
<div class="card-deck dashboard-card-deck one-row" role="list">
<div class="card-deck dashboard-card-deck one-row" data-region="items-list" role="list">
{{#items}}
<a class="card dashboard-card mb-1 py-2 coursename" href="{{{viewurl}}}">
<div class="card-body course-info-container">
<a class="card dashboard-card mb-1" href="{{{viewurl}}}">
<div class="card-body p-2 m-1">
<div class="d-flex text-truncate">
<div class="d-flex align-self-center activityiconcontainer {{purpose}}">
{{{icon}}}
@ -57,3 +57,10 @@
</a>
{{/items}}
</div>
{{#hasmoreitems}}
<div data-region="more-items-button-container" class="mt-2 px-1">
<button type="button" class="btn btn-secondary btn-sm" data-action="more-items">
{{#str}}moreitems, block_recentlyaccesseditems {{/str}}
</button>
</div>
{{/hasmoreitems}}

View File

@ -31,3 +31,29 @@ Feature: The recently accessed items block allows users to easily access their m
When I am on the "Test forum name" "forum activity" page
And I follow "Dashboard"
Then I should see "Test forum name" in the "Recently accessed items" "block"
And I should not see "Show/hide more" in the "Recently accessed items" "block"
Scenario: User has accessed more than 3 items
Given the following "activities" exist:
| activity | name | intro | course | idnumber |
| assign | Test assignment name | Test assignment description | C1 | assign1 |
| book | Test book name | Test book description | C1 | book1 |
| choice | Test choice name | Test choice description | C1 | choice1 |
| data | Test database name | Test database description | C1 | data1 |
And I change window size to "large"
And I am on the "Test forum name" "forum activity" page
And I am on the "Test assignment name" "assign activity" page
And I am on the "Test book name" "book activity" page
And I am on the "Test choice name" "choice activity" page
When I follow "Dashboard"
Then I should see "Show more" in the "Recently accessed items" "block"
And I should not see "Test forum name" in the "Recently accessed items" "block"
And I follow "Show more..."
And I should see "Test forum name" in the "Recently accessed items" "block"
And I turn editing mode on
And I configure the "Recently accessed items" block
And I set the following fields to these values:
| Region | content |
And I press "Save changes"
And I turn editing mode off
And I should not see "Show more" in the "Recently accessed items" "block"

View File

@ -267,10 +267,22 @@ $card-gutter : $card-deck-margin * 2;
}
.block_recentlyaccesseditems {
img.icon {
height: 24px;
width: 24px;
margin-right: 6px;
.activityiconcontainer {
width: 40px;
height: 40px;
}
aside[id^="block-region-side-"] & .dashboard-card-deck.one-row {
flex-flow: wrap;
overflow-x: hidden;
}
aside[id^="block-region-side-"] & .dashboard-card-deck .card:nth-of-type(n+4) {
display: none;
}
#block-region-content & [data-region="more-items-button-container"] {
display: none;
}
}

View File

@ -13091,10 +13091,19 @@ body.dragging .dragging {
#block-region-side-pre .block_recentlyaccessedcourses .paging-bar-container {
margin-top: 0; }
.block_recentlyaccesseditems img.icon {
height: 24px;
width: 24px;
margin-right: 6px; }
.block_recentlyaccesseditems .activityiconcontainer {
width: 40px;
height: 40px; }
aside[id^="block-region-side-"] .block_recentlyaccesseditems .dashboard-card-deck.one-row {
flex-flow: wrap;
overflow-x: hidden; }
aside[id^="block-region-side-"] .block_recentlyaccesseditems .dashboard-card-deck .card:nth-of-type(n+4) {
display: none; }
#block-region-content .block_recentlyaccesseditems [data-region="more-items-button-container"] {
display: none; }
.block_myoverview .content {
min-height: 19.35rem; }

View File

@ -13091,10 +13091,19 @@ body.dragging .dragging {
#block-region-side-pre .block_recentlyaccessedcourses .paging-bar-container {
margin-top: 0; }
.block_recentlyaccesseditems img.icon {
height: 24px;
width: 24px;
margin-right: 6px; }
.block_recentlyaccesseditems .activityiconcontainer {
width: 40px;
height: 40px; }
aside[id^="block-region-side-"] .block_recentlyaccesseditems .dashboard-card-deck.one-row {
flex-flow: wrap;
overflow-x: hidden; }
aside[id^="block-region-side-"] .block_recentlyaccesseditems .dashboard-card-deck .card:nth-of-type(n+4) {
display: none; }
#block-region-content .block_recentlyaccesseditems [data-region="more-items-button-container"] {
display: none; }
.block_myoverview .content {
min-height: 19.35rem; }