From 1939760cb2436192c53c7904cfb522ba31f1db74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kr=C3=B6ger?= Date: Wed, 13 Mar 2024 12:09:51 +0100 Subject: [PATCH] Add help from Servershell plugins --- .../static/js/servershell/command.js | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/serveradmin/servershell/static/js/servershell/command.js b/serveradmin/servershell/static/js/servershell/command.js index fc36aa26..ea3eabd3 100644 --- a/serveradmin/servershell/static/js/servershell/command.js +++ b/serveradmin/servershell/static/js/servershell/command.js @@ -172,6 +172,16 @@ function validate_selected(min=1, max=-1) { return true; } +// Servershell plugins can add help for their commands here. +servershell.commands_help = [ + // Example: + // { + // "command": "foo", + // "arguments": "attr_name", + // "description": "A foo that bars", + // } +] + servershell.commands = { pin: function() { let selected_ids = servershell.get_selected(); @@ -770,7 +780,23 @@ function execute_command() { } $(document).ready(function() { - $('#command_form').submit(function(event) { + + // Collect help description from Servershell plugins and add them to the + // help modal. + servershell.commands_help.forEach(function(command_help) { + let row = document.createElement("tr"); + row.id = `cmd-${command_help["command"]}`; + + for (let index of ["command", "arguments", "description"]) { + let cell = document.createElement("td"); + cell.innerText = command_help[index]; + row.appendChild(cell); + } + + $("#help_command").append(row); + }); + + $('#command_form').submit(function(event) { event.preventDefault(); // Workaround: @@ -786,5 +812,5 @@ $(document).ready(function() { if (execute_command()) { servershell.command = ''; } - }) + }); });