This commit is contained in:
Ilya Tregubov 2023-06-01 10:12:14 +08:00
commit 59cd47c02f
No known key found for this signature in database
GPG key ID: 0F58186F748E55C1
29 changed files with 395 additions and 455 deletions

View file

@ -1,10 +1,10 @@
define("block_myoverview/repository",["exports","core/ajax","core/notification"],(function(_exports,_ajax,Notification){var obj; define("block_myoverview/repository",["exports","core/ajax"],(function(_exports,_ajax){var obj;
/** /**
* A javascript module to retrieve enrolled coruses from the server. * A javascript module to retrieve enrolled coruses from the server.
* *
* @module block_myoverview/repository * @module block_myoverview/repository
* @copyright 2018 Bas Brands <base@moodle.com> * @copyright 2018 Bas Brands <base@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.updateUserPreferences=_exports.setFavouriteCourses=_exports.getEnrolledCoursesByTimeline=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj},Notification=function(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}newObj.default=obj,cache&&cache.set(obj,newObj);return newObj}(Notification);_exports.getEnrolledCoursesByTimeline=args=>{const request={methodname:"core_course_get_enrolled_courses_by_timeline_classification",args:args};return _ajax.default.call([request])[0]};_exports.setFavouriteCourses=args=>{const request={methodname:"core_course_set_favourite_courses",args:args};return _ajax.default.call([request])[0]};_exports.updateUserPreferences=args=>{const request={methodname:"core_user_update_user_preferences",args:args};_ajax.default.call([request])[0].fail(Notification.exception)}})); */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.setFavouriteCourses=_exports.getEnrolledCoursesByTimeline=void 0,_ajax=(obj=_ajax)&&obj.__esModule?obj:{default:obj};_exports.getEnrolledCoursesByTimeline=args=>{const request={methodname:"core_course_get_enrolled_courses_by_timeline_classification",args:args};return _ajax.default.call([request])[0]};_exports.setFavouriteCourses=args=>{const request={methodname:"core_course_set_favourite_courses",args:args};return _ajax.default.call([request])[0]}}));
//# sourceMappingURL=repository.min.js.map //# sourceMappingURL=repository.min.js.map

View file

@ -1 +1 @@
{"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * A javascript module to retrieve enrolled coruses from the server.\n *\n * @module block_myoverview/repository\n * @copyright 2018 Bas Brands <base@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\nimport * as Notification from 'core/notification';\n\n/**\n * Retrieve a list of enrolled courses.\n *\n * Valid args are:\n * string classification future, inprogress, past\n * int limit number of records to retreive\n * int Offset offset for pagination\n * int sort sort by lastaccess or name\n *\n * @method getEnrolledCoursesByTimeline\n * @param {object} args The request arguments\n * @return {promise} Resolved with an array of courses\n */\nexport const getEnrolledCoursesByTimeline = args => {\n const request = {\n methodname: 'core_course_get_enrolled_courses_by_timeline_classification',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Set the favourite state on a list of courses.\n *\n * Valid args are:\n * Array courses list of course id numbers.\n *\n * @param {Object} args Arguments send to the webservice.\n * @return {Promise} Resolve with warnings.\n */\nexport const setFavouriteCourses = args => {\n const request = {\n methodname: 'core_course_set_favourite_courses',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Update the user preferences.\n *\n * @param {Object} args Arguments send to the webservice.\n *\n * Sample args:\n * {\n * preferences: [\n * {\n * type: 'block_example_user_sort_preference'\n * value: 'title'\n * }\n * ]\n * }\n */\nexport const updateUserPreferences = args => {\n const request = {\n methodname: 'core_user_update_user_preferences',\n args: args\n };\n\n Ajax.call([request])[0]\n .fail(Notification.exception);\n};\n"],"names":["args","request","methodname","Ajax","call","fail","Notification","exception"],"mappings":";;;;;;;2rCAuC4CA,aAClCC,QAAU,CACZC,WAAY,8DACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU,iCAYGD,aACzBC,QAAU,CACZC,WAAY,oCACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU,mCAkBKD,aAC3BC,QAAU,CACZC,WAAY,oCACZF,KAAMA,oBAGLI,KAAK,CAACH,UAAU,GAChBI,KAAKC,aAAaC"} {"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * A javascript module to retrieve enrolled coruses from the server.\n *\n * @module block_myoverview/repository\n * @copyright 2018 Bas Brands <base@moodle.com>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport Ajax from 'core/ajax';\n\n/**\n * Retrieve a list of enrolled courses.\n *\n * Valid args are:\n * string classification future, inprogress, past\n * int limit number of records to retreive\n * int Offset offset for pagination\n * int sort sort by lastaccess or name\n *\n * @method getEnrolledCoursesByTimeline\n * @param {object} args The request arguments\n * @return {promise} Resolved with an array of courses\n */\nexport const getEnrolledCoursesByTimeline = args => {\n const request = {\n methodname: 'core_course_get_enrolled_courses_by_timeline_classification',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n\n/**\n * Set the favourite state on a list of courses.\n *\n * Valid args are:\n * Array courses list of course id numbers.\n *\n * @param {Object} args Arguments send to the webservice.\n * @return {Promise} Resolve with warnings.\n */\nexport const setFavouriteCourses = args => {\n const request = {\n methodname: 'core_course_set_favourite_courses',\n args: args\n };\n\n return Ajax.call([request])[0];\n};\n"],"names":["args","request","methodname","Ajax","call"],"mappings":";;;;;;;iOAsC4CA,aAClCC,QAAU,CACZC,WAAY,8DACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU,iCAYGD,aACzBC,QAAU,CACZC,WAAY,oCACZF,KAAMA,aAGHG,cAAKC,KAAK,CAACH,UAAU"}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -1,9 +1,9 @@
define("block_myoverview/view_nav",["exports","jquery","core/custom_interaction_events","block_myoverview/repository","block_myoverview/view","block_myoverview/selectors"],(function(_exports,_jquery,CustomEvents,Repository,View,_selectors){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}} define("block_myoverview/view_nav",["exports","jquery","core/custom_interaction_events","core/notification","core_user/repository","block_myoverview/view","block_myoverview/selectors"],(function(_exports,_jquery,CustomEvents,_notification,_repository,View,_selectors){function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}function _interopRequireDefault(obj){return obj&&obj.__esModule?obj:{default:obj}}
/** /**
* Manage the timeline view navigation for the overview block. * Manage the timeline view navigation for the overview block.
* *
* @copyright 2018 Bas Brands <bas@moodle.com> * @copyright 2018 Bas Brands <bas@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),CustomEvents=_interopRequireWildcard(CustomEvents),Repository=_interopRequireWildcard(Repository),View=_interopRequireWildcard(View),_selectors=_interopRequireDefault(_selectors);const updatePreferences=(filter,value)=>{let type=null;type="display"===filter?"block_myoverview_user_view_preference":"sort"===filter?"block_myoverview_user_sort_preference":"customfieldvalue"===filter?"block_myoverview_user_grouping_customfieldvalue_preference":"block_myoverview_user_grouping_preference",Repository.updateUserPreferences({preferences:[{type:type,value:value}]})};_exports.init=root=>{(root=>{const Selector=root.find(_selectors.default.FILTERS);CustomEvents.define(Selector,[CustomEvents.events.activate]),Selector.on(CustomEvents.events.activate,_selectors.default.FILTER_OPTION,((e,data)=>{const option=(0,_jquery.default)(e.target);if(option.hasClass("active"))return;const filter=option.attr("data-filter"),pref=option.attr("data-pref"),customfieldvalue=option.attr("data-customfieldvalue");root.find(_selectors.default.courseView.region).attr("data-"+filter,option.attr("data-value")),updatePreferences(filter,pref),customfieldvalue&&(root.find(_selectors.default.courseView.region).attr("data-customfieldvalue",customfieldvalue),updatePreferences("customfieldvalue",customfieldvalue));const page=document.querySelector(_selectors.default.region.selectBlock),input=page.querySelector(_selectors.default.region.searchInput);if(""!==input.value){const clearIcon=page.querySelector(_selectors.default.region.clearIcon);input.value="",View.clearSearch(clearIcon,root)}else View.init(root);data.originalEvent.preventDefault()})),Selector.on(CustomEvents.events.activate,_selectors.default.DISPLAY_OPTION,((e,data)=>{const option=(0,_jquery.default)(e.target);if(option.hasClass("active"))return;const filter=option.attr("data-display-option"),pref=option.attr("data-pref");root.find(_selectors.default.courseView.region).attr("data-display",option.attr("data-value")),updatePreferences(filter,pref),View.reset(root),data.originalEvent.preventDefault()}))})(root=(0,_jquery.default)(root))}})); */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=_interopRequireDefault(_jquery),CustomEvents=_interopRequireWildcard(CustomEvents),_notification=_interopRequireDefault(_notification),View=_interopRequireWildcard(View),_selectors=_interopRequireDefault(_selectors);const updatePreferences=(filter,value)=>{let type=null;return type="display"===filter?"block_myoverview_user_view_preference":"sort"===filter?"block_myoverview_user_sort_preference":"customfieldvalue"===filter?"block_myoverview_user_grouping_customfieldvalue_preference":"block_myoverview_user_grouping_preference",(0,_repository.setUserPreference)(type,value).catch(_notification.default.exception)};_exports.init=root=>{(root=>{const Selector=root.find(_selectors.default.FILTERS);CustomEvents.define(Selector,[CustomEvents.events.activate]),Selector.on(CustomEvents.events.activate,_selectors.default.FILTER_OPTION,((e,data)=>{const option=(0,_jquery.default)(e.target);if(option.hasClass("active"))return;const filter=option.attr("data-filter"),pref=option.attr("data-pref"),customfieldvalue=option.attr("data-customfieldvalue");root.find(_selectors.default.courseView.region).attr("data-"+filter,option.attr("data-value")),updatePreferences(filter,pref),customfieldvalue&&(root.find(_selectors.default.courseView.region).attr("data-customfieldvalue",customfieldvalue),updatePreferences("customfieldvalue",customfieldvalue));const page=document.querySelector(_selectors.default.region.selectBlock),input=page.querySelector(_selectors.default.region.searchInput);if(""!==input.value){const clearIcon=page.querySelector(_selectors.default.region.clearIcon);input.value="",View.clearSearch(clearIcon,root)}else View.init(root);data.originalEvent.preventDefault()})),Selector.on(CustomEvents.events.activate,_selectors.default.DISPLAY_OPTION,((e,data)=>{const option=(0,_jquery.default)(e.target);if(option.hasClass("active"))return;const filter=option.attr("data-display-option"),pref=option.attr("data-pref");root.find(_selectors.default.courseView.region).attr("data-display",option.attr("data-value")),updatePreferences(filter,pref),View.reset(root),data.originalEvent.preventDefault()}))})(root=(0,_jquery.default)(root))}}));
//# sourceMappingURL=view_nav.min.js.map //# sourceMappingURL=view_nav.min.js.map

File diff suppressed because one or more lines are too long

View file

@ -22,7 +22,6 @@
*/ */
import Ajax from 'core/ajax'; import Ajax from 'core/ajax';
import * as Notification from 'core/notification';
/** /**
* Retrieve a list of enrolled courses. * Retrieve a list of enrolled courses.
@ -63,28 +62,3 @@ export const setFavouriteCourses = args => {
return Ajax.call([request])[0]; return Ajax.call([request])[0];
}; };
/**
* Update the user preferences.
*
* @param {Object} args Arguments send to the webservice.
*
* Sample args:
* {
* preferences: [
* {
* type: 'block_example_user_sort_preference'
* value: 'title'
* }
* ]
* }
*/
export const updateUserPreferences = args => {
const request = {
methodname: 'core_user_update_user_preferences',
args: args
};
Ajax.call([request])[0]
.fail(Notification.exception);
};

View file

@ -32,6 +32,7 @@ import SELECTORS from 'block_myoverview/selectors';
import * as PagedContentEvents from 'core/paged_content_events'; import * as PagedContentEvents from 'core/paged_content_events';
import * as Aria from 'core/aria'; import * as Aria from 'core/aria';
import {debounce} from 'core/utils'; import {debounce} from 'core/utils';
import {setUserPreference} from 'core_user/repository';
const TEMPLATES = { const TEMPLATES = {
COURSES_CARDS: 'block_myoverview/view-cards', COURSES_CARDS: 'block_myoverview/view-cards',
@ -343,14 +344,9 @@ const setCourseHiddenState = (courseId, status) => {
if (status === false) { if (status === false) {
status = null; status = null;
} }
return Repository.updateUserPreferences({
preferences: [ return setUserPreference(`block_myoverview_hidden_course_${courseId}`, status)
{ .catch(Notification.exception);
type: 'block_myoverview_hidden_course_' + courseId,
value: status
}
]
});
}; };
/** /**

View file

@ -22,7 +22,8 @@
import $ from 'jquery'; import $ from 'jquery';
import * as CustomEvents from 'core/custom_interaction_events'; import * as CustomEvents from 'core/custom_interaction_events';
import * as Repository from 'block_myoverview/repository'; import Notification from 'core/notification';
import {setUserPreference} from 'core_user/repository';
import * as View from 'block_myoverview/view'; import * as View from 'block_myoverview/view';
import SELECTORS from 'block_myoverview/selectors'; import SELECTORS from 'block_myoverview/selectors';
@ -31,6 +32,7 @@ import SELECTORS from 'block_myoverview/selectors';
* *
* @param {String} filter The type of filter: display/sort/grouping. * @param {String} filter The type of filter: display/sort/grouping.
* @param {String} value The current preferred value. * @param {String} value The current preferred value.
* @return {Promise}
*/ */
const updatePreferences = (filter, value) => { const updatePreferences = (filter, value) => {
let type = null; let type = null;
@ -44,14 +46,8 @@ const updatePreferences = (filter, value) => {
type = 'block_myoverview_user_grouping_preference'; type = 'block_myoverview_user_grouping_preference';
} }
Repository.updateUserPreferences({ return setUserPreference(type, value)
preferences: [ .catch(Notification.exception);
{
type: type,
value: value
}
]
});
}; };
/** /**

View file

@ -1,3 +1,4 @@
define("block_online_users/change_user_visibility",["exports","core/str","core/notification","core_user/repository"],(function(_exports,_str,_notification,_repository){var obj;
/** /**
* A javascript module that handles the change of the user's visibility in the * A javascript module that handles the change of the user's visibility in the
* online users block. * online users block.
@ -5,7 +6,6 @@
* @module block_online_users/change_user_visibility * @module block_online_users/change_user_visibility
* @copyright 2018 Mihail Geshoski <mihail@moodle.com> * @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_notification=(obj=_notification)&&obj.__esModule?obj:{default:obj};const SELECTORS_CHANGE_VISIBILITY_LINK="#change-user-visibility",SELECTORS_CHANGE_VISIBILITY_ICON="#change-user-visibility .icon",oppositeAction=action=>"show"==action?"hide":"show",changeVisibilityLinkAttr=action=>getTitle(action).then((title=>{const link=document.querySelector(SELECTORS_CHANGE_VISIBILITY_LINK);return link.dataset.action=action,link.title=title,link})),changeVisibilityIconAttr=action=>getTitle(action).then((title=>{const icon=document.querySelector(SELECTORS_CHANGE_VISIBILITY_ICON);return icon.setAttribute("title",title),icon.setAttribute("aria-label",title),icon.closest("img")?(icon.setAttribute("src",M.util.image_url("t/".concat(action))),icon.setAttribute("alt",title)):(icon.classList.add(getIconClass(action)),icon.classList.remove(getIconClass(oppositeAction(action)))),title})),getIconClass=action=>"show"==action?"fa-eye-slash":"fa-eye",getTitle=action=>(0,_str.get_string)("online_status:".concat(action),"block_online_users");_exports.init=()=>{document.addEventListener("click",(e=>{const link=e.target.closest(SELECTORS_CHANGE_VISIBILITY_LINK);var action,userid;link&&(e.preventDefault(),action=link.dataset.action,userid=link.dataset.userid,(0,_repository.setUserPreference)("block_online_users_uservisibility","show"==action?1:0,userid).then((data=>{if(data.saved){const newAction=oppositeAction(action);changeVisibilityLinkAttr(newAction),changeVisibilityIconAttr(newAction)}return data})).catch(_notification.default.exception))}))}}));
define("block_online_users/change_user_visibility",["jquery","core/ajax","core/str","core/notification"],(function($,Ajax,Str,Notification){var SELECTORS_CHANGE_VISIBILITY_LINK="#change-user-visibility",SELECTORS_CHANGE_VISIBILITY_ICON="#change-user-visibility .icon",oppositeAction=function(action){return"show"==action?"hide":"show"},changeVisibilityLinkAttr=function(action){getTitle(action).then((function(title){$(SELECTORS_CHANGE_VISIBILITY_LINK).attr({"data-action":action,title:title})})).catch(Notification.exception)},changeVisibilityIconAttr=function(action){var icon=$(SELECTORS_CHANGE_VISIBILITY_ICON);getTitle(action).then((function(title){$(icon).attr({title:title,"aria-label":title}),icon.is("img")?$(icon).attr({src:M.util.image_url("t/"+action),alt:title}):($(icon).addClass(getIconClass(action)),$(icon).removeClass(getIconClass(oppositeAction(action))))})).catch(Notification.exception)},getIconClass=function(action){return"show"==action?"fa-eye-slash":"fa-eye"},getTitle=function(action){return Str.get_string("online_status:"+action,"block_online_users")};return{init:function(){$(SELECTORS_CHANGE_VISIBILITY_LINK).on("click",(function(e){e.preventDefault(),function(action,userid){var request={methodname:"core_user_set_user_preferences",args:{preferences:[{name:"block_online_users_uservisibility",value:"show"==action?1:0,userid:userid}]}};Ajax.call([request])[0].then((function(data){if(data.saved){var newAction=oppositeAction(action);changeVisibilityLinkAttr(newAction),changeVisibilityIconAttr(newAction)}})).catch(Notification.exception)}($(this).attr("data-action"),$(this).attr("data-userid"))}))}}}));
//# sourceMappingURL=change_user_visibility.min.js.map //# sourceMappingURL=change_user_visibility.min.js.map

File diff suppressed because one or more lines are too long

View file

@ -21,54 +21,46 @@
* @copyright 2018 Mihail Geshoski <mihail@moodle.com> * @copyright 2018 Mihail Geshoski <mihail@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
define(['jquery', 'core/ajax', 'core/str', 'core/notification'],
function($, Ajax, Str, Notification) {
/** import {get_string as getString} from 'core/str';
import Notification from 'core/notification';
import {setUserPreference} from 'core_user/repository';
/**
* Selectors. * Selectors.
* *
* @access private * @access private
* @type {Object} * @type {Object}
*/ */
var SELECTORS = { const SELECTORS = {
CHANGE_VISIBILITY_LINK: '#change-user-visibility', CHANGE_VISIBILITY_LINK: '#change-user-visibility',
CHANGE_VISIBILITY_ICON: '#change-user-visibility .icon' CHANGE_VISIBILITY_ICON: '#change-user-visibility .icon',
}; };
/** /**
* Change user visibility in the online users block. * Change user visibility in the online users block.
* *
* @method changeVisibility * @method changeVisibility
* @param {String} action * @param {String} action
* @param {String} userid * @param {String} userid
* @returns {Promise}
* @private * @private
*/ */
var changeVisibility = function(action, userid) { const changeVisibility = (action, userid) => setUserPreference(
'block_online_users_uservisibility',
var value = action == "show" ? 1 : 0; action == "show" ? 1 : 0,
var preferences = [{ userid,
'name': 'block_online_users_uservisibility', )
'value': value, .then((data) => {
'userid': userid
}];
var request = {
methodname: 'core_user_set_user_preferences',
args: {
preferences: preferences
}
};
Ajax.call([request])[0].then(function(data) {
if (data.saved) { if (data.saved) {
var newAction = oppositeAction(action); const newAction = oppositeAction(action);
changeVisibilityLinkAttr(newAction); changeVisibilityLinkAttr(newAction);
changeVisibilityIconAttr(newAction); changeVisibilityIconAttr(newAction);
} }
return; return data;
}).catch(Notification.exception); }).catch(Notification.exception);
};
/** /**
* Get the opposite action. * Get the opposite action.
* *
* @method oppositeAction * @method oppositeAction
@ -76,58 +68,53 @@ define(['jquery', 'core/ajax', 'core/str', 'core/notification'],
* @return {String} * @return {String}
* @private * @private
*/ */
var oppositeAction = function(action) { const oppositeAction = (action) => action == 'show' ? 'hide' : 'show';
return action == 'show' ? 'hide' : 'show';
};
/** /**
* Change the attribute values of the user visibility link in the online users block. * Change the attribute values of the user visibility link in the online users block.
* *
* @method changeVisibilityLinkAttr * @method changeVisibilityLinkAttr
* @param {String} action * @param {String} action
* @returns {Promise}
* @private * @private
*/ */
var changeVisibilityLinkAttr = function(action) { const changeVisibilityLinkAttr = (action) => getTitle(action)
getTitle(action).then(function(title) { .then((title) => {
$(SELECTORS.CHANGE_VISIBILITY_LINK).attr({ const link = document.querySelector(SELECTORS.CHANGE_VISIBILITY_LINK);
'data-action': action, link.dataset.action = action;
'title': title link.title = title;
return link;
}); });
return;
}).catch(Notification.exception);
};
/** /**
* Change the attribute values of the user visibility icon in the online users block. * Change the attribute values of the user visibility icon in the online users block.
* *
* @method changeVisibilityIconAttr * @method changeVisibilityIconAttr
* @param {String} action * @param {String} action
* @returns {Promise}
* @private * @private
*/ */
var changeVisibilityIconAttr = function(action) { const changeVisibilityIconAttr = (action) => getTitle(action)
var icon = $(SELECTORS.CHANGE_VISIBILITY_ICON); .then((title) => {
getTitle(action).then(function(title) { const icon = document.querySelector(SELECTORS.CHANGE_VISIBILITY_ICON);
// Add the proper title to the icon. // Add the proper title to the icon.
$(icon).attr({ icon.setAttribute('title', title);
'title': title, icon.setAttribute('aria-label', title);
'aria-label': title
}); if (icon.closest("img")) {
// If the icon is an image. // If the icon is an image.
if (icon.is("img")) { icon.setAttribute('src', M.util.image_url(`t/${action}`));
$(icon).attr({ icon.setAttribute('alt', title);
'src': M.util.image_url('t/' + action),
'alt': title
});
} else { } else {
// Add the new icon class and remove the old one. // Add the new icon class and remove the old one.
$(icon).addClass(getIconClass(action)); icon.classList.add(getIconClass(action));
$(icon).removeClass(getIconClass(oppositeAction(action))); icon.classList.remove(getIconClass(oppositeAction(action)));
} }
return; return title;
}).catch(Notification.exception); });
};
/** /**
* Get the proper class for the user visibility icon in the online users block. * Get the proper class for the user visibility icon in the online users block.
* *
* @method getIconClass * @method getIconClass
@ -135,11 +122,9 @@ define(['jquery', 'core/ajax', 'core/str', 'core/notification'],
* @return {String} * @return {String}
* @private * @private
*/ */
var getIconClass = function(action) { const getIconClass = (action) => (action == 'show') ? 'fa-eye-slash' : 'fa-eye';
return action == 'show' ? 'fa-eye-slash' : 'fa-eye';
};
/** /**
* Get the title description of the user visibility link in the online users block. * Get the title description of the user visibility link in the online users block.
* *
* @method getTitle * @method getTitle
@ -147,24 +132,23 @@ define(['jquery', 'core/ajax', 'core/str', 'core/notification'],
* @return {object} jQuery promise * @return {object} jQuery promise
* @private * @private
*/ */
var getTitle = function(action) { const getTitle = (action) => getString(`online_status:${action}`, 'block_online_users');
return Str.get_string('online_status:' + action, 'block_online_users');
};
return { /**
// Public variables and functions.
/**
* Initialise change user visibility function. * Initialise change user visibility function.
* *
* @method init * @method init
*/ */
init: function() { export const init = () => {
$(SELECTORS.CHANGE_VISIBILITY_LINK).on('click', function(e) { document.addEventListener('click', (e) => {
e.preventDefault(); const link = e.target.closest(SELECTORS.CHANGE_VISIBILITY_LINK);
var action = ($(this).attr('data-action')); if (!link) {
var userid = ($(this).attr('data-userid')); return;
changeVisibility(action, userid);
});
} }
}; e.preventDefault();
}); changeVisibility(
link.dataset.action,
link.dataset.userid,
);
});
};

View file

@ -1,9 +1,9 @@
define("block_timeline/view_nav",["exports","jquery","core/custom_interaction_events","block_timeline/view","core/notification","core/utils","core_user/repository"],(function(_exports,_jquery,CustomEvents,View,Notification,Utils,UserRepository){var obj;
/** /**
* Manage the timeline view navigation for the timeline block. * Manage the timeline view navigation for the timeline block.
* *
* @copyright 2018 Ryan Wyllie <ryan@moodle.com> * @copyright 2018 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */function _getRequireWildcardCache(nodeInterop){if("function"!=typeof WeakMap)return null;var cacheBabelInterop=new WeakMap,cacheNodeInterop=new WeakMap;return(_getRequireWildcardCache=function(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop})(nodeInterop)}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule)return obj;if(null===obj||"object"!=typeof obj&&"function"!=typeof obj)return{default:obj};var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj))return cache.get(obj);var newObj={},hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj)if("default"!==key&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;desc&&(desc.get||desc.set)?Object.defineProperty(newObj,key,desc):newObj[key]=obj[key]}return newObj.default=obj,cache&&cache.set(obj,newObj),newObj}Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.init=void 0,_jquery=(obj=_jquery)&&obj.__esModule?obj:{default:obj},CustomEvents=_interopRequireWildcard(CustomEvents),View=_interopRequireWildcard(View),Notification=_interopRequireWildcard(Notification),Utils=_interopRequireWildcard(Utils),UserRepository=_interopRequireWildcard(UserRepository);const SELECTORS_TIMELINE_DAY_FILTER='[data-region="day-filter"]',SELECTORS_TIMELINE_DAY_FILTER_OPTION="[data-from]",SELECTORS_TIMELINE_VIEW_SELECTOR='[data-region="view-selector"]',SELECTORS_DATA_DAYS_OFFSET="[data-days-offset]",SELECTORS_TIMELINE_SEARCH_INPUT='[data-action="search"]',SELECTORS_TIMELINE_SEARCH_CLEAR_ICON='[data-action="clearsearch"]',SELECTORS_NO_COURSES_EMPTY_MESSAGE='[data-region="no-courses-empty-message"]',activeSearchState=(clearSearchIcon,timelineViewRoot)=>{clearSearchIcon.removeClass("d-none"),View.reset(timelineViewRoot)},clearSearchState=(clearSearchIcon,timelineViewRoot)=>{clearSearchIcon.addClass("d-none"),View.reset(timelineViewRoot)};_exports.init=function(root,timelineViewRoot){(function(root,timelineViewRoot){const viewSelector=root.find(SELECTORS_TIMELINE_VIEW_SELECTOR);viewSelector.on("shown shown.bs.tab",(function(e){View.shown(timelineViewRoot),(0,_jquery.default)(e.target).removeClass("active")})),CustomEvents.define(viewSelector,[CustomEvents.events.activate]),viewSelector.on(CustomEvents.events.activate,"[data-toggle='tab']",(function(e){var filtername=(0,_jquery.default)(e.currentTarget).data("filtername");UserRepository.setUserPreference("block_timeline_user_sort_preference",filtername).catch(Notification.exception)}))})(root=(0,_jquery.default)(root),timelineViewRoot),root.find(SELECTORS_NO_COURSES_EMPTY_MESSAGE).length||(function(root,timelineViewRoot){const timelineDaySelectorContainer=root.find(SELECTORS_TIMELINE_DAY_FILTER);CustomEvents.define(timelineDaySelectorContainer,[CustomEvents.events.activate]),timelineDaySelectorContainer.on(CustomEvents.events.activate,SELECTORS_TIMELINE_DAY_FILTER_OPTION,(function(e,data){var filtername=(0,_jquery.default)(e.currentTarget).data("filtername");UserRepository.setUserPreference("block_timeline_user_filter_preference",filtername).catch(Notification.exception);var option=(0,_jquery.default)(e.target).closest(SELECTORS_TIMELINE_DAY_FILTER_OPTION);if("true"!=option.attr("aria-current")){var daysOffset=option.attr("data-from"),daysLimit=option.attr("data-to"),elementsWithDaysOffset=root.find(SELECTORS_DATA_DAYS_OFFSET);elementsWithDaysOffset.attr("data-days-offset",daysOffset),null!=daysLimit?elementsWithDaysOffset.attr("data-days-limit",daysLimit):elementsWithDaysOffset.removeAttr("data-days-limit"),"overdue"===option.attr("data-filtername")?elementsWithDaysOffset.attr("data-filter-overdue",!0):elementsWithDaysOffset.removeAttr("data-filter-overdue"),View.reset(timelineViewRoot),data.originalEvent.preventDefault()}}))}(root,timelineViewRoot),((root,timelineViewRoot)=>{const searchInput=root.find(SELECTORS_TIMELINE_SEARCH_INPUT),clearSearchIcon=root.find(SELECTORS_TIMELINE_SEARCH_CLEAR_ICON);searchInput.on("input",Utils.debounce((()=>{""!==searchInput.val()?activeSearchState(clearSearchIcon,timelineViewRoot):clearSearchState(clearSearchIcon,timelineViewRoot)}),1e3)),clearSearchIcon.on("click",(()=>{searchInput.val(""),clearSearchState(clearSearchIcon,timelineViewRoot),searchInput.focus()}))})(root,timelineViewRoot))}}));
define("block_timeline/view_nav",["jquery","core/custom_interaction_events","block_timeline/view","core/ajax","core/notification","core/utils"],(function($,CustomEvents,View,Ajax,Notification,Utils){var SELECTORS_TIMELINE_DAY_FILTER='[data-region="day-filter"]',SELECTORS_TIMELINE_DAY_FILTER_OPTION="[data-from]",SELECTORS_TIMELINE_VIEW_SELECTOR='[data-region="view-selector"]',SELECTORS_DATA_DAYS_OFFSET="[data-days-offset]",SELECTORS_TIMELINE_SEARCH_INPUT='[data-action="search"]',SELECTORS_TIMELINE_SEARCH_CLEAR_ICON='[data-action="clearsearch"]',SELECTORS_NO_COURSES_EMPTY_MESSAGE='[data-region="no-courses-empty-message"]',updateUserPreferences=function(type,value){var request={methodname:"core_user_update_user_preferences",args:{preferences:[{type:type,value:value}]}};Ajax.call([request])[0].fail(Notification.exception)};const activeSearchState=(clearSearchIcon,timelineViewRoot)=>{clearSearchIcon.removeClass("d-none"),View.reset(timelineViewRoot)},clearSearchState=(clearSearchIcon,timelineViewRoot)=>{clearSearchIcon.addClass("d-none"),View.reset(timelineViewRoot)};return{init:function(root,timelineViewRoot){(function(root,timelineViewRoot){var viewSelector=root.find(SELECTORS_TIMELINE_VIEW_SELECTOR);viewSelector.on("shown shown.bs.tab",(function(e){View.shown(timelineViewRoot),$(e.target).removeClass("active")})),CustomEvents.define(viewSelector,[CustomEvents.events.activate]),viewSelector.on(CustomEvents.events.activate,"[data-toggle='tab']",(function(e){var filtername=$(e.currentTarget).data("filtername");updateUserPreferences("block_timeline_user_sort_preference",filtername)}))})(root=$(root),timelineViewRoot),root.find(SELECTORS_NO_COURSES_EMPTY_MESSAGE).length||(function(root,timelineViewRoot){var timelineDaySelectorContainer=root.find(SELECTORS_TIMELINE_DAY_FILTER);CustomEvents.define(timelineDaySelectorContainer,[CustomEvents.events.activate]),timelineDaySelectorContainer.on(CustomEvents.events.activate,SELECTORS_TIMELINE_DAY_FILTER_OPTION,(function(e,data){var filtername=$(e.currentTarget).data("filtername");updateUserPreferences("block_timeline_user_filter_preference",filtername);var option=$(e.target).closest(SELECTORS_TIMELINE_DAY_FILTER_OPTION);if("true"!=option.attr("aria-current")){var daysOffset=option.attr("data-from"),daysLimit=option.attr("data-to"),elementsWithDaysOffset=root.find(SELECTORS_DATA_DAYS_OFFSET);elementsWithDaysOffset.attr("data-days-offset",daysOffset),null!=daysLimit?elementsWithDaysOffset.attr("data-days-limit",daysLimit):elementsWithDaysOffset.removeAttr("data-days-limit"),"overdue"===option.attr("data-filtername")?elementsWithDaysOffset.attr("data-filter-overdue",!0):elementsWithDaysOffset.removeAttr("data-filter-overdue"),View.reset(timelineViewRoot),data.originalEvent.preventDefault()}}))}(root,timelineViewRoot),((root,timelineViewRoot)=>{const searchInput=root.find(SELECTORS_TIMELINE_SEARCH_INPUT),clearSearchIcon=root.find(SELECTORS_TIMELINE_SEARCH_CLEAR_ICON);searchInput.on("input",Utils.debounce((()=>{""!==searchInput.val()?activeSearchState(clearSearchIcon,timelineViewRoot):clearSearchState(clearSearchIcon,timelineViewRoot)}),1e3)),clearSearchIcon.on("click",(()=>{searchInput.val(""),clearSearchState(clearSearchIcon,timelineViewRoot),searchInput.focus()}))})(root,timelineViewRoot))}}}));
//# sourceMappingURL=view_nav.min.js.map //# sourceMappingURL=view_nav.min.js.map

File diff suppressed because one or more lines are too long

View file

@ -20,25 +20,14 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
define( import $ from 'jquery';
[ import * as CustomEvents from 'core/custom_interaction_events';
'jquery', import * as View from 'block_timeline/view';
'core/custom_interaction_events', import * as Notification from 'core/notification';
'block_timeline/view', import * as Utils from 'core/utils';
'core/ajax', import * as UserRepository from 'core_user/repository';
'core/notification',
'core/utils'
],
function(
$,
CustomEvents,
View,
Ajax,
Notification,
Utils
) {
var SELECTORS = { const SELECTORS = {
TIMELINE_DAY_FILTER: '[data-region="day-filter"]', TIMELINE_DAY_FILTER: '[data-region="day-filter"]',
TIMELINE_DAY_FILTER_OPTION: '[data-from]', TIMELINE_DAY_FILTER_OPTION: '[data-from]',
TIMELINE_VIEW_SELECTOR: '[data-region="view-selector"]', TIMELINE_VIEW_SELECTOR: '[data-region="view-selector"]',
@ -47,39 +36,16 @@ function(
TIMELINE_SEARCH_INPUT: '[data-action="search"]', TIMELINE_SEARCH_INPUT: '[data-action="search"]',
TIMELINE_SEARCH_CLEAR_ICON: '[data-action="clearsearch"]', TIMELINE_SEARCH_CLEAR_ICON: '[data-action="clearsearch"]',
NO_COURSES_EMPTY_MESSAGE: '[data-region="no-courses-empty-message"]', NO_COURSES_EMPTY_MESSAGE: '[data-region="no-courses-empty-message"]',
}; };
/** /**
* Generic handler to persist user preferences
*
* @param {string} type The name of the attribute you're updating
* @param {string} value The value of the attribute you're updating
*/
var updateUserPreferences = function(type, value) {
var request = {
methodname: 'core_user_update_user_preferences',
args: {
preferences: [
{
type: type,
value: value
}
]
}
};
Ajax.call([request])[0]
.fail(Notification.exception);
};
/**
* Event listener for the day selector ("Next 7 days", "Next 30 days", etc). * Event listener for the day selector ("Next 7 days", "Next 30 days", etc).
* *
* @param {object} root The root element for the timeline block * @param {object} root The root element for the timeline block
* @param {object} timelineViewRoot The root element for the timeline view * @param {object} timelineViewRoot The root element for the timeline view
*/ */
var registerTimelineDaySelector = function(root, timelineViewRoot) { const registerTimelineDaySelector = function(root, timelineViewRoot) {
var timelineDaySelectorContainer = root.find(SELECTORS.TIMELINE_DAY_FILTER); const timelineDaySelectorContainer = root.find(SELECTORS.TIMELINE_DAY_FILTER);
CustomEvents.define(timelineDaySelectorContainer, [CustomEvents.events.activate]); CustomEvents.define(timelineDaySelectorContainer, [CustomEvents.events.activate]);
timelineDaySelectorContainer.on( timelineDaySelectorContainer.on(
@ -89,7 +55,8 @@ function(
// Update the user preference // Update the user preference
var filtername = $(e.currentTarget).data('filtername'); var filtername = $(e.currentTarget).data('filtername');
var type = 'block_timeline_user_filter_preference'; var type = 'block_timeline_user_filter_preference';
updateUserPreferences(type, filtername); UserRepository.setUserPreference(type, filtername)
.catch(Notification.exception);
var option = $(e.target).closest(SELECTORS.TIMELINE_DAY_FILTER_OPTION); var option = $(e.target).closest(SELECTORS.TIMELINE_DAY_FILTER_OPTION);
@ -123,9 +90,9 @@ function(
data.originalEvent.preventDefault(); data.originalEvent.preventDefault();
} }
); );
}; };
/** /**
* Event listener for the "sort" button in the timeline navigation that allows for * Event listener for the "sort" button in the timeline navigation that allows for
* changing between the timeline dates and courses views. * changing between the timeline dates and courses views.
* *
@ -135,8 +102,8 @@ function(
* @param {object} root The root element for the timeline block * @param {object} root The root element for the timeline block
* @param {object} timelineViewRoot The root element for the timeline view * @param {object} timelineViewRoot The root element for the timeline view
*/ */
var registerViewSelector = function(root, timelineViewRoot) { const registerViewSelector = function(root, timelineViewRoot) {
var viewSelector = root.find(SELECTORS.TIMELINE_VIEW_SELECTOR); const viewSelector = root.find(SELECTORS.TIMELINE_VIEW_SELECTOR);
// Listen for when the user changes tab so that we can show the first set of courses // Listen for when the user changes tab so that we can show the first set of courses
// and load their events when they request the sort by courses view for the first time. // and load their events when they request the sort by courses view for the first time.
@ -151,18 +118,19 @@ function(
viewSelector.on(CustomEvents.events.activate, "[data-toggle='tab']", function(e) { viewSelector.on(CustomEvents.events.activate, "[data-toggle='tab']", function(e) {
var filtername = $(e.currentTarget).data('filtername'); var filtername = $(e.currentTarget).data('filtername');
var type = 'block_timeline_user_sort_preference'; var type = 'block_timeline_user_sort_preference';
updateUserPreferences(type, filtername); UserRepository.setUserPreference(type, filtername)
.catch(Notification.exception);
}); });
}; };
/** /**
* Event listener for the "search" input field in the timeline navigation that allows for * Event listener for the "search" input field in the timeline navigation that allows for
* searching the activity name, course name and activity type. * searching the activity name, course name and activity type.
* *
* @param {object} root The root element for the timeline block * @param {object} root The root element for the timeline block
* @param {object} timelineViewRoot The root element for the timeline view * @param {object} timelineViewRoot The root element for the timeline view
*/ */
const registerSearch = (root, timelineViewRoot) => { const registerSearch = (root, timelineViewRoot) => {
const searchInput = root.find(SELECTORS.TIMELINE_SEARCH_INPUT); const searchInput = root.find(SELECTORS.TIMELINE_SEARCH_INPUT);
const clearSearchIcon = root.find(SELECTORS.TIMELINE_SEARCH_CLEAR_ICON); const clearSearchIcon = root.find(SELECTORS.TIMELINE_SEARCH_CLEAR_ICON);
searchInput.on('input', Utils.debounce(() => { searchInput.on('input', Utils.debounce(() => {
@ -177,38 +145,38 @@ function(
clearSearchState(clearSearchIcon, timelineViewRoot); clearSearchState(clearSearchIcon, timelineViewRoot);
searchInput.focus(); searchInput.focus();
}); });
}; };
/** /**
* Show the clear search icon. * Show the clear search icon.
* *
* @param {object} clearSearchIcon Clear search icon element. * @param {object} clearSearchIcon Clear search icon element.
* @param {object} timelineViewRoot The root element for the timeline view * @param {object} timelineViewRoot The root element for the timeline view
*/ */
const activeSearchState = (clearSearchIcon, timelineViewRoot) => { const activeSearchState = (clearSearchIcon, timelineViewRoot) => {
clearSearchIcon.removeClass('d-none'); clearSearchIcon.removeClass('d-none');
View.reset(timelineViewRoot); View.reset(timelineViewRoot);
}; };
/** /**
* Hide the clear search icon. * Hide the clear search icon.
* *
* @param {object} clearSearchIcon Clear search icon element. * @param {object} clearSearchIcon Clear search icon element.
* @param {object} timelineViewRoot The root element for the timeline view * @param {object} timelineViewRoot The root element for the timeline view
*/ */
const clearSearchState = (clearSearchIcon, timelineViewRoot) => { const clearSearchState = (clearSearchIcon, timelineViewRoot) => {
clearSearchIcon.addClass('d-none'); clearSearchIcon.addClass('d-none');
View.reset(timelineViewRoot); View.reset(timelineViewRoot);
}; };
/** /**
* Initialise the timeline view navigation by adding event listeners to * Initialise the timeline view navigation by adding event listeners to
* the navigation elements. * the navigation elements.
* *
* @param {object} root The root element for the timeline block * @param {jQuery|HTMLElement} root The root element for the timeline block
* @param {object} timelineViewRoot The root element for the timeline view * @param {object} timelineViewRoot The root element for the timeline view
*/ */
var init = function(root, timelineViewRoot) { export const init = function(root, timelineViewRoot) {
root = $(root); root = $(root);
registerViewSelector(root, timelineViewRoot); registerViewSelector(root, timelineViewRoot);
@ -218,9 +186,4 @@ function(
registerTimelineDaySelector(root, timelineViewRoot); registerTimelineDaySelector(root, timelineViewRoot);
registerSearch(root, timelineViewRoot); registerSearch(root, timelineViewRoot);
} }
}; };
return {
init: init
};
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -24,8 +24,8 @@
import selectors from './selectors'; import selectors from './selectors';
import {get_string as getString} from 'core/str'; import {get_string as getString} from 'core/str';
import Prefetch from 'core/prefetch'; import Prefetch from 'core/prefetch';
import Ajax from 'core/ajax';
import Notification from 'core/notification'; import Notification from 'core/notification';
import {setUserPreference} from 'core_user/repository';
/** /**
* Set up the contentbank views. * Set up the contentbank views.
@ -168,19 +168,8 @@ const setViewListPreference = function(viewList) {
viewList = null; viewList = null;
} }
const request = { return setUserPreference('core_contentbank_view_list', viewList)
methodname: 'core_user_update_user_preferences', .catch(Notification.exception);
args: {
preferences: [
{
type: 'core_contentbank_view_list',
value: viewList
}
]
}
};
return Ajax.call([request])[0].catch(Notification.exception);
}; };
/** /**

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -28,7 +28,7 @@ define(
'core/paged_content', 'core/paged_content',
'core/paged_content_events', 'core/paged_content_events',
'core/pubsub', 'core/pubsub',
'core/ajax' 'core_user/repository'
], ],
function( function(
$, $,
@ -37,7 +37,7 @@ function(
PagedContent, PagedContent,
PagedContentEvents, PagedContentEvents,
PubSub, PubSub,
Ajax UserRepository
) { ) {
var TEMPLATES = { var TEMPLATES = {
PAGED_CONTENT: 'core/paged_content' PAGED_CONTENT: 'core/paged_content'
@ -520,25 +520,9 @@ function(
* @return {callback} * @return {callback}
*/ */
var generateLimitHandler = function(persistentLimitKey) { var generateLimitHandler = function(persistentLimitKey) {
var callback = function(limit) { return function(limit) {
var args = { UserRepository.setUserPreference(persistentLimitKey, limit);
preferences: [
{
type: persistentLimitKey,
value: limit
}
]
}; };
var request = {
methodname: 'core_user_update_user_preferences',
args: args
};
Ajax.call([request]);
};
return callback;
}; };
/** /**

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -22,8 +22,8 @@
* @since 3.1 * @since 3.1
*/ */
define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete', define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete',
'core/ajax', 'mod_assign/grading_form_change_checker'], 'core/ajax', 'core_user/repository', 'mod_assign/grading_form_change_checker'],
function($, notification, str, autocomplete, ajax, checker) { function($, notification, str, autocomplete, ajax, UserRepository, checker) {
/** /**
* GradingNavigation class. * GradingNavigation class.
@ -219,12 +219,7 @@ define(['jquery', 'core/notification', 'core/str', 'core/form-autocomplete',
}); });
} }
return ajax.call([{ return UserRepository.setUserPreferences(preferences);
methodname: 'core_user_set_user_preferences',
args: {
preferences: preferences
}
}])[0];
}; };
/** /**
* Turn a filter on or off. * Turn a filter on or off.

View file

@ -1,3 +1,3 @@
define("core_user/repository",["exports","core/ajax"],(function(_exports,_ajax){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.unenrolUser=_exports.submitUserEnrolmentForm=_exports.sendMessagesToUsers=_exports.createNotesForUsers=void 0;_exports.unenrolUser=userEnrolmentId=>(0,_ajax.call)([{methodname:"core_enrol_unenrol_user_enrolment",args:{ueid:userEnrolmentId}}])[0];_exports.submitUserEnrolmentForm=formdata=>(0,_ajax.call)([{methodname:"core_enrol_submit_user_enrolment_form",args:{formdata:formdata}}])[0];_exports.createNotesForUsers=notes=>(0,_ajax.call)([{methodname:"core_notes_create_notes",args:{notes:notes}}])[0];_exports.sendMessagesToUsers=messages=>(0,_ajax.call)([{methodname:"core_message_send_instant_messages",args:{messages:messages}}])[0]})); define("core_user/repository",["exports","core/ajax"],(function(_exports,_ajax){Object.defineProperty(_exports,"__esModule",{value:!0}),_exports.unenrolUser=_exports.submitUserEnrolmentForm=_exports.setUserPreferences=_exports.setUserPreference=_exports.sendMessagesToUsers=_exports.getUserPreferences=_exports.getUserPreference=_exports.createNotesForUsers=void 0;_exports.getUserPreference=function(name){let userid=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return getUserPreferences(name,userid).then((response=>response.preferences[0].value))};const getUserPreferences=function(){let name=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,userid=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(0,_ajax.call)([{methodname:"core_user_get_user_preferences",args:{name:name,userid:userid}}])[0]};_exports.getUserPreferences=getUserPreferences;_exports.setUserPreference=function(name){let value=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,userid=arguments.length>2&&void 0!==arguments[2]?arguments[2]:0;return setUserPreferences([{name:name,value:value,userid:userid}])};const setUserPreferences=preferences=>(0,_ajax.call)([{methodname:"core_user_set_user_preferences",args:{preferences:preferences}}])[0];_exports.setUserPreferences=setUserPreferences;_exports.unenrolUser=userEnrolmentId=>(0,_ajax.call)([{methodname:"core_enrol_unenrol_user_enrolment",args:{ueid:userEnrolmentId}}])[0];_exports.submitUserEnrolmentForm=formdata=>(0,_ajax.call)([{methodname:"core_enrol_submit_user_enrolment_form",args:{formdata:formdata}}])[0];_exports.createNotesForUsers=notes=>(0,_ajax.call)([{methodname:"core_notes_create_notes",args:{notes:notes}}])[0];_exports.sendMessagesToUsers=messages=>(0,_ajax.call)([{methodname:"core_message_send_instant_messages",args:{messages:messages}}])[0]}));
//# sourceMappingURL=repository.min.js.map //# sourceMappingURL=repository.min.js.map

View file

@ -1 +1 @@
{"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle AJAX interactions.\n *\n * @module core_user/repository\n * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\nimport {call as fetchMany} from 'core/ajax';\n\n/**\n * Unenrol the user with the specified user enrolmentid ID.\n *\n * @param {Number} userEnrolmentId\n * @return {Promise}\n */\nexport const unenrolUser = userEnrolmentId => {\n return fetchMany([{\n methodname: 'core_enrol_unenrol_user_enrolment',\n args: {\n ueid: userEnrolmentId,\n },\n }])[0];\n};\n\n/**\n * Submit the user enrolment form with the specified form data.\n *\n * @param {String} formdata\n * @return {Promise}\n */\nexport const submitUserEnrolmentForm = formdata => {\n return fetchMany([{\n methodname: 'core_enrol_submit_user_enrolment_form',\n args: {\n formdata,\n },\n }])[0];\n};\n\nexport const createNotesForUsers = notes => {\n return fetchMany([{\n methodname: 'core_notes_create_notes',\n args: {\n notes\n }\n }])[0];\n};\n\nexport const sendMessagesToUsers = messages => {\n return fetchMany([{\n methodname: 'core_message_send_instant_messages',\n args: {messages}\n }])[0];\n};\n"],"names":["userEnrolmentId","methodname","args","ueid","formdata","notes","messages"],"mappings":"oRA8B2BA,kBAChB,cAAU,CAAC,CACdC,WAAY,oCACZC,KAAM,CACFC,KAAMH,oBAEV,oCAS+BI,WAC5B,cAAU,CAAC,CACdH,WAAY,wCACZC,KAAM,CACFE,SAAAA,aAEJ,gCAG2BC,QACxB,cAAU,CAAC,CACdJ,WAAY,0BACZC,KAAM,CACFG,MAAAA,UAEJ,gCAG2BC,WACxB,cAAU,CAAC,CACdL,WAAY,qCACZC,KAAM,CAACI,SAAAA,aACP"} {"version":3,"file":"repository.min.js","sources":["../src/repository.js"],"sourcesContent":["// This file is part of Moodle - http://moodle.org/\n//\n// Moodle is free software: you can redistribute it and/or modify\n// it under the terms of the GNU General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// Moodle is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU General Public License for more details.\n//\n// You should have received a copy of the GNU General Public License\n// along with Moodle. If not, see <http://www.gnu.org/licenses/>.\n\n/**\n * Module to handle AJAX interactions.\n *\n * @module core_user/repository\n * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>\n * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later\n */\n\nimport {call as fetchMany} from 'core/ajax';\n\n/**\n * Get single user preference\n *\n * @param {String} name Name of the preference\n * @param {Number} userid User ID (defaults to current user)\n * @return {Promise}\n */\nexport const getUserPreference = (name, userid = 0) => {\n return getUserPreferences(name, userid)\n .then(response => response.preferences[0].value);\n};\n\n/**\n * Get multiple user preferences\n *\n * @param {String|null} name Name of the preference (omit if you want to retrieve all)\n * @param {Number} userid User ID (defaults to current user)\n * @return {Promise}\n */\nexport const getUserPreferences = (name = null, userid = 0) => {\n return fetchMany([{\n methodname: 'core_user_get_user_preferences',\n args: {name, userid}\n }])[0];\n};\n\n/**\n * Set single user preference\n *\n * @param {String} name Name of the preference\n * @param {String|null} value Value of the preference (omit if you want to remove the current value)\n * @param {Number} userid User ID (defaults to current user)\n * @return {Promise}\n */\nexport const setUserPreference = (name, value = null, userid = 0) => {\n return setUserPreferences([{name, value, userid}]);\n};\n\n/**\n * Set multiple user preferences\n *\n * @param {Object[]} preferences Array of preferences containing name/value/userid attributes\n * @return {Promise}\n */\nexport const setUserPreferences = (preferences) => {\n return fetchMany([{\n methodname: 'core_user_set_user_preferences',\n args: {preferences}\n }])[0];\n};\n\n/**\n * Unenrol the user with the specified user enrolmentid ID.\n *\n * @param {Number} userEnrolmentId\n * @return {Promise}\n */\nexport const unenrolUser = userEnrolmentId => {\n return fetchMany([{\n methodname: 'core_enrol_unenrol_user_enrolment',\n args: {\n ueid: userEnrolmentId,\n },\n }])[0];\n};\n\n/**\n * Submit the user enrolment form with the specified form data.\n *\n * @param {String} formdata\n * @return {Promise}\n */\nexport const submitUserEnrolmentForm = formdata => {\n return fetchMany([{\n methodname: 'core_enrol_submit_user_enrolment_form',\n args: {\n formdata,\n },\n }])[0];\n};\n\nexport const createNotesForUsers = notes => {\n return fetchMany([{\n methodname: 'core_notes_create_notes',\n args: {\n notes\n }\n }])[0];\n};\n\nexport const sendMessagesToUsers = messages => {\n return fetchMany([{\n methodname: 'core_message_send_instant_messages',\n args: {messages}\n }])[0];\n};\n"],"names":["name","userid","getUserPreferences","then","response","preferences","value","methodname","args","setUserPreferences","userEnrolmentId","ueid","formdata","notes","messages"],"mappings":"wYAgCiC,SAACA,UAAMC,8DAAS,SACtCC,mBAAmBF,KAAMC,QAC3BE,MAAKC,UAAYA,SAASC,YAAY,GAAGC,eAUrCJ,mBAAqB,eAACF,4DAAO,KAAMC,8DAAS,SAC9C,cAAU,CAAC,CACdM,WAAY,iCACZC,KAAM,CAACR,KAAAA,KAAMC,OAAAA,WACb,8EAWyB,SAACD,UAAMM,6DAAQ,KAAML,8DAAS,SACpDQ,mBAAmB,CAAC,CAACT,KAAAA,KAAMM,MAAAA,MAAOL,OAAAA,iBAShCQ,mBAAsBJ,cACxB,cAAU,CAAC,CACdE,WAAY,iCACZC,KAAM,CAACH,YAAAA,gBACP,uEASmBK,kBAChB,cAAU,CAAC,CACdH,WAAY,oCACZC,KAAM,CACFG,KAAMD,oBAEV,oCAS+BE,WAC5B,cAAU,CAAC,CACdL,WAAY,wCACZC,KAAM,CACFI,SAAAA,aAEJ,gCAG2BC,QACxB,cAAU,CAAC,CACdN,WAAY,0BACZC,KAAM,CACFK,MAAAA,UAEJ,gCAG2BC,WACxB,cAAU,CAAC,CACdP,WAAY,qCACZC,KAAM,CAACM,SAAAA,aACP"}

View file

@ -20,8 +20,60 @@
* @copyright 2020 Andrew Nicols <andrew@nicols.co.uk> * @copyright 2020 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */
import {call as fetchMany} from 'core/ajax'; import {call as fetchMany} from 'core/ajax';
/**
* Get single user preference
*
* @param {String} name Name of the preference
* @param {Number} userid User ID (defaults to current user)
* @return {Promise}
*/
export const getUserPreference = (name, userid = 0) => {
return getUserPreferences(name, userid)
.then(response => response.preferences[0].value);
};
/**
* Get multiple user preferences
*
* @param {String|null} name Name of the preference (omit if you want to retrieve all)
* @param {Number} userid User ID (defaults to current user)
* @return {Promise}
*/
export const getUserPreferences = (name = null, userid = 0) => {
return fetchMany([{
methodname: 'core_user_get_user_preferences',
args: {name, userid}
}])[0];
};
/**
* Set single user preference
*
* @param {String} name Name of the preference
* @param {String|null} value Value of the preference (omit if you want to remove the current value)
* @param {Number} userid User ID (defaults to current user)
* @return {Promise}
*/
export const setUserPreference = (name, value = null, userid = 0) => {
return setUserPreferences([{name, value, userid}]);
};
/**
* Set multiple user preferences
*
* @param {Object[]} preferences Array of preferences containing name/value/userid attributes
* @return {Promise}
*/
export const setUserPreferences = (preferences) => {
return fetchMany([{
methodname: 'core_user_set_user_preferences',
args: {preferences}
}])[0];
};
/** /**
* Unenrol the user with the specified user enrolmentid ID. * Unenrol the user with the specified user enrolmentid ID.
* *

View file

@ -1802,7 +1802,8 @@ class core_user_external extends \core_external\external_api {
array( array(
'name' => new external_value(PARAM_RAW, 'The name of the preference'), 'name' => new external_value(PARAM_RAW, 'The name of the preference'),
'value' => new external_value(PARAM_RAW, 'The value of the preference'), 'value' => new external_value(PARAM_RAW, 'The value of the preference'),
'userid' => new external_value(PARAM_INT, 'Id of the user to set the preference'), 'userid' => new external_value(PARAM_INT,
'Id of the user to set the preference (default to current user)', VALUE_DEFAULT, 0),
) )
) )
) )
@ -1830,18 +1831,20 @@ class core_user_external extends \core_external\external_api {
$userscache = array(); $userscache = array();
foreach ($params['preferences'] as $pref) { foreach ($params['preferences'] as $pref) {
$userid = $pref['userid'] ?: $USER->id;
// Check to which user set the preference. // Check to which user set the preference.
if (!empty($userscache[$pref['userid']])) { if (!empty($userscache[$userid])) {
$user = $userscache[$pref['userid']]; $user = $userscache[$userid];
} else { } else {
try { try {
$user = core_user::get_user($pref['userid'], '*', MUST_EXIST); $user = core_user::get_user($userid, '*', MUST_EXIST);
core_user::require_active_user($user); core_user::require_active_user($user);
$userscache[$pref['userid']] = $user; $userscache[$userid] = $user;
} catch (Exception $e) { } catch (Exception $e) {
$warnings[] = array( $warnings[] = array(
'item' => 'user', 'item' => 'user',
'itemid' => $pref['userid'], 'itemid' => $userid,
'warningcode' => 'invaliduser', 'warningcode' => 'invaliduser',
'message' => $e->getMessage() 'message' => $e->getMessage()
); );

View file

@ -6,7 +6,11 @@ This files describes API changes for code that uses the user API.
- `core_user::get_profile_picture` for retrieving user picture. - `core_user::get_profile_picture` for retrieving user picture.
- `core_user::get_profile_url` for retrieving profile url. - `core_user::get_profile_url` for retrieving profile url.
- `core_user::get_fullname` for retrieving user full name. - `core_user::get_fullname` for retrieving user full name.
* The `core_user/repository` Javascript module now exports new methods for manipulating user preferences:
- `[get|set]UserPreference`
- `[get|set]UserPreferences`
* The external `core_user_set_user_preferences` method will now default the `userid` property of each preference to
that of the current user, if omitted
* The following previously deprecated methods have been removed and can no longer be used: * The following previously deprecated methods have been removed and can no longer be used:
- `profile_display_fields` - `profile_display_fields`
- `profile_edit_category` - `profile_edit_category`