Skip to content

Commit

Permalink
MDL-67152 calendar: The day view should start from the current day
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Dec 9, 2019
1 parent 8cf4c97 commit f046b70
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 22 deletions.
2 changes: 1 addition & 1 deletion calendar/amd/build/repository.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/repository.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion calendar/amd/build/view_manager.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calendar/amd/build/view_manager.min.js.map

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions calendar/amd/src/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,12 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
* @param {Number} month Month
* @param {Number} courseid The course id.
* @param {Number} categoryid The category id.
* @param {Bool} includenavigation Whether to include navigation.
* @param {Bool} mini Whether the month is in mini view.
* @param {Boolean} includenavigation Whether to include navigation.
* @param {Boolean} mini Whether the month is in mini view.
* @param {Number} day Day (optional)
* @return {promise} Resolved with the month view data.
*/
var getCalendarMonthData = function(year, month, courseid, categoryid, includenavigation, mini) {
var getCalendarMonthData = function(year, month, courseid, categoryid, includenavigation, mini, day = 1) {
var request = {
methodname: 'core_calendar_get_calendar_monthly_view',
args: {
Expand All @@ -107,7 +108,8 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
courseid: courseid,
categoryid: categoryid,
includenavigation: includenavigation,
mini: mini
mini: mini,
day: day
}
};

Expand Down
18 changes: 11 additions & 7 deletions calendar/amd/src/view_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ define([
var link = $(e.currentTarget);

if (view === 'month') {
changeMonth(root, link.attr('href'), link.data('year'), link.data('month'), courseId, categoryId);
changeMonth(root, link.attr('href'), link.data('year'), link.data('month'), courseId, categoryId,
link.data('day'));
e.preventDefault();
} else if (view === 'day') {
changeDay(root, link.attr('href'), link.data('year'), link.data('month'), link.data('day'),
Expand Down Expand Up @@ -124,7 +125,7 @@ define([
categoryId = option.data('categoryid');

if (view == 'month') {
refreshMonthContent(root, year, month, courseId, categoryId, root, 'core_calendar/calendar_month')
refreshMonthContent(root, year, month, courseId, categoryId, root, 'core_calendar/calendar_month', day)
.then(function() {
return window.history.pushState({}, '', '?view=month');
}).fail(Notification.exception);
Expand Down Expand Up @@ -153,17 +154,18 @@ define([
* @param {Number} categoryid The id of the category whose events are shown
* @param {object} target The element being replaced. If not specified, the calendarwrapper is used.
* @param {String} template The template to be rendered.
* @param {Number} day Day (optional)
* @return {promise}
*/
var refreshMonthContent = function(root, year, month, courseid, categoryid, target, template) {
var refreshMonthContent = function(root, year, month, courseid, categoryid, target, template, day = 1) {
startLoading(root);

target = target || root.find(CalendarSelectors.wrapper);
template = template || root.attr('data-template');
M.util.js_pending([root.get('id'), year, month, courseid].join('-'));
var includenavigation = root.data('includenavigation');
var mini = root.data('mini');
return CalendarRepository.getCalendarMonthData(year, month, courseid, categoryid, includenavigation, mini)
return CalendarRepository.getCalendarMonthData(year, month, courseid, categoryid, includenavigation, mini, day)
.then(function(context) {
context.viewingmonth = true;
return Templates.render(template, context);
Expand Down Expand Up @@ -191,10 +193,11 @@ define([
* @param {Number} month Month
* @param {Number} courseid The id of the course whose events are shown
* @param {Number} categoryid The id of the category whose events are shown
* @param {Number} day Day (optional)
* @return {promise}
*/
var changeMonth = function(root, url, year, month, courseid, categoryid) {
return refreshMonthContent(root, year, month, courseid, categoryid)
var changeMonth = function(root, url, year, month, courseid, categoryid, day = 1) {
return refreshMonthContent(root, year, month, courseid, categoryid, null, null, day)
.then(function() {
if (url.length && url !== '#') {
window.history.pushState({}, '', url);
Expand All @@ -218,6 +221,7 @@ define([
var reloadCurrentMonth = function(root, courseId, categoryId) {
var year = root.find(CalendarSelectors.wrapper).data('year');
var month = root.find(CalendarSelectors.wrapper).data('month');
var day = root.find(CalendarSelectors.wrapper).data('day');

if (typeof courseId === 'undefined') {
courseId = root.find(CalendarSelectors.wrapper).data('courseid');
Expand All @@ -227,7 +231,7 @@ define([
categoryId = root.find(CalendarSelectors.wrapper).data('categoryid');
}

return refreshMonthContent(root, year, month, courseId, categoryId);
return refreshMonthContent(root, year, month, courseId, categoryId, null, null, day);
};


Expand Down
Loading

0 comments on commit f046b70

Please sign in to comment.