From a27af206dadeeae77198a95ec9ea3ad8844f7d8b Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch> Date: Tue, 12 Dec 2023 16:07:52 +0100 Subject: [PATCH] simplify init of shellcmd plugin --- public_html/deployment/js/functions.js | 26 +++++++++++++++++++ .../plugins/shellcmd/load/render.js | 14 +--------- .../plugins/shellcmd/processes/render.js | 15 +---------- .../deployment/plugins/shellcmd/top/render.js | 14 +--------- 4 files changed, 29 insertions(+), 40 deletions(-) diff --git a/public_html/deployment/js/functions.js b/public_html/deployment/js/functions.js index f17fd271..e6161ebb 100644 --- a/public_html/deployment/js/functions.js +++ b/public_html/deployment/js/functions.js @@ -452,6 +452,11 @@ function filterTable() { // ---------------------------------------------------------------------- // API secret // ---------------------------------------------------------------------- +/** + * for project settings - generate api key + * @param {integer} length length of the key to generate + * @return {string} + */ function generateSecret(length) { var result = ''; @@ -464,3 +469,24 @@ function generateSecret(length) { } // ---------------------------------------------------------------------- + +/** + * initialize a shellcmd plugin + * @param {string} sPlugin name of the shellcmd plugin + * @param {function} oRenderer rendering function for incoming data + * @param {integer} iTtl ttl in minutes + */ +function shellcmd_plugin_init(sPlugin, oRenderer, iTtl){ + var sDomid="divPluginshellcmd"+sPlugin; + var sUrl="/deployment/plugins/shellcmd/getdata.php?plugin="+sPlugin; + var oUbd=new ubd( + { + "domid": sDomid, + "url": sUrl, + "renderer": oRenderer, + "ttl": iTtl, + } + ); + // oUbdLoad.render('waiting for first data...'); + oUbd.update(); +} diff --git a/public_html/deployment/plugins/shellcmd/load/render.js b/public_html/deployment/plugins/shellcmd/load/render.js index 4bb3ddd4..0adc72ac 100644 --- a/public_html/deployment/plugins/shellcmd/load/render.js +++ b/public_html/deployment/plugins/shellcmd/load/render.js @@ -26,17 +26,5 @@ function load_render(aData){ ; } -function load_init(){ - oUbdLoad=new ubd( - { - "domid": "divPluginshellcmdload", - "url": "/deployment/plugins/shellcmd/getdata.php?plugin=load", - "renderer": load_render, - "ttl": 2, - } - ); - // oUbdLoad.render('waiting for first data...'); - oUbdLoad.update(); -} -window.setTimeout("load_init()", 200); \ No newline at end of file +window.setTimeout("shellcmd_plugin_init('load', "+load_render+", 2);", 200); \ No newline at end of file diff --git a/public_html/deployment/plugins/shellcmd/processes/render.js b/public_html/deployment/plugins/shellcmd/processes/render.js index ae6d2d96..16ee7ab9 100644 --- a/public_html/deployment/plugins/shellcmd/processes/render.js +++ b/public_html/deployment/plugins/shellcmd/processes/render.js @@ -26,17 +26,4 @@ function processes_render(aData){ return sReturn; } -function processes_init(){ - oUbdProcesses=new ubd( - { - "domid": "divPluginshellcmdprocesses", - "url": "/deployment/plugins/shellcmd/getdata.php?plugin=processes", - "renderer": processes_render, - "ttl": 2, - } - ); - // oUbdLoad.render('waiting for first data...'); - oUbdProcesses.update(); -} - -window.setTimeout("processes_init()", 200); \ No newline at end of file +window.setTimeout("shellcmd_plugin_init('processes', "+processes_render+", 2);", 200); \ No newline at end of file diff --git a/public_html/deployment/plugins/shellcmd/top/render.js b/public_html/deployment/plugins/shellcmd/top/render.js index 9b014784..2085df5a 100644 --- a/public_html/deployment/plugins/shellcmd/top/render.js +++ b/public_html/deployment/plugins/shellcmd/top/render.js @@ -26,17 +26,5 @@ function top_render(aData){ return sReturn; } -function top_init(){ - oUbdLoad=new ubd( - { - "domid": "divPluginshellcmdtop", - "url": "/deployment/plugins/shellcmd/getdata.php?plugin=top", - "renderer": top_render, - "ttl": 5, - } - ); - // oUbdLoad.render('waiting for first data...'); - oUbdLoad.update(); -} -window.setTimeout("top_init()", 200); \ No newline at end of file +window.setTimeout("shellcmd_plugin_init('top', "+top_render+", 2);", 200); -- GitLab