mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 05:58:34 +01:00
MDL-62678 core: Improve efficiency of notifications and avoid ajax call
This commit is contained in:
parent
e049d30613
commit
f3844e595e
2
lib/amd/build/notification.min.js
vendored
2
lib/amd/build/notification.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -292,9 +292,8 @@ export const exception = async ex => {
|
||||
*
|
||||
* @param {Number} contextId
|
||||
* @param {Array} notificationList
|
||||
* @param {Boolean} userLoggedIn
|
||||
*/
|
||||
export const init = (contextId, notificationList, userLoggedIn) => {
|
||||
export const init = (contextId, notificationList) => {
|
||||
currentContextId = contextId;
|
||||
|
||||
// Setup the message target region if it isn't setup already
|
||||
@ -303,11 +302,6 @@ export const init = (contextId, notificationList, userLoggedIn) => {
|
||||
// Add provided notifications.
|
||||
addNotifications(notificationList);
|
||||
|
||||
// If the user is not logged in then we can not fetch anything for them.
|
||||
if (userLoggedIn) {
|
||||
// Perform an initial poll for any new notifications.
|
||||
fetchNotifications();
|
||||
}
|
||||
};
|
||||
|
||||
// To maintain backwards compatability we export default here.
|
||||
|
@ -58,7 +58,8 @@ class notification {
|
||||
public static function add($message, $level = null) {
|
||||
global $PAGE, $SESSION;
|
||||
|
||||
if ($PAGE && $PAGE->state === \moodle_page::STATE_IN_BODY) {
|
||||
if ($PAGE && ($PAGE->state === \moodle_page::STATE_IN_BODY
|
||||
|| $PAGE->state === \moodle_page::STATE_DONE)) {
|
||||
// Currently in the page body - just render and exit immediately.
|
||||
// We insert some code to immediately insert this into the user-notifications created by the header.
|
||||
$id = uniqid();
|
||||
|
@ -1425,8 +1425,7 @@ class core_renderer extends renderer_base {
|
||||
if (!empty($this->page->context->id)) {
|
||||
$this->page->requires->js_call_amd('core/notification', 'init', array(
|
||||
$this->page->context->id,
|
||||
\core\notification::fetch_as_array($this),
|
||||
isloggedin()
|
||||
\core\notification::fetch_as_array($this)
|
||||
));
|
||||
}
|
||||
$footer = str_replace($this->unique_end_html_token, $this->page->requires->get_end_code(), $footer);
|
||||
|
@ -86,7 +86,16 @@ class core_notification_testcase extends advanced_testcase {
|
||||
|
||||
$PAGE->set_state(\moodle_page::STATE_DONE);
|
||||
\core\notification::add('Example after page', \core\notification::INFO);
|
||||
$this->assertCount(3, $SESSION->notifications);
|
||||
$this->assertCount(2, $SESSION->notifications);
|
||||
$this->expectOutputRegex('/Example after page/');
|
||||
|
||||
\core\session\manager::write_close();
|
||||
\core\notification::add('Example after write_close', \core\notification::INFO);
|
||||
$this->assertCount(2, $SESSION->notifications);
|
||||
$this->expectOutputRegex('/Example after write_close/');
|
||||
|
||||
// Simulate shutdown handler which calls fetch.
|
||||
$this->assertCount(2, \core\notification::fetch());
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user