Merge branch 'MDL-72893-master' of https://github.com/HuongNV13/moodle

This commit is contained in:
Sara Arjona 2021-11-29 09:58:32 +01:00
commit d1667b684b
4 changed files with 11 additions and 6 deletions

View File

@ -1,2 +1,2 @@
define ("block_timeline/event_list",["jquery","core/notification","core/templates","core/str","core/user_date","block_timeline/calendar_events_repository"],function(a,b,c,d,e,f){var g=!1,h={EMPTY_MESSAGE:"[data-region=\"empty-message\"]",ROOT:"[data-region=\"event-list-container\"]",EVENT_LIST_CONTENT:"[data-region=\"event-list-content\"]",EVENT_LIST_WRAPPER:"[data-region=\"event-list-wrapper\"]",EVENT_LIST_LOADING_PLACEHOLDER:"[data-region=\"event-list-loading-placeholder\"]",TIMELINE_BLOCK:"[data-region=\"timeline\"]",TIMELINE_SEARCH:"[data-region=\"search-input\"]",MORE_ACTIVITIES_BUTTON:"[data-action=\"more-events\"]",MORE_ACTIVITIES_BUTTON_CONTAINER:"[data-region=\"more-events-button-container\"]"},i={EVENT_LIST_CONTENT:"block_timeline/event-list-content",MORE_ACTIVITIES_BUTTON:"block_timeline/event-list-loadmore",LOADING_ICON:"core/loading"},j=function(a){a.find(h.EVENT_LIST_CONTENT).addClass("hidden");a.find(h.EMPTY_MESSAGE).removeClass("hidden")},k=function(a){a.find(h.EVENT_LIST_CONTENT).removeClass("hidden");a.find(h.EMPTY_MESSAGE).addClass("hidden")},l=function(a){a.find(h.EVENT_LIST_CONTENT).empty()},m=function(a){var b={},c={courseview:g,eventsbyday:[]};a.forEach(function(a){var c=a.timeusermidnight;if(b[c]){b[c].push(a)}else{b[c]=[a]}});Object.keys(b).forEach(function(a){var d=b[a];c.eventsbyday.push({dayTimestamp:a,events:d})});return c},n=function(a){var b=m(a),d=i.EVENT_LIST_CONTENT;return c.render(d,b)},o=function(a,b,c,d,e,g,h){var i=d!=void 0?a+d*86400:!1,j={starttime:a+c*86400,limit:b};if(e){j.aftereventid=e}if(i){j.endtime=i}if(h){j.searchvalue=h}if(g){j.courseid=g;return f.queryByCourse(j)}else{return f.queryByTime(j)}},p=function(a,c,d,e,f,g,h,i,j){return q(a,d,e,f,g,h,i,j).then(function(a){if(a.calendarEvents.length){var b=a.calendarEvents.at(-1).id,d=a.calendarEvents.at(-1).timeusermidnight;c.resolve({hasContent:!0,lastId:b,lastTimeStamp:d,loadedAll:a.loadedAll});return n(a.calendarEvents,e)}else{c.resolve({hasContent:!1,lastId:0,lastTimeStamp:0,loadedAll:!0});return a.calendarEvents}}).catch(b.exception)},q=function(a,b,c,d,f,g,h,i){var j=o(c,b+1,g,h,d,f,i),k=[],l=!0;return j.then(function(d){if(!d.events.length){return{calendarEvents:k,loadedAll:l}}var f=document.querySelector("[data-filtername='overdue']"),g=f&&f.getAttribute("aria-current");k=d.events.filter(function(a){if("open"==a.eventtype||"opensubmission"==a.eventtype){var b=e.getUserMidnightForTimestamp(a.timesort,c);return b>c}return!g||a.overdue});l=k.length<=b;if(!l){k.pop()}if(k.length){var h=k.at(-1).id;t(a,h)}return{calendarEvents:k,loadedAll:l}})},r=function(d){var e=parseInt(d.attr("data-midnight"),10),f=d.attr("data-course-id"),g=parseInt(d.attr("data-days-offset"),10),j=d.attr("data-days-limit"),k=s(d),l=d.find(h.EVENT_LIST_WRAPPER),m=d.closest(h.TIMELINE_BLOCK).find(h.TIMELINE_SEARCH).val(),o=q(d,10,e,k,f,g,j,m);o.then(function(e){if(e.calendarEvents.length){var f=n(e.calendarEvents),g=u(d);f.then(function(b,f){b=a(b);b.find("[data-timestamp=\"".concat(g,"\"]")).remove();c.appendNodeContents(l,b.html(),f);if(!e.loadedAll){c.render(i.MORE_ACTIVITIES_BUTTON,{}).then(function(a){l.append(a);v(d,e.calendarEvents.at(-1).timeusermidnight);y(d);return a}).catch(function(){return!1})}return b}).catch(b.exception)}return e}).then(function(){return x(d)}).catch(b.exception)},s=function(a){return parseInt(a.attr("data-lazyload-offset"),10)},t=function(a,b){a.attr("data-lazyload-offset",b)},u=function(a){return parseInt(a.attr("data-timestamp"),10)},v=function(a,b){a.attr("data-timestamp",b)},w=function(a){var b=a.find(h.MORE_ACTIVITIES_BUTTON);b.prop("disabled",!0);c.render(i.LOADING_ICON,{}).then(function(a){b.append(a);return a}).catch(function(){return!1})},x=function(a){var b=a.find(h.MORE_ACTIVITIES_BUTTON_CONTAINER);b.remove()},y=function(a){var b=a.find(h.MORE_ACTIVITIES_BUTTON);b.on("click",function(){w(a);r(a)})};return{init:function init(d){var e=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{};d=a(d);g=!!e.courseview;var f=a.Deferred(),m=d.find(h.EVENT_LIST_CONTENT),n=d.find(h.EVENT_LIST_LOADING_PLACEHOLDER),o=d.attr("data-course-id"),q=parseInt(d.attr("data-days-offset"),10),r=d.attr("data-days-limit"),s=parseInt(d.attr("data-midnight"),10),t=d.closest(h.TIMELINE_BLOCK).find(h.TIMELINE_SEARCH).val();l(d);k(d);n.removeClass("hidden");if(r!=void 0){r=parseInt(r,10)}return p(d,f,5,s,0,o,q,r,t).then(function(b,e){f.then(function(f){if(!f.hasContent){n.addClass("hidden");return j(d)}b=a(b);b.addClass("hidden");c.replaceNodeContents(m,b,e);b.removeClass("hidden");n.addClass("hidden");if(!f.loadedAll){c.render(i.MORE_ACTIVITIES_BUTTON,{}).then(function(a){m.append(a);v(d,f.lastTimeStamp);y(d);return a}).catch(function(){return!1})}return f}).catch(function(){return!1});return b}).catch(b.exception)},rootSelector:h.ROOT}});
define ("block_timeline/event_list",["jquery","core/notification","core/templates","core/str","core/user_date","block_timeline/calendar_events_repository","core/pending"],function(a,b,c,d,e,f,g){var h=!1,i={EMPTY_MESSAGE:"[data-region=\"empty-message\"]",ROOT:"[data-region=\"event-list-container\"]",EVENT_LIST_CONTENT:"[data-region=\"event-list-content\"]",EVENT_LIST_WRAPPER:"[data-region=\"event-list-wrapper\"]",EVENT_LIST_LOADING_PLACEHOLDER:"[data-region=\"event-list-loading-placeholder\"]",TIMELINE_BLOCK:"[data-region=\"timeline\"]",TIMELINE_SEARCH:"[data-region=\"search-input\"]",MORE_ACTIVITIES_BUTTON:"[data-action=\"more-events\"]",MORE_ACTIVITIES_BUTTON_CONTAINER:"[data-region=\"more-events-button-container\"]"},j={EVENT_LIST_CONTENT:"block_timeline/event-list-content",MORE_ACTIVITIES_BUTTON:"block_timeline/event-list-loadmore",LOADING_ICON:"core/loading"},k=function(a){a.find(i.EVENT_LIST_CONTENT).addClass("hidden");a.find(i.EMPTY_MESSAGE).removeClass("hidden")},l=function(a){a.find(i.EVENT_LIST_CONTENT).removeClass("hidden");a.find(i.EMPTY_MESSAGE).addClass("hidden")},m=function(a){a.find(i.EVENT_LIST_CONTENT).empty()},n=function(a){var b={},c={courseview:h,eventsbyday:[]};a.forEach(function(a){var c=a.timeusermidnight;if(b[c]){b[c].push(a)}else{b[c]=[a]}});Object.keys(b).forEach(function(a){var d=b[a];c.eventsbyday.push({dayTimestamp:a,events:d})});return c},o=function(a){var b=n(a),d=j.EVENT_LIST_CONTENT;return c.render(d,b)},p=function(a,b,c,d,e,g,h){var i=d!=void 0?a+d*86400:!1,j={starttime:a+c*86400,limit:b};if(e){j.aftereventid=e}if(i){j.endtime=i}if(h){j.searchvalue=h}if(g){j.courseid=g;return f.queryByCourse(j)}else{return f.queryByTime(j)}},q=function(a,c,d,e,f,g,h,i,j){return r(a,d,e,f,g,h,i,j).then(function(a){if(a.calendarEvents.length){var b=a.calendarEvents.at(-1).id,d=a.calendarEvents.at(-1).timeusermidnight;c.resolve({hasContent:!0,lastId:b,lastTimeStamp:d,loadedAll:a.loadedAll});return o(a.calendarEvents,e)}else{c.resolve({hasContent:!1,lastId:0,lastTimeStamp:0,loadedAll:!0});return a.calendarEvents}}).catch(b.exception)},r=function(a,b,c,d,f,g,h,i){var j=p(c,b+1,g,h,d,f,i),k=[],l=!0;return j.then(function(d){if(!d.events.length){return{calendarEvents:k,loadedAll:l}}var f=document.querySelector("[data-filtername='overdue']"),g=f&&f.getAttribute("aria-current");k=d.events.filter(function(a){if("open"==a.eventtype||"opensubmission"==a.eventtype){var b=e.getUserMidnightForTimestamp(a.timesort,c);return b>c}return!g||a.overdue});l=k.length<=b;if(!l){k.pop()}if(k.length){var h=k.at(-1).id;u(a,h)}return{calendarEvents:k,loadedAll:l}})},s=function(d){var e=parseInt(d.attr("data-midnight"),10),f=d.attr("data-course-id"),g=parseInt(d.attr("data-days-offset"),10),h=d.attr("data-days-limit"),k=t(d),l=d.find(i.EVENT_LIST_WRAPPER),m=d.closest(i.TIMELINE_BLOCK).find(i.TIMELINE_SEARCH).val(),n=r(d,10,e,k,f,g,h,m);n.then(function(e){if(e.calendarEvents.length){var f=o(e.calendarEvents),g=v(d);f.then(function(b,f){b=a(b);b.find("[data-timestamp=\"".concat(g,"\"]")).remove();c.appendNodeContents(l,b.html(),f);if(!e.loadedAll){c.render(j.MORE_ACTIVITIES_BUTTON,{}).then(function(a){l.append(a);w(d,e.calendarEvents.at(-1).timeusermidnight);z(d);return a}).catch(function(){return!1})}return b}).catch(b.exception)}return e}).then(function(){return y(d)}).catch(b.exception)},t=function(a){return parseInt(a.attr("data-lazyload-offset"),10)},u=function(a,b){a.attr("data-lazyload-offset",b)},v=function(a){return parseInt(a.attr("data-timestamp"),10)},w=function(a,b){a.attr("data-timestamp",b)},x=function(a){var b=a.find(i.MORE_ACTIVITIES_BUTTON);b.prop("disabled",!0);c.render(j.LOADING_ICON,{}).then(function(a){b.append(a);return a}).catch(function(){return!1})},y=function(a){var b=a.find(i.MORE_ACTIVITIES_BUTTON_CONTAINER);b.remove()},z=function(a){var b=a.find(i.MORE_ACTIVITIES_BUTTON);b.on("click",function(){x(a);s(a)})};return{init:function init(d){var e=1<arguments.length&&arguments[1]!==void 0?arguments[1]:{},f=new g("block/timeline:event-init");d=a(d);h=!!e.courseview;var n=a.Deferred(),o=d.find(i.EVENT_LIST_CONTENT),p=d.find(i.EVENT_LIST_LOADING_PLACEHOLDER),r=d.attr("data-course-id"),s=parseInt(d.attr("data-days-offset"),10),t=d.attr("data-days-limit"),u=parseInt(d.attr("data-midnight"),10),v=d.closest(i.TIMELINE_BLOCK).find(i.TIMELINE_SEARCH).val();m(d);l(d);p.removeClass("hidden");if(t!=void 0){t=parseInt(t,10)}return q(d,n,5,u,0,r,s,t,v).then(function(b,e){n.then(function(f){if(!f.hasContent){p.addClass("hidden");return k(d)}b=a(b);b.addClass("hidden");c.replaceNodeContents(o,b,e);b.removeClass("hidden");p.addClass("hidden");if(!f.loadedAll){c.render(j.MORE_ACTIVITIES_BUTTON,{}).then(function(a){o.append(a);w(d,f.lastTimeStamp);z(d);return a}).catch(function(){return!1})}return f}).catch(function(){return!1});return b}).then(function(){return f.resolve()}).catch(b.exception)},rootSelector:i.ROOT}});
//# sourceMappingURL=event_list.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -28,7 +28,8 @@ define(
'core/templates',
'core/str',
'core/user_date',
'block_timeline/calendar_events_repository'
'block_timeline/calendar_events_repository',
'core/pending'
],
function(
$,
@ -36,7 +37,8 @@ function(
Templates,
Str,
UserDate,
CalendarEventsRepository
CalendarEventsRepository,
Pending
) {
var SECONDS_IN_DAY = 60 * 60 * 24;
@ -215,6 +217,7 @@ function(
* @param {object} additionalConfig Additional config options to pass to pagedContentFactory.
*/
var init = function(root, additionalConfig = {}) {
const pendingPromise = new Pending('block/timeline:event-init');
root = $(root);
courseview = !!additionalConfig.courseview;
@ -286,6 +289,8 @@ function(
});
return html;
}).then(() => {
return pendingPromise.resolve();
})
.catch(Notification.exception);
};

View File

@ -42,8 +42,8 @@ Feature: The timeline block allows users to see upcoming courses
And I click on "Next 30 days" "link" in the "Timeline" "block"
And I click on "Sort timeline items" "button" in the "Timeline" "block"
When I click on "Sort by courses" "link" in the "Timeline" "block"
Then I should see "Course 1" in the "Timeline" "block"
And I should see "Course 2" in the "Timeline" "block"
Then I should see "Course 1" in the ".block_timeline [data-region='view-courses']" "css_element"
And I should see "Course 2" in the ".block_timeline [data-region='view-courses']" "css_element"
And I should see "Show more courses" in the "Timeline" "block"
And "Test choice 1" "link" should exist in the "Timeline" "block"
And I should see "Choice closes" in the "Timeline" "block"