Skip to content

Commit

Permalink
Add help from Servershell plugins defined in JavaScript
Browse files Browse the repository at this point in the history
  • Loading branch information
kofrezo committed Mar 13, 2024
1 parent 92a9e2f commit a2fe290
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
32 changes: 30 additions & 2 deletions serveradmin/servershell/static/js/servershell/command.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,18 @@ function validate_selected(min=1, max=-1) {
return true;
}

// Serveradmin Servershell plugins can provide help for custom commands by
// extending the servershell.commands_help array like in the example below in
// their static/js/$app.servershell.plugin.js
servershell.commands_help = [
// Example:
// {
// "command": "foo",
// "arguments": "attr_name",
// "description": "A foo that bars",
// }
]

servershell.commands = {
pin: function() {
let selected_ids = servershell.get_selected();
Expand Down Expand Up @@ -770,7 +782,23 @@ function execute_command() {
}

$(document).ready(function() {
$('#command_form').submit(function(event) {

// Gather description for custom commands 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:
Expand All @@ -786,5 +814,5 @@ $(document).ready(function() {
if (execute_command()) {
servershell.command = '';
}
})
});
});
4 changes: 2 additions & 2 deletions serveradmin/servershell/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ def servershell_plugins():
"""Find $app.servershell.plugin.js files from Serveradmin apps
Scans all apps beginning with serveradmin_ for files that follow the pattern
$app.servershell.plugin.js and return them. This allows apps to add
commands to the Servershell.
$app.servershell.plugin.js and return them. This allows Serveradmin apps to
extend the Servershell for example with custom commands.
@return:
"""
Expand Down

0 comments on commit a2fe290

Please sign in to comment.