Skip to content

Commit a2e7d16

Browse files
committed
Fix Hm_Debug
1 parent 9e76359 commit a2e7d16

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

lib/dispatch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ public function unpack_messages($request, $session) {
114114
if (!empty($request->cookie['hm_msgs'])) {
115115
$msgs = @json_decode(base64_decode($request->cookie['hm_msgs']), true);
116116
if (is_array($msgs)) {
117-
array_walk($msgs, function($v, $k) { Hm_Msgs::add($v, $k); });
117+
array_walk($msgs, function($v) { Hm_Msgs::add($v['text'], $v['type']); });
118118
}
119119
$session->delete_cookie($request, 'hm_msgs');
120120
return true;

lib/output.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ trait Hm_List {
7373
* @param string $string message to add
7474
* @return void
7575
*/
76-
public static function add($string, $type = 'info') {
77-
self::$msgs[$type] = self::str($string, false);
76+
public static function add($string, $type = 'success') {
77+
self::$msgs[] = ['type' => $type, 'text' => self::str($string, false)];
7878
}
7979

8080
/**
@@ -115,7 +115,10 @@ public static function str($mixed, $return_type = true) {
115115
* @return bool
116116
*/
117117
public static function show() {
118-
return Hm_Functions::error_log(print_r(self::$msgs, true));
118+
$msgs = array_map(function ($msg) {
119+
return strtoupper($msg['type']) . ': ' . $msg['text'];
120+
}, self::$msgs);
121+
return Hm_Functions::error_log(print_r($msgs, true));
119122
}
120123
}
121124

modules/core/output_modules.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ protected function output() {
360360
if (!$this->get('router_login_state') && !empty($msgs)) {
361361
$logged_out_class = ' logged_out';
362362
}
363-
$res .= '<div class="d-none position-fixed top-0 col-sm-4 col-md-3 end-0 mt-3 me-3 sys_messages'.$logged_out_class.'"></div>';
363+
$res .= '<div class="position-fixed top-0 col-sm-4 col-md-3 end-0 mt-3 me-3 sys_messages'.$logged_out_class.'"></div>';
364364
$res .= '<script type="text/javascript">var hm_msgs = '.json_encode($msgs).'</script>';
365365
return $res;
366366
}

modules/core/site.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,8 +1501,9 @@ var Hm_Utils = {
15011501
* Shows pending messages added with the add_sys_message method
15021502
*/
15031503
show_sys_messages: function() {
1504-
hm_msg.forEach((v, k) => {
1505-
alert.createAlert(v, k);
1504+
const hm_alert = new Hm_Alert();
1505+
hm_msgs.forEach((msg) => {
1506+
hm_alert.createAlert(msg.text, msg.type);
15061507
});
15071508
},
15081509

@@ -1515,9 +1516,8 @@ var Hm_Utils = {
15151516
if (!msg) {
15161517
return;
15171518
}
1518-
const icon = type == 'success' ? 'bi-check-circle' : 'bi-exclamation-circle';
1519-
$('.sys_messages').append('<div class="alert alert-'+type+' alert-dismissible fade show" role="alert"><i class="bi '+icon+' me-2"></i><span class="' + type + '">'+msg+'</span><button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>');
1520-
this.show_sys_messages();
1519+
const hm_alert = new Hm_Alert();
1520+
hm_alert.createAlert(msg, type);
15211521
},
15221522

15231523
clear_sys_messages: function () {
@@ -1838,9 +1838,6 @@ $(function() {
18381838
/* fire up the job scheduler */
18391839
Hm_Timer.fire();
18401840

1841-
/* Use this to create alerts */
1842-
var alert = new Hm_Alert();
1843-
18441841
/* show any pending notices */
18451842
Hm_Utils.show_sys_messages();
18461843

@@ -2425,8 +2422,9 @@ class Hm_Alert {
24252422
* @param {string} message - The message to display.
24262423
* @param {string} type - The type of alert (primary, secondary, success, danger, warning, info).
24272424
* @param {boolean} dismissible - Whether the alert can be dismissed.
2425+
* @param {integer} dismissTime - Number of seconds before alert auto-closes
24282426
*/
2429-
createAlert(message, type = 'primary', dismissible = true) {
2427+
createAlert(message, type = 'primary', dismissible = true, dismissTime = 10) {
24302428
if (!this.container) {
24312429
return;
24322430
}
@@ -2442,7 +2440,7 @@ class Hm_Alert {
24422440
iconContainer.appendChild(icon);
24432441

24442442
const messageElement = document.createElement('div');
2445-
messageElement.className = 'flex-grow-1 pe-2';
2443+
messageElement.className = 'flex-grow-1 pe-4';
24462444
messageElement.textContent = message;
24472445

24482446
alert.appendChild(iconContainer);
@@ -2460,15 +2458,16 @@ class Hm_Alert {
24602458

24612459
this.container.appendChild(alert);
24622460

2463-
// Auto close after 10 seconds with animation
2461+
dismissTime *= 1000;
2462+
// Auto close with animation
24642463
setTimeout(() => {
24652464
alert.style.opacity = '0';
24662465
alert.style.transform = 'translateY(-20px)';
24672466
setTimeout(() => {
24682467
const bsAlert = new bootstrap.Alert(alert);
24692468
bsAlert.close();
24702469
}, 500);
2471-
}, 10000);
2470+
}, dismissTime);
24722471
}
24732472

24742473
toggleVisibility() {

0 commit comments

Comments
 (0)