From 25d55d5d0025ba97c2bf2ee809a5342b0bbd7e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20D=C3=B6tsch?= Date: Fri, 5 Jul 2024 10:04:43 +0200 Subject: [PATCH] servershell: add autocompletion for "new" command --- .../static/js/servershell/autocomplete/command.js | 13 +++++++++++++ .../servershell/templates/servershell/index.html | 1 + serveradmin/servershell/views.py | 1 + 3 files changed, 15 insertions(+) diff --git a/serveradmin/servershell/static/js/servershell/autocomplete/command.js b/serveradmin/servershell/static/js/servershell/autocomplete/command.js index f30e4238..5e18e8ec 100644 --- a/serveradmin/servershell/static/js/servershell/autocomplete/command.js +++ b/serveradmin/servershell/static/js/servershell/autocomplete/command.js @@ -179,6 +179,19 @@ $(document).ready(function() { }); } } + if (command === 'new') { + let search_string = values.split(' ').shift(); + servershell.servertypes.forEach(function(servertype) { + if (search_string && !servertype.startsWith(search_string)) { + return; + } + + choices.push({ + 'label': `Servertype: ${servertype}`, + 'value': `${command} ${servertype}`, + }); + }); + } } // Don't auto complete if the user has already entered everything diff --git a/serveradmin/servershell/templates/servershell/index.html b/serveradmin/servershell/templates/servershell/index.html index 4c2c4c18..8c843e26 100644 --- a/serveradmin/servershell/templates/servershell/index.html +++ b/serveradmin/servershell/templates/servershell/index.html @@ -205,6 +205,7 @@ servershell.command = ""; servershell.understood = ""; servershell.attributes = {% autoescape off %}{{ attributes|json }}{% endautoescape %}; + servershell.servertypes = {% autoescape off %}{{ servertypes|json }}{% endautoescape %}; servershell.offset = {{ offset }}; servershell.limit = {{ limit }}; servershell.order_by = "{{ order_by }}"; diff --git a/serveradmin/servershell/views.py b/serveradmin/servershell/views.py index 9c582fa7..0a3239a6 100644 --- a/serveradmin/servershell/views.py +++ b/serveradmin/servershell/views.py @@ -102,6 +102,7 @@ def index(request): 'shown_attributes': shown_attributes, 'deep_link': bool(strtobool(request.GET.get('deep_link', 'false'))), 'attributes': attributes_json, + 'servertypes': list(Servertype.objects.values_list('servertype_id', flat=True)), 'offset': 0, 'limit': request.session.get('limit', NUM_SERVERS_DEFAULT), 'order_by': 'hostname',