Skip to content
Permalink
Browse files
Merge branch 'MDL-63817-master' of git://github.com/peterRd/moodle
  • Loading branch information
David Monllao committed Nov 19, 2018
2 parents a356db0 + 2044a53 commit 94db315b50c307906ccf03e00b019e4f71eea2ef

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

@@ -300,6 +300,7 @@ function(
* @param {Number} daysOffset How many days (from midnight) to offset the results from
* @param {int|undefined} daysLimit How many dates (from midnight) to limit the result to
* @param {string} paginationAriaLabel String to set as the aria label for the pagination bar.
* @param {object} additionalConfig Additional config options to pass to pagedContentFactory
* @return {object} jQuery promise.
*/
var createPagedContent = function(
@@ -310,15 +311,16 @@ function(
courseId,
daysOffset,
daysLimit,
paginationAriaLabel
paginationAriaLabel,
additionalConfig
) {
// Remember the last event id we loaded on each page because we can't
// use the offset value since the backend can skip events if the user doesn't
// have the capability to see them. Instead we load the next page of events
// based on the last seen event id.
var lastIds = {'1': 0};
var hasContent = false;
var config = $.extend({}, DEFAULT_PAGED_CONTENT_CONFIG);
var config = $.extend({}, DEFAULT_PAGED_CONTENT_CONFIG, additionalConfig);

return Str.get_string(
'ariaeventlistpagelimit',
@@ -396,8 +398,9 @@ function(
* @param {int|array} pageLimit A single limit or list of limits as options for the paged content
* @param {object} preloadedPages An object of preloaded page data. Page number as key, data promise as value.
* @param {string} paginationAriaLabel String to set as the aria label for the pagination bar.
* @param {object} additionalConfig Additional config options to pass to pagedContentFactory
*/
var init = function(root, pageLimit, preloadedPages, paginationAriaLabel) {
var init = function(root, pageLimit, preloadedPages, paginationAriaLabel, additionalConfig) {
root = $(root);

// Create a promise that will be resolved once the first set of page
@@ -425,7 +428,8 @@ function(
}

// Created the paged content element.
createPagedContent(pageLimit, preloadedPages, midnight, firstLoad, courseId, daysOffset, daysLimit, paginationAriaLabel)
return createPagedContent(pageLimit, preloadedPages, midnight, firstLoad, courseId, daysOffset, daysLimit,
paginationAriaLabel, additionalConfig)
.then(function(html, js) {
html = $(html);
// Hide the content for now.
@@ -25,33 +25,87 @@ define(
[
'jquery',
'core/str',
'block_timeline/event_list'
'block_timeline/event_list',
'core/pubsub',
'core/paged_content_events'
],
function(
$,
Str,
EventList
EventList,
PubSub,
PagedContentEvents
) {

var SELECTORS = {
EVENT_LIST_CONTAINER: '[data-region="event-list-container"]',
};

var DEFAULT_PAGE_LIMIT = [5, 10, 25];

/**
* Generate a paged content array of limits taking into account user preferences
*
* @param {object} root The root element for the timeline dates view.
* @return {array} Array of limit objects
*/
var getPagingLimits = function(root) {
var limitPref = parseInt(root.data('limit'), 10);
var isDefaultSet = false;
var limits = DEFAULT_PAGE_LIMIT.map(function(value) {
if (limitPref == value) {
isDefaultSet = true;
}

return {
value: value,
active: limitPref == value
};
});

if (!isDefaultSet) {
limits[0].active = true;
}

return limits;
};

/**
* Setup the listeners for the timeline block
*
* @param {string} root view dates container
* @param {string} namespace The namespace for the paged content
*/
var registerEventListeners = function(root, namespace) {
var event = namespace + PagedContentEvents.SET_ITEMS_PER_PAGE_LIMIT;
PubSub.subscribe(event, function(limit) {
$(root).data('limit', limit);
});
};

/**
* Initialise the event list and being loading the events.
*
* @param {object} root The root element for the timeline dates view.
*/
var load = function(root) {
var eventListContainer = root.find(SELECTORS.EVENT_LIST_CONTAINER);
var namespace = $(eventListContainer).attr('id') + "user_block_timeline" + Math.random();
registerEventListeners(root, namespace);

var limits = getPagingLimits(root);
var config = {
persistentLimitKey: "block_timeline_user_limit_preference",
eventNamespace: namespace
};
Str.get_string('ariaeventlistpaginationnavdates', 'block_timeline')
.then(function(string) {
EventList.init(eventListContainer, [5, 10, 25], {}, string);
EventList.init(eventListContainer, limits, {}, string, config);
return string;
})
.catch(function() {
// Ignore if we can't load the string. Still init the event list.
EventList.init(eventListContainer, [5, 10, 25]);
EventList.init(eventListContainer, limits, {}, "", config);
});
};

@@ -65,7 +119,7 @@ function(
root = $(root);
if (root.hasClass('active')) {
load(root);
root.attr('data-seen', true);
root.data('seen', true);
}
};

@@ -79,7 +133,7 @@ function(
root.removeAttr('data-seen');
if (root.hasClass('active')) {
load(root);
root.attr('data-seen', true);
root.data('seen', true);
}
};

@@ -89,9 +143,9 @@ function(
* @param {object} root The root element for the timeline courses view.
*/
var shown = function(root) {
if (!root.attr('data-seen')) {
if (!root.data('seen')) {
load(root);
root.attr('data-seen', true);
root.data('seen', true);
}
};

@@ -52,8 +52,9 @@ public function get_content() {

$sort = get_user_preferences('block_timeline_user_sort_preference');
$filter = get_user_preferences('block_timeline_user_filter_preference');
$limit = get_user_preferences('block_timeline_user_limit_preference');

$renderable = new \block_timeline\output\main($sort, $filter);
$renderable = new \block_timeline\output\main($sort, $filter, $limit);
$renderer = $this->page->get_renderer('block_timeline');

$this->content = (object) [
@@ -54,15 +54,22 @@ class main implements renderable, templatable {
*/
public $order;

/**
* @var string The current limit preference
*/
public $limit;

/**
* main constructor.
*
* @param string $order Constant sort value from ../timeline/lib.php
* @param string $filter Constant sort value from ../timeline/lib.php
* @param string $filter Constant filter value from ../timeline/lib.php
* @param string $limit Constant limit value from ../timeline/lib.php
*/
public function __construct($order, $filter) {
public function __construct($order, $filter, $limit) {
$this->order = $order ? $order : BLOCK_TIMELINE_SORT_BY_DATES;
$this->filter = $filter ? $filter : BLOCK_TIMELINE_FILTER_BY_7_DAYS;
$this->limit = $limit ? $limit : BLOCK_TIMELINE_LIMIT_DEFAULT;
}

/**
@@ -165,6 +172,7 @@ public function export_for_template(renderer_base $output) {
'hasdaysoffset' => true,
'hasdayslimit' => $offsets['dayslimit'] !== false ,
'nodayslimit' => $offsets['dayslimit'] === false ,
'limit' => $this->limit
];
return array_merge($contextvariables, $filters, $offsets);
}
@@ -44,6 +44,7 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l
public static function get_metadata(collection $collection) : collection {
$collection->add_user_preference('block_timeline_user_sort_preference', 'privacy:metadata:timelinesortpreference');
$collection->add_user_preference('block_timeline_user_filter_preference', 'privacy:metadata:timelinefilterpreference');
$collection->add_user_preference('block_timeline_user_limit_preference', 'privacy:metadata:timelinelimitpreference');
return $collection;
}

@@ -68,5 +69,13 @@ public static function export_user_preferences(int $userid) {
get_string('privacy:metadata:timelinefilterpreference', 'block_timeline')
);
}

$preference = get_user_preferences('block_timeline_user_limit_preference', null, $userid);
if (isset($preference)) {
\core_privacy\local\request\writer::export_user_preference('block_timeline', 'block_timeline_user_limit_preference',
$preference,
get_string('privacy:metadata:timelinelimitpreference', 'block_timeline')
);
}
}
}
@@ -49,3 +49,4 @@
$string['viewcourse'] = 'View course';
$string['privacy:metadata:timelinesortpreference'] = 'The user sort preference for the timeline block.';
$string['privacy:metadata:timelinefilterpreference'] = 'The user day filter preference for the timeline block.';
$string['privacy:metadata:timelinelimitpreference'] = 'The user page limit preference for the timeline block.';
@@ -38,6 +38,7 @@
define('BLOCK_TIMELINE_FILTER_BY_30_DAYS', 'next30days');
define('BLOCK_TIMELINE_FILTER_BY_3_MONTHS', 'next3months');
define('BLOCK_TIMELINE_FILTER_BY_6_MONTHS', 'next6months');
define('BLOCK_TIMELINE_LIMIT_DEFAULT', 2);

/**
* Returns the name of the user preferences as well as the details this plugin uses.
@@ -66,5 +67,11 @@ function block_timeline_user_preferences() {
)
);

$preferences['block_timeline_user_limit_preference'] = array(
'null' => NULL_NOT_ALLOWED,
'default' => BLOCK_TIMELINE_LIMIT_DEFAULT,
'type' => PARAM_INT
);

return $preferences;
}
@@ -42,12 +42,13 @@
"next3months": false,
"next6months": false,
"daysoffset": -14,
"dayslimit": false
"dayslimit": false,
"limit": 0
}
}}
<div data-region="timeline-view">
<div class="tab-content">
<div class="tab-pane {{#sorttimelinedates}}active show{{/sorttimelinedates}} fade" data-region="view-dates" id="view_dates_{{uniqid}}">
<div class="tab-pane {{#sorttimelinedates}}active show{{/sorttimelinedates}} fade" data-limit="{{limit}}" data-region="view-dates" id="view_dates_{{uniqid}}">
{{> block_timeline/view-dates }}
</div>
<div

0 comments on commit 94db315

Please sign in to comment.