From b99a762a5011c0efccd8d2a3b03ce2afa7489f46 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Sun, 3 Oct 2021 17:50:34 +0300 Subject: index.html: safer DOM generation using jQuery I learned how to do it, currently evaluating if it's actually safer and maintanable. --- index.html | 62 +++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 33 insertions(+), 29 deletions(-) diff --git a/index.html b/index.html index 0c2911a..7c8c542 100644 --- a/index.html +++ b/index.html @@ -111,39 +111,43 @@ function set_system(data) { var users = []; +function create_user_block(name, lbl, cmd) { + let pre_id = `${lbl}_user_${name}`; + let collapse_id = `collapse_${pre_id}`; + let button_params = { + 'class': 'btn btn-outline-primary btn-sm button-expand', + 'data-toggle': 'collapse', + 'data-target': '#' + collapse_id + }; + let a_params = { + href: '#' + collapse_id, + 'data-toggle': 'collapse' + }; + return $('
') + .append($('

') + .append($('systemctl --user list-units --failed

-
-

-    
-
-

systemctl --user status

-
-

-    
-
-

systemctl --user list-timers --all

-
-

-    
-
-

journalctl --user -b --lines=20

-
-

-    
-
-
- -`; - $('#users').append(text); + let container = $('
', {'class': 'row', id: 'user_' + name}) + .append($('
', {'class': 'col'}) + .append($('

').text(name)) + .append($('
')) + .append(create_user_block(name, 'failed', 'systemctl --user list-units --failed')) + .append(create_user_block(name, 'overview', 'systemctl --user status')) + .append(create_user_block(name, 'timers', 'systemctl --user list-timers --all')) + .append(create_user_block(name, 'journal', 'journalctl --user -b --lines=20'))); + + $('#users').append(container); + $('#collapse_failed_user_' + name).addClass('show'); users.push(name); } -- cgit v1.2.3