This commit is contained in:
Jun Pataleta 2024-08-27 10:00:31 +08:00
commit 76cacbd856
No known key found for this signature in database
GPG Key ID: F83510526D99E2C7
14 changed files with 117 additions and 7 deletions

View File

@ -0,0 +1,8 @@
issueNumber: MDL-82297
notes:
core:
- message: >
Add optional icon and title to notification. Two parameters have been added to the `core\output\notification` so when creating a notification you can pass
an icon and a title.
type: improved

View File

@ -295,6 +295,7 @@ class core_admin_renderer extends plugin_renderer_base {
$output .= $this->header();
$output .= $this->output->heading(get_string('notifications', 'admin'));
$output .= $this->upgrade_news_message();
$output .= $this->maturity_info($maturity);
$output .= empty($CFG->disableupdatenotifications) ? $this->available_updates($availableupdates, $availableupdatesfetch) : '';
$output .= $this->insecure_dataroot_warning($insecuredataroot);
@ -754,6 +755,22 @@ class core_admin_renderer extends plugin_renderer_base {
return $this->box($copyrighttext, 'copyright');
}
/**
* Display a transient notification for important upgrades messages for
* specific releases.
*
* @return string HTML to output.
*/
protected function upgrade_news_message() {
return $this->notification(
get_string('importantupdates_content', 'admin'),
'info',
false,
get_string('importantupdates_title', 'admin'),
'i/circleinfo, core'
);
}
/**
* Display a warning about installing development code if necesary.
* @param int $maturity

File diff suppressed because one or more lines are too long

View File

@ -762,6 +762,11 @@ $string['taskh5pcleanup'] = 'Unused H5P files cleanup';
$string['iconvrequired'] = 'Installing ICONV extension is required.';
$string['igbinary322buggyversion'] = 'The php-igbinary extension installed on the site can lead to problems when running with PHP 7.2. You are recommended to either upgrade to php-igbinary 3.2.5 or later, or alternatively to upgrade to PHP 7.3 or later.';
$string['ignore'] = 'Ignore';
$string['importantupdates_content'] = '<p>In the next Moodle 5.0, planned for release in April 2025, the Chat and Survey activities will
be removed from core Moodle. They will be available as plugins in the
<a href="https://moodle.org/plugins/">Moodle plugins directory</a>.</p>
<p>If you wish to continue using Chat or Survey in your site, you will be able to install them as plugins before upgrading to Moodle 5.0.</p>';
$string['importantupdates_title'] = 'Important update about Chat and Survey activities';
$string['includemoduleuserdata'] = 'Include module user data';
$string['incompatibleblocks'] = 'Incompatible blocks';
$string['indexdata'] = 'Index data';

View File

@ -2635,9 +2635,12 @@ EOD;
* @param string $message The message to print out.
* @param ?string $type The type of notification. See constants on notification.
* @param bool $closebutton Whether to show a close icon to remove the notification (default true).
* @param ?string $title The title of the notification.
* @param ?string $titleicon if the title should have an icon you can give the icon name with the component
* (e.g. 'i/circleinfo, core' or 'i/circleinfo' if the icon is from core)
* @return string the HTML to output.
*/
public function notification($message, $type = null, $closebutton = true) {
public function notification($message, $type = null, $closebutton = true, ?string $title = null, ?string $titleicon = null) {
$typemappings = [
// Valid types.
'success' => notification::NOTIFY_SUCCESS,
@ -2681,7 +2684,7 @@ EOD;
}
}
$notification = new notification($message, $type, $closebutton);
$notification = new notification($message, $type, $closebutton, $title, $titleicon);
if (count($extraclasses)) {
$notification->set_extra_classes($extraclasses);
}

View File

@ -79,8 +79,11 @@ class core_renderer_ajax extends core_renderer {
* @param string $message The message to print out.
* @param string $type The type of notification. See constants on \core\output\notification.
* @param bool $closebutton Whether to show a close icon to remove the notification (default true).
* @param string|null $title The title of the notification.
* @param ?string $titleicon if the title should have an icon you can give the icon name with the component
* (e.g. 'i/circleinfo, core' or 'i/circleinfo' if the icon is from core)
*/
public function notification($message, $type = null, $closebutton = true) {
public function notification($message, $type = null, $closebutton = true, ?string $title = null, ?string $titleicon = null) {
}
/**

View File

@ -227,9 +227,12 @@ class core_renderer_cli extends core_renderer {
* @param string $message The message to print out.
* @param string $type The type of notification. See constants on \core\output\notification.
* @param bool $closebutton Whether to show a close icon to remove the notification (default true).
* @param string|null $title The title of the notification.
* @param ?string $titleicon if the title should have an icon you can give the icon name with the component
* (e.g. 'i/circleinfo, core' or 'i/circleinfo' if the icon is from core)
* @return string A template fragment for a notification
*/
public function notification($message, $type = null, $closebutton = true) {
public function notification($message, $type = null, $closebutton = true, ?string $title = null, ?string $titleicon = null) {
$message = clean_text($message);
if ($type === 'notifysuccess' || $type === 'success') {
return "++ $message ++\n";

View File

@ -209,6 +209,7 @@ class icon_system_fontawesome extends icon_system_font {
'core:i/checked' => 'fa-check',
'core:i/checkedcircle' => 'fa-circle-check',
'core:i/checkpermissions' => 'fa-user-lock',
'core:i/circleinfo' => 'fa-circle-info',
'core:i/cloudupload' => 'fa-cloud-upload',
'core:i/cohort' => 'fa-users-line',
'core:i/competencies' => 'fa-list-check',

View File

@ -59,6 +59,16 @@ class notification implements renderable, templatable {
*/
protected $message = '';
/**
* @var string Title payload.
*/
protected ?string $title = null;
/**
* @var string Title icon name.
*/
protected ?string $titleicon = null;
/**
* @var string Message type.
*/
@ -85,8 +95,17 @@ class notification implements renderable, templatable {
* @param string $message the message to print out
* @param ?string $messagetype one of the NOTIFY_* constants..
* @param bool $closebutton Whether to show a close icon to remove the notification (default true).
* @param ?string $title the title of the notification
* @param ?string $titleicon if the title should have an icon you can give the icon name with the component
* (e.g. 'i/circleinfo, core' or 'i/circleinfo' if the icon is from core
*/
public function __construct($message, $messagetype = null, $closebutton = true) {
public function __construct(
$message,
$messagetype = null,
$closebutton = true,
?string $title = null,
?string $titleicon = null
) {
$this->message = $message;
if (empty($messagetype)) {
@ -96,6 +115,10 @@ class notification implements renderable, templatable {
$this->messagetype = $messagetype;
$this->closebutton = $closebutton;
$this->title = $title;
$this->titleicon = $titleicon;
}
/**
@ -159,6 +182,18 @@ class notification implements renderable, templatable {
* @return array data context for a mustache template
*/
public function export_for_template(\renderer_base $output) {
$titleicon = null;
if (!empty($this->titleicon)) {
$icon = $this->titleicon;
$component = 'core';
if (strpos($icon, ',') !== false) {
list($icon, $component) = explode(',', $icon);
}
$titleicon = (object) [
'icon' => $icon,
'component' => $component,
];
}
return [
'message' => clean_text($this->message),
'extraclasses' => implode(' ', $this->extraclasses),
@ -168,6 +203,8 @@ class notification implements renderable, templatable {
'isinfo' => $this->messagetype === 'info',
'iswarning' => $this->messagetype === 'warning',
'iserror' => $this->messagetype === 'error',
'title' => $this->title,
'titleicon' => $titleicon,
];
}

View File

@ -38,11 +38,28 @@
"message": "<p>Hello <a href=\"#\">World!</a></p><p>Your pants are on fire!</p>",
"closebutton": 1,
"announce": 1,
"extraclasses": "foo bar"
"extraclasses": "foo bar",
"title": "Notification title",
"titleicon": {
"icon": "i/circleinfo",
"component": "core"
}
}
}}
<div class="alert {{$alertclass}}alert-secondary{{/alertclass}} alert-block fade in {{ extraclasses }} {{#closebutton}}alert-dismissible{{/closebutton}}" {{!
}}{{# announce }} role="alert" data-aria-autofocus="true"{{/ announce }}>
{{#title}}
<div class="mb-2 mt-1 d-flex alert-heading">
{{#titleicon}}
<span>
{{#pix}}{{icon}}, {{component}}{{/pix}}
</span>
{{/titleicon}}
<h3 class="h6 mb-0">
<span class="align-middle">{{.}}</span>
</h3>
</div>
{{/title}}
{{{ message }}}
{{# closebutton }}{{!
}}<button type="button" class="btn-close" data-dismiss="alert">

1
pix/i/circleinfo.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><!--!Font Awesome Free 6.6.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M256 512A256 256 0 1 0 256 0a256 256 0 1 0 0 512zM216 336l24 0 0-64-24 0c-13.3 0-24-10.7-24-24s10.7-24 24-24l48 0c13.3 0 24 10.7 24 24l0 88 8 0c13.3 0 24 10.7 24 24s-10.7 24-24 24l-80 0c-13.3 0-24-10.7-24-24s10.7-24 24-24zm40-208a32 32 0 1 1 0 64 32 32 0 1 1 0-64z"/></svg>

After

Width:  |  Height:  |  Size: 495 B

View File

@ -427,6 +427,11 @@
text-align: center;
}
#page-admin-index #page-content a {
font-weight: normal;
text-decoration: underline;
}
// Plugins overview page at admin/plugins.php
#page-admin-plugins {
#plugins-overview-panel {

View File

@ -26839,6 +26839,11 @@ img.icon {
text-align: center;
}
#page-admin-index #page-content a {
font-weight: normal;
text-decoration: underline;
}
#page-admin-plugins #plugins-overview-panel .info {
display: inline-block;
margin-right: 1em;

View File

@ -26839,6 +26839,11 @@ img.icon {
text-align: center;
}
#page-admin-index #page-content a {
font-weight: normal;
text-decoration: underline;
}
#page-admin-plugins #plugins-overview-panel .info {
display: inline-block;
margin-right: 1em;